Skill Tracer
Skills › Scientific Agent Skills › bulk-rnaseq › design-and-qc.md

design-and-qc.md

73 lines · skills/bulk-rnaseq/references/design-and-qc.md at 5f2bc03

Open on GitHub
1# Experimental design and QC
2
3The statistics downstream are only as good as the design and the QC gates. Decide design **before** sequencing; apply QC **before, during, and after** quantification. This is what makes a bulk RNA-seq result defensible.
4

Experimental design and QC

The statistics downstream are only as good as the design and the QC gates. Decide design before sequencing; apply QC before, during, and after quantification. This is what makes a bulk RNA-seq result defensible.

Raw lines 1 to 4
5## Experimental design
6

Experimental design

Raw lines 5 to 6
7### Replication
8- Use **biological** replicates (independent samples), not technical (same library re-sequenced). Technical replicates measure machine noise, not biological variability, and don't license generalization.
9- **≥3 per group is a planning starting point**, not a power guarantee; choose sample size from expected dispersion, effect sizes and the intended contrast. Two per group can be fitted but give fragile inference. The bundled validator uses a conservative policy of at least two per group and recommends three; this is not a universal DESeq2 mathematical requirement.
10- Once adequate depth is reached, biological replication often adds more power than deeper sequencing. Evaluate the tradeoff for the assay and target genes.

Replication

  • Use biological replicates (independent samples), not technical (same library re-sequenced). Technical replicates measure machine noise, not biological variability, and don't license generalization.
  • ≥3 per group is a planning starting point, not a power guarantee; choose sample size from expected dispersion, effect sizes and the intended contrast. Two per group can be fitted but give fragile inference. The bundled validator uses a conservative policy of at least two per group and recommends three; this is not a universal DESeq2 mathematical requirement.
  • Once adequate depth is reached, biological replication often adds more power than deeper sequencing. Evaluate the tradeoff for the assay and target genes.
Raw lines 7 to 11
12### Depth, length, layout
13- ~20–30M mapped reads/sample is a rough planning example for many mammalian gene-level studies, not a QC cutoff. Push higher (50M+) for lowly expressed genes, novel transcripts, or isoform-level work.
14- Paired-end and longer reads help mapping/isoforms but aren't required for gene-level DE; single-end is fine if that's what you have.
15- Keep layout, read length, kit, and depth **consistent across all samples** in a comparison.

Depth, length, layout

  • ~20–30M mapped reads/sample is a rough planning example for many mammalian gene-level studies, not a QC cutoff. Push higher (50M+) for lowly expressed genes, novel transcripts, or isoform-level work.
  • Paired-end and longer reads help mapping/isoforms but aren't required for gene-level DE; single-end is fine if that's what you have.
  • Keep layout, read length, kit, and depth consistent across all samples in a comparison.
Raw lines 12 to 16
17### Avoid confounding (the design killer)
18- A **batch** is anything technical that varies across samples: processing day, sequencing lane/flowcell, kit lot, operator, RNA extraction round.
19- If a batch is perfectly aligned with your condition (all treated processed Monday, all controls Tuesday), the biological effect is **mathematically unrecoverable**. No analysis fixes this.
20- Defenses: **randomize** sample-to-batch assignment, and **balance** so every batch contains every condition. Record all batch variables in the metadata.

Avoid confounding (the design killer)

  • A batch is anything technical that varies across samples: processing day, sequencing lane/flowcell, kit lot, operator, RNA extraction round.
  • If a batch is perfectly aligned with your condition (all treated processed Monday, all controls Tuesday), the biological effect is mathematically unrecoverable. No analysis fixes this.
  • Defenses: randomize sample-to-batch assignment, and balance so every batch contains every condition. Record all batch variables in the metadata.
Raw lines 17 to 21
22### Design formulas (hand to PyDESeq2)
23- A conventional additive design is: `~batch + condition`.
24- Continuous covariate: `~age + condition` (ensure it's numeric).
25- Interaction (does the treatment effect differ by genotype?): `~genotype + condition + genotype:condition`.
26- The design matrix must be **full rank** with positive residual degrees of freedom. A crosstab is an initial diagnostic, not proof of estimability; check the complete encoded matrix including subjects, interactions and covariates. Do not discard a confounded batch and then claim an isolated treatment effect. Set reference levels and an explicit contrast: column order alone does not specify the scientific comparison.

Design formulas (hand to PyDESeq2)

  • A conventional additive design is: ~batch + condition.
  • Continuous covariate: ~age + condition (ensure it's numeric).
  • Interaction (does the treatment effect differ by genotype?): ~genotype + condition + genotype:condition.
  • The design matrix must be full rank with positive residual degrees of freedom. A crosstab is an initial diagnostic, not proof of estimability; check the complete encoded matrix including subjects, interactions and covariates. Do not discard a confounded batch and then claim an isolated treatment effect. Set reference levels and an explicit contrast: column order alone does not specify the scientific comparison.
Raw lines 22 to 27
28## QC gates
30The ranges below are investigation triggers, not universal pass/fail limits. Interpret them
31against organism, library protocol, RNA integrity, reference and study-wide distributions.

QC gates

The ranges below are investigation triggers, not universal pass/fail limits. Interpret them against organism, library protocol, RNA integrity, reference and study-wide distributions.

Raw lines 28 to 32
33### Raw-read QC (FastQC / MultiQC)
34- **Per-base quality** — bulk of bases ≥ Q30; some drop at read ends is normal (trimming/soft-clipping handles it).
35- **Adapter content** — flagged adapters → trim (Path B step 2; Path A does it automatically).
36- **Over-represented sequences** — adapters, rRNA, or highly expressed transcripts. Persistent rRNA suggests poor depletion.
37- **GC content** — a bimodal/odd distribution can indicate contamination.
38- **Sequence duplication** — high duplication is *expected* in RNA-seq (highly expressed genes); see below.

Raw-read QC (FastQC / MultiQC)

  • Per-base quality — bulk of bases ≥ Q30; some drop at read ends is normal (trimming/soft-clipping handles it).
  • Adapter content — flagged adapters → trim (Path B step 2; Path A does it automatically).
  • Over-represented sequences — adapters, rRNA, or highly expressed transcripts. Persistent rRNA suggests poor depletion.
  • GC content — a bimodal/odd distribution can indicate contamination.
  • Sequence duplication — high duplication is expected in RNA-seq (highly expressed genes); see below.
Raw lines 33 to 39
40### Alignment / quantification QC
41- **STAR uniquely-mapped %** — typically >70–80% for a good library/reference. Low → wrong/old reference, contamination, or degraded RNA.
42- **Salmon mapping rate** (`logs/salmon_quant.log`) — usually >70%. Low → investigate reference mismatch, contamination, read quality and library type. Decoys improve assignment specificity and can reduce transcript mapping; their absence is not a simple explanation for a low rate.
43- **featureCounts assigned %** — low "assigned" with high "unassigned_NoFeatures" often means **wrong strandedness** (`-s`).
44- **rRNA fraction** — high rRNA wastes reads; note it, and consider `--remove_ribo_rna` on Path A.
45- Verify **strandedness** matches across tools (see `upstream-manual.md`).

Alignment / quantification QC

  • STAR uniquely-mapped % — typically >70–80% for a good library/reference. Low → wrong/old reference, contamination, or degraded RNA.
  • Salmon mapping rate (logs/salmon_quant.log) — usually >70%. Low → investigate reference mismatch, contamination, read quality and library type. Decoys improve assignment specificity and can reduce transcript mapping; their absence is not a simple explanation for a low rate.
  • featureCounts assigned % — low "assigned" with high "unassigned_NoFeatures" often means wrong strandedness (-s).
  • rRNA fraction — high rRNA wastes reads; note it, and consider --remove_ribo_rna on Path A.
  • Verify strandedness matches across tools (see upstream-manual.md).
Raw lines 40 to 46
47### Don't deduplicate for standard DE
48PCR/optical duplicates look alarming but in RNA-seq mostly reflect genuine high expression. Standard gene-level DE (DESeq2) does **not** remove duplicates. Only consider dedup with UMIs (use the UMI, not coordinate dedup).

Don't deduplicate for standard DE

PCR/optical duplicates look alarming but in RNA-seq mostly reflect genuine high expression. Standard gene-level DE (DESeq2) does not remove duplicates. Only consider dedup with UMIs (use the UMI, not coordinate dedup).

Raw lines 47 to 49
50### Post-quantification QC (before trusting DE)
51Always do this on the counts, ideally on variance-stabilized/log values:
52- **PCA** — do biological replicates cluster? Does the main axis separate your condition, or a batch? A technical batch dominating PC1 warrants checking design and data quality; include it only when estimable and scientifically justified. An obvious outlier may be a swap/failure.
53- **Sample-distance heatmap / hierarchical clustering** — confirms grouping and exposes mislabeled or swapped samples.
54- If a batch clearly structures the data, add it to the design (`~batch + condition`); if it's unknown, consider surrogate-variable / RUV approaches (out of scope here — note it).

Post-quantification QC (before trusting DE)

Always do this on the counts, ideally on variance-stabilized/log values:

  • PCA — do biological replicates cluster? Does the main axis separate your condition, or a batch? A technical batch dominating PC1 warrants checking design and data quality; include it only when estimable and scientifically justified. An obvious outlier may be a swap/failure.
  • Sample-distance heatmap / hierarchical clustering — confirms grouping and exposes mislabeled or swapped samples.
  • If a batch clearly structures the data, add it to the design (~batch + condition); if it's unknown, consider surrogate-variable / RUV approaches (out of scope here — note it).
Raw lines 50 to 55
56### After DE: p-value histogram
57- Under a calibrated continuous null, null p-values are uniform; real signal may add a peak near zero. Discrete low-count tests and filtering can change the appearance, so interpret the histogram with model diagnostics.
58- A peak near one or a U-shape is not by itself proof of a broken design. Inspect count distributions, outliers, filtering and covariates. Do not tune the model or exclude samples simply to obtain the desired histogram or more discoveries.

After DE: p-value histogram

  • Under a calibrated continuous null, null p-values are uniform; real signal may add a peak near zero. Discrete low-count tests and filtering can change the appearance, so interpret the histogram with model diagnostics.
  • A peak near one or a U-shape is not by itself proof of a broken design. Inspect count distributions, outliers, filtering and covariates. Do not tune the model or exclude samples simply to obtain the desired histogram or more discoveries.
Raw lines 56 to 59
60## Quick gate checklist
62```
63[ ] >=3 biological replicates per group
64[ ] batch recorded and NOT confounded with condition
65[ ] raw FastQC reviewed; adapters trimmed
66[ ] mapping/assignment rate acceptable; strandedness verified
67[ ] PCA + sample-distance heatmap inspected; outliers/swaps resolved
68[ ] design full-rank, residual degrees of freedom positive, contrast explicit
69[ ] p-value histogram sane after DE
70[ ] versions pinned (pipeline -r, tools, genome+annotation release)
71```
73Official statistical reference: [DESeq2 vignette](https://bioconductor.org/packages/release/bioc/vignettes/DESeq2/inst/doc/DESeq2.html), including design rank, contrasts and transformed-count QC.

Quick gate checklist

[ ] >=3 biological replicates per group
[ ] batch recorded and NOT confounded with condition
[ ] raw FastQC reviewed; adapters trimmed
[ ] mapping/assignment rate acceptable; strandedness verified
[ ] PCA + sample-distance heatmap inspected; outliers/swaps resolved
[ ] design full-rank, residual degrees of freedom positive, contrast explicit
[ ] p-value histogram sane after DE
[ ] versions pinned (pipeline -r, tools, genome+annotation release)

Official statistical reference: DESeq2 vignette, including design rank, contrasts and transformed-count QC.

Raw lines 60 to 73