https://github.com/noamteyssier/faiquery
perform interval queries on an indexed fasta file
https://github.com/noamteyssier/faiquery
fai fasta indexed-fasta query
Last synced: 3 months ago
JSON representation
perform interval queries on an indexed fasta file
- Host: GitHub
- URL: https://github.com/noamteyssier/faiquery
- Owner: noamteyssier
- License: mit
- Created: 2023-08-22T17:50:38.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-23T18:39:15.000Z (almost 3 years ago)
- Last Synced: 2025-12-14T02:27:19.823Z (7 months ago)
- Topics: fai, fasta, indexed-fasta, query
- Language: Rust
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# faiquery
[](./LICENSE.md)

[](https://docs.rs/faiquery/latest/faiquery/)
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`](http://www.htslib.org/doc/samtools-faidx.html).
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
```rust
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:
- [faimm](https://crates.io/crates/faimm)
- [noodles](https://crates.io/crates/noodles)
- [rust-bio](https://crates.io/crates/bio)
If you are looking for a powerful concurrent reader I recommend
using the [faimm](https://crates.io/crates/faimm) crate.