Skip to content

Repository files navigation

mako

Fast SAM/BAM sorter.

crates.io Bioconda CI License: MIT DOI

mako is a focused, single-purpose command-line tool for sorting SAM and BAM files. It sorts by coordinate, queryname (lexicographic or natural), or template-coordinate, and can verify whether a file is already correctly sorted without rewriting it.

Highlights

  • External merge-sort — handles BAM files larger than available RAM via spill-to-disk.
  • Parallel radix sort for in-memory chunks.
  • Multiple sort orders:
    • coordinate — standard genomic order (tid → pos → strand); use for IGV, variant calling, etc.
    • queryname — lexicographic read name (default sub-sort, fast).
    • queryname::naturalsamtools-compatible natural numeric order.
    • template-coordinate — paired-end reads grouped by template position.
  • --verify mode — check a file's sortedness in one streaming pass without writing output.
  • Drop-in for samtools sort for the common cases.

Install

From crates.io — note the package name is fg-mako (the unprefixed mako is taken on crates.io by an unrelated, abandoned crate), but the installed binary is mako:

cargo install fg-mako

Or grab a pre-built binary from the GitHub releases page for Linux and macOS on x86_64 and aarch64.

Usage

Sort by coordinate:

mako -i in.bam -o out.bam --order coordinate --threads 8

Sort by query name (samtools-compatible natural order):

mako -i in.bam -o out.bam --order queryname::natural

Verify sort order without rewriting:

mako -i sorted.bam --verify --order coordinate

Pipe the sorted stream into another process without paying for BGZF compression that the consumer will only undo. --compression-level 0 writes uncompressed (stored) BGZF — a valid BAM with no DEFLATE — which is faster when the output is consumed immediately rather than written to disk:

mako -i in.bam -o /dev/stdout --order coordinate --compression-level 0 | downstream-tool

Run mako --help for the full list of options including memory limits, temp-directory placement, compression level, and verification mode.

Sort orders

--order Order Typical use
coordinate tid → pos → strand IGV, variant calling, indexing
queryname Lexicographic read name (default sub-sort) Fast queryname sort
queryname::natural Natural numeric read name samtools-compatible
template-coordinate Paired reads grouped by template UMI grouping pipelines

Performance

mako inherits its sort engine from fgumi. On a 30M-read WGS BAM, the engine sorts roughly 1.9× faster than samtools sort for template-coordinate order. See the fgumi documentation for detailed benchmarks and tuning guidance.

mako overrides no engine defaults. Notably, --max-temp-files defaults to auto, which sizes the spilled-run consolidation limit from the process's own RLIMIT_NOFILE budget rather than to a fixed 64. Consolidating spilled runs is close to pure overhead: it rewrites already-sorted data without making the final merge cheaper, since the k-way merge is insensitive to fan-in at these counts. On a 1.29B-read WGS BAM (93 spilled runs), a limit above the run count skips a 117-second consolidation pass and finishes 14% sooner, and auto lands well above that run count on any host with a conventional ulimit -n. Pass a number to --max-temp-files to pin the limit instead; raise ulimit -n if the auto-sized one still falls below what your input spills.

Built on

mako is a focused packaging of the SAM/BAM sort engine from fgumi. All sort logic lives upstream; mako tracks fgumi releases and exists to provide a small, stable, easily installed sort binary for users who don't need fgumi's broader UMI tooling.

Contributing

See CONTRIBUTING.md. Issues that look like sort engine bugs (correctness, performance) belong on the fgumi issue tracker; mako-specific issues (CLI ergonomics, packaging, distribution) belong here.

License

MIT — see LICENSE and THIRDPARTY.toml.

Releases

Packages

Contributors

Languages