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

Regressing out genes #492

Open
joshuahwu opened this issue Feb 18, 2019 · 2 comments
Open

Regressing out genes #492

joshuahwu opened this issue Feb 18, 2019 · 2 comments
Labels
Enhancement ✨ good first issue easy first issue to get started in OSS community contribution!

Comments

@joshuahwu
Copy link

In Seurat, there is an option of selecting a list of genes in the pre-processing regressOut function. I was wondering if there was similar functionality in Scanpy. Doing something like below does not work for me as a lot of the cells have 0 expression, giving me a PerfectSeparationError.

adata.obs[gene] = adata[:, adata.var_names==gene].X
sc.pp.regress_out(adata,gene)

Any help would be appreciated. Thank you!

@LuckyMD
Copy link
Contributor

LuckyMD commented Feb 19, 2019

Hi,
I'm not entirely sure how Seurat does it, but I assume you could take the mean expression level (or mean z-score) of a couple of genes, store that in a .var column, and regress that out by sc.pp.regress_out(adata, var_col)?

Something like this:

adata.var['genes_of_interest'] = adata.X[:,gene_list].mean(0)
sc.pp.regress_out(adata, genes_of_interest)

If you want to ensure an equal contribution of all the genes to the gene score without weighting by mean gene expression, you could first use sc.pp.scale() on a copy of the adata object like this:

adata_tmp = adata.copy()
sc.pp.scale(adata_tmp)
adata.var['genes_of_interest'] = adata_tmp.X[:,gene_list].mean(0)
sc.pp.regress_out(adata, genes_of_interest)

Note that I have not tested this code... so no guarantees ;).

@ivirshup
Copy link
Member

ivirshup commented Jan 24, 2021

This would be very easy to implement with: sc.get.obs_df(adata, keys).

That would not solve the problem of (I believe) constant genes giving errors.

@ivirshup ivirshup added the good first issue easy first issue to get started in OSS community contribution! label Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ good first issue easy first issue to get started in OSS community contribution!
Projects
None yet
Development

No branches or pull requests

3 participants