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

Allow flexible index column name in adata.var #12

Open
Rebecza opened this issue Aug 7, 2023 · 1 comment
Open

Allow flexible index column name in adata.var #12

Rebecza opened this issue Aug 7, 2023 · 1 comment

Comments

@Rebecza
Copy link

Rebecza commented Aug 7, 2023

adata.var.index.name or adata.var_names.name can be other than None, as I noticed with a publicly available dataset.

SCEPIA expects this column to be called "index" (see code below where this throws an error) which would be the case with adata.var.index.name=None.

Solution could be to set adata.var.index.name to None within SCEPIA, if we change the index column name within SCEPIA, we should do the same for the adata.raw. Or change the code without the hardcoded "index".

Lines in sc.py where the index column name is taken from the adata object

    unique_factors = my_adata.raw.var_names[detected].str.upper()
    real = pd.DataFrame(
        real,
        index=unique_factors,
        columns=my_adata.uns["scepia"]["motif_activity"].index,
    )

Lines 612-617 in sc.py where the error is thrown

    tmp = (
        real.reset_index()
        .melt(id_vars="index", var_name="motif", value_name="correlation")
        .rename(columns={"index": "factor"})
        .set_index(["motif", "factor"])
    )

Throws a KeyError: 'index'

@simonvh
Copy link
Member

simonvh commented Aug 25, 2023

This can be changed to:

index_name = real.index.name or "index"  
tmp = (
        real.reset_index()
        .melt(id_vars=index_name , var_name="motif", value_name="correlation")
        .rename(columns={index_name: "factor"})
        .set_index(["motif", "factor"])
    )

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

2 participants