Skip to content

adds support for bam input, with tag preservation - #72

Open
bwlang wants to merge 1 commit into
lh3:masterfrom
bwlang:bam_input
Open

adds support for bam input, with tag preservation#72
bwlang wants to merge 1 commit into
lh3:masterfrom
bwlang:bam_input

Conversation

@bwlang

@bwlang bwlang commented Aug 11, 2026

Copy link
Copy Markdown

This is a feature addition that can speed up typical pipelines that use UMIs by avoiding the rigamarole of stitching the tags back into aligned reads (e.g. via zipperbams).
Both unaligned and aligned BAMs are supported, with aligned BAMs having their alignments discarded and remapped.
I avoided an htslib dependency by unzipping directly.

ubams are eaxily created using samtools import or fgbio's fastqtobam

BAM Input Support and Integration:

  • Added a new BAM parser (bam.c, bam.h) that reads BAM files without external dependencies, supporting both unaligned and aligned BAM and handling auxiliary tags appropriately.
  • Integrated BAM support into the sequence reading pipeline by updating bseq.c and bseq.h to auto-detect BAM files, manage BAM/FASTA/FASTQ input transparently, and expose header and pairing information.

User-Facing Features and Bugfixes:

  • Documented BAM input support, usage instructions, and new features in README.md and NEWS.md, including header/tag handling, paired-end validation, and a small bugfix for handling read2 singletons in --meth mode.

Summary of Most Important Changes:

BAM Input and Parsing:

  • Introduced new files bam.c and bam.h implementing a BAM parser, supporting reading, header extraction, paired-end detection, and auxiliary tag filtering.
  • Updated bseq.c to auto-detect BAM vs. FASTA/FASTQ input, manage BAM file streams, and expose new helper functions for header and pairing info.

Paired-End and Tag Handling:

  • Enhanced paired-end mode: auto-detects from BAM FLAG, validates input order, and rejects coordinate-sorted BAMs in PE mode.
  • Improved auxiliary tag handling: only non-alignment tags are carried over from BAM input, with an option to suppress all tags.

@bwlang

bwlang commented Aug 11, 2026

Copy link
Copy Markdown
Author

I also did a comprehensive alignment, coverage, and methylation comparison with bwa-meth on real EM-seq data.
In the 900M reads I examined ~ 10% had material differences favoring minibwa in the 3 major difference categories: read placement, CIGAR representation, and intra-chromosomal alignments. @lh3, let me know if you want more details on the comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant