dynamo-release icon indicating copy to clipboard operation
dynamo-release copied to clipboard

acceleration/curvature layer missing when using umap

Open chansigit opened this issue 2 years ago • 1 comments

it seems that the current implementation of curvature() and acceleration() only insert a new layer when basis=pca

I calculated the acceleration using umap and ran the rank test

dyn.vf.acceleration(adata, basis='umap')
dyn.vf.curvature(adata, basis='umap')
dyn.vf.rank_curvature_genes(adata, groups='field_leiden')
dyn.vf.rank_acceleration_genes(adata, groups='field_leiden', akey='acceleration')

got the following error messages, and found I did not have a acceleration or curvature layer in my adata.

File ~/.local/lib/python3.10/site-packages/dynamo/vectorfield/vector_calculus.py:928, in rank_genes(adata, arr_key, groups, genes, abs, normalize, fcn_pool, dtype, output_values)
    887 def rank_genes(
    888     adata,
    889     arr_key,
   (...)
    896     output_values=False,
    897 ):
    898     """Rank gene's absolute, positive, negative vector field metrics by different cell groups.
    899 
    900     Parameters
   (...)
    925             A dictionary of gene names and values based on which the genes are sorted for each cell group.
    926     """
--> 928     genes, arr = get_rank_array(
    929         adata,
    930         arr_key,
    931         genes=genes,
    932         abs=abs,
    933         dtype=dtype,
    934     )
    936     if arr.ndim > 1:
    937         if normalize:

File ~/.local/lib/python3.10/site-packages/dynamo/tools/utils.py:2354, in get_rank_array(adata, arr_key, genes, abs, dtype)
   2352         arr = index_gene(adata, adata.var[arr_key], genes)
   2353     else:
-> 2354         raise Exception(f"Key {arr_key} not found in neither .layers nor .var.")
   2355 else:
   2356     arr = index_gene(adata, arr_key, genes)

Exception: Key curvature not found in neither .layers nor .var.

I checked https://github.com/aristoteleo/dynamo-release/blob/d6a48e1c84e74bff4c66665a95987f0c567a2803/dynamo/vectorfield/vector_calculus.py#L620-L632 and https://github.com/aristoteleo/dynamo-release/blob/d6a48e1c84e74bff4c66665a95987f0c567a2803/dynamo/vectorfield/vector_calculus.py#L704-L713

it seems that the elif make basis arguments other than "pca" fail to get a layer inserted.

The tutorial works well probably because it used pca. Should I use umap in the acceleration and curvature calculations? If I could, can you please fix this issue?

chansigit avatar May 28 '22 17:05 chansigit

when acceleration, curvature calculated on pca, it cannot be projected back to original gene expression space for the ranking analyses. you can only visualize the magnitude of each quantity for each cell or draw the 2D umap acceleration, curvature field.

When you calculate them in pca space, you can project back to original gene expression space to perform the ranking and differential analyses

Xiaojieqiu avatar May 28 '22 19:05 Xiaojieqiu

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 14 days

github-actions[bot] avatar Sep 01 '22 00:09 github-actions[bot]

when acceleration, curvature calculated on pca, it cannot be projected back to original gene expression space for the ranking analyses. you can only visualize the magnitude of each quantity for each cell or draw the 2D umap acceleration, curvature field.

When you calculate them in pca space, you can project back to original gene expression space to perform the ranking and differential analyses

Hi - for this, do you mean that when the acceleration and curvature are calculated on UMAP space that it cannot be projected back to the original gene expression space for ranking analysis?

I've been calculating the acceleration and curvature on PCA space, but somehowwhen I try dyn.pl.umap(adata, color=['gene_of_interest'], layer = 'acceleration'),

I get an error: 1746 raise RuntimeError("matplotlib does not " 1747 "support generators as input") 1748 else: -> 1749 return next(val for val in obj if safe_isfinite(val))

Can I check what might be going wrong?

andrewjkwok avatar Dec 04 '22 09:12 andrewjkwok