Summary
create_tn5bams fails intermittently/repeatedly for some replicates when building Tn5 BAM outputs, due to malformed BED coordinates generated during Tn5 site conversion.
Observed Failure
In a recent run, Snakemake repeatedly retried create_tn5bams and failed at the first bedToBam step with:
Error: malformed BED entry ... Start Coordinate detected that is < 0. Exiting.
Example run context:
- Workdir:
/data/Boufraqech_group/analysis/.temp/aspen_run_for_Ying
- Rule:
create_tn5bams
- Failing command stage:
bedToBam -i ...tn5sites.bed -g ...hs1_chrR.genome
Root Cause
Current logic in workflow/scripts/ccbr_atac_bam2tn5bed.py:
- Applies a reverse-read shift of
-5 without lower-bound guarding.
- Derives start/end from pair-level min/max boundaries, then applies shifts tied to read orientation in a way that can produce incorrect or out-of-range cut positions.
- Writes BED rows without enforcing valid BED interval constraints.
This can emit entries with negative starts (especially for alignments near chromosome start), which causes bedToBam to abort.
Why This Matters
- Blocks pipeline progress for affected samples.
- Causes repeated cluster retries and wasted compute.
- Risks downstream inconsistency in tn5/reads counting and visualization paths.
Proposed Fix
Update workflow/scripts/ccbr_atac_bam2tn5bed.py to:
- Use strand-correct per-read cut-site derivation for ATAC conventions (+4/-5), aligned to ENCODE/deepTools semantics.
- Guard and sanitize coordinates before BED write:
- enforce
start >= 0
- enforce
end > start
- clamp to valid bounds as needed
- Apply the same validation/sanitization policy to both outputs:
- Emit counters/warnings for clipped/skipped entries to aid QC.
Validation Plan
- Re-run failing replicate(s) and confirm no malformed BED / negative-coordinate
bedToBam errors.
- Assert generated BED intermediates have no invalid intervals.
- Confirm both BAM outputs and indexes are produced:
tn5sites.bam(.bai)
reads.bam(.bai)
- Smoke-test downstream counting and bigwig generation for both methods (
tn5sites, reads).
Acceptance Criteria
create_tn5bams completes successfully on previously failing replicates.
- No malformed BED coordinate errors in logs.
- Downstream outputs remain complete and consistent.
References
- Script:
workflow/scripts/ccbr_atac_bam2tn5bed.py
- Rule:
workflow/rules/align.smk (create_tn5bams)
⚡ Generated using AI ⚡
Summary
create_tn5bamsfails intermittently/repeatedly for some replicates when building Tn5 BAM outputs, due to malformed BED coordinates generated during Tn5 site conversion.Observed Failure
In a recent run, Snakemake repeatedly retried
create_tn5bamsand failed at the firstbedToBamstep with:Error: malformed BED entry ... Start Coordinate detected that is < 0. Exiting.Example run context:
/data/Boufraqech_group/analysis/.temp/aspen_run_for_Yingcreate_tn5bamsbedToBam -i ...tn5sites.bed -g ...hs1_chrR.genomeRoot Cause
Current logic in
workflow/scripts/ccbr_atac_bam2tn5bed.py:-5without lower-bound guarding.This can emit entries with negative starts (especially for alignments near chromosome start), which causes
bedToBamto abort.Why This Matters
Proposed Fix
Update
workflow/scripts/ccbr_atac_bam2tn5bed.pyto:start >= 0end > starttn5sites.bedreads.bedValidation Plan
bedToBamerrors.tn5sites.bam(.bai)reads.bam(.bai)tn5sites,reads).Acceptance Criteria
create_tn5bamscompletes successfully on previously failing replicates.References
workflow/scripts/ccbr_atac_bam2tn5bed.pyworkflow/rules/align.smk(create_tn5bams)⚡ Generated using AI ⚡