mantispy.tl.edistance#
- mantispy.tl.edistance(adata, groupby='Metadata_Perturbation', reference='negcon', use_rep=None, n_permutations=1000, threshold=0.05, max_reference=2000, seed=0, key_added='edistance', copy=False, *, replicate=None)[source]#
Energy distance between each group and the controls, or between every pair.
Energy distance,
2E|a-b| - E|a-a'| - E|b-b'|, compares whole distributions and is zero only when they are equal. It makes no distributional assumption and responds to changes in spread or shape as well as shifts, which suits single-cell resolution, where a perturbation is a population.- Parameters:
- adata
AnnData Object to score. Most informative at cell resolution.
- groupby
str(default:'Metadata_Perturbation') Column defining the populations.
- reference
str|None(default:'negcon') Rows to compare against. Each group is compared with them and gets a permutation p-value in
uns["mantispy"][key_added]. WithNone, the group-by-group distance matrix is written touns["mantispy"][key_added + "_pairwise"]as a square frame labeled by group, without p-values. Its cost is quadratic in the number of groups, which is expensive for a whole screen at cell level.max_referenceandseedapply on this path too, capping the rows taken from each group.- use_rep
str|None(default:None) Score
obsm[use_rep]instead ofX.- n_permutations
int(default:1000) Number of label permutations in the null.
- threshold
float(default:0.05) q-value below which a group is marked
is_hit.- max_reference
int(default:2000) Maximum number of rows sampled from the reference and, separately, from each group. The pooled distance matrix is quadratic in their sum, so large values need a lot of memory.
- seed
int(default:0) Seed for the subsampling and the permutations.
- key_added
str(default:'edistance') Name for the outputs.
- copy
bool(default:False) Return a modified copy instead of mutating in place.
- replicate
str|Sequence[str] |None(default:None) obscolumn, or sequence of columns, whose groups are the design’s exchangeable unit: the well in an arrayed screen, the guide ("Metadata_sgRNA") in a pooled one. The permutation null then draws whole replicates rather than cells, since cells within a well are not independent replicates (see Notes). LeftNone, it defaults to the physical well on an object stamped cell resolution with replicated wells; it warns and permutes cells when no complete well column is present, and raises on a pooled design, where some well holds both reference and tested cells.
- adata
- Return type:
- Returns:
None, or the modified copy. With a reference, writesuns["mantispy"][key_added]withgroup,n_obs,distance,pvalue,qvalueandis_hit, wheren_obscounts the rows the statistic actually used, after any subsampling and after splitting the reference. Withreference=None, writes only the square, group-labeled matrix atuns["mantispy"][key_added + "_pairwise"].- Raises:
ValueError –
referenceselects fewer than two rows, the profiles hold missing values, which cannot be scored, orreplicateis not given on a pooled design at cell resolution.
Notes
The null permutes the group and reference labels over the pooled rows and recomputes the statistic, the standard permutation test for a two-sample quantity. At cell resolution the exchangeable unit is the well, not the cell, so
replicatedraws whole wells for the pseudo-group instead; without a usable well column it warns and permutes cells, which is anti-conservative. In a pooled screen every well holds every perturbation, so drawing whole wells cannot separate a group from the reference; the exchangeable unit is the guide, and the call raises untilreplicatenames it.A group that is the reference itself is scored by splitting its rows in half, by whole replicates when one is in use. A group with fewer than two rows on either side, or a reference group with fewer than four rows, gets a NaN p-value and a warning.
Check the false positive rate on your own screen with
diagnose_testing(), which relabels control wells as pseudo-treatments of the same size and reports the fraction that are called.