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

Find gene symbols exist only in .raw attribute #962

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mw201608
Copy link

This change fixed an issue of retrieving data for gene symbols which exist only in the .raw attribute of an AnnData object.

This change fixed issues of plotting gene symbols which exist only in .raw attribute of AnnData object.
Find gene symbols exist only in .raw attribute
Copy link
Member

@ivirshup ivirshup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

I think you could use code we already have in the codebase for this method.

Comment on lines +2988 to +3019
# translate gene_symbols to var_names
# slow method but gives a meaningful error if no gene symbol is found:
if use_raw:
if gene_symbols is not None and gene_symbols in adata.raw.var.columns:
translated_var_names = []
for symbol in var_names:
if symbol not in adata.raw.var[gene_symbols].values:
logg.error(
f"Gene symbol {symbol!r} not found in given "
f"gene_symbols column: {gene_symbols!r}"
)
return
translated_var_names.append(
adata.raw.var[adata.raw.var[gene_symbols] == symbol].index[0]
)
return
translated_var_names.append(
adata.var[adata.var[gene_symbols] == symbol].index[0]
)
symbols = var_names
var_names = translated_var_names
symbols = var_names
var_names = translated_var_names
else:
if gene_symbols is not None and gene_symbols in adata.var.columns:
translated_var_names = []
for symbol in var_names:
if symbol not in adata.var[gene_symbols].values:
logg.error(
f"Gene symbol {symbol!r} not found in given "
f"gene_symbols column: {gene_symbols!r}"
)
return
translated_var_names.append(
adata.var[adata.var[gene_symbols] == symbol].index[0]
)
symbols = var_names
var_names = translated_var_names
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using sc.get.obs_df for this? I believe it already has the logic you're implementing.

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

Successfully merging this pull request may close these issues.

2 participants