LouisFaure / scFates

a scalable python suite for tree inference and advanced pseudotime analysis from scRNAseq data.
https://scfates.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
47 stars 1 forks source link

imcompatible with cellrank version2 #33

Closed wangmhan closed 2 weeks ago

wangmhan commented 1 month ago

Hi, Thank you for the package.

I tried to use cellrank results as input, followed this tutorial: https://scfates.readthedocs.io/en/latest/Conversion_from_CellRank_pipeline.html

However, some code is based on cellrank v1, but deprecated in version2, i.e.cr.pl.lineages(adata) I tried to downgrade my cellrank from v2.0.2 to v1.5.1, but it is not compatible with scFates v1.0.1.

That is the code I tried to adapt GPCCA

from cellrank.estimators import GPCCA weight_connectivities=0.2 mode="stochastic" n_jobs=4 softmax_scale=None

from cellrank.kernels import PseudotimeKernel pk = PseudotimeKernel(adata, time_key="dpt_pseudotime") pk.compute_transition_matrix()

Black and yellow dots indicate random walk start and terminal cells, respectively.

pk.plot_random_walks( seed=0, n_sims=100, start_ixs={"seurat_clusters": "3"}, basis="xtsne_cell_embeddings", legend_loc="right", dpi=150, )

from cellrank.estimators import GPCCA g = GPCCA(pk) g.fit(n_states=10, cluster_key="seurat_clusters") g.plot_macrostates(which="all",basis="xtsne_cell_embeddings") g.predict_initial_states() g.plot_macrostates(which="initial",basis="xtsne_cell_embeddings", legend_loc="right", s=100) g.predict_terminal_states(method="top_n", n_states=6) g.plot_macrostates(which="terminal",basis="xtsne_cell_embeddings") g.set_terminal_states(states=["2", "1_3"]) g.plot_macrostates(which="terminal",basis="xtsne_cell_embeddings", legend_loc="right", s=100) g.compute_fate_probabilities() g.plot_fate_probabilities(legend_loc="right",basis="xtsne_cell_embeddings")

I get stuck at this step: Converting Cellrank output into a principal tree

Run into errors

scf.tl.cellrank_to_tree(adata,time="dpt_pseudotime",Nodes=300,seed=1)

KeyError Traceback (most recent call last) Cell In[21], line 1 ----> 1 scf.tl.cellrank_to_tree(adata,time="dpt_pseudotime",Nodes=300,seed=1)

File ~/miniforge3/envs/scFates/lib/python3.11/site-packages/scFates/tools/conversion.py:93, in cellrank_to_tree(adata, time, Nodes, method, ppt_lambda, auto_root, root_params, reassign_pseudotime, copy, **kwargs) 89 auto_root = True 91 adata = adata.copy() if copy else adata ---> 93 n_states = adata.obsm["to_terminal_states"].shape[1] 95 if n_states == 2: 96 adata.obsm["X_fates"] = np.vstack( 97 [ 98 np.array(adata.obsm["to_terminal_states"][:, 0].flatten()), 99 adata.obs[time], 100 ] 101 ).T

File ~/miniforge3/envs/scFates/lib/python3.11/site-packages/anndata/_core/aligned_mapping.py:178, in AlignedActualMixin.getitem(self, key) 177 def getitem(self, key: str) -> V: --> 178 return self._data[key]

KeyError: 'to_terminal_states'

It would be great if you can give any suggestions how to adapt the code. & If scFates only works with cellrank v1, then could you please specify the version of all packages needed?

Thank you!

LouisFaure commented 2 weeks ago

Hi, compatibility with cellrank2 is now fixed in version 1.0.8