aristoteleo / dynamo-release

Inclusive model of expression dynamics with conventional or metabolic labeling based scRNA-seq / multiomics, vector field reconstruction and differential geometry analyses
https://dynamo-release.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
417 stars 59 forks source link

Possible Bug: Iconsistance between Function-calling and Implementation of prepare_dim_reduction() #213

Closed kevin-de-granta closed 3 years ago

kevin-de-granta commented 3 years ago

There was an error when we were trying to invoke function dyn.tl.hdbscan(),

dyn.tl.hdbscan(adata, basis='umap') Traceback (most recent call last): File "", line 1, in File "/data/brdd/app/miniconda3/envs/singlecell/lib/python3.6/site-packages/dynamo/tools/clustering.py", line 89, in hdbscan n_components=n_components, ValueError: not enough values to unpack (expected 4, got 3)

The error seems due to inconsistance between function-calling and implementation of prepare_dim_reduction(). In dynamo/tools/clustering.py, four values are expected during calling,

if X_data is None: _, n_components, has_basis, basis = prepare_dim_reduction( adata, genes=genes, layer=layer, basis=basis, dims=dims, n_pca_components=n_pca_components, n_components=n_components, )

, while within the implementation(dynamo/tools/utils_reduceDimension.py, prepare_dim_reduction()), only three values are returned,

return X_data, n_components, basis

So, could you please consider improving it if necessary, or offer us some advice regarding how to better use it?

It is deeply appreciated.

Xiaojieqiu commented 3 years ago

hey @kevin-de-granta thanks for using dynamo and pointing out the bug. I have fixed this in my latest commit, can you please pull the changes and re-install the package to see whether it works now? I am tested the code via the following snippet which may be helpful:


import dynamo as dyn

adata = dyn.sample_data.pancreatic_endocrinogenesis()

dyn.pp.recipe_monocle(adata, num_dim=30)
dyn.pl.biplot(adata)
dyn.pl.variance_explained(adata)
dyn.pl.loading(adata)
dyn.tl.reduceDimension(adata)
dyn.tl.reduceDimension(adata, n_pca_components=30, enforce=True)
dyn.pl.umap(adata, color='clusters')
dyn.tl.dynamics(adata, model="stochastic", cores=2)

dyn.tl.hdbscan(adata, basis='umap') # note you can pass different arguments from hdbscan to this function
dyn.pl.umap(adata, color='hdbscan')
Xiaojieqiu commented 3 years ago

please also note that dynamo implemented louvain and leiden clustering too, so you can use:

dyn.tl.louvain(adata)  # louvain and leiden clustering are pretty flexible, for example, you can pass `adj_mat_key = "pearson_transition_matrix"` to those functions to use the transition graph calculated from RNA velocity to do the  cell clustering
dyn.tl.leiden(adata) 
dyn.pl.umap(adata, color=['louvain', 'leiden'])

Let me know whether this helps