paraseq
A high-performance Rust library for parallel processing of FASTA/FASTQ sequence files, optimized for modern hardware and large datasets.
Summary
paraseq is built specifically for processing paired-end FASTA/FASTQ sequences in a parallel manner.
It uses RecordSets as the primary unit of buffering, with each set directly reading a fixed number of records from the input stream.
To handle incomplete records it uses the shared Reader as an overflow buffer.
It adaptively manages buffer sizes based on observed record sizes, estimating the required space for the number of records in the set and minimizing the number of copies between buffers.
paraseq is most efficient in cases where the variance in record sizes is low as it can accurately minimize the number of copies between buffers.
It matches performance of non-record-set parsers (like seq_io and needletail), but can get higher-throughput in record-set contexts (i.e. multi-threaded contexts) by skipping a full copy of the input.
See benchmarking repo for benchmarking implementation.
If you're interested in reading more about it, I wrote a small blog post discussing its design and motivation.
Usage
The benefit of using paraseq is that it makes it easy to distribute paired-end records to per-record and per-batch processing functions.
Code Examples
Check out the examples directory for code examples or the API documentation for more information.
Feel free to also explore seqpls a parallel paired-end FASTA/FASTQ sequence grepper to see how paraseq can be used in a non-toy example.
Basic Usage
This is a simple example using paraseq in a single-threaded context.
use File;
use ;
use Record;
Parallel Processing
To distribute processing across multiple threads you can implement the ParallelProcessor trait on your arbitrary struct.
For an example of a single-end parallel processor see the parallel example.
use File;
use ;
Paired-End Processing
Paired end processing is as simple as single-end processing, but involves implementing the PairedParallelProcessor trait on your struct.
For an example of paired parallel processing see the paired example.
use File;
use ;
Interleaved Processing
Interleaved processing is also supported by implementing the InterleavedParallelProcessor trait on your struct.
For an example of interleaved parallel processing see the interleaved example.
use File;
use ;
Limitations
-
In cases where records have high variance in size, the buffer size predictions will become inaccurate and the shared
Readeroverflow buffer will incur more copy operations. This may lead to suboptimal performance. -
Multiline FASTA is now supported! However, you will incur additional memory usage when calling the
Record::seq()method with multiline FASTA - as it incurs an allocation to remove newlines from the sequence. You can choose to avoid this by using the newly introducedRecord::seq_raw()method which will return the sequence buffer without any modifications (though it may have newlines). Here there be dragons! -
Each
RecordSetmaintains its own buffer, so memory usage practically scales with the number of threads and record capacity. This shouldn't be a concern unless you're running this on a system with very limited memory.
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Similar Projects
This work is inspired by the following projects:
This project aims to be directed more specifically at ergonomically processing of paired records in parallel and is optimized mainly for FASTQ files.
It can be faster than seq_io for some use cases, but it is not currently as rigorously tested. However, it now supports both single-line and multi-line FASTA files with optimized performance.
If the libraries assumptions do not fit your use case, you may want to consider using seq_io or fastq instead.