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

rank_genes_groups refactoring #723

Open
Koncopd opened this issue Jul 2, 2019 · 3 comments
Open

rank_genes_groups refactoring #723

Koncopd opened this issue Jul 2, 2019 · 3 comments
Assignees
Labels
Area – Differential Expression Differential expression

Comments

@Koncopd
Copy link
Member

Koncopd commented Jul 2, 2019

Hi, @falexwolf
Do you have any specific things in mind for rank_genes_groups refactoring? What should be done?

@Koncopd Koncopd self-assigned this Jul 2, 2019
@ivirshup
Copy link
Member

ivirshup commented Jul 4, 2019

I think there was some discussion of this (among other topics) here: #562

@falexwolf
Copy link
Member

Some notes from a brief discussion with Sergei.

  1. make helper functions for each method so that level of indentation and length is decreased
  2. replace lists rankings_gene_... by DataFrame
  3. think about simplifying the wilcoxon implementation, compare with scipy stats implementation and potentially update the test
  4. investigate how the logreg implementation behaves for different choices of reference groups

@fidelram
Copy link
Collaborator

fidelram commented Aug 30, 2019

Can rank_genes_groups be linked to use diffxpy on top of the available methods?

I am using the following code to convert the output of rank_genes_groups to a data frame, in case is useful:

def rank_genes_groups_df(adata, key='rank_genes_groups'):
    # create a data frame with columns from .uns['rank_genes_groups'] (eg. names, 
    # logfoldchanges, pvals). 
    # Ideally, the list of columns should be consistent between methods
    # but 'logreg' does not return logfoldchanges for example

    dd = []
    groupby = adata.uns['rank_genes_groups']['params']['groupby']
    for group in adata.obs[groupby].cat.categories:
        cols = []
        # inner loop to make data frame by concatenating the columns per group
        for col in adata.uns[key].keys():
            if col != 'params':
                   cols.append(pd.DataFrame(adata.uns[key][col][group], columns=[col]))
        
        df = pd.concat(cols,axis=1)
        df['group'] = group
        dd.append(df)

    # concatenate the individual group data frames into one long data frame
    rgg = pd.concat(dd)
    rgg['group'] = rgg['group'].astype('category')
    return rgg.set_index('group')

This results on a table like this:

image

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

No branches or pull requests

4 participants