pub struct ConsensusSequence { /* private fields */ }Expand description
Consensus sequence with per-base annotations.
This struct maintains parallel vectors for bases, quality scores, depths, and errors. All vectors are guaranteed to have the same length through the API.
§Layout
Uses a Structure-of-Arrays layout for cache-friendly access:
- Sequential access to all bases is cache-efficient
- Sequential access to all qualities is cache-efficient
- etc.
§Example
use fgumi_lib::consensus::ConsensusSequence;
let mut seq = ConsensusSequence::new();
seq.push(b'A', 30, 10, 0);
seq.push(b'C', 25, 8, 1);
assert_eq!(seq.len(), 2);
assert_eq!(seq.bases(), &[b'A', b'C']);
assert_eq!(seq.quals(), &[30, 25]);Implementations§
Source§impl ConsensusSequence
impl ConsensusSequence
Sourcepub fn new() -> ConsensusSequence
pub fn new() -> ConsensusSequence
Creates a new empty consensus sequence.
Sourcepub fn with_capacity(capacity: usize) -> ConsensusSequence
pub fn with_capacity(capacity: usize) -> ConsensusSequence
Creates a new consensus sequence with the given capacity.
Sourcepub fn from_vecs(
bases: Vec<u8>,
quals: Vec<u8>,
depths: Vec<u16>,
errors: Vec<u16>,
) -> ConsensusSequence
pub fn from_vecs( bases: Vec<u8>, quals: Vec<u8>, depths: Vec<u16>, errors: Vec<u16>, ) -> ConsensusSequence
Creates a consensus sequence from parallel vectors.
§Panics
Panics if the vectors have different lengths.
Sourcepub fn push(&mut self, base: u8, qual: u8, depth: u16, error: u16)
pub fn push(&mut self, base: u8, qual: u8, depth: u16, error: u16)
Appends a single base with its annotations.
Sourcepub fn extend(&mut self, other: &ConsensusSequence)
pub fn extend(&mut self, other: &ConsensusSequence)
Extends this sequence with another.
Sourcepub fn bases_mut(&mut self) -> &mut [u8] ⓘ
pub fn bases_mut(&mut self) -> &mut [u8] ⓘ
Returns mutable access to the consensus bases.
§Note
The caller should not change the length (slices prevent this anyway).
Sourcepub fn quals_mut(&mut self) -> &mut [u8] ⓘ
pub fn quals_mut(&mut self) -> &mut [u8] ⓘ
Returns mutable access to the quality scores.
§Note
The caller should not change the length (slices prevent this anyway).
Sourcepub fn depths_mut(&mut self) -> &mut [u16]
pub fn depths_mut(&mut self) -> &mut [u16]
Returns mutable access to the per-base depths.
§Note
The caller should not change the length (slices prevent this anyway).
Sourcepub fn errors_mut(&mut self) -> &mut [u16]
pub fn errors_mut(&mut self) -> &mut [u16]
Returns mutable access to the per-base error counts.
§Note
The caller should not change the length (slices prevent this anyway).
Sourcepub fn error_rate(&self) -> f32
pub fn error_rate(&self) -> f32
Returns the error rate (total errors / total depth).
Sourcepub fn into_vecs(self) -> (Vec<u8>, Vec<u8>, Vec<u16>, Vec<u16>)
pub fn into_vecs(self) -> (Vec<u8>, Vec<u8>, Vec<u16>, Vec<u16>)
Decomposes this sequence into its component vectors.
This is useful when the caller needs ownership of the vectors.
Sourcepub fn padded(
&self,
new_length: usize,
left: bool,
base: u8,
qual: u8,
) -> ConsensusSequence
pub fn padded( &self, new_length: usize, left: bool, base: u8, qual: u8, ) -> ConsensusSequence
Pads the sequence to a new length by adding values to the left or right.
§Arguments
new_length- Target length (must be >= current length)left- If true, pad on the left side; otherwise pad on the rightbase- Base to use for padding (default: ‘n’)qual- Quality to use for padding (default: 2)
§Panics
Panics if new_length < current length
Trait Implementations§
Source§impl Clone for ConsensusSequence
impl Clone for ConsensusSequence
Source§fn clone(&self) -> ConsensusSequence
fn clone(&self) -> ConsensusSequence
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ConsensusSequence
impl Debug for ConsensusSequence
Source§impl Default for ConsensusSequence
impl Default for ConsensusSequence
Source§fn default() -> ConsensusSequence
fn default() -> ConsensusSequence
Auto Trait Implementations§
impl Freeze for ConsensusSequence
impl RefUnwindSafe for ConsensusSequence
impl Send for ConsensusSequence
impl Sync for ConsensusSequence
impl Unpin for ConsensusSequence
impl UnsafeUnpin for ConsensusSequence
impl UnwindSafe for ConsensusSequence
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