scverse / scverse/spatialdata-io

Cosmx reader: CellOverlay is skipped

Open
#313 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
103
Forks
65
Avg merge
1h 8m
Merged PRs (30d)
3

Description

Dear,

First, thank you for creating this package! It's been incredibly helpful in processing my CosMx data.

I wanted to share a quick observation in case it helps anyone else. When downloading raw CosMx data, there are not only CellComposite folders, but also CellOverlay folder. These overlays are part of the standard CosMx workflow, where cells are segmented and the images are included in the download. However, the current CosMx reader doesn’t load these CellOverlay images into the spatial data object.

To address this, I've added a few lines to cosmx.py to enable the reading of these images. While it’s not the cleanest solution, it works for now. Here’s the code snippet I used:

        for fname in os.listdir(path / cell_overlay):
            if fname.endswith(file_extensions):
                fov = str(int(pat.findall(fname)[0]))
                if fov in fovs_counts:
                    aff = affine_transforms_to_global[fov]
                    im = imread(path / cell_overlay / fname, **imread_kwargs).squeeze()
                    flipped_im = da.flip(im, axis=0)
                    parsed_im = Image2DModel.parse(
                        flipped_im,
                        transformations={
                            fov: Identity(),
                            "global": aff,
                            "global_only_image": aff,
                        },
                        dims=("y", "x", "c"),
                        rgb=None,
                        **image_models_kwargs,
                    )
                    images[f"{fov}_overlay"] = parsed_im
                else:
                    logger.warning(f"FOV {fov} not found in counts file. Skipping image {fname}.")

To implement this, simply add the code to line 208 in CosMx.py, and it should work.

I’m happy to help further or discuss any potential improvements to this solution.

Kind regards,
Steven

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in cosmx.py around line 208 and compare how CellComposite folders are discovered and loaded with the reported CellOverlay case. Verify the proposed handling for overlay filenames, FOV matching, image parsing, and transformations, then confirm that CellOverlay images appear in the spatial data object without skipping valid files.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.