mantispy.tl.subpopulation_hits

mantispy.tl.subpopulation_hits#

mantispy.tl.subpopulation_hits(adata, cluster_key='leiden', groupby='Metadata_Perturbation', reference='negcon', use_rep=None, min_cells=3, key_added='subpopulation_hits', copy=False)[source]#

Test each perturbation against the controls within each cluster.

An effect confined to one cell state is diluted by the other states in a well median. Comparing cells within a cluster avoids that.

Parameters:
  • adata (AnnData) – Clustered single-cell object.

  • cluster_key (str (default: 'leiden')) – obs column holding the cluster label.

  • groupby (str (default: 'Metadata_Perturbation')) – obs column holding the perturbation.

  • reference (str | None (default: 'negcon')) – Which rows are the controls, "negcon" or the name of a boolean obs column.

  • use_rep (str | None (default: None)) – Measure in obsm[use_rep] instead of X.

  • min_cells (int (default: 3)) – Skip a (cluster, group) pair with fewer cells than this on either side.

  • key_added (str (default: 'subpopulation_hits')) – 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 cluster, group, n_cells, statistic (KS), pvalue and qvalue.

Notes

Each cell is reduced to its Euclidean distance from the control centroid of its own cluster, and a KS test compares the treated cells’ distances with the controls’. This is close to hit_calling(method="ks"), restricted to comparable cells. A distance is used rather than a single feature so that the test means the same on every dataset.