Skip to content

fg-labs/rust-yara

Build Status crates.io docs.rs License: MIT

rust-yara

Rust FFI bindings for the YARA read mapper.

Fulcrum Genomics

Visit us at Fulcrum Genomics to learn more about how we can power your Bioinformatics with rust-yara and beyond.

Overview

rust-yara provides safe Rust bindings for the YARA read mapper, a fast and accurate read mapper based on the SeqAn2 C++ library. The workspace supports both building FM indices from FASTA reference files and mapping paired-end reads against a pre-built index — all from Rust, without SAM serialization/deserialization overhead.

Crate Structure

Crate Description
yara-seqan2-sys Vendored SeqAn2 headers for the YARA read mapper
yara-mapper-sys Low-level FFI bindings to the YARA read mapper (SeqAn2)
yara-mapper Safe Rust wrapper for the YARA read mapper

Prerequisites

  • Rust stable toolchain (see rust-toolchain.toml for the pinned version)
  • zlib development headers
  • OpenMP:
    • macOS: brew install libomp
    • Linux: libgomp (typically included with GCC; install libomp-dev if using Clang)

Quick Start

Add yara-mapper to your Cargo.toml:

cargo add yara-mapper

Build an index and map reads:

use yara_mapper::{IndexerOptions, MapperOptions, ReadBatch, YaraIndexer, YaraMapper};

// Build an index from a FASTA file.
let indexer = YaraIndexer::build("ref.fasta", "ref", &IndexerOptions::default()).unwrap();
println!("Indexed {} contigs", indexer.contig_count());

// Open the index and map reads.
let mapper = YaraMapper::open("ref", &MapperOptions::default()).unwrap();
let mut batch = ReadBatch::new();
batch.push("read1", b"ACGTACGT", b"IIIIIIII", b"TGCATGCA", b"IIIIIIII").unwrap();
let records = mapper.map_paired(&batch).unwrap();
for rec in &records {
    println!("contig={} pos={} mapq={}", rec.contig_id, rec.pos, rec.mapq);
}

Examples

Build an FM index from a FASTA reference:

cargo run --example build_index -- ref.fasta ref

Map reads against a pre-built index:

cargo run --example align -- ref

Building from Source

cargo build                  # debug build
cargo clippy --all-targets   # lint
cargo fmt --check            # format check

To use a local SeqAn2 checkout instead of the vendored headers, set SEQAN_DIR:

export SEQAN_DIR=/path/to/seqan

License

This project is licensed under the MIT License.

The vendored SeqAn2 headers and YARA application sources are licensed under the BSD 3-Clause License — see yara-seqan2-sys/vendor/include/seqan/LICENSE and yara-seqan2-sys/vendor/apps/yara/LICENSE.

Contributing

See CONTRIBUTING.md for development setup and guidelines.

About

Safe Rust FFI bindings for the YARA read mapper and indexer (SeqAn2)

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors