distmat

crates-io-v crates-io-l docs-rs

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.

```rust use distmat::{DistMatrix, SquareMatrix}; use distmat::formats::{PhylipDialect, Separator, TabularShape};

fn main() { // A symmetric matrix stored as the lower triangle: // 153 // 1| // 5| 4 // 3| 2 2 let matrix1 = DistMatrix::frompwdistances(&[1, 5, 3]); asserteq!(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();

}

```

Purpose

Goals:

Non-goals:

License

Dual-licensed under MIT or Apache 2.0.

© Western Sydney Local Health District, NSW Health.