# bdb-genomics/chipseq-pipeline architecture

> Architecture diagram of the GitHub repository bdb-genomics/chipseq-pipeline, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bdb-genomics/chipseq-pipeline
- Repository: https://github.com/bdb-genomics/chipseq-pipeline

## Overview

1. This repository is a Snakemake-based ChIP-seq workflow, not an application server. The central orchestration boundary is the `Snakefile`, which wires together modular rule files under `rules/` and uses `config.yaml` plus the sample sheet in `data/fastp/samples.tsv` as the main inputs.

2. The pipeline is organized as a linear-but-branching genomics DAG that starts with raw paired-end FASTQ files and ends with QC reports, peak annotations, motif discovery, and summary outputs. The main processing stages are: read trimming, alignment, post-alignment cleanup, signal generation, peak calling, QC assessment, and downstream biological interpretation.

3. Input/data contract:
   - `data/fastp/samples.tsv` defines samples, conditions, replicates, FASTQ paths, and optional matched controls.
   - `config.yaml` holds all runtime parameters and file locations, including Bowtie2 index, reference genome paths, genome sizes, mitochondrial chromosome name, MACS2 settings, and QC thresholds.
   - `rules/scripts/validate_config.py` validates the config and sample sheet before execution, so bad metadata fails early rather than during job submission.

4. Pre-alignment subsystem:
   - `rules/fastp.smk` trims adapters and low-quality bases.
   - `rules/fastqc.smk` generates per-sample QC after trimming.
   These are the first quality boundary: they transform raw FASTQs into cleaned reads plus early QC artifacts.

5. Alignment and BAM processing subsystem:
   - `rules/bowtie2.smk` performs paired-end alignment.
   - `rules/samtools_sort.smk`, `rules/samtools_fixmate.smk`, `rules/samtools_markdup.smk`, `rules/samtools_view.smk`, and indexing rules handle sorting, mate correction, duplicate marking, MAPQ/flag filtering, and BAM indexing.
   - `rules/remove_mito_reads.smk` and `rules/calculate_mito_reads.smk` split out mitochondrial read handling and metrics.
   This stage turns aligned reads into analysis-ready filtered BAMs and alignment statistics.

6. Core QC and library-quality subsystem:
   - `rules/samtools_stats.smk` collects post-filter alignment stats.
   - `rules/fragment_size_analysis.smk`, `rules/picard_alignment_metrics.smk`, `rules/picard_insert_size_metrics.smk`, `rules/phantompeakqualtool.smk`, `rules/preseq.smk`, and `rules/qualimap_bamqc.smk` provide complementary assessments of fragment distribution, alignment quality, strand cross-correlation, library complexity, and BAM-level QC.
   These outputs feed the workflow’s QC decision points rather than the biological analysis directly.

7. Signal and track generation subsystem:
   - `rules/bedtools_genomecov.smk`, `rules/sorted_bedgraph.smk`, and `rules/bigwig_conversion.smk` create genome coverage tracks.
   - `rules/normalize_coverage.smk` produces normalized coverage.
   - `rules/bamCompare.smk` creates control-aware log2 ChIP-vs-control signal tracks when matched controls are present.
   This branch is the main visualization/data-sharing layer for genome browsers and downstream heatmaps.

8. Peak calling and peak refinement subsystem:
   - `rules/macs2_peak_calling.smk` performs narrow peak calling.
   - `rules/blacklist_region_filter.smk` removes peaks overlapping ENCODE blacklist regions.
   - `rules/frip_calculation.smk` computes fraction of reads in peaks.
   These steps define the primary biological signal outputs used by later annotation and QC gating.

9. Downstream interpretation subsystem:
   - `rules/heatmap.smk` generates matrix/heatmap outputs, likely centered on genomic features such as TSS regions.
   - `rules/peak_annotation.smk` uses ChIPseeker for functional annotation.
   - `rules/motif_analysis.smk` runs HOMER for de novo motif discovery.
   - `rules/correlation_analysis.smk` computes sample-level correlations from BigWig summaries.
   This is the interpretive layer that turns peaks and tracks into biological summaries.

10. QC enforcement is an explicit architectural boundary:
    - `rules/qc_gate.smk` applies threshold-based pass/fail checks on metrics such as FRiP, NSC, RSC, mapping rate, and duplicate rate.
    - The pipeline is therefore not just reporting QC; it can stop or flag samples based on configured acceptance criteria.
    This makes quality control part of the workflow logic, not an afterthought.

11. Reporting and aggregation:
    - `rules/multiqc.smk` aggregates outputs from many tools into a single MultiQC report.
    - The README indicates `results/multiqc/` is the main entry point for inspection.
    This is the top-level human-facing output boundary that consolidates the entire run.

12. Environment and reproducibility boundary:
    - `rules/envs/*.yaml` define Conda environments for the tools.
    - The README also describes Galaxy Project Singularity containers as the preferred execution model.
    This repository separates workflow logic from tool provisioning, so the same DAG can run locally or on clusters with consistent software versions.

13. Cluster/runtime deployment is handled externally via Snakemake profiles:
    - `profiles/local/` and `profiles/slurm/` provide execution settings.
    - The rules declare resources such as threads, memory, and time, making the workflow scheduler-friendly for SLURM and similar systems.
    The compute boundary is therefore Snakemake-managed, not hardcoded in the rules.

14. The repository’s output structure mirrors the workflow stages under `results/`, which makes the architecture easy to diagram as a left-to-right transform: raw reads → cleaned reads → aligned/filtered BAMs → coverage/peaks/QC/annotation → aggregated report. The key branches are control-aware signal generation and QC gating, which distinguish this pipeline from a simple align-and-call workflow.

Main entry points: [`rules/multiqc.smk`](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/multiqc.smk) (MultiQC), [`rules/samtools_sort.smk`](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/samtools_sort.smk) (BAM process), [`rules/bedtools_genomecov.smk`](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/bedtools_genomecov.smk) (Coverage), [`rules/blacklist_region_filter.smk`](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/blacklist_region_filter.smk) (Blacklist filter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Orchestration"]
  node_snakefile["Snakefile<br/>workflow entry"]
end

subgraph group_inputs["Inputs"]
  node_config["Config<br/>[config.yaml]"]
  node_samples["Sample sheet<br/>metadata table<br/>[samples.tsv]"]
  node_validate["Validate<br/>config check<br/>[validate_config.py]"]
end

subgraph group_prealign["Pre-alignment"]
  node_fastp["Fastp<br/>trim QC<br/>[fastp.smk]"]
  node_fastqc["FastQC<br/>read QC<br/>[fastqc.smk]"]
end

subgraph group_alignment["Alignment"]
  node_align["Bowtie2<br/>alignment<br/>[bowtie2.smk]"]
  node_bamproc["BAM process<br/>BAM cleanup<br/>[samtools_sort.smk]"]
  node_mito["Mito reads<br/>mitochondrial filter"]
end

subgraph group_qc["QC"]
  node_stats["Align stats<br/>alignment metrics<br/>[samtools_stats.smk]"]
  node_fragqc["Fragment QC<br/>library QC"]
  node_qcgate["QC gate<br/>pass/fail check<br/>[qc_gate.smk]"]
end

subgraph group_signal["Signal"]
  node_signal["Coverage<br/>track generation"]
  node_bamcompare["ChIP signal<br/>control-aware track<br/>[bamCompare.smk]"]
end

subgraph group_peaks["Peaks"]
  node_macs2["MACS2<br/>peak calling"]
  node_blacklist["Blacklist filter<br/>peak filter"]
  node_frip["FRiP<br/>peak QC"]
end

subgraph group_interpretation["Interpretation"]
  node_annotate["Peak annotation<br/>functional annotation"]
  node_motif["Motif analysis<br/>motif discovery<br/>[motif_analysis.smk]"]
  node_heatmap["Heatmaps<br/>matrix summary<br/>[heatmap.smk]"]
  node_corr["Correlation<br/>sample summary"]
end

subgraph group_reporting["Reporting"]
  node_multiqc["MultiQC<br/>run report<br/>[multiqc.smk]"]
end

node_samples -->|"metadata check"| node_validate
node_config -->|"runtime params"| node_validate
node_validate -->|"enable run"| node_snakefile
node_snakefile -->|"trim reads"| node_fastp
node_fastp -->|"clean reads"| node_fastqc
node_fastp -->|"reads"| node_align
node_align -->|"BAM"| node_bamproc
node_bamproc -->|"filtered BAM"| node_mito
node_bamproc -->|"alignment stats"| node_stats
node_bamproc -->|"BAM QC"| node_fragqc
node_stats -->|"metrics"| node_qcgate
node_fragqc -->|"library metrics"| node_qcgate
node_bamproc -->|"aligned reads"| node_signal
node_bamproc -->|"aligned reads"| node_bamcompare
node_signal -->|"tracks"| node_multiqc
node_bamcompare -->|"tracks"| node_multiqc
node_bamproc -->|"aligned reads"| node_macs2
node_macs2 -->|"raw peaks"| node_blacklist
node_blacklist -->|"peaks"| node_frip
node_blacklist -->|"peaks"| node_annotate
node_blacklist -->|"peaks"| node_motif
node_signal -->|"coverage"| node_heatmap
node_signal -->|"coverage"| node_corr
node_qcgate -->|"QC status"| node_multiqc
node_fastqc -->|"read QC"| node_multiqc
node_stats -->|"alignment QC"| node_multiqc
node_frip -->|"peak QC"| node_multiqc
node_annotate -->|"annotation"| node_multiqc
node_motif -->|"motifs"| node_multiqc
node_heatmap -->|"summaries"| node_multiqc
node_corr -->|"summaries"| node_multiqc

click node_snakefile "https://github.com/bdb-genomics/chipseq-pipeline/tree/main/Snakefile"
click node_config "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/config.yaml"
click node_samples "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/data/fastp/samples.tsv"
click node_validate "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/scripts/validate_config.py"
click node_fastp "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/fastp.smk"
click node_fastqc "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/fastqc.smk"
click node_align "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/bowtie2.smk"
click node_bamproc "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/samtools_sort.smk"
click node_mito "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/remove_mito_reads.smk"
click node_stats "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/samtools_stats.smk"
click node_fragqc "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/fragment_size_analysis.smk"
click node_qcgate "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/qc_gate.smk"
click node_signal "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/bedtools_genomecov.smk"
click node_bamcompare "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/bamCompare.smk"
click node_macs2 "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/macs2_peak_calling.smk"
click node_blacklist "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/blacklist_region_filter.smk"
click node_frip "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/frip_calculation.smk"
click node_annotate "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/peak_annotation.smk"
click node_motif "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/motif_analysis.smk"
click node_heatmap "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/heatmap.smk"
click node_corr "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/correlation_analysis.smk"
click node_multiqc "https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/multiqc.smk"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_snakefile,node_macs2,node_blacklist,node_frip toneBlue
class node_config,node_samples,node_validate,node_annotate,node_motif,node_heatmap,node_corr toneAmber
class node_fastp,node_fastqc,node_multiqc toneMint
class node_align,node_bamproc,node_mito toneRose
class node_stats,node_fragqc,node_qcgate toneIndigo
class node_signal,node_bamcompare toneTeal
```

## Components

### Orchestration

Workflow entrypoint and rule composition

- [Snakefile](https://github.com/bdb-genomics/chipseq-pipeline/tree/main/Snakefile): workflow entry · Top-level Snakemake DAG that wires together modular rule files · `Snakefile`

### Inputs

Sample metadata and runtime configuration

- [Config](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/config.yaml): runtime config · Main workflow parameters, reference paths, and thresholds · `config.yaml`
- [Sample sheet](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/data/fastp/samples.tsv): metadata table · Sample, condition, replicate, FASTQ, and control definitions · `data/fastp/samples.tsv`
- [Validate](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/scripts/validate_config.py): config check · Early validation of config and sample sheet · `rules/scripts/validate_config.py`

### Pre-alignment

Read cleaning and early QC

- [Fastp](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/fastp.smk): trim QC · Adapter and quality trimming of paired-end reads · `rules/fastp.smk`
- [FastQC](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/fastqc.smk): read QC · Per-sample QC on trimmed reads · `rules/fastqc.smk`

### Alignment

Mapping and BAM processing

- [Bowtie2](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/bowtie2.smk): alignment · Paired-end read alignment to the reference genome · `rules/bowtie2.smk`
- [BAM process](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/samtools_sort.smk): BAM cleanup · Sorting, mate fixing, duplicate marking, filtering, and indexing · `rules/samtools_sort.smk`
- [Mito reads](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/remove_mito_reads.smk): mitochondrial filter · Separate mitochondrial reads and compute mito metrics · `rules/remove_mito_reads.smk`

### QC

Quality metrics and gating

- [Align stats](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/samtools_stats.smk): alignment metrics · Post-filter alignment statistics and summaries · `rules/samtools_stats.smk`
- [Fragment QC](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/fragment_size_analysis.smk): library QC · Fragment size, insert size, cross-correlation, complexity, and BAM QC · `rules/fragment_size_analysis.smk`
- [QC gate](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/qc_gate.smk): pass/fail check · Threshold-based acceptance checks on library and mapping metrics · `rules/qc_gate.smk`

### Signal

Coverage and browser tracks

- [Coverage](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/bedtools_genomecov.smk): track generation · Genome coverage, normalized signal, and browser track creation · `rules/bedtools_genomecov.smk`
- [ChIP signal](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/bamCompare.smk): control-aware track · ChIP-vs-control log2 signal tracks when matched controls exist · `rules/bamCompare.smk`

### Peaks

Peak calling and filtering

- [MACS2](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/macs2_peak_calling.smk): peak calling · Narrow peak calling from aligned ChIP-seq reads · `rules/macs2_peak_calling.smk`
- [Blacklist filter](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/blacklist_region_filter.smk): peak filter · Remove peaks overlapping blacklist regions · `rules/blacklist_region_filter.smk`
- [FRiP](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/frip_calculation.smk): peak QC · Fraction of reads in peaks as a peak-quality measure · `rules/frip_calculation.smk`

### Interpretation

Downstream biological summaries

- [Peak annotation](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/peak_annotation.smk): functional annotation · ChIPseeker-based annotation of peaks to genomic features · `rules/peak_annotation.smk`
- [Motif analysis](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/motif_analysis.smk): motif discovery · HOMER-driven de novo motif discovery on peaks · `rules/motif_analysis.smk`
- [Heatmaps](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/heatmap.smk): matrix summary · Signal matrices and heatmap summaries around genomic features · `rules/heatmap.smk`
- [Correlation](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/correlation_analysis.smk): sample summary · Sample-level correlations from coverage summaries · `rules/correlation_analysis.smk`

### Reporting

Run-wide aggregation and final inspection

- [MultiQC](https://github.com/bdb-genomics/chipseq-pipeline/blob/main/rules/multiqc.smk): run report · Aggregate report across QC, alignment, peak, and signal outputs · `rules/multiqc.smk`

## Connections

- Sample sheet → Validate: metadata check · Validate sample sheet structure and required fields
- Config → Validate: runtime params · Validate configured resources, references, and thresholds
- Validate → Snakefile: enable run · Fail early if inputs or config are invalid
- Snakefile → Fastp: trim reads · Dispatch trimming stage
- Fastp → FastQC: clean reads · Run QC on trimmed reads
- Fastp → Bowtie2: reads · Feed cleaned paired-end reads into alignment
- Bowtie2 → BAM process: BAM · Sort and clean aligned reads
- BAM process → Mito reads: filtered BAM · Split mitochondrial and non-mitochondrial reads
- BAM process → Align stats: alignment stats · Collect post-processing alignment metrics
- BAM process → Fragment QC: BAM QC · Derive library-quality metrics from processed BAMs
- Align stats → QC gate: metrics · Use alignment metrics in QC decisions
- Fragment QC → QC gate: library metrics · Use library-quality metrics in QC decisions
- BAM process → Coverage: aligned reads · Generate coverage from processed alignments
- BAM process → ChIP signal: aligned reads · Create control-aware signal tracks when controls are present
- Coverage → MultiQC: tracks · Contribute coverage outputs to the report
- ChIP signal → MultiQC: tracks · Contribute ChIP-vs-control signal outputs
- BAM process → MACS2: aligned reads · Call peaks from filtered alignments
- MACS2 → Blacklist filter: raw peaks · Filter peaks against blacklist regions
- Blacklist filter → FRiP: peaks · Compute FRiP on cleaned peak set
- Blacklist filter → Peak annotation: peaks · Annotate filtered peaks to genomic features
- Blacklist filter → Motif analysis: peaks · Run motif discovery on filtered peaks
- Coverage → Heatmaps: coverage · Build matrices and heatmaps from signal tracks
- Coverage → Correlation: coverage · Compute sample correlations from track summaries
- QC gate → MultiQC: QC status · Surface pass/fail thresholds in the final report
- FastQC → MultiQC: read QC · Aggregate early QC results
- Align stats → MultiQC: alignment QC · Aggregate alignment-level statistics
- FRiP → MultiQC: peak QC · Aggregate peak-derived QC metrics
- Peak annotation → MultiQC: annotation · Aggregate functional annotation outputs
- Motif analysis → MultiQC: motifs · Aggregate motif discovery outputs
- Heatmaps → MultiQC: summaries · Aggregate interpretive plots and matrices
- Correlation → MultiQC: summaries · Aggregate correlation summaries
