mantispy.tl.moa_enrichment#

mantispy.tl.moa_enrichment(adata, moa_key='Metadata_MOA', groupby='Metadata_Perturbation', k=10, metric='cosine', use_rep=None, key_added='moa_enrichment', copy=False)[source]#

Test which mechanisms are over-represented among each profile’s nearest neighbors.

For each profile and mechanism, a hypergeometric test asks whether the mechanism is more common among the k nearest neighbors than among all other profiles.

Parameters:
adata AnnData

Profiles to test, one row per treatment or per well.

moa_key str (default: 'Metadata_MOA')

obs column holding the mechanism labels.

groupby str (default: 'Metadata_Perturbation')

obs column naming each profile in the output table.

k int (default: 10)

Number of neighbors considered, capped at n_obs - 1. Smaller values are more local and less powerful.

metric str (default: 'cosine')

As in nn_moa_classify().

use_rep str | None (default: None)

As in nn_moa_classify().

key_added str (default: 'moa_enrichment')

Name for the output table.

copy bool (default: False)

Return a modified copy instead of mutating in place.

Return type:

AnnData | None

Returns:

None, or the modified copy. Writes uns["mantispy"][key_added] with group, moa, n_neighbours, pvalue and qvalue, one row per annotated profile and per mechanism found among its neighbors.

Raises:

ValueError – k is less than 1, or obs[moa_key] has no annotated rows.

Notes

Unannotated profiles are not tested, but they can be neighbors. They take up places among the k neighbors without adding to any mechanism’s count, and they are part of the population the test draws from. The profile itself is excluded from both its neighborhood and the population.