Skip to content

Commit

Permalink
adjusted CellComposite and CellLabels loading in read_nanostring (#766)
Browse files Browse the repository at this point in the history
Co-authored-by: Francesca Drummer <francescadrummer@Francescas-MacBook-Air.local>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Francesca Drummer <francescadrummer@Francescas-MacBook-Air.fritz.box>
Co-authored-by: Giovanni Palla <25887487+giovp@users.noreply.github.com>
  • Loading branch information
5 people committed Nov 21, 2023
1 parent c528ce7 commit aa60e26
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/squidpy/read/_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def nanostring(
"""
Read *Nanostring* formatted dataset.
In addition to reading the regular *Nanostring* output, it loads the metadata file, *CellComposite* and *CellLabels*
In addition to reading the regular *Nanostring* output, it loads the metadata file, if present *CellComposite* and *CellLabels*
directories containing the images and optionally the field of view file.
.. seealso::
Expand Down Expand Up @@ -252,11 +252,16 @@ def nanostring(

pat = re.compile(r".*_F(\d+)")
for subdir in ["CellComposite", "CellLabels"]:
kind = "hires" if subdir == "CellComposite" else "segmentation"
for fname in os.listdir(path / subdir):
if fname.endswith(file_extensions):
fov = str(int(pat.findall(fname)[0]))
adata.uns[Key.uns.spatial][fov]["images"][kind] = _load_image(path / subdir / fname)
if os.path.exists(path / subdir) and os.path.isdir(path / subdir):
kind = "hires" if subdir == "CellComposite" else "segmentation"
for fname in os.listdir(path / subdir):
if fname.endswith(file_extensions):
fov = str(int(pat.findall(fname)[0]))
try:
adata.uns[Key.uns.spatial][fov]["images"][kind] = _load_image(path / subdir / fname)
except KeyError:
logg.warning(f"FOV `{str(fov)}` does not exist in {subdir} folder, skipping it.")
continue

if fov_file is not None:
fov_positions = pd.read_csv(path / fov_file, header=0, index_col=fov_key)
Expand Down

0 comments on commit aa60e26

Please sign in to comment.