minimap2-cr

CI Lines of Code

Crystal bindings for minimap2 (long-read mapper).

This shard downloads/builds minimap2 during install (see shard.yml postinstall).

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      minimap2:
        github: kojix2/minimap2-cr
  2. Run shards install

System requirements (Linux)

Building minimap2 requires a C toolchain and zlib headers.

sudo apt-get update
sudo apt-get install -y build-essential curl bzip2 zlib1g-dev

Usage

Quick Start

require "minimap2"

aligner = Minimap2::Aligner.new(
  "reference.fasta",
  preset: "map-ont",
  cigar: true,
  threads: 4
)

hits = aligner.map("ACGTACGTACGT", cs: true, md: true, ds: true)
pp hits.first?

Builder Style (recommended for explicit config)

require "minimap2"

aligner = Minimap2::Aligner.build
  .map_hifi
  .with_cigar
  .with_index_threads(4)
  .with_index("reference.fasta")

Available builder presets:

Practical Mapping Options

map supports these high-level toggles:

Returned fields are available on Minimap2::Mapping as cs, md, and ds.

You can also pass minimap2 flags directly via extra_flags:

hits = aligner.map(
  query,
  extra_flags: [
    Minimap2::LibMinimap2::OUT_MD.to_u64,
    Minimap2::LibMinimap2::EQX.to_u64,
  ]
)

API Notes

Upstream minimap2 references

Utilities

require "minimap2"

puts Minimap2.revcomp("ACGTN")

Development

If you see runtime linker errors, try:

export LD_LIBRARY_PATH="$PWD/ext"