Nanostring reader error
Hello, I get the following error while trying to replicate the Nanostring tutorial. I tried installing both the 'dev' version from Github as well as Squidpy 1.2.2.
KeyError Traceback (most recent call last)
<ipython-input-4-7bda0e6b47ad> in <module>
2 sample_dir = "/jnmark/Nanostring/Lung5_Rep1/Lung5_Rep1-Flat_files/"
3
----> 4 adata = sq.read.nanostring(
5 path=sample_dir,
6 counts_file="Lung5_Rep1_exprMat_file.csv",
~/.local/lib/python3.8/site-packages/squidpy/read/_read.py in nanostring(path, counts_file, meta_file, fov_file)
238 if fname.endswith(file_extensions):
239 fov = str(int(pat.findall(fname)[0]))
--> 240 adata.uns[Key.uns.spatial][fov]["images"][kind] = _load_image(path / subdir / fname)
241
242 if fov_file is not None:
KeyError: '31'
hi @jnmark , can you try to install from current main? the problem should be fixed
fixed in main
Hello @giovp , I have a similar issue (on squidpy 1.2.4.dev2+g1397d11):
KeyError Traceback (most recent call last) Input In [2], in <cell line: 4>() 1 nanostring_dir = Path().resolve() / "Spatial_platform_evaluation" 2 sample_dir = nanostring_dir / "Nanostring_Lung" ----> 4 adata = sq.read.nanostring( 5 path=sample_dir, 6 counts_file="Lung5_Rep1_exprMat_file.csv", 7 meta_file="Lung5_Rep1_metadata_file.csv", 8 fov_file="Lung5_Rep1_fov_positions_file.csv", 9 )
File ~/.conda/envs/stpy/lib/python3.8/site-packages/squidpy/read/_read.py:255, in nanostring(path, counts_file, meta_file, fov_file) 253 if fname.endswith(file_extensions): 254 fov = str(int(pat.findall(fname)[0])) --> 255 adata.uns[Key.uns.spatial][fov]["images"][kind] = _load_image(path / subdir / fname) 257 if fov_file is not None: 258 fov_positions = pd.read_csv(path / fov_file, header=0, index_col=fov_key)
KeyError: '32'
Thanks!
hi @carlosf79 ,
I just tried by re-downloading the data and using latest squidpy from main and don't have any issue, it reads properly with these 2 expected warnings
WARNING: FOV `31` does not exist, skipping it.
WARNING: FOV `32` does not exist, skipping it.
could it be that you have 2 versions of squidpy installed in your conda env>?
Hi @giovp , thanks for checking this.
I have tried with two freshly made condaenvs, one with
pip install 'squidpy[interactive]'
and one with
pip install git+https://github.com/scverse/squidpy@main
I have the same error in both cases. If I have installed things correctly, then it should be something else with my system - will look into it. Do you have any suggestions on what could potentially be? Thanks!
can you share the code snippet you used?
@giovp I am also getting this Key Error pointing at this line in the sq.read.nanostring function, Squidpy v1.2.2
I'm wondering whether this actually has something to do with the files provided by Nanostring, do you have any sense of which input file I should look in to see if there is something improperly annotated as '26'?
Worth noting that the function worked just fine in the same Conda environment on two other slides of data from the same Nanostring CosMx run
Wait, yeah, this is probably an issue with the files provided by Nanostring. I just checked in /5 Raw Data/RunXXXX/CellComposite, CellLabels, etc. contain the wrong FOVs (from another slide of data that had 26 FOV instead of 23). I'd bet that's the problem
Edit: Last update on this, I think that TAP has some bugs in the R code they use to generate these directories. The first 23 FOVs are correct but FOVs 24-26 are the same images as present for my other sample. So it must append extra images in certain cases! I manually deleted the extra FOV image files and I was able to import the dataset without trouble
I think at should add a check that warns if the FOV file is present (but not in the annotations) and vice-versa.
it'd be useful to know which dataset you have tried @cdpolt @carlosf79 , thanks!
@giovp it is a dataset we generated from Nanostring Tech Access Program (if you think it would be helpful we can try figure out a way I can share some of the files with you to reproduce) but I am nearly positive the issue I am seeing with reader key error is due to their delivery of the data being misformatted, nothing to do with squidpy itself! just want others dropping by this thread to be able to try to fix their issue by removing the extra files from the folder as I did.
I had the same error as above when downloading the dataset from this tutorial: https://squidpy.readthedocs.io/en/stable/external_tutorials/tutorial_nanostring.html
!mkdir tutorial_data
!mkdir tutorial_data/nanostring_data
!wget -P tutorial_data/nanostring_data https://nanostring-public-share.s3.us-west-2.amazonaws.com/SMI-Compressed/Lung5_Rep2/Lung5_Rep2+SMI+Flat+data.tar.gz
!tar -xzf tutorial_data/nanostring_data/Lung5_Rep2+SMI+Flat+data.tar.gz -C tutorial_data/nanostring_data/.
I fixed it by removing the lines with fov greater than 30 in the file "Lung5_Rep2_fov_positions_file.csv".