[][src]Struct multi_seq_align::Alignment

pub struct Alignment<T> { /* fields omitted */ }

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

impl<T> Alignment<T>[src]

#[must_use]pub const fn length(&self) -> &usize[src]

Returns the fixed length of the Alignment self

#[must_use]pub const fn n_sequences(&self) -> &usize[src]

Returns the number of sequences contained in self

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

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

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

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

#[must_use]pub const fn new(length: usize) -> Self[src]

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

#[must_use]pub const fn is_empty(&self) -> bool[src]

Returns true if self doesn't contains any sequence

Examples

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

assert!(alignment.is_empty())

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

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

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

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.

#[must_use]pub fn nth_position(&self, n: usize) -> Option<Vec<&T>>[src]

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.

#[must_use]pub fn nth_sequence(&self, index: usize) -> Option<Vec<&T>>[src]

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

impl<T: Clone> Clone for Alignment<T>[src]

impl<T: Debug> Debug for Alignment<T>[src]

impl<T> Default for Alignment<T> where
    T: Clone
[src]

impl<T: Eq> Eq for Alignment<T>[src]

impl<A> FromIterator<Vec<A>> for Alignment<A> where
    A: Clone
[src]

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

Panics

Panics if sequences are of different lengths

impl<T: Hash> Hash for Alignment<T>[src]

impl<T: Ord> Ord for Alignment<T>[src]

impl<T: PartialEq> PartialEq<Alignment<T>> for Alignment<T>[src]

impl<T: PartialOrd> PartialOrd<Alignment<T>> for Alignment<T>[src]

impl<T> StructuralEq for Alignment<T>[src]

impl<T> StructuralPartialEq for Alignment<T>[src]

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.