mantispy.pp.regress_out

Contents

mantispy.pp.regress_out#

mantispy.pp.regress_out(adata, keys=('Metadata_CellCount',), by='Metadata_Plate', key_added=None, copy=False)[source]#

Regress confounders out of every feature, within groups.

Parameters:
  • adata (AnnData) – Object to correct.

  • keys (Sequence[str] (default: ('Metadata_CellCount',))) – obs columns to regress out. Numeric columns enter directly; categorical ones are one-hot encoded with the first level dropped.

  • by (str | None (default: 'Metadata_Plate')) – Fit separately within each group of this column, usually the plate, which sc.pp.regress_out cannot do. None fits one model globally.

  • key_added (str | None (default: None)) – Write to layers[key_added] instead of overwriting X.

  • copy (bool (default: False)) – Return a modified copy instead of mutating in place.

Return type:

AnnData | None

Returns:

None, or the modified copy. Each feature is replaced by its residual plus the fitted value at an anchor: the mean over the whole object for a numeric covariate, and the group’s own mean for a categorical one. This keeps the units of the data.

Notes

Missing values stay missing, and a feature with gaps is fitted on the rows where it was measured. A group with no more rows than design columns is left uncorrected and logged.