Crates.io | distmat |
lib.rs | distmat |
version | 0.3.0 |
source | src |
created_at | 2022-09-29 03:03:31.407567 |
updated_at | 2022-12-08 01:18:21.911995 |
description | Distance matrix data types and file formats |
homepage | |
repository | https://github.com/cidm-ph/distmat/ |
max_upload_size | |
id | 676338 |
size | 95,379 |
Distance matrix data types and file formats
Matrix types specialised for storing pairwise distance data, and parsers for some common file formats for storing such data.
use distmat::{DistMatrix, SquareMatrix};
use distmat::formats::{PhylipDialect, Separator, TabularShape};
fn main() {
// A symmetric matrix stored as the lower triangle:
// _1__5__3
// 1|
// 5| 4
// 3| 2 2
let matrix1 = DistMatrix::from_pw_distances(&[1, 5, 3]);
assert_eq!(matrix1.get_symmetric(1, 2), Some(2));
// A square matrix stored in row major order:
// _1___5___3
// 1| 0 -4 -2
// 5| 4 0 2
// 3| 2 -2 0
let matrix2 = SquareMatrix::from_pw_distances_with(&[1, 5, 3], |x, y| x - y);
let mut total = 0;
for row in matrix2.iter_rows() {
total += row.sum();
}
let _matrix =
SquareMatrix::from_tabular_file("snp-dists.dat", Separator::Char('\t'), TabularShape::Wide).unwrap();
let _matrix =
SquareMatrix::from_phylip_file("phylip.dist", PhylipDialect::Strict).unwrap();
let _matrix =
DistMatrix::from_phylip_file("phylip_lt.dist", PhylipDialect::Relaxed).unwrap();
}
Goals:
Non-goals:
Linear algebra. There are many linear algebra libraries available with matrix data structures. At most distmat will help you export your data to these libraries.
Algorithms. You can provide a closure to distmat to construct a distance matrix, but any specialised algorithms or distance measures are best implemented elsewhere.
Dual-licensed under MIT or Apache 2.0.
© Western Sydney Local Health District, NSW Health.