mantispy.pp.normalize#
- mantispy.pp.normalize(adata, method='mad_robustize', by='Metadata_Plate', reference='negcon', epsilon=1e-18, keep_raw=False, layer=None, key_added=None, copy=False)[source]#
Normalize features within groups, optionally fitting on reference rows only.
- Parameters:
- adata
AnnData Object to normalize.
- method
str(default:'mad_robustize') "mad_robustize"computes(x - median) / (1.4826 * MAD + epsilon),"standardize"computes(x - mean) / sd, and"robustize"computes(x - median) / IQR.- by
str|list[str] |None(default:'Metadata_Plate') Column(s) defining the groups statistics are computed within, usually the plate.
Nonefits one set of statistics globally.- reference
str|None(default:'negcon') Rows to fit on:
"negcon"(the default) for the rows whoseMetadata_Control_Typeis"negcon",Nonefor all rows, or the name of a booleanobscolumn.- epsilon
float(default:1e-18) Added to the MAD, matching pycytominer’s
mad_robustize_epsilon. Unused by the other methods.- keep_raw
bool(default:False) Store the pre-normalization matrix in
layers["raw"]. Off by default, because the layer doubles memory and the raw table is already on disk.- layer
str|None(default:None) Read this layer instead of
X.- key_added
str|None(default:None) Write to
layers[key_added]instead of overwritingX.- copy
bool(default:False) Return a normalized copy instead of normalizing in place.
- adata
- Return type:
- Returns:
None, or the normalized copy whencopy=True. WritesXorlayers[key_added], andvar["degenerate_scale"], orvar["degenerate_scale_<key_added>"]when writing to a layer, which flags features that have no spread in some group or no reference values to centre on there, and comes with a warning; drop those features before computing distances.- Raises:
ValueError – If
methodis unknown, orreferenceselects no rows at all or none in some group.