oxygraph/lib.rs
1//! `oxygraph` is a crate to aid in the analysis
2//! of ecological bipartite graphs. Still in development
3//! and *might* support other ecological graph types in the
4//! future.
5//!
6//! Creation of `BipartiteGraph` structs can be done through
7//! an input TSV:
8//!
9//! ```rust
10//! use oxygraph;
11//! use oxygraph::bipartite::Strata;
12//! use std::path::PathBuf;
13//!
14//! let path = PathBuf::from("./path/to/bipartite.tsv");
15//!
16//! // load into a BipartiteGraph structure
17//! // a quick peek at the source codes shows you
18//! // it's a thin wrapper over `petgraph`.
19//! let bpgraph = oxygraph::BipartiteGraph::from_dsv(&path, b'\t').unwrap();
20//!
21//! // check it's bipartite
22//! let check = match bpgraph.is_bipartite() {
23//! Strata::Yes(_) => "it's bipartite!",
24//! Strata::No => "it's not bipartite :(",
25//! };
26//!
27//!
28//! // create an interaction matrix
29//! let int_mat = oxygraph::InteractionMatrix::from_bipartite(bpgraph);
30//! // and look at some basic stats
31//! let stats = int_mat.stats();
32//!
33//! ```
34//!
35//! Or by creating a `petgraph` graph e.g.:
36//!
37//! ```rust
38//! use petgraph::Graph;
39//! use oxygraph::BipartiteGraph;
40//! use oxygraph::bipartite::SpeciesNode;
41//!
42//! let mut graph: Graph<SpeciesNode, f64> = Graph::new();
43//!
44//! // add nodes/edges etc...
45//!
46//! // now wrap in `BipartiteGraph` and access
47//! // all the methods associated.
48//! let bpgraph = BipartiteGraph(graph);
49//!
50//! ```
51//!
52//! More information and tutorials to follow.
53
54/// Create, analyse, and visualise bipartite
55/// graphs from tab delimited input data.
56pub mod bipartite;
57pub use bipartite::BipartiteGraph;
58pub use bipartite::BipartiteStats;
59/// Create, analyse, and visualise
60/// interaction matrices generated from a
61/// `BipartiteGraph`.
62pub mod int_matrix;
63pub use int_matrix::InteractionMatrix;
64pub use int_matrix::InteractionMatrixStats;
65
66/// The derived graphs of a bipartite graph.
67///
68/// There are two derived graphs, one for each stratum,
69/// and the edges in the graph correspond to how frequent
70/// shared connections are between two nodes in that stratum.
71pub mod derived;
72pub use derived::DerivedGraphStats;
73pub use derived::DerivedGraphs;
74
75/// Modularity calculations are in their own module, but they
76/// are built on top of an interaction matrix. Included are
77/// two algorithms from Beckett 2016.
78pub mod modularity;
79pub use modularity::LpaWbPlus;
80
81/// Sorting algorithms on arrays.
82pub mod sort;
83
84/// The margins for the all the graph plots
85/// used in this crate.
86const MARGIN_LR: f64 = 20.0;
87
88/// Scale a number between zero and 1, given a min/max.
89pub fn scale_fit(x: f64, min_x: f64, max_x: f64) -> f64 {
90 ((1.0 - 0.1) * ((x - min_x) / (max_x - min_x))) + 0.1
91}