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 char
s. This allows an easy access to columns and rows of the alignment.
Implementations§
Source§impl<T> Alignment<T>
impl<T> Alignment<T>
Sourcepub const fn n_sequences(&self) -> &usize
pub const fn n_sequences(&self) -> &usize
Returns the number of sequences contained in self
Sourcepub fn iter_positions(
&self,
) -> impl Iterator<Item = Vec<&T>> + ExactSizeIterator<Item = Vec<&T>>where
T: Clone,
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)
}
Sourcepub fn iter_sequences(
&self,
) -> impl Iterator<Item = Vec<&T>> + ExactSizeIterator<Item = Vec<&T>>where
T: Clone,
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)
}
Sourcepub const fn new(length: usize) -> Self
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);
Sourcepub const fn is_empty(&self) -> bool
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())
Sourcepub fn with_sequences(sequences: &[Vec<T>]) -> Result<Self, MultiSeqAlignError>where
T: Clone,
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).
Sourcepub fn add<'a>(
&'a mut self,
sequence: Vec<T>,
) -> Result<&'a mut Self, MultiSeqAlignError>
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.
Sourcepub fn nth_position(&self, n: usize) -> Option<Vec<&T>>
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.
Sourcepub fn nth_sequence(&self, index: usize) -> Option<Vec<&T>>
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.