Skip to content

Regressing out genes #492

Description

@joshuahwu

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!

Activity

  1. LuckyMD commented on Feb 19, 2019

    @LuckyMD
    Contributor

    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 ;).

  2. ivirshup commented on Jan 24, 2021

    @ivirshup
    Member

    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.

  3. added
    good first issueeasy first issue to get started in OSS community contribution!
    on Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy first issue to get started in OSS community contribution!

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions