Module hpo::similarity
source · Expand description
Methods to calculate the Similarity between two terms or sets of terms
Several methods and algorithms to calculate the similarity are already
provided in the library, but you can easily add your own as well.
The easiest way is to use the Builtins
enum.
§Examples
§Using built-in methods
use hpo::Ontology;
use hpo::similarity::{Builtins, Similarity};
use hpo::term::InformationContentKind;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let term1 = ontology.hpo(12638u32).unwrap();
let term2 = ontology.hpo(100547u32).unwrap();
let ic = Builtins::GraphIc(InformationContentKind::Omim);
let similarity = ic.calculate(&term1, &term2);
println!("The termss {} and {} have a similarity of {}", term1.id(), term2.id(), similarity);
// ==> "The terms HP:0012638 and HP:0100547 have a similarity of 0.2704636"
§Create a custom similarity algorithm
Creating you own similarity algorithm is as easy as implementing the Similarity trait.
use hpo::{Ontology, HpoTerm};
use hpo::similarity::Similarity;
struct Foo {}
impl Similarity for Foo {
/// Calculate similarity based on length of the term names
fn calculate(&self, a: &HpoTerm, b: &HpoTerm) -> f32 {
return (a.name().len() - b.name().len()) as f32
}
}
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let term1 = ontology.hpo(12638u32).unwrap();
// ==> "Abnormal nervous system physiology"
let term2 = ontology.hpo(100547u32).unwrap();
// ==> "Abnormal forebrain morphology"
let ic = Foo{};
let similarity = ic.calculate(&term1, &term2);
assert_eq!(similarity, 5.0);
Re-exports§
pub use defaults::Distance;
pub use defaults::GraphIc;
pub use defaults::InformationCoefficient;
pub use defaults::Jc;
pub use defaults::Lin;
pub use defaults::Mutation;
pub use defaults::Relevance;
pub use defaults::Resnik;
Modules§
- Contains implementation for some Similarity algorithms that are considered to be default implementations.
Structs§
Enums§
- Contains similarity methods for the standard built-in algorithms
- Default implementations for combining similarity scores of 2
HpoSet
s