theislab / scvelo

RNA Velocity generalized through dynamical modeling
https://scvelo.org
BSD 3-Clause "New" or "Revised" License
414 stars 102 forks source link

Cannot compute velocities (or even plot UMAP) #961

Closed DaianeH closed 1 year ago

DaianeH commented 1 year ago

Hi, I'm new to scRNA-seq analysis with Python, so following the tutorial example in: https://uci-genpals.github.io/pseudotime/2021/02/09/scvelo-tutorial.html

My exact commands were:

import scvelo as scv
import scanpy as sc
import cellrank as cr
import numpy as np
import pandas as pd
import anndata as ad

scv.settings.verbosity = 3
scv.settings.set_figure_params('scvelo', facecolor='white', dpi=100, frameon=False)
cr.settings.verbosity = 2

# Read loom
ldata = scv.read('SCRNA-D7.loom', cache=True)

# Read ann data
adata = sc.read_h5ad('seurat.d7.h5ad')

# make variable names unique
ldata.var_names_make_unique()

# merge matrices into the original adata object
adata = scv.utils.merge(adata, ldata)

# plot umap to check
sc.pl.umap(adata, color='seurat_clusters', frameon=False, legend_loc='on data', title='', save='_celltypes.pdf')

The UMAP plot I get however looks like something I've never seen:

umap_celltypes.pdf

When I further try to compute trajectories and plot them with:

scv.pp.filter_and_normalize(adata)
scv.pp.moments(adata)
scv.tl.velocity(adata, mode='stochastic')
scv.tl.velocity_graph(adata)
scv.pl.velocity_embedding_grid(adata, basis='umap', color='seurat_clusters', save='embedding_grid.pdf', title='', scale=0.25)

I get the error:

"ValueError: Expected n_neighbors > 0. Got 0"

What can be causing this problem? Could it be a problem with my files? I don't have experience with scRNA-seq analysis in Python, so this is what the merged dataset looks like:

>>> adata
AnnData object with n_obs à n_vars = 3 à 27257
    obs: 'orig.ident', 'nCount_RNA', 'nFeature_RNA', 'percent.mt', 'percent.ribo', 'RNA_snn_res.0.5', 'seurat_clusters', 'Cluster1', 'Cluster2', 'Cluster3', 'Cluster4', 'Cluster5', 'Cluster6', 'Cluster7', 'Cluster8', 'Cluster9', 'Cluster10', 'Cluster11', 'Cluster12', 'Cluster13', 'Cluster14', 'Cluster15', 'cluster.names', 'initial_size_spliced', 'initial_size_unspliced', 'initial_size', 'n_counts', 'velocity_self_transition'
    var: 'vst.mean', 'vst.variance', 'vst.variance.expected', 'vst.variance.standardized', 'vst.variable', 'Accession', 'Chromosome', 'End', 'Start', 'Strand', 'velocity_gamma', 'velocity_qreg_ratio', 'velocity_r2', 'velocity_genes'
    uns: 'neighbors', 'velocity_params', 'velocity_graph', 'velocity_graph_neg'
    obsm: 'X_pca', 'X_tsne', 'X_umap', 'velocity_umap'
    varm: 'PCs'
    layers: 'ambiguous', 'matrix', 'spliced', 'unspliced', 'Ms', 'Mu', 'velocity', 'variance_velocity'
    obsp: 'distances', 'connectivities'

Any help is greatly appreciated.

Versions ```pytb scvelo==0.2.4 scanpy==1.7.2 anndata==0.7.8 loompy==3.0.7 numpy==1.19.5 scipy==1.5.4 matplotlib==3.3.4 sklearn==0.24.2 pandas==1.1.5 ```
DaianeH commented 1 year ago

Just adding, seurat object was converted to ann file in R with:

library(Seurat) library(SeuratDisk) seurat.d7<- readRDS(file = "(seurat.d7.rds") SaveH5Seurat(seurat.d7, filename = "seurat.d7.h5Seurat") Convert("seurat.d7.h5Seurat", dest = "h5ad")

DaianeH commented 1 year ago

Also adding:

When I plot my adata BEFORE merging with the loom matrix, the UMAP plot looks like what I expect. The problem happens after merging with the loom. What can be wrong with the loom, or with the merging process?