bwa mem prints its whole usage and exits 1

An option was written after the input files, and on macOS bwa counts it as extra input instead of an option

why

bwa mem reads its options with the system getopt. GNU getopt, on Linux, reorders argv, so an option written after the positional arguments is still picked up. BSD getopt, which is what macOS uses, stops at the first non-option argument, so everything after it counts as input. bwa mem ref.fa r1.fq r2.fq -t 4 therefore arrives with five positional arguments, and the check in fastmap.c rejects anything over three: if (optind + 1 >= argc || optind + 3 < argc) prints the usage and returns 1. There is no error line to go looking for. bwa never opened the index. The identical command works on Linux, which is why a pipeline that hardcodes this ordering only fails for Mac users.

what to do

Put the options before the files: bwa mem -t 4 ref.fa r1.fq r2.fq. If the ordering is baked into a pipeline (AMR++ does this in modules/Alignment/bwa.nf), either edit that line or run the pipeline in its Docker or Singularity container, where the Linux userland makes the ordering stop mattering.

traced · AMR++ on macOS, Biostars, Sep 2026
This is one entry from BioErrors, a catalogue of bioinformatics error messages that point at the wrong thing. Every entry was traced to its real cause before it was written down.
If your error is not in it, paste it there and it gets traced and added.