#fasta #indexed #fai

faiquery

Queryable indexed fasta using a mmapped file

4 releases

0.1.3 Aug 23, 2023
0.1.2 Aug 23, 2023
0.1.1 Aug 22, 2023
0.1.0 Aug 22, 2023

#1490 in Parser implementations

Download history 10/week @ 2024-02-04 5/week @ 2024-02-18 16/week @ 2024-02-25 7/week @ 2024-03-03 7/week @ 2024-03-10 1/week @ 2024-03-24 85/week @ 2024-03-31

94 downloads per month
Used in 2 crates

MIT license

29KB
370 lines

faiquery

MIT licensed actions status docs.rs

perform interval queries on an indexed fasta file

Description

This is a simple utility library to request interval queries on an indexed fasta file.

Ths index is assumed samtools faidx.

The fasta file is memory-mapped and a single mutable buffer is kept for the indexed fasta reader. This buffer is used to return a slice reference to the query sequence but allows for a non-contiguous sequence (i.e. can return sequences without newlines)

Note that because a mutable buffer is kept, this is not the best approach for concurrent operations.

However, for single-threaded applications, this performs very well with low memory overhead and runtime.

Usage

use anyhow::Result;
use faiquery::{FastaIndex, IndexedFasta};

fn main() -> Result<()> {
    let index = FastaIndex::from_filepath("example_data/example.fa.fai")?;
    let mut faidx = IndexedFasta::new(index, "example_data/example.fa")?;

    // Query the first 10 bases of chr1
    let seq = faidx.query("chr1", 0, 10)?;
    assert_eq!(seq, b"ACCTACGATC");

    // Query the first 10 bases of chr2
    let seq = faidx.query("chr2", 0, 10)?;
    assert_eq!(seq, b"TTTTGATCGA");

    Ok(())
}

Similar Approaches

There are other index fasta readers that are available, here is a nonexhaustive list of those:

If you are looking for a powerful concurrent reader I recommend using the faimm crate.

Dependencies

~3–4.5MB
~64K SLoC