

Whether a lab uses bash scripts, Python workflows, Snakemake pipelines, or custom solutions, the in-house pipeline often works well locally. It may have been running for years. As the research scales, though, the same pipeline becomes harder to reproduce across teams and needs frequent manual fixes.
Workflow managers help with this, but before migrating an entire pipeline to Nextflow (or any professional workflow manager), the hardest question has to be answered first: will the new pipeline produce the same results? This post describes a three-step framework for migrating a bioinformatics pipeline while keeping the results comparable: establish a reproducibility baseline, control non-deterministic behavior, and validate outputs against the baseline. For migrations to Nextflow specifically, nf-test can automate much of the validation.
An in-house pipeline (bash, Python, Snakemake, or custom) often does not scale beyond the machine it was written on. Moving to a workflow manager changes several things:
The in-house pipeline problem:
Benefits of a workflow manager (Nextflow, Snakemake, or CWL):
An in-house pipeline is a body of institutional knowledge. It was usually built incrementally, never designed for reproducibility across teams, and probably contains undocumented quirks that make it work. Rewriting it in Nextflow and assuming identical results is risky.
Migration can introduce subtle bugs that are hard to detect: a variant is called differently, a read is filtered out, a threshold is slightly different, a file is processed in a different order. Sometimes the biological impact is small, but without a way to trace what changed, the difference is difficult to explain.
Before replacing an in-house pipeline with a workflow manager, three things are needed:
The framework is the same regardless of the source. The tooling differs by target: for migrations to Nextflow, nf-test can automate much of this process.
The first step is a "golden standard": verified outputs from the original in-house pipeline that serve as a reference. This baseline is independent of the target workflow manager.
Create a script that records everything:
#!/bin/bash# original_pipeline.sh - Reference implementation with full documentation
set -euo pipefail
# ConfigurationREFERENCE="/data/reference/hg38.fasta"READS="/data/reads/sample.fastq"OUTPUT_DIR="/results/baseline"MANIFEST="${OUTPUT_DIR}/manifest.txt"
# Create output directorymkdir -p "${OUTPUT_DIR}"
# Record software versionsecho "=== Pipeline Execution Record ===" > "${MANIFEST}"echo "Date: $(date -Iseconds)" >> "${MANIFEST}"echo "" >> "${MANIFEST}"echo "=== Software Versions ===" >> "${MANIFEST}"echo "bwa: $(bwa 2>&1 | grep Version)" >> "${MANIFEST}"echo "samtools: $(samtools --version | head -1)" >> "${MANIFEST}"echo "bcftools: $(bcftools --version | head -1)" >> "${MANIFEST}"echo "" >> "${MANIFEST}"
# Record input file hashesecho "=== Input File Checksums ===" >> "${MANIFEST}"md5sum "${REFERENCE}" >> "${MANIFEST}"md5sum "${READS}" >> "${MANIFEST}"echo "" >> "${MANIFEST}"
# Step 1: Alignmentecho "=== Step 1: BWA Alignment ===" >> "${MANIFEST}"bwa mem -t 8 "${REFERENCE}" "${READS}" | \ samtools sort -@ 4 -o "${OUTPUT_DIR}/aligned.bam" -md5sum "${OUTPUT_DIR}/aligned.bam" >> "${MANIFEST}"echo "aligned.bam: $(md5sum ${OUTPUT_DIR}/aligned.bam | cut -d' ' -f1)"
# Step 2: Mark Duplicatesecho "=== Step 2: Mark Duplicates ===" >> "${MANIFEST}"samtools markdup "${OUTPUT_DIR}/aligned.bam" "${OUTPUT_DIR}/marked.bam"md5sum "${OUTPUT_DIR}/marked.bam" >> "${MANIFEST}"echo "marked.bam: $(md5sum ${OUTPUT_DIR}/marked.bam | cut -d' ' -f1)"
# Step 3: Call Variantsecho "=== Step 3: Call Variants ===" >> "${MANIFEST}"bcftools mpileup -f "${REFERENCE}" "${OUTPUT_DIR}/marked.bam" | \ bcftools call -m -o "${OUTPUT_DIR}/variants.vcf"md5sum "${OUTPUT_DIR}/variants.vcf" >> "${MANIFEST}"echo "variants.vcf: $(md5sum ${OUTPUT_DIR}/variants.vcf | cut -d' ' -f1)"
echo ""echo "Baseline execution complete. Manifest saved to: ${MANIFEST}"cat "${MANIFEST}"Execute the pipeline several times with identical inputs to check determinism:
#!/bin/bash# Verify pipeline reproducibility
RUNS=3REFERENCE_DIR="/results/baseline"
echo "Running original pipeline $RUNS times..."
for i in $(seq 1 $RUNS); do OUTPUT_DIR="/results/baseline_run_$i" bash original_pipeline.sh > /tmp/run_$i.log 2>&1done
# Compare outputsecho ""echo "=== Reproducibility Check ==="md5sum "${REFERENCE_DIR}/aligned.bam" /results/baseline_run_*/aligned.bammd5sum "${REFERENCE_DIR}/marked.bam" /results/baseline_run_*/marked.bammd5sum "${REFERENCE_DIR}/variants.vcf" /results/baseline_run_*/variants.vcf
# Extract just the checksums and compareBASELINE_ALIGNED=$(md5sum "${REFERENCE_DIR}/aligned.bam" | cut -d' ' -f1)BASELINE_MARKED=$(md5sum "${REFERENCE_DIR}/marked.bam" | cut -d' ' -f1)BASELINE_VARIANTS=$(md5sum "${REFERENCE_DIR}/variants.vcf" | cut -d' ' -f1)
echo ""echo "Baseline checksums:"echo " aligned.bam: $BASELINE_ALIGNED"echo " marked.bam: $BASELINE_MARKED"echo " variants.vcf: $BASELINE_VARIANTS"Expected output if the pipeline is deterministic:
98a4d5f8c7b2e9f3a1d6c4b5 /results/baseline/aligned.bam98a4d5f8c7b2e9f3a1d6c4b5 /results/baseline_run_1/aligned.bam98a4d5f8c7b2e9f3a1d6c4b5 /results/baseline_run_2/aligned.bam98a4d5f8c7b2e9f3a1d6c4b5 /results/baseline_run_3/aligned.bam
All checksums match - Pipeline is deterministic!Some bioinformatics tools produce non-deterministic output by design (random seeds, floating-point precision, threading order). These have to be identified and handled explicitly:
# Tools that need seed control# These must be configured with hard-coded seeds
# Example 1: Tools with random sampling (seqtk)seqtk sample -s 42 reads.fastq 0.5 > sampled.fastq
# Example 2: Tools with randomized output order (bowtie2 with threading)bowtie2 --seed 42 -p 8 -x index -U reads.fastq -S output.sam
# Example 3: Python-based tools with numpy/scipy randomnesspython process.py --seed 42
# Example 4: R-based tools# In R script:set.seed(42)Create a mapping document:
# Non-Deterministic Tools in Our Pipeline
| Tool | Reason | Solution || ------------------- | ---------------------- | -------------------- || seqtk sample | Random sampling | Use --seed 42 || bowtie2 | Thread-based shuffling | Use --seed 42 || custom_py_script.py | numpy random | Set seed in code || variant_filter.R | R randomization | set.seed(42) in code |
All tools must use hard-coded seeds (42 chosen arbitrarily).Create a versioned baseline that future pipelines must match:
# baseline_checksums.txt# Generated: 2026-02-11T10:30:00Z# Pipeline Version: 1.0# Tools: bwa-0.7.17, samtools-1.18, bcftools-1.18
aligned.bam:98a4d5f8c7b2e9f3a1d6c4b5e2f3g4h5marked.bam: a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7variants.vcf: x9y8z7w6v5u4t3s2r1q0p9o8n7m6l5k4The next step is to migrate the bash pipeline to Nextflow while maintaining deterministic behavior through seed control.
Convert each bash step to a Nextflow process, setting seeds explicitly:
process BWA_ALIGN { tag "$meta.id" label 'process_high'
container 'community.wave.seqera.io/library/bwa_samtools:56c9f8d5201889a4'
input: tuple val(meta), path(reads) path reference path reference_index
output: tuple val(meta), path("*.bam"), emit: bam path "versions.yml", emit: versions
script: """ # Seed control: bwa uses thread-based order # To maintain determinism, use single-threaded or # use sorted output from samtools
bwa mem \\ -t ${task.cpus} \\ ${reference} \\ ${reads} | \\ samtools sort \\ -@ ${task.cpus} \\ -o ${meta.id}.bam \\ -
# Verify output samtools view -c ${meta.id}.bam
cat <<-END_VERSIONS > versions.yml "${task.process}": bwa: \$(echo \$(bwa 2>&1) | sed 's/^.*Version: //; s/Contact:.*\$//') samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//') END_VERSIONS """}process MARK_DUPLICATES { tag "$meta.id" label 'process_medium'
container 'community.wave.seqera.io/library/samtools:1.18'
input: tuple val(meta), path(bam)
output: tuple val(meta), path("*marked.bam"), emit: bam path "versions.yml", emit: versions
script: """ # samtools markdup is deterministic when input is sorted samtools markdup \\ -M \\ ${bam} \\ ${meta.id}.marked.bam
cat <<-END_VERSIONS > versions.yml "${task.process}": samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//') END_VERSIONS """}process CALL_VARIANTS { tag "$meta.id" label 'process_medium'
container 'community.wave.seqera.io/library/bcftools:1.18'
input: tuple val(meta), path(bam) path reference
output: tuple val(meta), path("*.vcf"), emit: vcf path "versions.yml", emit: versions
script: """ # bcftools is deterministic when output format is sorted bcftools mpileup \\ -f ${reference} \\ ${bam} | \\ bcftools call \\ -m \\ -o ${meta.id}.variants.vcf
# Sort VCF for reproducibility vcf-sort ${meta.id}.variants.vcf > ${meta.id}.variants.sorted.vcf mv ${meta.id}.variants.sorted.vcf ${meta.id}.variants.vcf
cat <<-END_VERSIONS > versions.yml "${task.process}": bcftools: \$(echo \$(bcftools --version 2>&1) | sed 's/^.*bcftools //; s/ .*\$//') END_VERSIONS """}process { shell = ['/bin/bash', '-euo', 'pipefail']
withLabel: process_high { cpus = 8 memory = { 16.GB * task.attempt } time = { 4.h * task.attempt } }
withLabel: process_medium { cpus = 4 memory = { 8.GB * task.attempt } time = { 2.h * task.attempt } }}
profiles { docker { docker.enabled = true } singularity { singularity.enabled = true } standard { process.executor = 'local' }}include { BWA_ALIGN } from './modules/bwa_align'include { MARK_DUPLICATES } from './modules/mark_duplicates'include { CALL_VARIANTS } from './modules/call_variants'
workflow { // Input channel input_samples = Channel .fromPath(params.input_dir + '/*.fastq') .map { file -> def meta = [id: file.baseName] tuple(meta, file) }
// Reference files reference = file(params.reference) reference_index = file(params.reference + '.bwt')
// Run pipeline BWA_ALIGN(input_samples, reference, reference_index) MARK_DUPLICATES(BWA_ALIGN.out.bam) CALL_VARIANTS(MARK_DUPLICATES.out.bam, reference)}input_dir: './data/reads'reference: './data/reference/hg38.fasta'After running the Nextflow pipeline, compare outputs with the baseline systematically.
#!/bin/bash# validate_migration.sh - Compare Nextflow outputs with bash baseline
set -euo pipefail
BASELINE_DIR="/results/baseline"NEXTFLOW_DIR="/results/nextflow"VALIDATION_REPORT="/results/validation_report.txt"
{ echo "=== Pipeline Migration Validation Report ===" echo "Generated: $(date -Iseconds)" echo ""
# Function to compare checksums compare_file() { local filename=$1 local baseline="${BASELINE_DIR}/${filename}" local migrated="${NEXTFLOW_DIR}/${filename}"
if [ ! -f "$baseline" ]; then echo "BASELINE MISSING: $filename" return 1 fi
if [ ! -f "$migrated" ]; then echo "MIGRATED MISSING: $filename" return 1 fi
local baseline_md5=$(md5sum "$baseline" | cut -d' ' -f1) local migrated_md5=$(md5sum "$migrated" | cut -d' ' -f1)
if [ "$baseline_md5" == "$migrated_md5" ]; then echo "PASS: $filename" echo " MD5: $baseline_md5" return 0 else echo "FAIL: $filename" echo " Baseline MD5: $baseline_md5" echo " Migrated MD5: $migrated_md5" return 1 fi }
# Compare all output files echo "=== File Comparisons ===" declare -i pass=0 declare -i fail=0
for file in aligned.bam marked.bam variants.vcf; do if compare_file "$file"; then ((pass++)) else ((fail++)) fi done
echo "" echo "=== Summary ===" echo "Passed: $pass" echo "Failed: $fail" echo ""
if [ $fail -eq 0 ]; then echo "VALIDATION SUCCESSFUL: All outputs match baseline!" exit 0 else echo "VALIDATION FAILED: $fail file(s) differ from baseline" exit 1 fi
} | tee "$VALIDATION_REPORT"#!/bin/bash# Run the migration validation
# First, ensure baseline existsif [ ! -d "/results/baseline" ]; then echo "Error: Baseline not found. Run original_pipeline.sh first." exit 1fi
# Run Nextflow pipelineecho "Running Nextflow migration..."nextflow run main.nf \ --input_dir ./data/reads \ --reference ./data/reference/hg38.fasta \ -profile docker \ -resume
# Validate outputsecho ""echo "Validating migration..."bash validate_migration.shIf checksums do not match, investigate the difference:
#!/bin/bash# deep_diff.sh - Detailed analysis of differences
BASELINE=$1MIGRATED=$2FILENAME=$(basename "$BASELINE")
echo "=== Detailed Comparison: $FILENAME ==="
# 1. Check file sizesBASELINE_SIZE=$(stat -f%z "$BASELINE" 2>/dev/null || stat -c%s "$BASELINE")MIGRATED_SIZE=$(stat -f%z "$MIGRATED" 2>/dev/null || stat -c%s "$MIGRATED")
echo "File sizes:"echo " Baseline: $BASELINE_SIZE bytes"echo " Migrated: $MIGRATED_SIZE bytes"
if [ "$BASELINE_SIZE" != "$MIGRATED_SIZE" ]; then echo " Size difference detected"fi
# 2. For BAM files: compare with samtoolsif [[ "$FILENAME" == *.bam ]]; then echo "" echo "BAM file analysis:"
# Compare read counts BASELINE_READS=$(samtools view -c "$BASELINE") MIGRATED_READS=$(samtools view -c "$MIGRATED") echo " Baseline reads: $BASELINE_READS" echo " Migrated reads: $MIGRATED_READS"
if [ "$BASELINE_READS" != "$MIGRATED_READS" ]; then echo " Read count mismatch!" fi
# Compare first 10 reads echo "" echo " First 10 reads comparison:" echo " --- Baseline ---" samtools view "$BASELINE" | head -10 echo " --- Migrated ---" samtools view "$MIGRATED" | head -10fi
# 3. For VCF files: compare variantsif [[ "$FILENAME" == *.vcf ]]; then echo "" echo "VCF file analysis:"
# Count variants (skip header) BASELINE_VARS=$(grep -v "^#" "$BASELINE" | wc -l) MIGRATED_VARS=$(grep -v "^#" "$MIGRATED" | wc -l)
echo " Baseline variants: $BASELINE_VARS" echo " Migrated variants: $MIGRATED_VARS"
if [ "$BASELINE_VARS" != "$MIGRATED_VARS" ]; then echo " Variant count mismatch!" fi
# Show first differences echo "" echo " First 5 variants (baseline vs migrated):" diff <(grep -v "^#" "$BASELINE" | head -5) <(grep -v "^#" "$MIGRATED" | head -5) || truefi
# 4. Compare line-by-line for text filesif [[ "$FILENAME" == *.vcf || "$FILENAME" == *.txt ]]; then echo "" echo "Line-by-line diff (first 20 differences):" diff "$BASELINE" "$MIGRATED" | head -20 || truefiSome differences are acceptable. Document them:
# Known Acceptable Differences Between Bash and Nextflow
## 1. Tool Versions- Bash: bwa 0.7.17, samtools 1.18- Nextflow: bwa 0.7.17, samtools 1.18→ If versions match, output should be identical
## 2. Threading Order (BAM files)- Threading can affect read order in BAM files- Solution: Use `samtools sort` or deterministic sort- Verification: Extract and compare SAM headers + sort order
## 3. VCF Header Timestamps- VCF files may have different generation timestamps- Solution: Strip headers before comparison# Compare VCF ignoring header differencescompare_vcf_body() { local baseline=$1 local migrated=$2
diff \ <(grep -v "^##" "$baseline" | grep -v "^#CHROM" | sort) \ <(grep -v "^##" "$migrated" | grep -v "^#CHROM" | sort)}
# Compare BAM files by extracting SAMcompare_bam_content() { local baseline=$1 local migrated=$2
diff \ <(samtools view "$baseline" | sort -k1,1) \ <(samtools view "$migrated" | sort -k1,1)}#!/bin/bashset -euo pipefail
SAMPLE="sample_001"REFERENCE="/ref/hg38.fasta"READS="/data/${SAMPLE}.fastq.gz"OUTPUT_DIR="/results/bash_original"
mkdir -p "$OUTPUT_DIR"
# Step 1: Alignmentbwa mem -t 8 "$REFERENCE" <(gunzip -c "$READS") | \ samtools sort -@ 4 -o "$OUTPUT_DIR/${SAMPLE}.aligned.bam" -
# Step 2: Mark Duplicatessamtools markdup "$OUTPUT_DIR/${SAMPLE}.aligned.bam" \ "$OUTPUT_DIR/${SAMPLE}.marked.bam"
# Step 3: Indexsamtools index "$OUTPUT_DIR/${SAMPLE}.marked.bam"
# Step 4: Call variantsbcftools mpileup -f "$REFERENCE" "$OUTPUT_DIR/${SAMPLE}.marked.bam" | \ bcftools call -m -o "$OUTPUT_DIR/${SAMPLE}.vcf"
# Generate checksumscd "$OUTPUT_DIR"md5sum *.bam *.vcf > checksums.txt// main.nf - Migrated to Nextflow
workflow VARIANT_CALLING { Channel .fromPath(params.reads) .map { file -> [file.baseName, file] } .set { input_reads }
BWA_ALIGN(input_reads, params.reference) MARK_DUPLICATES(BWA_ALIGN.out.bam) CALL_VARIANTS(MARK_DUPLICATES.out.bam, params.reference)}$ bash validate_migration.sh
=== Pipeline Migration Validation Report ===Generated: 2026-02-11T15:45:30Z
=== File Comparisons ===PASS: sample_001.aligned.bam MD5: 98a4d5f8c7b2e9f3a1d6c4b5e2f3g4h5PASS: sample_001.marked.bam MD5: a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7PASS: sample_001.vcf MD5: x9y8z7w6v5u4t3s2r1q0p9o8n7m6l5k4
=== Summary ===Passed: 3Failed: 0
VALIDATION SUCCESSFUL: All outputs match baseline!The manual validation approach works for any in-house pipeline migration. For migrations to Nextflow specifically, nf-test can automate part of that work.
nf-test is a testing framework for Nextflow pipelines. It helps with the MD5 snapshot and validation workflow described above, making migration validation more reproducible.
Manual validation approach:
nf-test approach:
nextflow_process { name "Test BWA_ALIGN" script "modules/bwa_align.nf" process "BWA_ALIGN"
test("Should align reads to reference") { when { process { input[0] = [[id: "sample1"], file("data/reads.fastq")] input[1] = file("data/reference.fasta") input[2] = file("data/reference.fasta.bwt") } }
then { assertAll( { assert process.success }, { assert snapshot(process.out.bam).match() }, { assert path(process.out.bam[0][1]).exists() } ) } }}What happens:
tests/modules/bwa_align.nf.test.snapnf-test test tests/modules/bwa_align.nf.test --update-snapshot when changes are intentional{ "Should align reads to reference": { "content": [ { "0": [ [ { "id": "sample1" }, "sample1.bam:98a4d5f8c7b2e9f3a1d6c4b5e2f3g4h5" ] ], "bam": [ [ { "id": "sample1" }, "sample1.bam:98a4d5f8c7b2e9f3a1d6c4b5e2f3g4h5" ] ] } ], "timestamp": "2026-02-11T15:45:30Z" }}Create comprehensive tests for the entire pipeline:
nextflow_workflow { name "Test Complete Variant Calling Pipeline" script "workflows/variant_calling.nf" workflow "VARIANT_CALLING"
test("Complete pipeline: reads to variants") { when { workflow { input[0] = [[id: "sample1"], file("data/reads.fastq.gz")] } }
then { assertAll( { assert workflow.success }, // Snapshot bam output { assert snapshot(workflow.out.bam).match() }, // Snapshot vcf output { assert snapshot(workflow.out.vcf).match() }, // Verify intermediate files { assert path(workflow.out.bam[0][1]).exists() }, { assert path(workflow.out.vcf[0][1]).exists() } ) } }}# Generate initial snapshots from your Nextflow pipelinenf-test test tests/main.nf.test --update-snapshot
# Compare against baseline (this is your validation step 3!)nf-test test tests/main.nf.test
# If tests fail, review the diff# If diff is intentional, update snapshotsnf-test test tests/main.nf.test --update-snapshot
# Run specific test filenf-test test tests/workflows/variant_calling.nf.test
# Run in CI/CD to catch regressions# .github/workflows/test.yml- name: Test Nextflow Pipeline run: nf-test test tests/ --profile dockerStep 1 (original pipeline): generate baseline MD5 snapshots
Step 2 (migrate to Nextflow): write the Nextflow pipeline and nf-test tests
Step 3 (validate with nf-test):
# Generate initial snapshots from migrated Nextflow pipelinenf-test test tests/main.nf.test --update-snapshot
# Run: nf-test test tests/main.nf.test# nf-test automatically compares against baseline!| Aspect | Manual Validation | nf-test |
|---|---|---|
| Snapshot generation | Manual scripting | Automatic |
| Version control | External files | Git-tracked |
| Team collaboration | Share scripts | Share snapshots |
| Regression detection | Manual comparison | Automatic CI/CD |
| Update process | Rerun scripts | nf-test test --update-snapshot |
| Documentation | Separate docs | Tests are docs |
| Maintenance | High effort | Low effort |
Pin tool versions in both pipelines:
# Bashbwa 0.7.17samtools 1.18.0bcftools 1.18
# Nextflow (container)container 'community.wave.seqera.io/library/bwa_samtools:56c9f8d5201889a4'# Container hash includes specific versionsSome tools produce slightly different floating-point values due to compilation or CPU differences:
# For VCF QUAL scores, allow small differencescompare_vcf_quality() { local baseline=$1 local migrated=$2 local tolerance=0.1
# Extract QUAL scores and compare with tolerance paste \ <(grep -v "^#" "$baseline" | awk '{print $6}') \ <(grep -v "^#" "$migrated" | awk '{print $6}') | \ awk -v tol=$tolerance '{ diff = ($1 - $2) if (diff < 0) diff = -diff if (diff > tol && $1 != ".") { print "DIFFER: " $1 " vs " $2 } }'}A migration checklist:
# Pipeline Migration Checklist
## Pre-Migration- [ ] Document original bash pipeline- [ ] Record all tool versions- [ ] Generate baseline MD5 checksums- [ ] Test reproducibility (3+ runs)- [ ] Identify non-deterministic components
## Migration- [ ] Convert each step to Nextflow process- [ ] Set seeds for random operations- [ ] Configure containerization- [ ] Implement resource directives- [ ] Add error handling
## Validation- [ ] Run Nextflow with same inputs- [ ] Generate MD5 checksums- [ ] Compare all outputs- [ ] Document acceptable differences- [ ] Validate on multiple samples
## Sign-Off- [ ] All checksums match or differences documented- [ ] Code review completed- [ ] Team approval- [ ] Migration completeWhether migrating from bash scripts, Python workflows, Snakemake pipelines, custom C++ tools, or anything else, the same three-step validation framework applies. The MD5-based approach is language-agnostic.
If targeting Nextflow: nf-test can automate parts of steps 2 and 3 with snapshot management and CI/CD integration.
set -o pipefail and explicit error checking in both pipelines.Once outputs have been validated, the in-house pipeline can be replaced with a workflow manager while keeping the results comparable and gaining the benefits of professional workflow management.