pub struct NamedMatrix { /* private fields */ }Expand description
A named matrix for storing pairwise distances/scores with sequence names
§Examples
let names = vec!["seq1".to_string(), "seq2".to_string(), "seq3".to_string()];
let mut matrix = NamedMatrix::new(names);
// Set some values
matrix.set(0, 1, 0.5);
matrix.set(0, 2, 0.7);
matrix.set(1, 2, 0.3);
// Get values
assert_eq!(matrix.size(), 3);
assert_eq!(matrix.get(0, 1), 0.5);
assert_eq!(matrix.get(1, 0), 0.5); // Symmetric matrixImplementations§
Source§impl NamedMatrix
impl NamedMatrix
pub fn new(names: Vec<String>) -> Self
pub fn size(&self) -> usize
pub fn get(&self, row: usize, col: usize) -> f32
pub fn set(&mut self, row: usize, col: usize, value: f32)
pub fn get_names(&self) -> Vec<&String>
Sourcepub fn get_by_name(&self, name1: &str, name2: &str) -> Option<f32>
pub fn get_by_name(&self, name1: &str, name2: &str) -> Option<f32>
Get matrix value by sequence names
let names = vec!["seq1".to_string(), "seq2".to_string()];
let mut matrix = NamedMatrix::new(names);
matrix.set(0, 1, 0.5);
assert_eq!(matrix.get_by_name("seq1", "seq2"), Some(0.5));
assert_eq!(matrix.get_by_name("seq1", "seq3"), None); // Non-existent nameSourcepub fn set_by_name(
&mut self,
name1: &str,
name2: &str,
value: f32,
) -> Result<(), String>
pub fn set_by_name( &mut self, name1: &str, name2: &str, value: f32, ) -> Result<(), String>
Set matrix value by sequence names
let names = vec!["seq1".to_string(), "seq2".to_string()];
let mut matrix = NamedMatrix::new(names);
assert!(matrix.set_by_name("seq1", "seq2", 0.5).is_ok());
assert_eq!(matrix.get_by_name("seq1", "seq2"), Some(0.5));
assert!(matrix.set_by_name("seq1", "seq3", 0.5).is_err()); // Non-existent namepub fn from_pair_scores(infile: &str, same: f32, missing: f32) -> Self
Sourcepub fn from_relaxed_phylip(infile: &str) -> Self
pub fn from_relaxed_phylip(infile: &str) -> Self
Creates a new matrix from a relaxed PHYLIP format file
let matrix = NamedMatrix::from_relaxed_phylip("input.phy");Trait Implementations§
Auto Trait Implementations§
impl Freeze for NamedMatrix
impl RefUnwindSafe for NamedMatrix
impl Send for NamedMatrix
impl Sync for NamedMatrix
impl Unpin for NamedMatrix
impl UnwindSafe for NamedMatrix
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
Mutably borrows from an owned value. Read more
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>
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 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>
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