STOmics / Stereopy

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

How to Integrate Three Biological Replicates within the same slice #171

Closed jmzhang1911 closed 10 months ago

jmzhang1911 commented 11 months ago

Hi, Thank you for developing such an elegant analysis tool. I have encountered some issues while using it. There are three biological replicates within the same slice, and I have noticed that the sample consistency is not very good when analyzing the entire section as a whole. Could the integration methods in stereopy address this situation?

I have separately read the split GEM files, processed them, and attempted to integrate them using the st.utils.data_helper.merge method. However, I encountered the following error message. Could you please advise on how to resolve this issue? Looking forward to your response.


N1 = res_dir / '210716_1_N1.TissueCut.gem'
N2 = res_dir / '210716_1_N2.TissueCut.gem'
N3 = res_dir / '210716_1_N3.TissueCut.gem'
​
N1 = st.io.read_gem(N1, bin_size=50)
N2 = st.io.read_gem(N2, bin_size=50)
N3 = st.io.read_gem(N3, bin_size=50)

N1.tl.cal_qc()
N2.tl.cal_qc()
N3.tl.cal_qc()

N1.plt.genes_count()
N2.plt.genes_count()
N3.plt.genes_count()

N1.tl.filter_cells(
        min_gene=15,
        min_n_genes_by_counts=3,
       # pct_counts_mt=5,
        inplace=True
        )

N2.tl.filter_cells(
        min_gene=15,
        min_n_genes_by_counts=3,
       # pct_counts_mt=5,
        inplace=True
        )

N3.tl.filter_cells(
        min_gene=15,
        min_n_genes_by_counts=3,
       # pct_counts_mt=5,
        inplace=True
        )

data_N = st.utils.data_helper.merge(N1, N2, N3)
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
Cell In[156], line 1
----> 1 data_N = st.utils.data_helper.merge(N1, N2, N3)

File /share/zhangjm/software/miniconda3/envs/stereo_seq/lib/python3.8/site-packages/stereo/utils/data_helper.py:164, in merge(reorganize_coordinate, horizontal_offset_additional, vertical_offset_additional, space_between, *data_list)
    162 new_data.position = np.concatenate([new_data.position, data.position])
    163 if data.position_z is None:
--> 164     current_position_z += space_between / data.attr['resolution']
    165     new_data.position_z = np.concatenate([new_data.position_z, np.repeat([[current_position_z]], repeats=data.position.shape[0], axis=0)])
    166 else:

ZeroDivisionError: float division by zero
UglyRay7 commented 11 months ago

You could try MSData on your dataset, referring to the tutorial https://stereopy.readthedocs.io/en/latest/Tutorials/MSData_Clustering.html.

Ray

tanliwei-coder commented 11 months ago

The function merge will calculate the z-coordinates of each slice, therefore, it need to use space_between representing distance between each slice and resolution representing resolution of sequencing chip, space_between is a parameter of merge needed you to input, resolution can be mapped from file name of the input data, but i note that your data file name isn't a standard name, it normally is the sn of sequencing chip, which results in the resolution is still 0, you can change the file name of each slice to the sn of sequencing chip like 'sn.N1.TissueCut.gem' to avoid this error.

MariaRosariaNucera commented 11 months ago

can I ask you how you separated the GEM files?