scverse / squidpy

Spatial Single Cell Analysis in Python
https://squidpy.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
440 stars 82 forks source link

Can Squidpy read in Nanostring data from more than one slide simultaneously? #655

Closed yingsun-ucsd closed 4 months ago

yingsun-ucsd commented 1 year ago

I have Nanostring data from 3 slides. I was able to use Squidpy on each of them. I am wondering if Squidpy can read several slides simultaneously. Currently, I combined the datasets from several slides before reading. Can you point me to the instruction about how to do it? Thanks. ...

giovp commented 1 year ago

hi @yingsun-ucsd ,

it can, you can check the tutorial notebook https://squidpy.readthedocs.io/en/latest/external_tutorials/tutorial_nanostring.html and check out the signature of the function https://squidpy.readthedocs.io/en/latest/api/squidpy.read.nanostring.html

yingsun-ucsd commented 1 year ago

Thank you for your reply. I am still confused a little. So if I have 3 reps, I can do the following to read them all together?

adata = squidpy.read.nanostring(
    path=[ sample_dir1, sample_dir2, sample_dir3 ],
    counts_file=["Lung5_Rep1_exprMat_file.csv", "Lung5_Rep2_exprMat_file.csv", "Lung5_Rep3_exprMat_file.csv"],
    meta_file=["Lung5_Rep1_metadata_file.csv", "Lung5_Rep2_metadata_file.csv", "Lung5_Rep3_metadata_file.csv"],
    fov_file=["Lung5_Rep1_fov_positions_file.csv", "Lung5_Rep2_fov_positions_file.csv","Lung5_Rep3_fov_positions_file.csv"],
)

Thanks again.

michalk8 commented 1 year ago

So if I have 3 reps, I can do the following to read them all together?

You'd have to read each replicate separately and concatenate, e.g.,:

adatas = []
sample_dirs = [sample_dir1, sample_dir2, sample_dir3]
counts_files = ["Lung5_Rep1_exprMat_file.csv", "Lung5_Rep2_exprMat_file.csv", "Lung5_Rep3_exprMat_file.csv"]
meta_files = ["Lung5_Rep1_metadata_file.csv", "Lung5_Rep2_metadata_file.csv", "Lung5_Rep3_metadata_file.csv"]
fov_files = ["Lung5_Rep1_fov_positions_file.csv", "Lung5_Rep2_fov_positions_file.csv","Lung5_Rep3_fov_positions_file.csv"]

for path, c, m, f in zip(sample_dirs, count_files, meta_files, fov_files):
   adata = squidpy.read.nanostring(path, counts_file=c, meta_file=m, fov_file=f)
   adatas.append(adata)

adata = adatas[0].concatenate(*adatas[1:], batch_key='replicate')
yingsun-ucsd commented 1 year ago

Thank you so much @michalk8 The read-in works very well.

I have one more question: if Rep1 has fov 1-22; Rep2 has fov 1-25; and Rep3 has fov 1-25. When I read them separately, I can use squidgy.pl.spatial_segment to visualize annotation, for example:

sq.pl.spatial_segment( adata, color="Max.GCG", library_key="fov", library_id=["3", "16"], title=["S1:FOV3", "S1:FOV16"], seg_cell_id="cell_ID", )

After I read all three replicates together, how can I distinguish the same "fov" from different replicates? For example, how can I plot "fov" 3 from all 3 replicates together? I tried the following, but it did not work. Could you please point me to the instructions for working with replicates? Thank you so much.

sq.pl.spatial_segment( adata, color="Max.GCG", replicate = ["1", "2", "3"], library_key="fov", library_id=["3", "16"], title=["S1:FOV3", "S2:FOV3", "S3:FOV3"], seg_cell_id="cell_ID", )

yingsun-ucsd commented 1 year ago

After read in the replicates, how can I got a specific FOV from a specific replicate? For example, FOV 3 from replicate 1. Thank you so much! @michalk8

giovp commented 4 months ago

I would suggest to move to the spatialdata ecosystem or IO of cosmx https://spatialdata.scverse.org/en/latest/tutorials/notebooks/notebooks/examples/technology_cosmx.html