Skip to content

addROI_omero

addROI_omero

addROI_omero(
    data,
    roi,
    xCoordinate="X_centroid",
    yCoordinate="Y_centroid",
    imageId="imageid",
    namingColumn="Name",
    subset=None,
    overwrite=True,
    label="ROI",
    bufferRoi=0,
    bufferRegions=None,
    nJobs=-1,
    verbose=False,
    outputDir=None,
    sdataTable=None,
)

Label cells by the OMERO ROI polygon they fall inside.

Export your ROIs from OMERO, pass the table here, and every cell gets the name of the region containing it — or 'Other' when it falls outside all of them. Polygons are parsed from WKT and tested point-in-polygon with shapely.

The ROI table needs a geometry column, found under any of geometry, polygon, or roi (case-insensitively), plus a name column given by namingColumn.

Parameters:

Name Type Description Default
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, required)

The ROI export: one row per region, with a WKT geometry column and a name column.

required
xCoordinate str

Column in obs holding x positions.

'X_centroid'
yCoordinate str

Column in obs holding y positions.

'Y_centroid'
imageId str

Column in obs holding image identifiers.

'imageid'
namingColumn str

Column in the ROI table holding each region's name.

'Name'
subset str | list

Only label cells from these images.

None
overwrite bool

Replace an existing obs[label] column. With False, existing labels are kept and only unlabelled cells are updated.

True
label str

Column in obs the region names are written to.

'ROI'
bufferRoi float

Grow (or, when negative, shrink) every polygon by this distance before testing, so cells just outside a boundary can still be included.

0
bufferRegions dict

Per-region buffers, {region name: distance}, overriding bufferRoi for the regions named.

None
nJobs int

Workers for the point-in-polygon test. The default -1 uses every core.

-1
verbose bool

Print progress messages.

False
outputDir str

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

None
sdataTable str

Which SpatialData table to work on. The labelled table replaces the one in the container, so keep its region_key and instance_key columns intact.

None

Returns:

Name Type Description
adata AnnData | SpatialData | None

The updated object with obs[label] naming each cell's region, or 'Other'. None when outputDir is given.

Raises:

Type Description
ImportError

When shapely is not installed. Install scimappro[roi].

ValueError

When the ROI table has no geometry, polygon, or roi column.

Example
import pandas as pd

roi = pd.read_csv("rois_from_omero.csv")
adata = sp.helpers.addROI_omero(adata, roi=roi, label="ROI")
adata.obs["ROI"].value_counts()

sp.pl.spatialScatterPlot(adata, colorBy="ROI", s=3)

# Then search the rest of the slide for regions that look like one of them.
adata = sp.tl.spatialSimilarityLookup(adata, roiColumn="ROI")