Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LDFLAGS=
INCLUDES=
LOBJS= kommon.o kalloc.o bwt.o l2bit.o options.o seed.o map-algo.o lchain.o align.o pe.o cs.o format.o \
ksw2_extz2_sse.o ksw2_extd2_sse.o ksw2_ll_sse.o
AOBJS= kthread.o libsais.o libsais64.o index.o bseq.o map-main.o fastmap.o
AOBJS= kthread.o libsais.o libsais64.o index.o bseq.o bam.o map-main.o fastmap.o
MALLOC_O= mimalloc.o
PROG= minibwa
LIBS= -lpthread -lz -lm
Expand Down Expand Up @@ -65,7 +65,8 @@ depend:

QSufSort.o: QSufSort.h
align.o: mbpriv.h minibwa.h l2bit.h bwt.h kommon.h bseq.h kalloc.h ksw2.h
bseq.o: bseq.h kommon.h kseq.h
bam.o: bam.h bseq.h kommon.h
bseq.o: bseq.h kommon.h bam.h kseq.h
bwt.o: kommon.h kalloc.h bwt.h
bwtgen.o: QSufSort.h
cs.o: mbpriv.h minibwa.h l2bit.h bwt.h kommon.h bseq.h kalloc.h
Expand Down
31 changes: 31 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
Unreleased
----------

Notable changes:

* New feature: BAM input. Minibwa reads BAM wherever it reads FASTA/FASTQ,
detecting the format from the file contents. Both unaligned and aligned BAM
work; for aligned input the old alignments are discarded and secondary and
supplementary records are skipped. Paired-end mode is turned on
automatically when the first record is flagged as paired.

* Bugfix: in `--meth` mode the bisulfite conversion was chosen from a read's
position within its fragment, so an unpaired read 2 -- which a BAM can carry
but a pair of FASTQ files cannot express -- was converted as if it were
read 1 and usually failed to map. With a BAM input the SAM FLAG now decides,
and the segment a read belongs to is carried through to the output FLAG, so
an unpaired read 2 is still reported as read 2 rather than as single-end.

* New feature: paired-end input is now validated. A coordinate-sorted BAM is
rejected in paired-end mode instead of being mapped as single-end, and two
query files whose reads are out of order are reported rather than silently
mispaired.

* New feature: with a BAM input, `@RG`, `@PG` and `@CO` header records and
per-record auxiliary tags such as `RX` are carried over to the output.
`@HD` and `@SQ` are replaced, as contigs come from the index, and tags
describing an alignment are dropped because minibwa recomputes them. Use
`--bam-tags=no` to copy no tags.



Release 0.7-r421 (6 August, 2026)
---------------------------------

Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,39 @@ Note in the default adaptive mode, `-g`/`-w`/`-W`/`-N`/`-m`/`-s` only changes
the short-read setting; the long-read setting is fixed. This mode is disabled
with `--adap=no` or when `-x sr` or `-x lr` is specified.

#### BAM input support

Minibwa reads BAM as well as FASTA/FASTQ; the format is detected from
the file contents, so no option is needed. Both unaligned BAM (uBAM) and
aligned BAM work — for aligned input the existing alignments are discarded and
the reads are re-mapped.
```sh
minibwa map -t8 ref.fa reads.ubam > aln.sam # read pairs interleaved in one uBAM
minibwa map -t8 ref.fa r1.bam r2.bam # read 1 and read 2 in separate BAMs
minibwa map -t8 ref.fa - < reads.ubam # BAM on stdin
samtools collate -@4 -Ou in.bam | minibwa map -t8 ref.fa - # collate first
```
If the first record of a BAM is flagged as paired, paired-end mode is turned on
automatically; `--pe=no` overrides this. Records must be collated by name, as
`samtools collate` or `samtools sort -n` produces: mates are found among
adjacent records, so minibwa rejects a coordinate-sorted BAM in paired-end mode.Secondary and supplementary input records are skipped so that a read is mapped only once.

When read 1 and read 2 are given as two files, mates are paired by position.
Minibwa checks that the names agree and aborts if the files are out of sync.

The primary advantage of bam input mode is that header (e.g. RG, SN, BC) and read tags (e.g. RX, BC, MI) are carried over from the input avoiding the need for a later step to stich these attributes back in.
BAM: `@HD` and `@SQ` are replaced (contigs come from the index), while `@RG`,
`@PG` and `@CO` are preserved, with `@RG` deduplicated by ID across inputs and
minibwa's own `@PG` chained via `PP:`. Tags that
describe an alignment (`NM`, `MD`, `AS`, `SA`, `MC`, `MQ`, `XA`, ...) are
dropped, as minibwa recomputes them. Use `--bam-tags=no` to copy no tags at
all. `-R` overrides any `RG` the records already carry, and replaces the input
`@RG` header lines.

BAM decompression is single-threaded and could become a bottleneck at high
thread counts. Piping in uncompressed BAM, as `samtools collate -Ou` above
does, avoids most of that cost.

#### Mapping with legacy bwa-mem CLI

Minibwa also provides legacy bwa-mem command-line interface (CLI) via the `mem` subcommand.
Expand Down
Loading