Skip to content

addRoiScatter

addRoiScatter

addRoiScatter(
    data,
    method=None,
    marker=None,
    threshold=0.5,
    raw=False,
    log=False,
    subset=None,
    imageId="imageid",
    xCoordinate="X_centroid",
    yCoordinate="Y_centroid",
    size=5,
    cmap="gist_heat",
    lassoAlpha=0.8,
    lassoLinewidth=3,
    lassoColor="red",
    roiName="selected_roi",
    label="roi_scatter",
    sdataTable=None,
)

Label a region of interest by thresholding a marker.

scimap's addROI_scatter opened a Matplotlib window and let you lasso cells by hand. That does not work in a script, a notebook running headless, or CI, so the scimappro version defines the ROI by a rule instead: cells above threshold for marker are labelled roiName, everything else 'Other', and the result goes into obs[label].

It is a thin wrapper over sp.tl.classify; use that directly when you want more than one positive marker or a negative one.

For hand-drawn ROIs, draw them in OMERO and import them with sp.helpers.addROI_omero.

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
method str

Accepted for signature compatibility with scimap. Only marker thresholding is implemented.

None
marker (str | list, required)

The marker(s) whose intensity defines the ROI. A ValueError is raised when omitted.

None
threshold float

Cells at or above this value are inside the ROI. 0.5 is the boundary on data rescaled by sp.pp.rescale.

0.5
raw bool

Accepted for signature compatibility with scimap.

False
log bool

Accepted for signature compatibility with scimap.

False
subset str | list

Accepted for signature compatibility with scimap.

None
imageId str

Column in obs holding image identifiers.

'imageid'
xCoordinate str

Column in obs holding x positions.

'X_centroid'
yCoordinate str

Column in obs holding y positions.

'Y_centroid'
size float

Accepted for signature compatibility with scimap's interactive plot.

5
cmap str

Accepted for signature compatibility with scimap's interactive plot.

'gist_heat'
lassoAlpha float

Accepted for signature compatibility with scimap's interactive plot.

0.8
lassoLinewidth float

Accepted for signature compatibility with scimap's interactive plot.

3
lassoColor str

Accepted for signature compatibility with scimap's interactive plot.

'red'
roiName str

Label given to cells inside the ROI.

'selected_roi'
label str

Column in obs the ROI labels are written to.

'roi_scatter'
sdataTable str

Which SpatialData table to use.

None

Returns:

Name Type Description
adata AnnData | SpatialData

The input with obs[label] set to roiName or 'Other'.

Example
adata = sp.pl.addRoiScatter(
    adata, marker="ECAD", threshold=0.5, roiName="tumour", label="roi"
)
adata.obs["roi"].value_counts()

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