In [1]:
# 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
In [2]:
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:90% !important; }</style>"))
%matplotlib inline

import dynamo as dyn
dyn.get_all_dependencies_version()
/usr/local/lib/python3.6/dist-packages/dask/config.py:161: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  data = yaml.load(f.read()) or {}
package colorcet loompy tqdm dynamo-release pynndescent cvxopt trimap numdifftools umap-learn hdbscan anndata matplotlib numba pandas python-igraph scikit-learn scipy seaborn statsmodels numpy setuptools
version 2.0.2 3.0.6 4.42.1 0.95.2 0.5.0 1.2.5 1.4.3.dev1 0.9.39 0.4.6 0.8.26 0.7.5 3.3.2 0.51.2 1.1.4 0.8.3 0.23.2 1.5.2 0.11.0 0.11.1 1.16.0 50.3.0
In [3]:
# emulate ggplot2 plotting styple with white background

dyn.configuration.set_figure_params('dynamo', background='white')  
In [4]:
adata = dyn.sample_data.chromaffin()
/home/xqiu/.local/lib/python3.6/site-packages/numba/np/ufunc/parallel.py:363: NumbaWarning: The TBB threading layer requires TBB version 2019.5 or later i.e., TBB_INTERFACE_VERSION >= 11005. Found TBB_INTERFACE_VERSION = 9107. The TBB threading layer is disabled.
  warnings.warn(problem)
In [5]:
dyn.pl.show_fraction(adata)
dyn.pl.basic_stats(adata)
In [6]:
dyn.pp.recipe_monocle(adata, n_top_genes=1000)
/home/xqiu/.local/lib/python3.6/site-packages/dynamo_release-0.95.2-py3.6.egg/dynamo/preprocessing/utils.py:439: UserWarning: `total_szfactor` is not `None` and it is not in adata object.
  warnings.warn("`total_szfactor` is not `None` and it is not in adata object.")
/home/xqiu/.local/lib/python3.6/site-packages/dynamo_release-0.95.2-py3.6.egg/dynamo/preprocessing/cell_cycle.py:70: RuntimeWarning: invalid value encountered in greater_equal
  return gene_list[corrs >= threshold]
Out[6]:
AnnData object with n_obs × n_vars = 384 × 23420
    obs: 'nGenes', 'nCounts', 'pMito', 'use_for_pca', 'spliced_Size_Factor', 'initial_spliced_cell_size', 'Size_Factor', 'initial_cell_size', 'unspliced_Size_Factor', 'initial_unspliced_cell_size', 'ntr', 'cell_cycle_phase'
    var: 'Accession', 'Chromosome', 'End', 'Start', 'Strand', 'nCells', 'nCounts', 'pass_basic_filter', 'log_cv', 'log_m', 'score', 'use_for_pca', 'ntr'
    uns: 'pp', 'velocyto_SVR', 'PCs', 'explained_variance_ratio_', 'pca_fit', 'feature_selection'
    obsm: 'X_pca', 'X', 'cell_cycle_scores'
    layers: 'matrix', 'ambiguous', 'spanning', 'spliced', 'unspliced', 'X_spliced', 'X_unspliced'
In [7]:
dyn.pl.variance_explained(adata)
dyn.pl.feature_genes(adata)
In [8]:
dyn.tl.dynamics(adata, model='stochastic') 
# or dyn.tl.dynamics(adata, model='deterministic')
# or dyn.tl.dynamics(adata, model='stochastic', est_method='negbin')
estimating gamma: 100%|██████████| 1000/1000 [00:05<00:00, 175.50it/s]
Out[8]:
AnnData object with n_obs × n_vars = 384 × 23420
    obs: 'nGenes', 'nCounts', 'pMito', 'use_for_pca', 'spliced_Size_Factor', 'initial_spliced_cell_size', 'Size_Factor', 'initial_cell_size', 'unspliced_Size_Factor', 'initial_unspliced_cell_size', 'ntr', 'cell_cycle_phase'
    var: 'Accession', 'Chromosome', 'End', 'Start', 'Strand', 'nCells', 'nCounts', 'pass_basic_filter', 'log_cv', 'log_m', 'score', 'use_for_pca', 'ntr', 'beta', 'gamma', 'half_life', 'alpha_b', 'alpha_r2', 'gamma_b', 'gamma_r2', 'gamma_logLL', 'delta_b', 'delta_r2', 'uu0', 'ul0', 'su0', 'sl0', 'U0', 'S0', 'total0', 'use_for_dynamics'
    uns: 'pp', 'velocyto_SVR', 'PCs', 'explained_variance_ratio_', 'pca_fit', 'feature_selection', 'dynamics'
    obsm: 'X_pca', 'X', 'cell_cycle_scores'
    layers: 'matrix', 'ambiguous', 'spanning', 'spliced', 'unspliced', 'X_spliced', 'X_unspliced', 'M_u', 'M_uu', 'M_s', 'M_us', 'M_ss', 'velocity_S'
    obsp: 'moments_con'
In [9]:
dyn.tl.reduceDimension(adata)
Out[9]:
AnnData object with n_obs × n_vars = 384 × 23420
    obs: 'nGenes', 'nCounts', 'pMito', 'use_for_pca', 'spliced_Size_Factor', 'initial_spliced_cell_size', 'Size_Factor', 'initial_cell_size', 'unspliced_Size_Factor', 'initial_unspliced_cell_size', 'ntr', 'cell_cycle_phase'
    var: 'Accession', 'Chromosome', 'End', 'Start', 'Strand', 'nCells', 'nCounts', 'pass_basic_filter', 'log_cv', 'log_m', 'score', 'use_for_pca', 'ntr', 'beta', 'gamma', 'half_life', 'alpha_b', 'alpha_r2', 'gamma_b', 'gamma_r2', 'gamma_logLL', 'delta_b', 'delta_r2', 'uu0', 'ul0', 'su0', 'sl0', 'U0', 'S0', 'total0', 'use_for_dynamics'
    uns: 'pp', 'velocyto_SVR', 'PCs', 'explained_variance_ratio_', 'pca_fit', 'feature_selection', 'dynamics', 'neighbors', 'umap_fit'
    obsm: 'X_pca', 'X', 'cell_cycle_scores', 'X_umap'
    layers: 'matrix', 'ambiguous', 'spanning', 'spliced', 'unspliced', 'X_spliced', 'X_unspliced', 'M_u', 'M_uu', 'M_s', 'M_us', 'M_ss', 'velocity_S'
    obsp: 'moments_con', 'connectivities', 'distances'
In [10]:
dyn.tl.cell_velocities(adata)
calculating transition matrix via pearson kernel with sqrt transform.: 100%|██████████| 384/384 [00:00<00:00, 522.92it/s]
projecting velocity vector to low dimensional embedding...: 100%|██████████| 384/384 [00:00<00:00, 2837.02it/s]
Out[10]:
AnnData object with n_obs × n_vars = 384 × 23420
    obs: 'nGenes', 'nCounts', 'pMito', 'use_for_pca', 'spliced_Size_Factor', 'initial_spliced_cell_size', 'Size_Factor', 'initial_cell_size', 'unspliced_Size_Factor', 'initial_unspliced_cell_size', 'ntr', 'cell_cycle_phase'
    var: 'Accession', 'Chromosome', 'End', 'Start', 'Strand', 'nCells', 'nCounts', 'pass_basic_filter', 'log_cv', 'log_m', 'score', 'use_for_pca', 'ntr', 'beta', 'gamma', 'half_life', 'alpha_b', 'alpha_r2', 'gamma_b', 'gamma_r2', 'gamma_logLL', 'delta_b', 'delta_r2', 'uu0', 'ul0', 'su0', 'sl0', 'U0', 'S0', 'total0', 'use_for_dynamics', 'use_for_transition'
    uns: 'pp', 'velocyto_SVR', 'PCs', 'explained_variance_ratio_', 'pca_fit', 'feature_selection', 'dynamics', 'neighbors', 'umap_fit', 'grid_velocity_umap'
    obsm: 'X_pca', 'X', 'cell_cycle_scores', 'X_umap', 'velocity_umap'
    layers: 'matrix', 'ambiguous', 'spanning', 'spliced', 'unspliced', 'X_spliced', 'X_unspliced', 'M_u', 'M_uu', 'M_s', 'M_us', 'M_ss', 'velocity_S'
    obsp: 'moments_con', 'connectivities', 'distances', 'pearson_transition_matrix'
In [11]:
gene_list = adata.var.index[adata.var.use_for_transition][:3]
In [12]:
dyn.pl.phase_portraits(adata, genes=gene_list, ncols=3, figsize=(3, 3), basis='umap', show_quiver=False)
/home/xqiu/.local/lib/python3.6/site-packages/dynamo_release-0.95.2-py3.6.egg/dynamo/plot/utils.py:194: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("glasbey_white"))
  cmap.set_bad("lightgray")
/home/xqiu/.local/lib/python3.6/site-packages/dynamo_release-0.95.2-py3.6.egg/dynamo/plot/utils.py:304: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("viridis"))
  cmap_.set_bad("lightgray")
/home/xqiu/.local/lib/python3.6/site-packages/dynamo_release-0.95.2-py3.6.egg/dynamo/plot/utils.py:304: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("div_blue_red"))
  cmap_.set_bad("lightgray")
/home/xqiu/.local/lib/python3.6/site-packages/dynamo_release-0.95.2-py3.6.egg/dynamo/plot/utils.py:194: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("glasbey_white"))
  cmap.set_bad("lightgray")
/home/xqiu/.local/lib/python3.6/site-packages/dynamo_release-0.95.2-py3.6.egg/dynamo/plot/utils.py:304: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("viridis"))
  cmap_.set_bad("lightgray")
/home/xqiu/.local/lib/python3.6/site-packages/dynamo_release-0.95.2-py3.6.egg/dynamo/plot/utils.py:304: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("div_blue_red"))
  cmap_.set_bad("lightgray")
/home/xqiu/.local/lib/python3.6/site-packages/dynamo_release-0.95.2-py3.6.egg/dynamo/plot/utils.py:194: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("glasbey_white"))
  cmap.set_bad("lightgray")
/home/xqiu/.local/lib/python3.6/site-packages/dynamo_release-0.95.2-py3.6.egg/dynamo/plot/utils.py:304: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("viridis"))
  cmap_.set_bad("lightgray")
/home/xqiu/.local/lib/python3.6/site-packages/dynamo_release-0.95.2-py3.6.egg/dynamo/plot/utils.py:304: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("div_blue_red"))
  cmap_.set_bad("lightgray")