Closed rohitarorayyc closed 2 years ago
Dear @Rohitarora21 thanks for using dynamo!
We recommend you to use dyn.ext.ddhodge(adata, basis='umap')
instead of the other functions to calculate potential (or vector field based pseudotime).
Your second error is self-explanatory (did you read the error message?). You will need to run dyn.vf.VectorField(adata, basis='pca')
first before you can use perturbation prediction. and you will also need to run dyn.tl.cell_velocities(adata, basis='pca')
to predict RNA velocity to pca space before you can learn RNA velocity vector field in pca space.
KeyError Traceback (most recent call last)
ddhodge can provide the same information of the potential and the Potential function is not currently well supported
Hello, Dr. Qiu:
Dynamo is so excellent and helps me a lot. Thank you very much for providing such a powerful tool.
When i run dyn.pd.perturbation, i am meeting an error. I really don’t know what caused this error. I sincerely hope you can help me solve this problem.
Thank you very much!
my code is :
dyn.pp.recipe_monocle(adata) dyn.tl.dynamics(adata, cores=48) dyn.tl.reduceDimension(adata)
dyn.tl.cell_velocities(adata,basis='pca') dyn.vf.VectorField(adata,basis='pca', M=1000) dyn.tl.cell_velocities(adata,basis='umap') dyn.vf.VectorField(adata,basis='umap', M=1000)
dyn.vf.rank_velocity_genes(adata, groups='leiden_anno', vkey="velocity_S");
rank_speed = adata.uns['rank_velocity_S']; rank_abs_speed = adata.uns['rank_abs_velocity_S']; dyn.vf.acceleration(adata, basis='pca')
dyn.vf.rank_acceleration_genes(adata, groups='leiden_anno', akey="acceleration", prefix_store="rank"); rank_acceleration = adata.uns['rank_acceleration']; rank_abs_acceleration = adata.uns['rank_abs_acceleration'];
dyn.vf.curvature(adata, basis='pca');
dyn.vf.rank_curvature_genes(adata, groups='leiden_anno');
dyn.pp.top_pca_genes(adata, n_top_genes=500); top_pca_genes = adata.var.index[adata.var.top_pca_genes];
top_pca_genes = ['RORA', 'PITX1','KRT3', 'KRT12',"MAL"] + list(top_pca_genes)
dyn.vf.jacobian(adata, regulators=top_pca_genes, effectors=top_pca_genes);
dyn.ext.ddhodge(adata, basis='pca') dyn.ext.ddhodge(adata, basis='umap')
basis = "pca" dyn.vf.speed(adata, basis=basis) dyn.vf.divergence(adata, basis=basis) dyn.vf.acceleration(adata, basis=basis) dyn.vf.curvature(adata, basis=basis)
basis = "umap" dyn.vf.speed(adata, basis=basis) dyn.vf.divergence(adata, basis=basis) dyn.vf.acceleration(adata, basis=basis) dyn.vf.curvature(adata, basis=basis)
gene = "RORA" dyn.pd.perturbation(adata, gene, [-100], emb_basis="umap")
|-----> In silico perturbation of single-cells and prediction of cell fate after perturbation... |-----> Retrive X_pca, PCs, pca_mean... |-----> Calculate perturbation effect matrix via \delta Y = J \dot \delta X....
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-25-d5be0df6f5b7> in <module> 1 gene = "RORA" ----> 2 dyn.pd.perturbation(adata, gene, [-100], emb_basis="umap") 3 #dyn.pl.streamline_plot(adata, color=["leiden_anno", gene], basis="umap_perturbation") ~/.local/lib/python3.8/site-packages/dynamo/prediction/perturbation.py in perturbation(adata, genes, expression, perturb_mode, cells, zero_perturb_genes_vel, pca_key, PCs_key, pca_mean_key, basis, emb_basis, jac_key, X_pca, delta_Y, projection_method, pertubation_method, J_jv_delta_t, delta_t, add_delta_Y_key, add_transition_key, add_velocity_key, add_embedding_key) 244 245 # project pca gene expression back to original gene expression: --> 246 X = pca_to_expr(X_pca, PCs, means) 247 248 # get gene position ~/.local/lib/python3.8/site-packages/dynamo/prediction/utils.py in pca_to_expr(X, PCs, mean, func) 489 # reverse project from PCA back to raw expression space 490 if PCs.shape[1] == X.shape[1]: --> 491 exprs = X @ PCs.T + mean 492 if func is not None: 493 exprs = func(exprs) TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'
------------------ Original ------------------ From: @.>; Date: Fri, Apr 21, 2023 03:03 AM To: @.>; Cc: @.>; @.>; Subject: Re: [aristoteleo/dynamo-release] Issue when running dyn.vf.Potential(adata, method = "umap") on data with precomputed umap coordinates. (Issue #353)
ddhodge can provide the same information of the potential and the Potential function is not currently well supported
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
Dear @Mingsenli please create a new github issue for a separate question and format your code and error in a more readable format. I am delight to address your question after you doing that
After running the following on an object with precomputed UMAP coordinates from Seurat:
adata = dyn.read('adata.h5ad') dyn.pp.recipe_monocle(adata) dyn.tl.dynamics(adata) dyn.tl.moments(adata) dyn.tl.reduceDimension(adata) dyn.tl.cell_velocities(adata) dyn.tl.cell_wise_confidence(adata) dyn.tl.gene_wise_confidence(adata, group='seurat_clusters', lineage_dict={0: [4]}) dyn.vf.VectorField(adata, basis='umap', M=100) dyn.vf.topography(adata, basis='umap') dyn.ext.ddhodge(adata, basis='umap')
I attempt to run "dyn.vf.Potential(adata, method = "umap") or dyn.vf.Potential(adata)" and end up with the error below in both cases:
KeyError Traceback (most recent call last) /var/folders/k3/0hvyvc1144lg85cq0yk0g5qr0000gn/T/ipykernel_31128/104691726.py in
----> 1 dyn.vf.Potential(adata, method = "umap")
~/.local/lib/python3.9/site-packages/dynamo/vectorfield/scPotential.py in Potential(adata, DiffMat, method, kwargs) 450 """ 451 --> 452 Function = adata.uns["VecFld"] 453 DiffMat = DiffusionMatrix if DiffMat is None else DiffMat 454 pot = Pot(Function, DiffMat, kwargs)
~/opt/anaconda3/lib/python3.9/site-packages/anndata/compat/_overloaded_dict.py in getitem(self, key) 98 return self.overloaded[key].get() 99 else: --> 100 return self.data[key] 101 102 def setitem(self, key, value):
KeyError: 'VecFld'
To try to remedy this issue, I ran the following lines of code:
adata.uns["VecFld"] = adata.uns["VecFld_umap"] dyn.vf.Potential(adata)
and get this error:
TypeError Traceback (most recent call last) /var/folders/k3/0hvyvc1144lg85cq0yk0g5qr0000gn/T/ipykernel_31128/1199676603.py in
----> 1 dyn.vf.Potential(adata, method = "umap")
~/.local/lib/python3.9/site-packages/dynamo/vectorfield/scPotential.py in Potential(adata, DiffMat, method, kwargs) 453 DiffMat = DiffusionMatrix if DiffMat is None else DiffMat 454 pot = Pot(Function, DiffMat, kwargs) --> 455 pot.fit(method=method) 456 457 return adata
TypeError: fit() missing 3 required positional arguments: 'adata', 'x_lim', and 'y_lim'
then, I tried to use
dyn.pp.recipe_monocle(adata) dyn.tl.dynamics(adata, cores=3)
dyn.tl.reduceDimension(adata) dyn.tl.cell_velocities(adata)
dyn.tl.cell_velocities(adata, basis='umap')
dyn.vf.VectorField(adata, basis='umap', M=100)
dyn.ext.ddhodge(adata, basis='umap')
gene = "genename" dyn.pd.perturbation(adata, gene, [-100], emb_basis="umap", basis = "umap") dyn.pl.streamline_plot(adata, color=["core_edge_anno", gene], basis="umap_perturbation")
and get this error:
ValueError Traceback (most recent call last) /var/folders/k3/0hvyvc1144lg85cq0yk0g5qr0000gn/T/ipykernel_31128/2359643397.py in
1 gene = "CNFN"
----> 2 dyn.pd.perturbation(adata, gene, [-100], emb_basis="umap", basis = "umap")
3 dyn.pl.streamline_plot(adata, color=["core_edge_anno", gene], basis="umap_perturbation")
~/.local/lib/python3.9/site-packages/dynamo/prediction/perturbation.py in perturbation(adata, genes, expression, perturb_mode, cells, zero_perturb_genes_vel, pca_key, PCs_key, pca_mean_key, basis, emb_basis, jac_key, X_pca, delta_Y, projection_method, pertubation_method, J_jv_delta_t, delta_t, add_delta_Y_key, add_transition_key, add_velocity_key, add_embedding_key) 307 # calculate Jacobian 308 if jac_key not in adata.uns_keys(): --> 309 jacobian(adata, regulators=valid_genes, effectors=valid_genes) 310 311 Js = adata.uns[jac_key]["jacobian"] # pcs x pcs x cells
~/.local/lib/python3.9/site-packages/dynamo/vectorfield/vector_calculus.py in jacobian(adata, regulators, effectors, cell_idx, sampling, sample_ncells, basis, Qkey, vector_field_class, method, store_in_adata, **kwargs) 258 259 if vector_field_class is None: --> 260 vf_dict = get_vf_dict(adata, basis=basis) 261 if "method" not in vf_dict.keys(): 262 vf_dict["method"] = "sparsevfc"
~/.local/lib/python3.9/site-packages/dynamo/vectorfield/utils.py in get_vf_dict(adata, basis, vf_key) 231 232 if vf_key not in adata.uns.keys(): --> 233 raise ValueError( 234 f"Vector field function {vf_key} is not included in the adata object! " 235 f"Try firstly running dyn.vf.VectorField(adata, basis='{basis}')"
ValueError: Vector field function VecFld_pca is not included in the adata object! Try firstly running dyn.vf.VectorField(adata, basis='pca')
I was wondering how I could remedy this issue?
Thank you in advance!