scanpy icon indicating copy to clipboard operation
scanpy copied to clipboard

"scanpy.pl.rank_genes_groups" and "scanpy.pl.rank_genes_groups_violin" are inconsistent with gene_names assignment

Open adkinsrs opened this issue 2 years ago • 0 comments

https://github.com/scverse/scanpy/blob/2e98705347ea484c36caa9ba10de1987b09081bf/scanpy/plotting/_tools/init.py#L1151-L1156

For reference, sc.pl.rank_genes_groups assigns "_gene_names" as such https://github.com/scverse/scanpy/blob/2e98705347ea484c36caa9ba10de1987b09081bf/scanpy/plotting/_tools/init.py#L402-L406

This is causing a situation where I can pass identical parameters to both functions but rank_genes_groups_violin fails where rank_genes_groups succeeds. Basically in the violin plot one, the get_obs_df function is creating a dataframe using the <gene_symbol_key> as the columns but using adata.var_names (stored in adata.uns["rank_genes_groups"]["names"]) as the key to search for. If the <gene_symbol_key> is not the index of adata.var, then this fails with a KeyError.

I am using scanpy==1.8.2 and anndata==0.7.8 but can confirm that this code is still present in the master branch (as shown above)

adkinsrs avatar May 19 '22 15:05 adkinsrs