Crates.io | faimm |
lib.rs | faimm |
version | 0.5.0 |
source | src |
created_at | 2018-08-17 12:02:53.301773 |
updated_at | 2024-04-09 14:04:53.812357 |
description | Random access to indexed fasta using a mmapped file |
homepage | https://github.com/veldsla/faimm |
repository | https://github.com/veldsla/faimm |
max_upload_size | |
id | 79922 |
size | 21,092 |
Random access to indexed fasta using a memory mapped file.
This crate provides indexed fasta access by using a memory mapped file to read the sequence data. It is intended for accessing sequence data on genome sized fasta files and provides random access based on base coordinates. Because an indexed fasta file uses a limited number of bases per line separated by (sometimes platform-specific) newlines you cannot directly use the bytes available from the mmap.
Access is provided using a view of the mmap using zero-based base coordinates.
This view can then be used to iterate over bases (represented as u8
) or
parsed into a string. Naive GC counting is also available.
Access to the sequence data doesn't require the IndexedFasta
to be mutable.
This makes it easy to share.
use faimm::IndexedFasta;
let fa = IndexedFasta::from_file("test/genome.fa").expect("Error opening fa");
let chr_index = fa.fai().tid("ACGT-25").expect("Cannot find chr in index");
let v = fa.view(chr_index,0,50).expect("Cannot get .fa view");
//count the bases
let counts = v.count_bases();
//or print the sequence
println!("{}", v.to_string());
The parser uses a simple ASCII mask for allowable characters (64..128), does
not apply any IUPAC conversion or validation. Anything outside this range is
silently skipped. This means that also invalid fasta
will be parsed. The mere
presence of an accompanying .fai
provides the assumption of a valid fasta.
Requires Rust >=1.64
Rust-bio provides a competent indexed fasta reader. The major difference is that it has an internal buffer an therefore needs to be mutable when performing read operations. faimm is also faster. If you want record based access (without an .fai index file) rust-bio or seq_io provide this.
Calculating the GC content of target regions of an exome (231_410 regions) on the Human reference (GRCh38) takes about 0.7 seconds (warm cache), slightly faster than bedtools nuc (0.9s probably a more sound implementation) and rust-bio (1.3s same implementation as example) Some tests show counting can also be improved using SIMD, but nothing has been released.