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 |
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 |
'X_centroid'
|
yCoordinate
|
str
|
Column in |
'Y_centroid'
|
imageId
|
str
|
Column in |
'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 |
True
|
label
|
str
|
Column in |
'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, |
None
|
nJobs
|
int
|
Workers for the point-in-polygon test. The default |
-1
|
verbose
|
bool
|
Print progress messages. |
False
|
outputDir
|
str
|
Directory to write the updated object to. With |
None
|
sdataTable
|
str
|
Which |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
adata |
AnnData | SpatialData | None
|
The updated object with |
Raises:
| Type | Description |
|---|---|
ImportError
|
When shapely is not installed. Install |
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")