https://github.com/cidm-ph/distmat
Distance matrix data types and file formats for Rust
https://github.com/cidm-ph/distmat
bioinformatics data-structures distance-matrix
Last synced: 7 months ago
JSON representation
Distance matrix data types and file formats for Rust
- Host: GitHub
- URL: https://github.com/cidm-ph/distmat
- Owner: cidm-ph
- License: apache-2.0
- Created: 2022-09-29T01:55:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-11T09:46:29.000Z (over 1 year ago)
- Last Synced: 2025-08-30T08:53:14.146Z (7 months ago)
- Topics: bioinformatics, data-structures, distance-matrix
- Language: Rust
- Homepage:
- Size: 118 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# distmat
[](https://crates.io/crates/distmat)

[](https://docs.rs/distmat)
> **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:
// _1__5__3
// 1|
// 5| 4
// 3| 2 2
let matrix1 = DistMatrix::from_pw_distances(&[1, 5, 3]);
assert_eq!(matrix1.get(1, 2), Some(&2));
assert_eq!(matrix1.get(2, 1), None);
assert_eq!(
matrix1.get_symmetric(2, 1).map(|x| x.get_or_default()),
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::();
}
assert_eq!(total, 0);
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](LICENSE-MIT) or [Apache 2.0](LICENSE-APACHE).
© Western Sydney Local Health District, NSW Health.