scmorph.pp.aggregate_mahalanobis

scmorph.pp.aggregate_mahalanobis#

scmorph.pp.aggregate_mahalanobis(adata, treatment_key='infer', control='DMSO', well_key='infer', per_treatment=False, cov_include_treatment=False, cov_from_single_cell=False, progress=False)[source]#

Measure distance between groups using mahalanobis distance

Parameters:
adata AnnData

Annotated data matrix

treatment_key str (default: 'infer')

Name of column in metadata used to define treatments

control str (default: 'DMSO')

Name of control treatment. Must be valid value in treatment_key.

well_key str (default: 'infer')

Name of column in metadata used to define wells. This is needed to define the covariance matrix for Mahalanobis distance.

per_treatment bool (default: False)

Whether to compute PCA and Mahalanobis distance for each treatment separately.

cov_include_treatment bool (default: False)

Whether to compute covariance matrix from control alone (False) or control and treatment together (True). If True, covariance matrices are combined through a weighted sum, where weights represent the number of replicates for this drug.

cov_from_single_cell bool (default: False)

Whether to compute covariance matrix from single cells. This computes distances directly on features with no prior PCA. As a result, cov_include_treatment and per_treatment will be ignored (both False).

progress bool (default: False)

Whether to show a progress bar

Return type:

DataFrame

Returns:

dists Mahalanobis distances between treatments