BiomedicalMachineLearning / stLearn

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

Could not control the root in the trajectory #279

Closed cynthier closed 3 months ago

cynthier commented 5 months ago

Hi, I set the root as cluster 4, but the trajectory start from cluster 0. Could you please help me?

data.uns["iroot"] = np.flatnonzero(data.obs["region_num"] == str(4))[0]
data.obs["region_num"] = pd.Categorical(data.obs["region_num"])
st.spatial.trajectory.pseudotime(data,eps=30,use_rep="X_pca",use_label="region_num", threshold_spots=1)
st.spatial.trajectory.pseudotimespace_global(data,use_label="region_num",list_clusters=[0, 4, 5]) 

All available trajectory paths are stored in adata.uns['available_paths'] with length < 4 nodes Start to construct the trajectory: 0 -> 5 -> 4

duypham2108 commented 5 months ago

Have you tried this to find the root spot?

data.uns["iroot"] = st.spatial.trajectory.set_root(data,use_label="region_num",cluster=4,use_raw=True)

Also, you can check this https://github.com/BiomedicalMachineLearning/stLearn/issues/86#issuecomment-778539173

cynthier commented 5 months ago

@duypham2108 Thank you for your reply. I get the same result using the code you recommended. Based on the prior knowledge, the cluster4 should be the root, but now the trajectory direction is reversed.

duypham2108 commented 5 months ago

How does this cluster4 look in the UMAP? If it's on the edge, you can manually pick the terminal spot (at the end of the cluster). If the number of spots is few, it may also lead to this issue. You should look at the pseudotime plot to identify the problem