Skip to main content

FastqChunkConfig

Struct FastqChunkConfig 

Source
#[non_exhaustive]
pub struct FastqChunkConfig { pub target_bases: u64, pub min_records: usize, pub max_bases: u64, }
Expand description

Chunking policy for FastqReader::next_chunk_with_sink.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§target_bases: u64

Target number of sequence bases to emit before returning a chunk.

A value of zero disables the target limit.

§min_records: usize

Minimum number of records required before the target-base limit may stop a chunk.

Values below one are raised to one.

§max_bases: u64

Hard maximum number of sequence bases to emit before returning a chunk.

A value of zero disables the hard limit. Unlike target_bases, this limit is not gated by min_records.

Implementations§

Source§

impl FastqChunkConfig

Source

pub fn new(target_bases: u64) -> Self

Create a chunking policy with a target base count.

Examples found in repository?
examples/fastq_chunk_sink.rs (line 48)
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}
Source

pub fn min_records(self, min_records: usize) -> Self

Return a copy with a minimum record count.

Examples found in repository?
examples/fastq_chunk_sink.rs (line 48)
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}
Source

pub fn max_bases(self, max_bases: u64) -> Self

Return a copy with a hard maximum base count.

Source

pub fn target_bases(self) -> u64

Target bases per chunk. Zero means no target-base limit.

Source

pub fn min_records_value(self) -> usize

Minimum records required before the target-base limit may stop a chunk.

Source

pub fn max_bases_value(self) -> u64

Hard maximum bases per chunk. Zero means no hard limit.

Source

pub fn estimated_records(self, read_len: usize) -> usize

Estimate records per chunk for a fixed or representative read length.

Examples found in repository?
examples/fastq_chunk_sink.rs (line 51)
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}

Trait Implementations§

Source§

impl Clone for FastqChunkConfig

Source§

fn clone(&self) -> FastqChunkConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for FastqChunkConfig

Source§

impl Debug for FastqChunkConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for FastqChunkConfig

Source§

impl PartialEq for FastqChunkConfig

Source§

fn eq(&self, other: &FastqChunkConfig) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for FastqChunkConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.