Skip to main content

SamStats

Struct SamStats 

Source
pub struct SamStats {
Show 24 fields pub total_reads: usize, pub mapped_reads: usize, pub unmapped_reads: usize, pub properly_paired: usize, pub duplicates: usize, pub secondary_alignments: usize, pub supplementary_alignments: usize, pub qc_failed: usize, pub mapq_stats: RunningStats, pub mapq_distribution: CategoryCounter<u8>, pub length_stats: RunningStats, pub length_distribution: CategoryCounter<usize>, pub reads_per_chrom: CategoryCounter<String>, pub high_quality_mapq10: usize, pub high_quality_mapq20: usize, pub high_quality_mapq30: usize, pub first_in_pair: usize, pub second_in_pair: usize, pub reverse_strand: usize, pub total_matches: u64, pub total_insertions: u64, pub total_deletions: u64, pub total_soft_clips: u64, pub total_hard_clips: u64,
}
Expand description

Comprehensive statistics for SAM files

Fields§

§total_reads: usize

Total number of reads

§mapped_reads: usize

Number of mapped reads

§unmapped_reads: usize

Number of unmapped reads

§properly_paired: usize

Number of reads mapped in proper pairs

§duplicates: usize

Number of duplicate reads

§secondary_alignments: usize

Number of secondary alignments

§supplementary_alignments: usize

Number of supplementary alignments

§qc_failed: usize

Number of QC-failed reads

§mapq_stats: RunningStats

Mapping quality statistics (for mapped reads only)

§mapq_distribution: CategoryCounter<u8>

Distribution of mapping qualities

§length_stats: RunningStats

Read length statistics

§length_distribution: CategoryCounter<usize>

Distribution of read lengths

§reads_per_chrom: CategoryCounter<String>

Reads per chromosome

§high_quality_mapq10: usize

Number of reads with MAPQ >= 10

§high_quality_mapq20: usize

Number of reads with MAPQ >= 20

§high_quality_mapq30: usize

Number of reads with MAPQ >= 30

§first_in_pair: usize

Paired-end statistics

§second_in_pair: usize§reverse_strand: usize§total_matches: u64

CIGAR operation statistics

§total_insertions: u64§total_deletions: u64§total_soft_clips: u64§total_hard_clips: u64

Implementations§

Source§

impl SamStats

Source

pub fn new() -> Self

Create a new statistics collector

Source

pub fn update(&mut self, record: &SamRecord)

Update statistics with a single record (streaming)

Optimized for single-pass processing: computes all statistics in one iteration over alignment data, avoiding repeated allocations and iterations.

Source

pub fn par_compute(_reader: &mut SamReader, _threads: usize) -> Result<Self>

Compute statistics in parallel (not yet implemented for SAM)

SAM files are text-based and harder to parallelize efficiently than binary BAM files. For now, use compute() for sequential processing, which is still fast.

Future implementation may support:

  • Chunked parallel processing with line-boundary detection
  • Memory-mapped file access with parallel scanning

For parallel statistics on alignment files, consider using BAM format instead.

Source

pub fn compute(reader: &mut SamReader) -> Result<Self>

Compute statistics from a SAM reader (sequential processing)

SAM files are text-based, so parallel processing is more complex than BAM. For now, we use sequential processing which is still very fast for text parsing.

§Example
use genomicframe_core::formats::sam::{SamReader, SamStats};

let mut reader = SamReader::from_path("alignments.sam")?;
reader.read_header()?;
let stats = SamStats::compute(&mut reader)?;
stats.print_summary();
Source

pub fn mean_length(&self) -> Option<f64>

Mean read length

Source

pub fn std_length(&self) -> Option<f64>

Standard deviation of read length

Source

pub fn min_length(&self) -> Option<f64>

Min read length

Source

pub fn max_length(&self) -> Option<f64>

Max read length

Source

pub fn mean_mapq(&self) -> Option<f64>

Mean mapping quality (for mapped reads)

Source

pub fn std_mapq(&self) -> Option<f64>

Standard deviation of mapping quality

Source

pub fn mapping_rate(&self) -> f64

Mapping rate (percentage of mapped reads)

Source

pub fn properly_paired_rate(&self) -> f64

Properly paired rate (percentage of properly paired reads)

Source

pub fn duplicate_rate(&self) -> f64

Duplicate rate (percentage of duplicate reads)

Source

pub fn percent_mapq10(&self) -> f64

Percentage of reads with MAPQ >= 10

Source

pub fn percent_mapq20(&self) -> f64

Percentage of reads with MAPQ >= 20

Source

pub fn percent_mapq30(&self) -> f64

Percentage of reads with MAPQ >= 30

Source

pub fn print_summary(&self)

Print a human-readable summary of statistics

Trait Implementations§

Source§

impl Clone for SamStats

Source§

fn clone(&self) -> SamStats

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SamStats

Source§

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

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

impl Default for SamStats

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Mergeable for SamStats

Implementation of Mergeable for parallel statistics computation

Merges SAM statistics from multiple threads/chunks. All statistics are correctly combined using the underlying Mergeable implementations for RunningStats and CategoryCounter.

Source§

fn merge(&mut self, other: Self)

Merge another stats object into this one Read more
Source§

fn merge_all(stats: Vec<Self>) -> Option<Self>

Merge multiple stats objects into one (convenience method)

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.