FastX
FastX implements low overhead readers for Fasta and FastQ.
- Version 0.3.0 added .gz support.
- Version 0.5.0 added iterator support.
- Version 0.5.2 added compressed fasta (fasta.gz).
- Version 0.6.0 added high-performance
for_eachiteration, improved FASTQ parsing correctness, and exposed public API for indexed random access (.fai and .gzi).
Examples
High-Performance Reading (Recommended)
For maximum performance, use the for_each methods which reuse the internal buffer for each record, avoiding allocations.
use ;
use Path;
Iterator-Based Reading (Convenient)
The iterator API is convenient for standard Rust loops but allocates a new buffer for each record.
use ;
use Path;
Random Access with Indexed Files
FastX supports random access to BGZF-compressed FASTA files using .fai and .gzi indexes.
use IndexedFastXReader;
use FastXRead;
use Path;
Features
FastX supports different compression backends through Cargo features. Choose the backend that best fits your needs:
Default: Pure Rust Backend
By default, FastX uses the rust-backend feature, which provides a pure Rust implementation (miniz_oxide) for gzip decompression:
[]
= "0.6"
This is the safest option with no C dependencies, making it ideal for cross-compilation and environments where you want to avoid native code.
Alternative Backends
For better performance, you can select different compression backends:
System zlib - Uses the zlib library installed on your system (typically fastest on systems with optimized zlib):
[]
= { = "0.6", = false, = ["zlib"] }
zlib-ng (compatibility mode) - Modern, fast implementation that's API-compatible with zlib:
[]
= { = "0.6", = false, = ["zlib-ng-compat"] }
zlib-ng (native API) - Fastest option using zlib-ng's native API:
[]
= { = "0.6", = false, = ["zlib-ng"] }
URL Support
Enable the url feature (enabled by default) to read indexed files directly from HTTP/HTTPS URLs:
let mut reader = from_url?;
Performance Considerations
- rust-backend: Safe, portable, no build dependencies. Moderate performance.
- zlib: Good performance if your system has an optimized zlib (e.g., Intel's optimized version).
- zlib-ng-compat: Better performance than standard zlib on most systems.
- zlib-ng: Best performance, but requires C compiler at build time.