pub struct FastqReader<R> { /* private fields */ }Expand description
Slab-based FASTQ reader over any Read input.
The reader frames four-line FASTQ records from a reusable byte slab. Records
crossing slab boundaries are carried into the next read. Returned batches
borrow from the reader and must be consumed before calling next_batch
again.
Implementations§
Source§impl<R: Read> FastqReader<R>
impl<R: Read> FastqReader<R>
Sourcepub fn new(reader: R) -> Self
pub fn new(reader: R) -> Self
Create a reader with FastqConfig::default.
Examples found in repository?
45fn main() -> Result<()> {
46 let stdin = io::stdin();
47 let mut reader = FastqReader::new(stdin.lock());
48 let config = FastqChunkConfig::new(10_000_000).min_records(40_000);
49 let mut sink = ReadBuffer::default();
50
51 sink.reserve_records(config.estimated_records(150));
52 while let Some(stats) = reader.next_chunk_with_sink(config, &mut sink)? {
53 let checksum: usize = sink
54 .reads
55 .iter()
56 .map(|read| read.name.len() ^ read.seq.len() ^ read.qual.len())
57 .sum();
58 eprintln!(
59 "chunk first_record={} records={} bases={} checksum={}",
60 stats.first_record_index(),
61 stats.records(),
62 stats.bases(),
63 checksum
64 );
65
66 // Downstream tools typically hand `sink.reads` to alignment or another
67 // processing stage here, then reuse the allocation for the next chunk.
68 sink.clear();
69 sink.reserve_records(config.estimated_records(150));
70 }
71
72 Ok(())
73}Sourcepub fn with_config(reader: R, config: FastqConfig) -> Self
pub fn with_config(reader: R, config: FastqConfig) -> Self
Create a reader with explicit configuration.
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Return the wrapped reader.
Sourcepub fn next_batch(&mut self) -> Result<Option<FastqBatch<'_>>>
pub fn next_batch(&mut self) -> Result<Option<FastqBatch<'_>>>
Read the next batch of FASTQ records.
Returns Ok(None) at EOF. Format errors include byte offset, record
index, and line index when the failing location is known.
Sourcepub fn visit_records<F>(&mut self, visit: F) -> Result<()>
pub fn visit_records<F>(&mut self, visit: F) -> Result<()>
Visit every record in the stream without building a batch side table.
This is the fastest public parse-only path for single-pass consumers.
It still honors FastqConfig::validate for record structure, but it
yields individual records and does not perform paired-end identifier
validation. Use next_batch,
interleaved_pairs, or
PairedFastqReader when pair validation is required.
Sourcepub fn count_records(&mut self) -> Result<FastqStats>
pub fn count_records(&mut self) -> Result<FastqStats>
Count remaining records and bases without building record views.
This consumes the reader to EOF. It validates the same four-line FASTQ
structure as visit_records when
FastqConfig::validate is enabled, but it avoids the per-record
visitor callback and borrowed-record construction.
Sourcepub fn next_chunk_with_sink<S>(
&mut self,
config: FastqChunkConfig,
sink: &mut S,
) -> Result<Option<FastqChunkStats>>where
S: FastqRecordSink,
pub fn next_chunk_with_sink<S>(
&mut self,
config: FastqChunkConfig,
sink: &mut S,
) -> Result<Option<FastqChunkStats>>where
S: FastqRecordSink,
Emit one resumable chunk of FASTQ records into a caller-owned sink.
This is the low-overhead path for downstream tools that already have a
target output representation. It does not build the RecordRef side
table used by next_batch, and it returns after the
configured chunk limit so callers can interleave parsing with their own
pipeline stages.
Returns Ok(None) only when EOF is reached before emitting another
record. A subsequent call resumes at the first unconsumed record.
Examples found in repository?
45fn main() -> Result<()> {
46 let stdin = io::stdin();
47 let mut reader = FastqReader::new(stdin.lock());
48 let config = FastqChunkConfig::new(10_000_000).min_records(40_000);
49 let mut sink = ReadBuffer::default();
50
51 sink.reserve_records(config.estimated_records(150));
52 while let Some(stats) = reader.next_chunk_with_sink(config, &mut sink)? {
53 let checksum: usize = sink
54 .reads
55 .iter()
56 .map(|read| read.name.len() ^ read.seq.len() ^ read.qual.len())
57 .sum();
58 eprintln!(
59 "chunk first_record={} records={} bases={} checksum={}",
60 stats.first_record_index(),
61 stats.records(),
62 stats.bases(),
63 checksum
64 );
65
66 // Downstream tools typically hand `sink.reads` to alignment or another
67 // processing stage here, then reuse the allocation for the next chunk.
68 sink.clear();
69 sink.reserve_records(config.estimated_records(150));
70 }
71
72 Ok(())
73}