-
Notifications
You must be signed in to change notification settings - Fork 608
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
base: main
Are you sure you want to change the base?
Conversation
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
There was a problem hiding this 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.
# 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 |
There was a problem hiding this comment.
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.
This change fixed an issue of retrieving data for gene symbols which exist only in the .raw attribute of an AnnData object.