ligrec plot order
when I use sq.pl.ligrec to plot the interaction, the axis wasn't ordered by leiden number, but by dict order. I changed the order of the leiden categories by:
adata.obs['leiden'] = pd.Categorical(adata.obs['leiden'],categories=(str(i) for i in np.arange(np.unique(adata.obs['leiden'])))
and plot again:
for leiden in adata.obs['leiden'].cat.categories:
sq.pl.ligrec(adata,cluster_key="leiden",pvalue_threshold=0.05,source_groups=leiden,target_groups=None,means_range=(1.4, np.inf),alpha=1e-4,swap_axes=True,save=leiden)
This time the axis order is still disordered, so how to set the leiden order ?
which axis order do you mean @wangjiawen2013 ?
The cluster number is 1,2,3,4,5,6,7,8,9,10,11, but it's displayed as 1, 10, 11, 2,3,4,5,6,7,8,9 on the plot.
what's the result of
adata.obs['leiden'].cat.categories
?
In [5]: adata.obs['leiden'].cat.categories
Out[5]:
Index(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],dtype='object')
I think I call sorted() on the categories here which causes this.
Will you update the code, or we fix it ourselves ?
Will you update the code, or we fix it ourselves ?
Would be great if you could open a PR.
I opened a PR, but I am afraid that the issue isn't resolved, because the plot order didn't change with or without "sorted" on my data.
thanks @wangjiawen2013 I'll take a look soon, sorry for delay!
hi @wangjiawen2013 ,
reposting here from the PR. I actually realized it's possible to just pass the order excpliticly, you can try out with this:
import squidpy as sq
adata = sq.datasets.seqfish()
import pandas as pd
adata.obs["leiden"] = pd.Categorical(
np.random.randint(0, 15, size=adata.obs.Area.shape)
)
res = sq.gr.ligrec(
adata,
n_perms=1,
cluster_key="leiden",
copy=True,
use_raw=False,
transmitter_params={"categories": "ligand"},
receiver_params={"categories": "receptor"},
)
sq.pl.ligrec(
res,
source_groups="1",
target_groups=adata.obs.leiden.cat.categories.astype(str),
alpha=0.005,
)
