Open llumdi opened 4 years ago
My understanding is that it should search for 'ENSG00000104814' in the index column and return the corresponding value in 'symbols', but it seems that is directly searching 'ENSG00000104814' in the 'symbols' column.
If you add the gene_symbol
parameter, scanpy will look for the var_names
in this column instead of looking into adata.var index
. It will not map between index and the gene_symbol
I you want to do the mapping of labels, you can do something like follows:
# set show=False to get the axes dictionary.
ax_dict = sc.pl.dotplot(adata, myg, groupby=condition)
# get ensembl ids and map them to gene symbol. Although you can directly map `myg`,
# the following method will work in any case, including `sc.pl.rank_genes_groups_dotplot`
# This method also works for `sc.pl.matrixplot`
ticklabels = [adata.var.loc[x]['gene_symbol'] for x in ax_dict['mainplot_ax'].get_xticklabels()]
# replace ensembls ids by gene symbol in plot
_ = ax_dict['mainplot_ax'].set_xticklabels(ticklabels)
Thanks for your answer and the code suggestion. When I do: ax_dict = sc.pl.dotplot(adata, myg, groupby=condition, show=False) The plot is still shown and ax_dict is:
GridSpec(2, 5, height_ratios=[0, 10.5], width_ratios=[0.7, 0, 0.2, 0.5, 0.25])
How do I have to set show=False to get the axes dictionary?
Thanks
Please update to the latest scanpy release (1.6)
hello, reporting the same issue using '1.7.2'
And, I could not get around with the above suggestion as the object becomes a list:
[Text(0, 0.5, 'ENSMUSG00000021565'), Text(0, 1.5, 'ENSMUSG00000097971'), Text(0, 2.5, 'ENSMUSG00000048905')],
Somehow I could not convert the gene id because of this obstacle in the above list 'Text' object is not iterable
.
Can someone fix the problem or provide a feasible solution?
Thanks!
Edited by providing my solution, since get_xticklabels
returns matplotlib.text.Text
t=g['mainplot_ax'].get_xticklabels() tx=list() for x in t: tx.append(x.get_text()) ticklabels = [adata.var.loc[x]['gene_symbols'] for x in tx] _ = g['mainplot_ax'].set_xticklabels(ticklabels)
I have an AnnData object:
print(adata)
AnnData object with n_obs × n_vars = 77430 × 1988 obs: 'CONDITION', 'input.path', 'experiment', 'Sample type', 'BiOmics Sample Name', 'PatientID', 'SampleID', 'Response', 'Respond', 'Response2', 'Adjuvant', 'CIT', 'CIT2', 'Lesion2', 'Lesion', 'Stage', 'Fresh', 'CD3IHC', 'CD3IHC_RICZ', 'Mutation2', 'Mutation', 'Site', 'Age', 'Gender', 'PBMCs', 'PBMCs2', 'Seq samples', 'Quality', 'n_counts', 'n_genes', 'percent_mito', 'n_cPg', 'n_cPg2', 'batch', 'louvain' var: 'symbol', 'n_cells' uns: 'louvain', 'louvain_colors', 'neighbors', 'pca' obsm: 'X_pca', 'X_umap' varm: 'PCs'
To label the dotplot with gene symbols instead of ensemblID (index column) I use the gene_symbols parameter:
sc.pl.dotplot(adata=adata, var_names = ['ENSG00000104814','ENSG00000043462'], gene_symbols='symbol')
But I get the following error:
Error: Gene symbol 'ENSG00000104814' not found in given gene_symbols column: 'symbol'
TypeError Traceback (most recent call last)