goatpy.batch_correction
Batch correction for MALDI SpatialData objects.
Supports two methods:
- Harmony
Operates on a PCA embedding. Corrected embeddings are stored in:
adata.obsm[“X_pca_harmony”]
The raw intensity matrix (adata.X) is NOT modified.
- ComBat
Operates directly on adata.X. Corrected intensities overwrite:
adata.X
This function assumes the data has already been normalised (e.g. TIC or RMS normalisation).
Applying batch correction to raw counts will produce misleading results.
USAGE
# Option 1 — merge inside batch_correction merged = batch_correction(
sdatas=[sdata1, sdata2], batch_names=[“A”, “B”], method=”harmony”,
)
# Option 2 — use an already merged object merged = batch_correction(
pre_merged=merged_sdata, method=”combat”,
)
Functions
|
Merge SpatialData objects and apply batch correction. |
Module Contents
- goatpy.batch_correction.batch_correction(sdatas: list[spatialdata.SpatialData] | None = None, batch_names: list[str] | None = None, pre_merged: spatialdata.SpatialData | None = None, method: Literal['harmony', 'combat'] = 'harmony', pcs: int = 30, covariates: list[str] | None = None, table_name: str = 'maldi_adata', batch_col: str = 'batch', feature_join: str = 'inner', random_state: int = 42) spatialdata.SpatialData[source]
Merge SpatialData objects and apply batch correction.
- Parameters:
sdatas – SpatialData objects to merge.
batch_names – Batch labels corresponding to sdatas.
pre_merged – Already merged SpatialData object. If provided, merge_spatialdata is skipped.
method – “harmony” or “combat”
pcs – Number of PCs for Harmony.
covariates – Covariates to preserve during ComBat.
table_name – AnnData table name.
batch_col – obs column containing batch labels.
feature_join – “inner” or “outer”
random_state – Random seed for Harmony.
- Return type:
SpatialData