Skip to main content

ConsensusSequence

Struct ConsensusSequence 

Source
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

Source

pub fn new() -> ConsensusSequence

Creates a new empty consensus sequence.

Source

pub fn with_capacity(capacity: usize) -> ConsensusSequence

Creates a new consensus sequence with the given capacity.

Source

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.

Source

pub fn len(&self) -> usize

Returns the length of the consensus sequence.

Source

pub fn is_empty(&self) -> bool

Returns true if the consensus sequence is empty.

Source

pub fn push(&mut self, base: u8, qual: u8, depth: u16, error: u16)

Appends a single base with its annotations.

Source

pub fn extend(&mut self, other: &ConsensusSequence)

Extends this sequence with another.

Source

pub fn clear(&mut self)

Clears all vectors.

Source

pub fn bases(&self) -> &[u8]

Returns the consensus bases.

Source

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).

Source

pub fn quals(&self) -> &[u8]

Returns the quality scores.

Source

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).

Source

pub fn depths(&self) -> &[u16]

Returns the per-base depths.

Source

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).

Source

pub fn errors(&self) -> &[u16]

Returns the per-base error counts.

Source

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).

Source

pub fn max_depth(&self) -> u16

Returns the maximum depth across all positions.

Source

pub fn min_depth(&self) -> u16

Returns the minimum depth across all positions.

Source

pub fn error_rate(&self) -> f32

Returns the error rate (total errors / total depth).

Source

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.

Source

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 right
  • base - 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

Source§

fn clone(&self) -> ConsensusSequence

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 ConsensusSequence

Source§

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

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

impl Default for ConsensusSequence

Source§

fn default() -> ConsensusSequence

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

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.