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. None fits one set of statistics globally.

reference str | None (default: 'negcon')

Rows to fit on: "negcon" (the default) for the rows whose Metadata_Control_Type is "negcon", None for all rows, or the name of a boolean obs column.

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 overwriting X.

copy bool (default: False)

Return a normalized copy instead of normalizing in place.

Return type:

AnnData | None

Returns:

None, or the normalized copy when copy=True. Writes X or layers[key_added], and var["degenerate_scale"], or var["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 method is unknown, or reference selects no rows at all or none in some group.