Crates.io | nafcodec |
lib.rs | nafcodec |
version | 0.2.0 |
source | src |
created_at | 2023-10-07 18:54:00.394224 |
updated_at | 2024-04-10 09:45:27.712665 |
description | Rust coder/decoder for Nucleotide Archive Format (NAF) files. |
homepage | https://github.com/althonos/nafcodec |
repository | https://github.com/althonos/nafcodec |
max_upload_size | |
id | 996541 |
size | 80,347 |
nafcodec
Rust coder/decoder for Nucleotide Archive Format (NAF) files.
Nucleotide Archive Format is a file format proposed in Kryukov et al.[1] in 2019 for storing compressed nucleotide or protein sequences combining 4-bit encoding and Zstandard compression. NAF files can be compressed and decompressed using the original C implementation.
This crate provides a Rust implementation of a NAF decoder, from scratch,
using nom
for parsing the binary format,
and zstd
for handling Zstandard
decompression. It provides a complete API that allows iterating over
the contents of a NAF file.
This is the Rust version, there is a Python package available as well.
Use a Decoder
to iterate over the contents of a Nucleotide Archive Format,
reading from any BufRead
+
Seek
implementor:
let mut decoder = nafcodec::Decoder::from_path("../data/LuxC.naf")
.expect("failed to open nucleotide archive");
for result in decoder {
let record = result.unwrap();
// .. do something with the record .. //
}
All fields of the obtained Record
are optional, and actually depend on the kind of data that was compressed.
The decoder can be configured through a
DecoderBuilder
to ignore some fields to make decompression faster, even if they are present
in the source archive:
let mut decoder = nafcodec::DecoderBuilder::new()
.quality(false)
.with_path("../data/phix.naf")
.expect("failed to open nucleotide archive");
// the archive contains quality strings...
assert!(decoder.header().flags().test(nafcodec::Flag::Quality));
// ... but we configured the decoder to ignore them
for result in decoder {
let record = result.unwrap();
assert!(record.quality.is_none())
}
Found a bug ? Have an enhancement request ? Head over to the GitHub issue tracker if you need to report or ask something. If you are filing in on a bug, please include as much information as you can about the issue, and try to recreate the same bug in a simple, easily reproducible situation.
This project adheres to Semantic Versioning and provides a changelog in the Keep a Changelog format.
This library is provided under the open-source MIT license. The NAF specification is in the public domain.
This project is in no way not affiliated, sponsored, or otherwise endorsed by the original NAF authors. It was developed by Martin Larralde during his PhD project at the European Molecular Biology Laboratory in the Zeller team.