mantispy.tl.neighbors_local_density#

mantispy.tl.neighbors_local_density(adata, k=15, by='Metadata_ImageID', key_added='Metadata_LocalDensity', copy=False)[source]#

Mean distance to the k nearest cells in the same field of view.

Local crowding changes morphology independently of treatment. Consider regressing it out with regress_out() before attributing a change to a perturbation.

Parameters:
adata AnnData

Single-cell object carrying Metadata_Center_X and Metadata_Center_Y.

k int (default: 15)

Number of neighbors averaged over.

by str (default: 'Metadata_ImageID')

obs column identifying the field of view. Neighbors are searched within each field only, since coordinates from different images are not comparable.

key_added str (default: 'Metadata_LocalDensity')

obs column written.

copy bool (default: False)

Return a modified copy instead of mutating in place.

Return type:

AnnData | None

Returns:

None, or the modified copy. Writes obs[key_added], and a cell alone in its field gets NaN.

Raises:

KeyError – obs is missing Metadata_Center_X or Metadata_Center_Y.