Alignment

Struct Alignment 

Source
pub struct Alignment<T> { /* private fields */ }
Expand description

An alignment of DNA or amino acids sequences

Aligned sequences should all have the same length. Each sequence is stored as one vector of chars. This allows an easy access to columns and rows of the alignment.

Implementations§

Source§

impl<T> Alignment<T>

Source

pub const fn length(&self) -> &usize

Returns the fixed length of the Alignment self

Source

pub const fn n_sequences(&self) -> &usize

Returns the number of sequences contained in self

Source

pub fn iter_positions( &self, ) -> impl Iterator<Item = Vec<&T>> + ExactSizeIterator<Item = Vec<&T>>
where T: Clone,

Returns an Iterator over the positions of the alignment

§Examples
let align = Alignment::with_sequences(
    &[
        b"AVEQTPRK".to_vec(),
        b"SVEQTPRK".to_vec(),
        b"SVEQTPKK".to_vec(),
    ],
)
.unwrap();

for position in align.iter_positions() {
    assert_eq!(position.len(), 3)
}
Source

pub fn iter_sequences( &self, ) -> impl Iterator<Item = Vec<&T>> + ExactSizeIterator<Item = Vec<&T>>
where T: Clone,

Returns an Iterator over the sequences of the alignment

§Examples
let align = Alignment::with_sequences(
    &[
        b"AVEQTPRK".to_vec(),
        b"SVEQTPRK".to_vec(),
        b"SVEQTPKK".to_vec(),
    ],
)
.unwrap();

for sequence in align.iter_sequences() {
    assert_eq!(sequence.len(), 8)
}
Source

pub const fn new(length: usize) -> Self

Returns an empty Alignment of fixed length

§Examples
 let alignment = Alignment::<char>::new(42);

 assert_eq!(*alignment.length(), 42 as usize);
 assert_eq!(*alignment.n_sequences(), 0 as usize);
Source

pub const fn is_empty(&self) -> bool

Returns true if self doesn’t contains any sequence

§Examples
let alignment = Alignment::<char>::new(42);

assert!(alignment.is_empty())
Source

pub fn with_sequences(sequences: &[Vec<T>]) -> Result<Self, MultiSeqAlignError>
where T: Clone,

Create an Alignment from same length vectors of names, descriptions, sequences

§Examples
let align = Alignment::with_sequences(
    &[
        b"AVEQTPRK".to_vec(),
        b"SVEQTPRK".to_vec(),
        b"SVEQTPKK".to_vec(),
    ],
)
.unwrap();

assert_eq!(*align.length(), 8);
assert_eq!(*align.n_sequences(), 3);
§Errors

Will return an error if names, descriptions and sequences have different lengths, and also if the sequences have different lengths (based on the first sequence).

Source

pub fn add<'a>( &'a mut self, sequence: Vec<T>, ) -> Result<&'a mut Self, MultiSeqAlignError>

Add a sequence to self

The new sequence must have the same length than self.length.

§Examples
let mut align = Alignment::new(8);

 assert_eq!(*align.n_sequences(), 0);

align
    .add(b"AVEQTPRK".to_vec())
    .unwrap();

assert_eq!(*align.n_sequences(), 1);

align
    .add(b"SVEQTPRK".to_vec())
    .unwrap();

assert_eq!(*align.n_sequences(), 2);
§Errors

Will return an error if the length of sequence is different from the one of the alignment.

Source

pub fn nth_position(&self, n: usize) -> Option<Vec<&T>>

Returns all amino acids / bases at a position in the alignment self. The returned vector has a length equal of number of sequences in self.

§Examples
let align = Alignment::<u8>::with_sequences(
    &[b"ELK".to_vec(), b"ILK".to_vec()],
)
.unwrap();

assert_eq!(align.nth_position(0).unwrap(), &[&b'E', &b'I']);
§Panics

Panics if n is greater or equal to the length of the Alignment.

Source

pub fn nth_sequence(&self, index: usize) -> Option<Vec<&T>>

Returns all amino acids / bases of the sequence at the index of the Alignment self. The returned vector has a length equal to the length of the Alignment self.

§Examples
let align = Alignment::<u8>::with_sequences(
    &[b"ELK".to_vec(), b"ILK".to_vec()],
)
.unwrap();

assert_eq!(align.nth_sequence(1).unwrap(), &[&b'I', &b'L', &b'K']);
§Panics

Panics if index is greater or equal to the n_sequences of the Alignment.

Trait Implementations§

Source§

impl<T: Clone> Clone for Alignment<T>

Source§

fn clone(&self) -> Alignment<T>

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<T: Debug> Debug for Alignment<T>

Source§

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

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

impl<T> Default for Alignment<T>
where T: Clone,

Source§

fn default() -> Self

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

impl<A> FromIterator<Vec<A>> for Alignment<A>
where A: Clone,

Source§

fn from_iter<I: IntoIterator<Item = Vec<A>>>(iter: I) -> Self

§Panics

Panics if sequences are of different lengths

Source§

impl<T: Hash> Hash for Alignment<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Ord> Ord for Alignment<T>

Source§

fn cmp(&self, other: &Alignment<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for Alignment<T>

Source§

fn eq(&self, other: &Alignment<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<T: PartialOrd> PartialOrd for Alignment<T>

Source§

fn partial_cmp(&self, other: &Alignment<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Eq> Eq for Alignment<T>

Source§

impl<T> StructuralPartialEq for Alignment<T>

Auto Trait Implementations§

§

impl<T> Freeze for Alignment<T>

§

impl<T> RefUnwindSafe for Alignment<T>
where T: RefUnwindSafe,

§

impl<T> Send for Alignment<T>
where T: Send,

§

impl<T> Sync for Alignment<T>
where T: Sync,

§

impl<T> Unpin for Alignment<T>
where T: Unpin,

§

impl<T> UnwindSafe for Alignment<T>
where T: UnwindSafe,

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.