Skip to content

addRoiImage

addRoiImage

addRoiImage(
    imagePath,
    data,
    roi=None,
    outputDir=None,
    show=True,
    returnData=False,
    returnFig=False,
    sdataTable=None,
    **kwargs
)

Attach ROI polygons to the cell table.

scimap's addROI_image opened the raw image in napari and let you draw regions by hand. scimappro takes the polygons as data instead: pass a roi table (the same shape sp.helpers.addROI_omero takes, i.e. an OMERO ROI export) and each cell is labelled by the region it falls in.

With roi=None the table is returned unchanged, which makes the function safe to leave in a pipeline whose ROIs have not been drawn yet.

Note that imagePath is the first parameter here — this is the one function in scimappro where data is not first, because the image is what identifies the ROIs.

Parameters:

Name Type Description Default
imagePath (str, required)

Path to the image the ROIs were drawn on. Recorded for provenance; the image is not read.

required
data (AnnData | SpatialData | str, required)

The cell table. An AnnData, a path to an .h5ad file, a SpatialData object, or a path to a .zarr SpatialData store.

required
roi DataFrame | str

ROI polygons to apply, in the OMERO export format. None returns the table unchanged.

None
outputDir str

Directory to write the updated object to. With None the object is returned.

None
show bool

Accepted for signature compatibility with scimap; nothing is drawn.

True
returnData bool

Return obs as a DataFrame instead of the object.

False
returnFig bool

Return (None, None) — or (None, None, obs) with returnData — for callers that unpack a plotting-style return value.

False
sdataTable str

Which SpatialData table to use.

None
**kwargs dict

Forwarded to sp.helpers.addROI_omero when roi is given.

{}

Returns:

Name Type Description
result AnnData | SpatialData | DataFrame | tuple

The updated object by default; obs with returnData=True; a (None, None) tuple with returnFig=True.

Example
import pandas as pd

roi = pd.read_csv("rois_from_omero.csv")
adata = sp.pl.addRoiImage("registration/image.tif", adata, roi=roi)
sp.pl.spatialScatterPlot(adata, colorBy="ROI", s=3)