How bdb-genomics/chipseq-pipeline works
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: multiqc.smk MultiQC · samtools_sort.smk BAM process · bedtools_genomecov.smk Coverage · blacklist_region_filter.smk Blacklist filter
Components 22
Orchestration
Workflow entrypoint and rule composition
- Snakefile · Top-level Snakemake DAG that wires together modular rule files
Snakefile
Inputs
Sample metadata and runtime configuration
- Config · Main workflow parameters, reference paths, and thresholds
config.yaml - Sample sheet · Sample, condition, replicate, FASTQ, and control definitions
data/fastp/samples.tsv - Validate · Early validation of config and sample sheet
rules/scripts/validate_config.py
Pre-alignment
Read cleaning and early QC
Alignment
Mapping and BAM processing
- Bowtie2 · Paired-end read alignment to the reference genome
rules/bowtie2.smk - BAM process · Sorting, mate fixing, duplicate marking, filtering, and indexing
rules/samtools_sort.smk - Mito reads · Separate mitochondrial reads and compute mito metrics
rules/remove_mito_reads.smk
QC
Quality metrics and gating
- Align stats · Post-filter alignment statistics and summaries
rules/samtools_stats.smk - Fragment QC · Fragment size, insert size, cross-correlation, complexity, and BAM QC
rules/fragment_size_analysis.smk - QC gate · Threshold-based acceptance checks on library and mapping metrics
rules/qc_gate.smk
Signal
Coverage and browser tracks
- Coverage · Genome coverage, normalized signal, and browser track creation
rules/bedtools_genomecov.smk - ChIP signal · ChIP-vs-control log2 signal tracks when matched controls exist
rules/bamCompare.smk
Peaks
Peak calling and filtering
- MACS2 · Narrow peak calling from aligned ChIP-seq reads
rules/macs2_peak_calling.smk - Blacklist filter · Remove peaks overlapping blacklist regions
rules/blacklist_region_filter.smk - FRiP · Fraction of reads in peaks as a peak-quality measure
rules/frip_calculation.smk
Interpretation
Downstream biological summaries
- Peak annotation · ChIPseeker-based annotation of peaks to genomic features
rules/peak_annotation.smk - Motif analysis · HOMER-driven de novo motif discovery on peaks
rules/motif_analysis.smk - Heatmaps · Signal matrices and heatmap summaries around genomic features
rules/heatmap.smk - Correlation · Sample-level correlations from coverage summaries
rules/correlation_analysis.smk
Reporting
Run-wide aggregation and final inspection
- MultiQC · Aggregate report across QC, alignment, peak, and signal outputs
rules/multiqc.smk
Connections 31
- 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