distmat

Crates.iodistmat
lib.rsdistmat
version0.3.0
sourcesrc
created_at2022-09-29 03:03:31.407567
updated_at2022-12-08 01:18:21.911995
descriptionDistance matrix data types and file formats
homepage
repositoryhttps://github.com/cidm-ph/distmat/
max_upload_size
id676338
size95,379
Carl Suster (arcresu)

documentation

README

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.

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

Purpose

Goals:

  • Read and write pairwise distance data from any reasonable formats, especially those used in bioinformatics.
  • Provide a convenient API to interact with distance data.

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.

License

Dual-licensed under MIT or Apache 2.0.

© Western Sydney Local Health District, NSW Health.

Commit count: 32

cargo fmt