Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scvelo neighbors #12

Closed
wangjiawen2013 opened this issue Oct 15, 2018 · 14 comments
Closed

scvelo neighbors #12

wangjiawen2013 opened this issue Oct 15, 2018 · 14 comments

Comments

@wangjiawen2013
Copy link

wangjiawen2013 commented Oct 15, 2018

Dear,
I am trying to get RNA velocity with scvelo and I find that scvelo will search neighbors by default. Now I have an scanpy anndata object, of which the neighbors are made by a customized method. I wanna keep these neighbors, are there any methods to stop scvelo re-searching neighbors automatically ?

@VolkerBergen
Copy link
Contributor

Good point! Neighbors get only updated if..

  • not computed yet
  • or n_neighbors attribute (default: 30) in scv.pp.moments is larger than the current one given in adata.uns['neighbors']['params']['n_neighbors']

If it got recomputed in your case, it prob traces back to your n_neighbors being less than 30. Just set it to a lower value in scv.pp.moments.

@wangjiawen2013
Copy link
Author

wangjiawen2013 commented Oct 15, 2018

Thanks!
Another question, I want to harmonize scanpy with scvelo. In scanpy pipeline, there is a step called sc.pl.scale() to scale the data, which is absent in scvelo. Will it affects sc.tl.louvain and sc.tl.umap or paga when projecting the velocity graph onto an embedding ?

@VolkerBergen
Copy link
Contributor

You can still use sc.tl.scale(). It will only affect the actual data matrix adata.X and thus implicitly any downstream.

The spliced and unspliced contained in adata.layers are not (and should not be) affected by sc.tl.scale()

@wangjiawen2013
Copy link
Author

And, during data preprocessing, could I replace scvelo's scv.pp.show_proportions(adata) and scv.pp.cleanup(adata, clean='all') and scv.pp.filter_and_normalize(adata) with scanpy's sc.pp.filter_cells() and sc.pp.filter_genes() and sc.pp.normalize_per_cell() ?

@VolkerBergen
Copy link
Contributor

Sure, you don't need to do any preprocessing within scvelo. Only normalization on the layers is necessary, which is automatically done within scv.pp.moments.

scv.pp.show_proportions does not do anything with your AnnData object; it just return the fractions of spliced/unspliced/ambiguous abundances, which can be useful to know.

scv.pp.cleanup(adata) is not needed at all; only if you have a very large datasets that needs to be cleaned.

scv.pp.filter_and_normalize is equivalent to running sc.pp.filter_genes and sc.pp.normalize_per_cell.

@wangjiawen2013
Copy link
Author

please have a look at this link: velocyto-team/velocyto-notebooks#9 (comment)
Could I merge the samples' anndata objects with scanpy ? Then I can minimize the batch effect with BBKNN (https://github.com/Teichlab/bbknn), which serves as an alternative to scanpy.api.pp.neighbors().

@VolkerBergen
Copy link
Contributor

Sure, that is simply adata = adata1.concatenate(adata2, adata3).

https://anndata.readthedocs.io/en/latest/anndata.AnnData.concatenate.html

@wangjiawen2013
Copy link
Author

When combining data from multiple 10x genomics libraries, cellranger recommend equalizing the read depth between libraries before merging, to reduce the batch effect introduced by sequencing, the command is "cellranger aggr --nomalize=mapped". Will scvelo equalize the read depth per cell per sample when merging mutliple samples ?

@wangjiawen2013
Copy link
Author

wangjiawen2013 commented Oct 24, 2018

And, when should I set the parameter renormalize=True in function scv.pp.moments() ? namesly, scv.pp.moments(adata, renormalize=True). Maybe it's better to have a detailed documents because RNA velocyto is an emerging field which few people are familiar to.

@VolkerBergen
Copy link
Contributor

Once the paper is out, it will shed light on yet unclear statements/attributes.

The renormalize attr just indicates whether to renormalize the first-order moments as explained here: https://scvelo.readthedocs.io/en/latest/api/docs.source.api.pp.moments.html#docs.source.api.pp.moments

It's recommended to use its default value (False). The option is only available as I tried out a couple methodological things. I might even drop this attr later.

@VolkerBergen
Copy link
Contributor

If I understood you correctly (w.r.t equalizing read depth), you can just create an AnnData object for each library, normalize them individually and then concatenate. When having all in one object it does not take difference in libraries into account.

VolkerBergen pushed a commit that referenced this issue Jun 12, 2019
michalk8 pushed a commit to Marius1311/scvelo that referenced this issue Oct 27, 2019
@fanxylab
Copy link

fanxylab commented Dec 1, 2021

Good point! Neighbors get only updated if..

  • not computed yet
  • or n_neighbors attribute (default: 30) in scv.pp.moments is larger than the current one given in adata.uns['neighbors']['params']['n_neighbors']

If it got recomputed in your case, it prob traces back to your n_neighbors being less than 30. Just set it to a lower value in scv.pp.moments.

Scanpy neighbors use all matrix data (unspliced + spliced + ambiguous) as input data to get neighbor matrixes.
I confuse whether its correct If I dont use the spliced matrix to get neighbor matrixes and return 'Ms' and 'Mu' .

@WeilerP
Copy link
Member

WeilerP commented Dec 1, 2021

@fanxylab, both Scanpy and scvelo use whatever data is stored in .X, i.e., if you store all counts (spliced + unspliced + ambiguous) in .X, scvelo will not calculate the neighbor graph using spliced counts but all instead.
Given that we usually have many more spliced than unspliced reads, I do not expect major differences between the two approaches. This is also what I observed on one or two datasets where the latent space was computed one time using the original count matrix and one time only spliced counts.

@brainfo
Copy link

brainfo commented Jan 24, 2025

Hi, could we specify "neighbors_key" to where in the anndata.uns to look at by scvelo.pp.moments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants