mantispy.pp.regress_out#
- mantispy.pp.regress_out(adata, keys=('Metadata_CellCount',), by='Metadata_Plate', key_added=None, copy=False)#
Regress confounders out of every feature, within groups.
- Parameters:
adata (
AnnData) – Object to correct.keys (
Sequence[str] (default:('Metadata_CellCount',))) –obscolumns 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, whichsc.pp.regress_outcannot do.Nonefits one model globally.key_added (
str|None(default:None)) – Write tolayers[key_added]instead of overwritingX.copy (
bool(default:False)) – Return a modified copy instead of mutating in place.
- Returns:
the mean over the whole object for a numeric covariate, and the group’s own mean for a categorical one, which keeps the units of the data.
- Return type:
- Raises:
KeyError – If any of
keysis not anobscolumn.ValueError – If a categorical covariate has missing values.
Notes
Missing and infinite values stay as they are, and a feature holding one is fitted on its finite rows. A group with no more rows than design columns is left uncorrected and logged.
Whether the cell count is a confounder at all depends on the screen. In the ORF and CRISPR arms of JUMP, whose plate layouts were not randomized, it is largely technical, and the recipe regresses it out [Chandrasekaran et al., 2023]. In a compound screen it is partly a treatment effect — a compound that kills cells is supposed to lower it — so regressing it out removes part of the phenotype along with the nuisance, and the recipe does not. Measure both ways before adopting either;
evaluate_correction()takes acovariatesargument for exactly this, andcytotoxicity()asks the question directly.A numeric covariate with a missing or infinite value is dropped from that group’s design and nothing is regressed out for it there, with a warning. A categorical covariate with a missing label is refused instead: the all-zero encoding of a missing category is also the encoding of the level
drop_firstremoved, so those rows would be corrected as the reference level and take every other row with them.