opendvp.tl.filter_by_annotation#
- opendvp.tl.filter_by_annotation(adata, path_to_geojson, cell_id_col='CellID', x_y=('X_centroid', 'Y_centroid'), any_label='ANY')#
Filter cells by annotation in a geojson file using spatial indexing.
This function assigns annotation classes to cells in an AnnData object by spatially joining cell centroids with polygons from a GeoJSON file. Each annotation class becomes a boolean column in
adata.obs
.- Return type:
Parameters:#
- adataad.AnnData
AnnData object with cell centroids in
adata.obs[['X_centroid', 'Y_centroid']]
and unique ‘CellID’.- path_to_geojsonstr
Path to the GeoJSON file containing polygon annotations with a ‘classification’ property.
- cell_id_colstr, default ‘CellID’
Name of the column in
adata.obs
that uniquely identifies each cell.- x_ySequence[str], default (“X_centroid”, “Y_centroid”)
Names of columns in
adata.obs
containing the X and Y spatial coordinates of cells.- any_labelstr, default ‘ANY’
Name for the column indicating if a cell is inside any annotation. This is to be used for naming the group of annotations, for example: If pathologist annotated tissue regions, call this: ‘tissue_ann’ If microscopist annotated imaging artefacts, call this: ‘img_arts’
Returns:#
- ad.AnnData
The input AnnData with new boolean columns in
.obs
for each annotation class and a summary column.
Raises:#
- ValueError
If the GeoJSON is missing geometry, not polygons, or if required columns are missing.