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

UnidentifiedImageError when reading in Nanostring CosMx Data #845

Open keiven-kun opened 4 months ago

keiven-kun commented 4 months ago

Hi,

I am receiving the error below when I am loading in Nanostring data. And I found that if I delete the imge folder ("CellComposite", "CellOverlay") and only keep the exprMat, matadata and fov CSV files, the CosMx data loads successfully. But in this way, images are missing. What is causing this issue? Is there anyway to fix it?

Thank you so much for help!

nanostring_dir = "E:/CosMx Data/CosMx_bone_small_full/1117small/20231118_015620_S1"
sample_dir = nanostring_dir + "/CellStatsDir" 
adata = sq.read.nanostring(
    path=sample_dir,
    counts_file="S0_exprMat_file.csv",
    meta_file="S0_metadata_file.csv",
    fov_file="S0_fov_positions_file.csv",
)

UnidentifiedImageError                    Traceback (most recent call last)
Cell In[4], line 4
      1 nanostring_dir = "E:/CosMx Data/CosMx_bone_small_full/1117small/20231118_015620_S1"
      2 sample_dir = nanostring_dir + "/CellStatsDir" 
----> 4 adata = sq.read.nanostring(
      5     path=sample_dir,
      6     counts_file="S0_exprMat_file.csv",
      7     meta_file="S0_metadata_file.csv",
      8     fov_file="S0_fov_positions_file.csv",
      9 )

File D:\Software\anaconda3\Lib\site-packages\squidpy\read\_read.py:260, in nanostring(path, counts_file, meta_file, fov_file)
    258 fov = str(int(pat.findall(fname)[0]))
    259 try:
--> 260     adata.uns[Key.uns.spatial][fov]["images"][kind] = _load_image(path / subdir / fname)
    261 except KeyError:
    262     logg.warning(f"FOV `{str(fov)}` does not exist in {subdir} folder, skipping it.")

File D:\Software\anaconda3\Lib\site-packages\squidpy\read\_utils.py:61, in _load_image(path)
     60 def _load_image(path: PathLike) -> NDArrayA:
---> 61     return np.asarray(Image.open(path))

File D:\Software\anaconda3\Lib\site-packages\PIL\Image.py:3309, in open(fp, mode, formats)
   3307     warnings.warn(message)
   3308 msg = "cannot identify image file %r" % (filename if filename else fp)
-> 3309 raise UnidentifiedImageError(msg)

UnidentifiedImageError: cannot identify image file 'E:\\CosMx Data\\CosMx_bone_small_full\\1117small\\20231118_015620_S1\\CellStatsDir\\CellComposite\\._CellComposite_F028.jpg'
giovp commented 4 months ago

hi @keiven-kun , I think the nanostring reader has been having issues, possibly due to bugs or new releases of the spec, there are other issues related to it. Unfortuantely, I don't have time to look at it, and would suggest to use https://github.com/scverse/spatialdata-io to read n the data

keiven-kun commented 4 months ago

hi @keiven-kun , I think the nanostring reader has been having issues, possibly due to bugs or new releases of the spec, there are other issues related to it. Unfortuantely, I don't have time to look at it, and would suggest to use https://github.com/scverse/spatialdata-io to read n the data

Hi @giovp , thank you for responding, I will try to use https://github.com/scverse/spatialdata-io to read the data