In [ ]:
# get the latest version from pypi 
# for other installations approaches, see https://dynamo-release.readthedocs.io/en/latest/ten_minutes_to_dynamo.html#how-to-install
!pip install dynamo-release --upgrade --quiet

Let us show that velocity estimation based on slam-seq data gives more consistent and clean results. Note that this is irrespective of the velocity tools you will use. Original scSLAM-seq authors show that velocyto gives better results when using slam-seq data. Here I am using the same result with the recently improved scvelo package. Please come back to see the result with dynamo!

In [1]:
import pandas as pd 
import numpy as np 

import dynamo as dyn
dyn.get_all_dependencies_version()
package dynamo-release tqdm anndata cvxopt hdbscan loompy matplotlib numba numpy pandas pynndescent python-igraph scikit-learn scipy seaborn setuptools statsmodels trimap umap-learn numdifftools colorcet
version 0.95.0 4.48.0 0.7.4 1.2.3 0.8.26 3.0.6 3.3.0 0.48.0 1.19.1 1.1.0 0.4.8 0.8.2 0.23.1 1.5.2 0.9.0 49.3.1 0.11.1 1.0.12 0.4.3 0.9.39 2.0.2
In [2]:
# emulate ggplot2 plotting styple with white background

dyn.configuration.set_figure_params('dynamo', background='white')  

data from Hendriks et al. 2018

Let us first run velocity estimation based on splicing data

use wget to download the raw_data_loom_combined file and then load the loom data

wget https://www.dropbox.com/s/a9ozcynpxudqdis/raw_data_loom_combined.loom?dl=1

here I just use data I have in my local directory

In [3]:
adata_MCMV = dyn.read_loom('/Users/xqiu/Dropbox (Personal)/dynamo/notebook_data/raw_data_loom_combined.loom')
Variable names are not unique. To make them unique, call `.var_names_make_unique`.
In [4]:
# add a treatment label to the adata_MCMV object
import re
batch = list()

for cell in adata_MCMV.obs.index.values:
    regex = re.compile('3LF70')
    result = regex.search(cell)
    if result is not None:
        label = 'mock'
    else:
        label = 'mcmv'
    batch.append(label)

# add it to the adata_MCMV object
adata_MCMV.obs['virus'] = np.array(batch)
In [5]:
adata_MCMV
Out[5]:
AnnData object with n_obs × n_vars = 1146 × 56007
    obs: 'virus'
    var: 'Accession', 'Chromosome', 'End', 'Start', 'Strand'
    layers: 'matrix', 'ambiguous', 'spliced', 'unspliced'
In [6]:
dyn.pp.recipe_monocle(adata_MCMV, n_top_genes=1000)
dyn.tl.dynamics(adata_MCMV, model='stochastic') 
# or dyn.tl.dynamics(adata, model='stochastic')
# or dyn.tl.dynamics(adata, model='stochastic', est_method='negbin')

dyn.tl.reduceDimension(adata_MCMV)

dyn.pl.umap(adata_MCMV, color='virus')
/Users/xqiu/anaconda3/lib/python3.6/site-packages/anndata/_core/anndata.py:1094: FutureWarning: is_categorical is deprecated and will be removed in a future version.  Use is_categorical_dtype instead
  if not is_categorical(df_full[k]):
/Users/xqiu/anaconda3/lib/python3.6/site-packages/dynamo_release-0.95.0-py3.6.egg/dynamo/preprocessing/preprocess.py:1441: UserWarning: Dynamo is not able to perform cell cycle staging for you automatically. 
Since dyn.pl.phase_diagram in dynamo by default color cells by its cell-cycle stage, 
you need to set color argument accordingly if confronting errors related to this.
  warnings.warn('Dynamo is not able to perform cell cycle staging for you automatically. \n'
/Users/xqiu/anaconda3/lib/python3.6/site-packages/anndata/_core/anndata.py:1094: FutureWarning: is_categorical is deprecated and will be removed in a future version.  Use is_categorical_dtype instead
  if not is_categorical(df_full[k]):
estimating gamma: 100%|██████████| 1000/1000 [00:09<00:00, 110.43it/s]
<Figure size 600x400 with 0 Axes>
In [7]:
dyn.tl.cell_velocities(adata_MCMV)
# dyn.pl.phase_portraits(adata_MCMV, genes=['RERE', 'ENO1', 'DHRS3'], ncols=3, figsize=(3, 3))
dyn.pl.cell_wise_vectors(adata_MCMV, color=['virus'], basis='umap', quiver_scale=2, show_legend='on data') # ['GRIA3', 'LINC00982', 'AFF2']
/Users/xqiu/anaconda3/lib/python3.6/site-packages/anndata/_core/anndata.py:1094: FutureWarning: is_categorical is deprecated and will be removed in a future version.  Use is_categorical_dtype instead
  if not is_categorical(df_full[k]):
calculating transition matrix via pearson kernel with sqrt transform.: 100%|██████████| 1146/1146 [00:02<00:00, 462.35it/s]
projecting velocity vector to low dimensional embedding...: 100%|██████████| 1146/1146 [00:00<00:00, 4117.77it/s]
<Figure size 600x400 with 0 Axes>
In [8]:
dyn.pl.grid_vectors(adata_MCMV, color=['virus'], basis='umap', xy_grid_nums=(60,60)) # ['GRIA3', 'LINC00982', 'AFF2']
<Figure size 600x400 with 0 Axes>
In [9]:
dyn.pl.streamline_plot(adata_MCMV, color=['virus'], basis='umap', method='gaussian', density=2) # ['GRIA3', 'LINC00982', 'AFF2']
<Figure size 600x400 with 0 Axes>