STOmics / Stereopy

A toolkit of spatial transcriptomic analysis.
MIT License
187 stars 64 forks source link

How to subset stereopy object? #134

Closed GokceOGUZ closed 1 year ago

GokceOGUZ commented 1 year ago

I have run the Square bin tutorial on my data and got my clusters. Now, I would like to subset the object according to my cluster of interests and do fine clustering with the new object.

I cannot use the add_select_area() code as the clusters are spread around. So I was wondering if there a specific function for subsetting based on cluster information.

To give an example, let's say I want to do fine clustering on cluster 4 & 7. How to generate a new subsetted object ? image

Thanks!

tanliwei-coder commented 1 year ago

Hi!!

If the version of the stereopy you installed is greater than 0.12.0, you can run datasubset = data.tl.filter_by_clusters(cluster_res_key='leiden', groups=['4', '7'], excluded=False, inplace=False) to get a new data object, the cluster_res_key is the same as the parameter res_key of the clustering function you ran.

But, I must to remind you , i think you have already normalized the data before clustering, so, the subset after filtering is a normalized data too.

GokceOGUZ commented 1 year ago

Dear tanliwei-coder,

Thanks for your response and quick implementation to the workflow. I have 2 follow-up questions:

1- I am running the code as you suggested but receiving the AttributeError: 'StereoExpData' object has no attribute '_position_z' error. Is this possible because the object I am using was generated with an earlier stereopy version? Is there a solution to this? image

2- I also ran the workflow with the stereopy 0.12.1, but getting the following Indexing Error message. How may I fix it?

image

Thank you so much for your attention and help!

tanliwei-coder commented 1 year ago

Sorry, we will fix this bug as soon as possible, a new version is expected up to next Friday.

UglyRay7 commented 1 year ago

We have fixed this function, please update the package to 0.13.0b1.

Thanks for your feedback and suggestion! Ray