causalbench / README.md
huggingbahl21's picture
Restore CausalBench preparation code and reproduction instructions
d11f31d verified
|
Raw History Blame Contribute Delete
4.59 kB
---
license: cc-by-4.0
tags:
- biology
- single-cell
- causal-discovery
- perturb-seq
configs:
- config_name: k562
data_files:
- split: full
path: data/prepared/causalbench_k562.tsv.gz
sep: "\t"
- config_name: rpe1
data_files:
- split: full
path: data/prepared/causalbench_rpe1.tsv.gz
sep: "\t"
---
# CausalBench: K562 and RPE1
Filtered single-cell CRISPRi perturbation data from
[Replogle et al. (2022)](https://doi.org/10.25452/figshare.plus.20029387.v1),
prepared following [CausalBench](https://www.nature.com/articles/s42003-025-07764-y).
This repo packages the original inputs, preparation code, and filtered outputs
so they are easier to download and use together.
| Dataset | Cells | Genes | File |
| --- | ---: | ---: | --- |
| K562 | 162,751 | 622 | `data/prepared/causalbench_k562.tsv.gz` |
| RPE1 | 162,733 | 383 | `data/prepared/causalbench_rpe1.tsv.gz` |
Rows are cells. Gene columns use Ensembl IDs and contain normalized,
log-transformed expression. Each table also has an `intervention` column:
- A gene ID identifies the targeted gene.
- `non-targeting` identifies control cells.
- `excluded` identifies unsupported targets. These rows remain in the data
and **must not be treated as controls**.
## Sources and preprocessing
Inputs: [K562 counts](https://ndownloader.figshare.com/files/35773219),
[RPE1 counts](https://ndownloader.figshare.com/files/35775606), and the
[perturbation summary workbook](https://ars.els-cdn.com/content/image/1-s2.0-S0092867422005979-mmc2.xlsx)
(sheets `TabB_K562_day6_summary_stat` and `TabC_RPE1_summary_statistic`).
1. Keep controls and strong perturbations: >50 differentially expressed genes,
knockdown ≤−0.3, and >25 filtered cells in the summary.
2. For measured targets, retain perturbed cells with target expression at or
below the control 10th percentile.
3. Remove zero-total cells. Normalize each cell’s total to the retained-cell
median using **all original genes**, then apply natural `log1p`.
4. Keep measured genes targeted in >100 retained cells. Preserve gene order
and relabel unsupported targets `excluded` without removing their rows.
K562 was prepared with the unmodified
[CausalBench preprocessing function at commit 1a2143c](https://github.com/causalbench/causalbench/blob/1a2143cffdc85f835b41ce8d52034be1bf903e71/causalscbench/data_access/utils/preprocessing.py).
RPE1 used a memory-saving implementation of the same rules. Reconstructing both
datasets from the raw inputs reproduced all saved expression values and ordered
labels exactly.
## Files and reproduction
```text
data/raw/ Original K562/RPE1 count files and summary workbook
prepare.py Download inputs and run preprocessing
upstream/preprocessing.py Unchanged CausalBench preprocessing function
data/prepared/ Filtered NPZ arrays and gzip TSV tables
pyproject.toml + uv.lock Python environment used for reproduction
```
To download the repo, install `huggingface_hub`, then run:
```bash
hf download huggingbahl21/causalbench --repo-type dataset --local-dir causalbench
cd causalbench
uv sync --locked
uv run prepare.py all --output-dir data/rebuilt
```
The full download includes about 19 GB of raw count data. Rebuilding uses the
original CausalBench function, which loads the full matrix and needs substantial
RAM. The NPZ outputs contain `expression_matrix`, `var_names`, and `interventions`;
the TSVs contain the same data in table form. Only the prepared files are needed
for analysis; the example below downloads one of them.
## Load a table
```python
import pandas as pd
from huggingface_hub import hf_hub_download
path = hf_hub_download(
repo_id="huggingbahl21/causalbench",
repo_type="dataset",
filename="data/prepared/causalbench_rpe1.tsv.gz", # or causalbench_k562.tsv.gz
)
expression = pd.read_csv(path, sep="\t")
interventions = expression.pop("intervention")
```
## Notes for downstream use
These are filtered expression values, not raw counts. The target-expression
filter selects cells with lower target expression, so knockdown strength in
these tables is partly determined by that selection. The tables mix control
and perturbed cells; separating the label column does not make them observational.
No complete ground-truth causal graph or train/test split is provided.
Perturbation effects can include indirect effects and do not establish direct edges.
Data: **CC BY 4.0**, credited to Replogle et al. The copied preprocessing code
retains its original attribution and [Apache 2.0 license](upstream/LICENSE.txt).