pub struct SeqStats {
pub count: u64,
pub total_length: u64,
pub min_length: Option<u64>,
pub max_length: Option<u64>,
pub bases: BaseCounts,
/* private fields */
}Expand description
Accumulates length, composition and quality statistics.
use fastx::{FastxReader, SeqStats};
let data = b">a\nACGTACGTAC\n>b\nGGCC\n";
let mut stats = SeqStats::default();
FastxReader::new(&data[..]).for_each_record(|r| { stats.push(r); Ok(()) })?;
assert_eq!(stats.count, 2);
assert_eq!(stats.total_length, 14);
assert_eq!(stats.min_length, Some(4));
assert_eq!(stats.max_length, Some(10));
assert_eq!(stats.n50(), Some(10));Fields§
§count: u64Number of records seen.
total_length: u64Sum of all sequence lengths.
min_length: Option<u64>Shortest record, if any.
max_length: Option<u64>Longest record, if any.
bases: BaseCountsBase composition across all records.
Implementations§
Source§impl SeqStats
impl SeqStats
Sourcepub fn merge(&mut self, other: &SeqStats)
pub fn merge(&mut self, other: &SeqStats)
Merge another accumulator, for parallel or per-file aggregation.
Sourcepub fn mean_length(&self) -> Option<f64>
pub fn mean_length(&self) -> Option<f64>
Mean sequence length.
Sourcepub fn median_length(&self) -> Option<u64>
pub fn median_length(&self) -> Option<u64>
Median sequence length (lower median for an even count).
Sourcepub fn gc_content(&self) -> Option<f64>
pub fn gc_content(&self) -> Option<f64>
GC fraction over unambiguous bases.
Sourcepub fn quality_bases(&self) -> u64
pub fn quality_bases(&self) -> u64
Number of quality characters seen across all records.
Sourcepub fn quality_histogram(&self) -> &[u64; 94]
pub fn quality_histogram(&self) -> &[u64; 94]
Counts per Phred score, indexed by score — the same data FastQC plots.
let mut stats = SeqStats::new();
stats.push(&Sequence::fastq("r", b"ACGT", b"IIII")?);
assert_eq!(stats.quality_histogram()[40], 4); // 'I' is Q40Sourcepub fn expected_errors(&self) -> f64
pub fn expected_errors(&self) -> f64
Expected number of wrong bases across all records.
Sourcepub fn mean_quality(&self) -> Option<f64>
pub fn mean_quality(&self) -> Option<f64>
Mean quality as a Phred score, derived from the mean error rate.
Sourcepub fn q20_fraction(&self) -> Option<f64>
pub fn q20_fraction(&self) -> Option<f64>
Fraction of bases at Q20 or better.
Sourcepub fn q30_fraction(&self) -> Option<f64>
pub fn q30_fraction(&self) -> Option<f64>
Fraction of bases at Q30 or better.
Sourcepub fn fraction_at_least(&self, score: u8) -> Option<f64>
pub fn fraction_at_least(&self, score: u8) -> Option<f64>
Fraction of bases whose Phred score is at least score.
Sourcepub fn to_json(&self) -> String
pub fn to_json(&self) -> String
Render the statistics as a JSON object, for pipelines that parse output.
The object is on one line, so a run over several files is valid
line-delimited JSON and streams straight into jq. Pipe through jq .
if you want it laid out.
Absent figures — quality for FASTA, N50 after
SeqStats::forget_lengths — come out as null rather than being
omitted, so the shape of the object never changes.
let mut stats = SeqStats::new();
stats.push(&Sequence::fasta("a", b"ACGT"));
let json = stats.to_json();
assert!(json.starts_with('{') && json.ends_with('}'));
assert!(!json.contains('\n'), "must stay on one line");
assert!(json.contains("\"records\":1"));
assert!(json.contains("\"mean_quality\":null"));Sourcepub fn forget_lengths(&mut self)
pub fn forget_lengths(&mut self)
Drop the retained per-record lengths to cap memory on huge inputs.
After this call SeqStats::n50, SeqStats::median_length and
SeqStats::l50 return None, but counts and means stay correct.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SeqStats
impl RefUnwindSafe for SeqStats
impl Send for SeqStats
impl Sync for SeqStats
impl Unpin for SeqStats
impl UnsafeUnpin for SeqStats
impl UnwindSafe for SeqStats
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more