# Batch Effect Correction

Use when correcting batch effects in merged bulk expression matrices with sample-level...

- Repository: https://github.com/aipoch/medical-research-skills (2020 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-09-17
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add aipoch/medical-research-skills --skill batch-effect-correction -g -a claude-code -y`
Codex: `npx skills add aipoch/medical-research-skills --skill batch-effect-correction -g -a codex -y`
Cursor: `npx skills add aipoch/medical-research-skills --skill batch-effect-correction -g -a cursor -y`
Gemini CLI: `npx skills add aipoch/medical-research-skills --skill batch-effect-correction -g -a gemini-cli -y`

## Description

Use when correcting batch effects in merged bulk expression matrices with sample-level batch metadata while preserving biological group structure and generating before-and-after QC plots. NOT for: single-cell integration, raw FASTQ processing, differential expression without batch labels, or datasets without biological groups.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Batch Effect Correction

## Prerequisites

Run the following before the first analysis to install all required R packages:

```bash
Rscript -e "if (!require('BiocManager', quietly=TRUE)) install.packages('BiocManager'); BiocManager::install(c('sva', 'limma')); install.packages('ggplot2', repos='https://cloud.r-project.org')"
```

> Note: `sva` and `limma` are Bioconductor packages and require `BiocManager` for installation. `ggplot2` is a standard CRAN package.

**The skill cannot run until these packages are installed.** In new or bare R environments, always run the prerequisite step first.

---

## When to Read External Files

| Situation | File to Read | Purpose |
|-----------|--------------|---------|
| **Need algorithm details** | `references/algorithm.md` | ComBat workflow, assumptions, and QC logic |
| **Need to run analysis** | `scripts/main.R` | Execute: `Rscript scripts/main.R --input_file ... --group_file ...` |
| **Encounter errors** | `references/troubleshooting.md` | Common errors and solutions |
| **Need CLI examples** | `references/cli-guide.md` | Detailed CLI usage examples and baseline run record |
| **Need test data** | `tests/data/` | Sample input files for testing |

---

## Usage

```bash
Rscript scripts/main.R \
  --input_file ./expression_matrix.csv \
  --group_file ./sample_info.csv \
  --output_dir ./output/ \
  --batch_column batch \
  --group_column group \
  --sample_column sample \
  --log_transform auto \
  --timeout_seconds 600 \
  --seed 42
```

---

## Arguments

The rest: https://github.com/aipoch/medical-research-skills/blob/HEAD/awesome-med-research-skills/Data Analysis/batch-effect-correction/SKILL.md
