BiomedicalMachineLearning / stLearn

A novel machine learning pipeline to analyse spatial transcriptomics data
Other
176 stars 23 forks source link

How to get the clade no.s after generating trajectory plot #261

Closed rialc13 closed 3 months ago

rialc13 commented 8 months ago

Hi. I am running the below code for creating trajectories -

st.spatial.trajectory.pseudotimespace_global(bdata,use_label="seurat_clusters",list_clusters=["4","13"])
st.pl.cluster_plot(bdata,use_label="seurat_clusters",show_trajectories=True,list_clusters=["4","13"],show_subcluster=True)
image

tree_plot(bdata, use_label="seurat_clusters")

image

After I generate the tree plot, I get the clade number information. Can you tell me how to fetch the number of clades & the clade number from my anndata object itself? For eg, if my iroot = cluster 0, & my list_clusters = 4,13, what will be the command for fetching the clade information just for this trajectory?

duypham2108 commented 8 months ago

The name of the clade will be the starting (after pseudoroot) node. Currently, we don't have any function to extract it automatically. You can manually extract them by every sub-clusters from "sub_cluster_labels" in .obs. For example adata.obs[adata.obs.sub_cluster_labels.isin(["3","1"]) in your case

rialc13 commented 8 months ago

Is there anyway we can get the clade information before generating the plot? For example, if I just run the function st.spatial.trajectory.pseudotimespace_global (not the st.pl.cluster_plot), how can I fetch the clade number?

duypham2108 commented 8 months ago

You can extract the graph like this

import networkx as nx
from stlearn.utils import _read_graph
G = _read_graph(data,"PTS_graph")
G.remove_node(9999)
nx.draw_networkx(G)