opendvp.tl.filter_by_annotation

opendvp.tl.filter_by_annotation#

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.

Parameters:
  • adata (anndata.AnnData) – AnnData object with cell centroids in adata.obs[['X_centroid', 'Y_centroid']] and unique ‘CellID’.

  • path_to_geojson (str) – Path to the GeoJSON file containing polygon annotations with a ‘classification’ property.

  • cell_id_col (str, default 'CellID') – Name of the column in adata.obs that uniquely identifies each cell.

  • x_y (Sequence[str], default ("X_centroid", "Y_centroid")) – Names of columns in adata.obs containing the X and Y spatial coordinates of cells.

  • any_label (str, 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:

The input AnnData with new boolean columns in .obs for each annotation class and a summary column.

Return type:

anndata.AnnData

Raises:

ValueError – If the GeoJSON is missing geometry, not polygons, or if required columns are missing.