Bulkrna batch correction

From TianGzlab/OmicsClaw · View interactive version

Bulkrna batch correction is an AI agent skill from the GitHub repository TianGzlab/OmicsClaw. Load when correcting batch effects in bulk expression using R sva ComBat or the legacy Python parametric approximation. Skip single-batch inputs; use sc-batch-integration for single-cell data or spatial-integrate for spatial slices.

How to use this skill

Skill file

bulkrna-batch-correction

When to use

Load when correcting batch effects in bulk expression using R sva ComBat or the legacy Python parametric approximation. Skip single-batch inputs; use sc-batch-integration for single-cell data or spatial-integrate for spatial slices.

Use from a step

from skills._sdk.notebook import load_skill, write_output
library = load_skill("bulkrna-batch-correction")
result = library.correct(data, batches=batches, backend="python")
write_output(result, "tables/result.csv")
write_output(library.pca_figure(result, batches=batches), "figures/result.png")

Read expression and metadata with read_input before calling the library.

examples/example_step.py constructs a small synthetic dataset and checks

its results through the step runner and fresh-kernel replay.

API

<!-- api:begin generated from _api.py; regenerate with run.py api <skill dir> --write -->

`correct(data: pd.DataFrame, *, batches: pd.DataFrame, mode: str='parametric', backend: str='auto') -> pd.DataFrame`

Return corrected expression, leaving the input unchanged.

:param data: Finite nonnegative expression, features by samples; correction uses this scale directly.

:param batches: Metadata with sample and batch columns, and optional biological condition.

:param mode: CLI default parametric, or non-parametric (requires R sva).

:param backend: auto prefers R as the CLI did; r requires R, python uses the legacy parametric approximation.

:returns: Corrected DataFrame with run_info diagnostics; values can be negative.

:raises ValueError: Data, metadata, mode or backend is invalid.

:raises ImportError: An explicitly requested R backend is unavailable.

:raises RuntimeError: R fails and the requested mode/design has no Python fallback.

`run_info(data: pd.DataFrame, *, keep: bool=True) -> dict`

Return backend diagnostics and before/after batch metrics.

:param data: Result of correct.

:param keep: Keep diagnostics by default; the CLI passes False.

:returns: Diagnostics dictionary.

:raises ValueError: No correction diagnostics are attached.

`pca_figure(data: pd.DataFrame, *, batches: pd.DataFrame)`

Plot PCA after signed log2(1+abs(x)), accepting negative corrections.

:param data: Original or corrected feature-by-sample expression.

:param batches: Metadata containing sample and batch.

:returns: Matplotlib Figure.

:raises ValueError: Samples lack batch metadata.

<!-- api:end -->

Methods and parameters

The function library returns DataFrames and Figures. The CLI loads the

same library and owns reports and file writes. R runs in a temporary

directory using Matrix Market, feature/sample identifiers and metadata.

No R intermediate is a permanent CLI output.

Gotchas

Inputs and outputs

Expression CSV with feature identifiers in the first column; metadata CSV with sample and batch, plus optional condition.

CLI outputs:

CLI

python skills/bulkrna/bulkrna-batch-correction/bulkrna_batch_correction.py --demo --output /tmp/bulkrna_batch_correction_demo

Run the script with --help for real-input arguments.

See also

Dependencies

matplotlib, numpy, pandas, scipy, sva, Matrix

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.