spared.layer_operations.combat_transformation
- spared.layer_operations.combat_transformation(adata: AnnData, batch_key: str, from_layer: str, to_layer: str) AnnData[source]
Perform batch correction with ComBat
Compute batch correction using the pycombat package. The batches are defined by
adata.obs[batch_key]so the user can define which variable to use as batch identifier. The input data for the batch correction isadata.layers[from_layer]and the output is stored inadata.layers[to_layer]. Importantly, as the original ComBat paper notes the data should be approximately normally distributed. Therefore, it is recommended to use this function over \(\log_2(TPM+1)\) data.- Parameters:
adata (ad.AnnData) – The AnnData object to transform. Must have logarithmically transformed data in
adata.layers[from_layer].batch_key (str) – The column in
adata.obsthat defines the batches.from_layer (str) – The layer to take the data from.
to_layer (str) – The layer to store the results of the transformation.
- Returns:
The updated AnnData object with batch corrected data in
adata.layers[to_layer].- Return type:
ad.AnnData