pub struct Ontology { /* private fields */ }
Expand description
Ontology
is the main interface of the hpo
crate and contains all data
The Ontology
struct holds all information about the ontology
and all HpoTerm
s, Gene
s and OmimDisease
s.
§Examples
use hpo::{Ontology, HpoTermId};
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
// get single terms from the ontology
let absent_term = HpoTermId::try_from("HP:9999999").unwrap();
assert!(ontology.hpo(absent_term).is_none());
let present_term = HpoTermId::try_from("HP:0000001").unwrap();
let root_term = ontology.hpo(present_term).unwrap();
assert_eq!(root_term.name(), "All");
// simplified way to get an `HpoTerm` by using the `u32` `HpoTermId`
let term = ontology.hpo(118u32).unwrap();
assert_eq!(term.name(), "Phenotypic abnormality");
// get all genes of the ontology
assert_eq!(ontology.genes().count(), 4852);
// get all diseases of the ontology
assert_eq!(ontology.omim_diseases().count(), 4431);
// Iterate all HPO terms
for term in &ontology {
// do something with term
println!("{}", term.name());
}
§Construction
There are two main ways to build the Ontology
-
Download the standard annotation data from Jax HPO itself. Then use
Ontology::from_standard
to load the data. You need the following files:phenotype.hpoa
(Required to connectOmimDisease
s toHpoTerm
s)genes_to_phenotype.txt
(Required to connectGene
s toHpoTerm
s)- alternatively:
phenotype_to_genes.txt
(useOntology::from_standard_transitive
)
- alternatively:
hp.obo
(Required forHpoTerm
s and their connection to each other)
-
Load the ontology from a binary build using
Ontology::from_binary
.The Github repository of this crate contains a binary build of the ontology https://github.com/anergictcell/hpo/blob/main/tests/ontology.hpo. The snapshot will not always be up to date, so please double-check yourself.
You can crate your own binary build of the ontology using the
examples/obo_to_bin.rs
example.cargo run --example --release obo_to_bin <PATH TO FOLDER WITH JAX DATA> <OUTPUT FILENAME>
You can also build it all by yourself (not recommended), in which case you will have to:
- construct an empty Ontology
Ontology::default
- Add all terms
Ontology::insert_term
- Connect terms to their parents
Ontology::add_parent
- Cache all parent, child and grandparent connections
Ontology::create_cache
- Add genes and diseases to the ontology
Ontology::add_gene
andOntology::add_omim_disease
- Connect genes and diseases to the
HpoTerm
s usingOntology::link_gene_term
andOntology::link_omim_disease_term
(this will automatically take care of “inheriting” the connection to all parent terms) - make sure to also add the linked terms to the genes and diseases
Gene::add_term
andOmimDisease::add_term
- Calculate the information content
Ontology::calculate_information_content
§Layout
The Ontology
contains all terms and all associated genes and diseases.
HpoTerm
s are connected to each other in a directed relationship. Every term
(except the term All
) has at least one parent term in an is_a
relationship.
Terms and crate::annotations
(Gene
s, OmimDisease
s) have a many-to-many relationship. The
Ontology
does not contain a direct relationship between genes and diseases. This relation
is only present indirectly via the connected HpoTerm
s.
§Transivity of relations
New in 0.9.0
During the construction of the Ontology, every HpoTerm
inherits all gene and disease
association of its child terms.
But Gene
s and OmimDisease
s will only contain links to direct HpoTerm
s. The annotations
are not transitiv.
§Relations of different public struct in this module
The below diagram looks complicated at first, but the
relationship of all entities follows a logical pattern.
HpoTerm
and HpoSet
are the most important public structs.
The HpoGroup
is more relevant for internal use, but can also be
useful for fast set-based operations.
§Example ontology
For all examples and tests in this documentation, we’re using the following small subset of the full Ontology:
Abnormal cellular physiology"] HP:0010662["HP:0010662
Abnormality of the diencephalon"] HP:0010662 --> HP:0012285 HP:0000005["HP:0000005
Mode of inheritance"] HP:0000005 --> HP:0034345 HP:0012648["HP:0012648
Decreased inflammatory response"] HP:0012443["HP:0012443
Abnormality of brain morphology"] HP:0012443 --> HP:0100547 HP:0003674["HP:0003674
Onset"] HP:0003674 --> HP:0003581 HP:0010978["HP:0010978
Abnormality of immune system physiology"] HP:0010978 --> HP:0012647 HP:0000707["HP:0000707
Abnormality of the nervous system"] HP:0000707 --> HP:0012638 HP:0000707 --> HP:0012639 HP:0034345["HP:0034345
Mendelian inheritance"] HP:0034345 --> HP:0000007 HP:0000001["HP:0000001
All"] HP:0000001 -----> HP:0000005 HP:0000001 --> HP:0000118 HP:0000001 --> HP:0012823 HP:0000818["HP:0000818
Abnormality of the endocrine system"] HP:0000818 --> HP:0000864 HP:0100547["HP:0100547
Abnormal forebrain morphology"] HP:0100547 ----> HP:0010662 HP:0012647["HP:0012647
Abnormal inflammatory response"] HP:0012647 --> HP:0012648 HP:0001939["HP:0001939
Abnormality of metabolism/homeostasis"] HP:0001939 --> HP:0011017 HP:0001939 ---> HP:0025454 HP:0003581["HP:0003581
Adult onset"] HP:0012823["HP:0012823
Clinical modifier"] HP:0012823 --> HP:0031797 HP:0012285["HP:0012285
Abnormal hypothalamus physiology"] HP:0012638["HP:0012638
Abnormal nervous system physiology"] HP:0012638 ----> HP:0012285 HP:0000118["HP:0000118
Phenotypic abnormality"] HP:0000118 --> HP:0000707 HP:0000118 --> HP:0000818 HP:0000118 --> HP:0001939 HP:0000118 -----> HP:0002715 HP:0002011["HP:0002011
Morphological central nervous system abnormality"] HP:0002011 --> HP:0012443 HP:0031797["HP:0031797
Clinical course"] HP:0031797 --> HP:0003674 HP:0012639["HP:0012639
Abnormal nervous system morphology"] HP:0012639 --> HP:0002011 HP:0002715["HP:0002715
Abnormality of the immune system"] HP:0002715 --> HP:0010978 HP:0025454["HP:0025454
Abnormal CSF metabolite concentration"] HP:0000007["HP:0000007
Autosomal recessive inheritance"] HP:0000864["HP:0000864
Abnormality of the hypothalamus-pituitary axis"] HP:0000864 ---> HP:0012285
Implementations§
source§impl Ontology
impl Ontology
Public API of the Ontology
Those methods are all safe to use
sourcepub fn from_standard(folder: &str) -> HpoResult<Self>
pub fn from_standard(folder: &str) -> HpoResult<Self>
Initialize the Ontology
from data provided by Jax HPO
You must download:
- Actual OBO data:
hp.obo
- Links between HPO and OMIM diseases:
phenotype.hpoa
- Links between HPO and Genes:
phenotype_to_genes.txt
and then specify the folder where the data is stored.
§Errors
This method can fail for various reasons:
- obo file not present or available:
HpoError::CannotOpenFile
Ontology::add_gene
failedOntology::add_omim_disease
failed
§Note
Since version 0.9.0
this method will not load genes transitively. That means
only directly linked HpoTerm
s are connected to each gene. However, every
HpoTerm
will still inherit all gene and disease associations from its children.
See this discussion for a more detailed
explanation
§Examples
use hpo::Ontology;
use hpo::HpoTermId;
let ontology = Ontology::from_standard("/path/to/jax_hpo_data/").unwrap();
assert!(ontology.len() == 26);
let absent_term = HpoTermId::try_from("HP:9999999").unwrap();
assert!(ontology.hpo(absent_term).is_none());
let present_term = HpoTermId::try_from("HP:0000001").unwrap();
let root_term = ontology.hpo(present_term).unwrap();
assert_eq!(root_term.name(), "All");
sourcepub fn from_standard_transitive(folder: &str) -> HpoResult<Self>
pub fn from_standard_transitive(folder: &str) -> HpoResult<Self>
Initialize the Ontology
from data provided by Jax HPO
You must download:
- Actual OBO data:
hp.obo
- Links between HPO and OMIM diseases:
phenotype.hpoa
- Links between HPO and Genes:
genes_to_phenotypes.txt
and then specify the folder where the data is stored.
§Errors
This method can fail for various reasons:
- obo file not present or available:
HpoError::CannotOpenFile
Ontology::add_gene
failedOntology::add_omim_disease
failed
§Note
This method has one difference to Ontology::from_standard
in that every Gene
contains directly linked HpoTerm
and all their ancestor terms.
See this discussion for a more detailed
explanation
§Examples
use hpo::Ontology;
use hpo::HpoTermId;
let ontology = Ontology::from_standard_transitive("/path/to/jax_hpo_data/").unwrap();
assert!(ontology.len() == 26);
let absent_term = HpoTermId::try_from("HP:9999999").unwrap();
assert!(ontology.hpo(absent_term).is_none());
let present_term = HpoTermId::try_from("HP:0000001").unwrap();
let root_term = ontology.hpo(present_term).unwrap();
assert_eq!(root_term.name(), "All");
sourcepub fn from_binary<P: AsRef<Path>>(filename: P) -> HpoResult<Self>
pub fn from_binary<P: AsRef<Path>>(filename: P) -> HpoResult<Self>
Build an Ontology from a binary data blob
The data must be in the proper format, as defined in
Ontology::as_bytes
. This method adds all terms, creates the
parent-child structure of the ontology, adds genes and Omim diseases
and ensures proper inheritance of gene/disease annotations.
It also calculates the InformationContent
for every term.
§Errors
This method can fail for various reasons:
- Binary file not available:
HpoError::CannotOpenFile
Ontology::add_genes_from_bytes
failed (TODO)Ontology::add_omim_disease_from_bytes
failed (TODO)add_terms_from_bytes
failed (TODO)add_parent_from_bytes
failed (TODO)- Size of binary data does not match the content:
HpoError::ParseBinaryError
§Examples
use hpo::{Ontology, HpoTermId};
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
assert_eq!(ontology.len(), 26);
let absent_term = HpoTermId::try_from("HP:9999999").unwrap();
assert!(ontology.hpo(absent_term).is_none());
let present_term = HpoTermId::try_from("HP:0000001").unwrap();
let root_term = ontology.hpo(present_term).unwrap();
assert_eq!(root_term.name(), "All");
sourcepub fn from_bytes(bytes: &[u8]) -> HpoResult<Self>
pub fn from_bytes(bytes: &[u8]) -> HpoResult<Self>
Build an Ontology from bytes
The data must be in the proper format, as defined in
Ontology::as_bytes
. This method adds all terms, creates the
parent-child structure of the ontology, adds genes and Omim diseases
and ensures proper inheritance of gene/disease annotations.
It also calculates the InformationContent
for every term.
§Errors
This method can fail for various reasons:
- Too few bytes or an invalid version
Ontology::hpo_version_from_bytes
failedOntology::add_genes_from_bytes
failedOntology::add_omim_disease_from_bytes
failedadd_terms_from_bytes
failedadd_parent_from_bytes
failed- Size of binary data does not match the content:
HpoError::ParseBinaryError
§Examples
use std::fs::File;
use std::io::Read;
use hpo::{Ontology, HpoTermId};
let mut bytes = Vec::new();
let mut file = File::open("tests/example.hpo").unwrap();
file.read_to_end(&mut bytes).unwrap();
let ontology = Ontology::from_bytes(&bytes).unwrap();
assert_eq!(ontology.len(), 26);
let absent_term = HpoTermId::try_from("HP:9999999").unwrap();
assert!(ontology.hpo(absent_term).is_none());
let present_term = HpoTermId::try_from("HP:0000001").unwrap();
let root_term = ontology.hpo(present_term).unwrap();
assert_eq!(root_term.name(), "All");
sourcepub fn as_bytes(&self) -> Vec<u8> ⓘ
pub fn as_bytes(&self) -> Vec<u8> ⓘ
Returns a binary representation of the Ontology
The binary data is separated into sections:
- Metadata (HPO and Bindat Version) (see
Ontology::metadata_as_bytes
) - Terms (Names + IDs) (see
HpoTermInternal::as_bytes
) - Term - Parent connection (Child ID - Parent ID)
(see
HpoTermInternal::parents_as_byte
) - Genes (Names + IDs + Connected HPO Terms) (
Gene::as_bytes
) - OMIM Diseases (Names + IDs + Connected HPO Terms)
(
OmimDisease::as_bytes
)
Every section starts with 4 bytes to indicate its size
(big-endian encoded u32
)
This method is only useful if you use are modifying the ontology and want to save data for later re-use.
§Panics
Panics when the buffer length of any subsegment larger than u32::MAX
§Examples
use hpo::Ontology;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let bytes = ontology.as_bytes();
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of HPO-Terms in the Ontology
§Examples
use hpo::Ontology;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
assert_eq!(ontology.len(), 26);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the Ontology does not contain any HPO-Terms
§Examples
use hpo::Ontology;
let ontology = Ontology::default();
assert!(ontology.is_empty());
sourcepub fn hpo<I: Into<HpoTermId>>(&self, term_id: I) -> Option<HpoTerm<'_>>
pub fn hpo<I: Into<HpoTermId>>(&self, term_id: I) -> Option<HpoTerm<'_>>
Returns the HpoTerm
of the provided HpoTermId
If no such term is present in the Ontolgy, None
is returned
§Examples
use hpo::Ontology;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let term = ontology.hpo(11017u32).unwrap();
assert_eq!(term.name(), "Abnormal cellular physiology");
assert!(ontology.hpo(66666u32).is_none());
sourcepub fn gene_by_name(&self, symbol: &str) -> Option<&Gene>
pub fn gene_by_name(&self, symbol: &str) -> Option<&Gene>
Returns a reference to the Gene
with the provided symbol / name
If no such gene is present, None
is returned
§Note
Gene
s are not index by name, so this method searches through all
genes. If you can, prefer using Ontology::gene
with the GeneId
.
§Examples
use hpo::Ontology;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let gene = ontology.gene_by_name("AARS2").unwrap();
assert_eq!(gene.name(), "AARS2");
assert!(ontology.gene_by_name("FOOBAR66").is_none());
sourcepub fn omim_disease(
&self,
omim_disease_id: &OmimDiseaseId
) -> Option<&OmimDisease>
pub fn omim_disease( &self, omim_disease_id: &OmimDiseaseId ) -> Option<&OmimDisease>
Returns a reference to the OmimDisease
of the provided OmimDiseaseId
If no such disease is present, None
is returned
§Examples
use hpo::Ontology;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let disease = ontology.omim_disease(&601495u32.into()).unwrap();
assert_eq!(disease.name(), "Agammaglobulinemia 1, autosomal recessive");
sourcepub fn omim_diseases(&self) -> Values<'_, OmimDiseaseId, OmimDisease>
pub fn omim_diseases(&self) -> Values<'_, OmimDiseaseId, OmimDisease>
Returns an Iterator of all OmimDisease
s from the Ontology
It is likely that the return type will change to a dedicated Iterator
§Examples
use hpo::Ontology;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
for disease in ontology.omim_diseases() {
println!("{}", disease.name());
}
sourcepub fn omim_diseases_by_name<'a>(
&'a self,
substring: &'a str
) -> OmimDiseaseFilter<'_>
pub fn omim_diseases_by_name<'a>( &'a self, substring: &'a str ) -> OmimDiseaseFilter<'_>
Returns an Iterator of all OmimDisease
s whose names contains the provided
substring.
§Examples
use hpo::Ontology;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
for result in ontology.omim_diseases_by_name("Cystinosis") {
println!("{:?}", result.name());
}
sourcepub fn omim_disease_by_name(&self, substring: &str) -> Option<&OmimDisease>
pub fn omim_disease_by_name(&self, substring: &str) -> Option<&OmimDisease>
Returns the first matching OmimDisease
whose name contains the provided
substring.
If no such substring is present, return None
.
§Examples
use hpo::Ontology;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let cystinosis = ontology.omim_disease_by_name("Cystinosis");
sourcepub fn hpo_version(&self) -> String
pub fn hpo_version(&self) -> String
Returns the Jax-Ontology release version
e.g. 2023-03-13
sourcepub fn compare<'a>(&'a self, other: &'a Ontology) -> Comparison<'_>
pub fn compare<'a>(&'a self, other: &'a Ontology) -> Comparison<'_>
Compares self
to another Ontology
to identify added/removed terms, genes and diseases
§Examples
use hpo::Ontology;
let ontology_1 = Ontology::from_binary("tests/example.hpo").unwrap();
let mut ontology_2 = Ontology::default();
ontology_2.add_gene("FOOBAR", "666666").unwrap();
let compare = ontology_1.compare(&ontology_2);
assert_eq!(compare.added_hpo_terms().len(), 0);
assert_eq!(compare.removed_hpo_terms().len(), 26);
assert_eq!(compare.added_genes().len(), 1);
sourcepub fn sub_ontology<'a, T: IntoIterator<Item = HpoTerm<'a>>>(
&self,
root: HpoTerm<'_>,
leaves: T
) -> Result<Self, HpoError>
pub fn sub_ontology<'a, T: IntoIterator<Item = HpoTerm<'a>>>( &self, root: HpoTerm<'_>, leaves: T ) -> Result<Self, HpoError>
Constructs a smaller ontology that contains only the leaves
terms and
all terms needed to connect to each leaf to root
§Errors
Fails if root
is not an ancestor of all leaves
§Examples
use hpo::Ontology;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let ontology_2 = ontology.sub_ontology(
ontology.hpo(118u32).unwrap(),
vec![ontology.hpo(11017u32).unwrap()]
).unwrap();
assert_eq!(ontology_2.len(), 3);
sourcepub fn as_mermaid(&self) -> String
pub fn as_mermaid(&self) -> String
Returns the code to create a Mermaid
flow diagram
This is meant to be used with smaller ontologies, e.g. from Ontology::sub_ontology
sourcepub fn as_graphviz(&self, layout: &str) -> String
pub fn as_graphviz(&self, layout: &str) -> String
Returns the code to create a graphviz
flow diagram
Only node names are printed with one word per line for readability
Layout must be specified: dot
is useful for structured data, similar to mermaid output,
fdp
can be used when graph should be focused on the root node,
neato
is an alternative but quite slow for larger graph.
This is meant to be used with smaller ontologies, e.g. from Ontology::sub_ontology
sourcepub fn categories(&self) -> &HpoGroup
pub fn categories(&self) -> &HpoGroup
Returns a reference to the categories of the Ontology
Categories are top-level HpoTermId
s used for
categorizing individual HpoTerm
s.
See Ontology::set_default_categories()
for more information
§Examples
use hpo::{HpoTerm, Ontology};
let mut ontology = Ontology::from_binary("tests/example.hpo").unwrap();
assert_eq!(ontology.categories().len(), 6);
sourcepub fn categories_mut(&mut self) -> &mut HpoGroup
pub fn categories_mut(&mut self) -> &mut HpoGroup
Returns a mutable reference to the categories vector
This is a vector that should contain top-level HpoTermId
s used for
categorizing individual HpoTerm
s.
sourcepub fn set_default_categories(&mut self) -> HpoResult<()>
pub fn set_default_categories(&mut self) -> HpoResult<()>
Sets the default categories for the Ontology
By default, each direct child of Phenotypic abnormality
is considered one category, e.g.:
HP:0000152 | Abnormality of head or neck
HP:0001507 | Growth abnormality
- …
In additon to all other direct children of HP:0000001 | All
, e.g.:
HP:0000005 | Mode of inheritance
HP:0012823 | Clinical modifier
- …
§Errors
This method requires that the main-category terms:
HP:0000001 | All
HP:0000118 | Phenotypic abnormality
are present in the Ontology.
sourcepub fn modifier(&self) -> &HpoGroup
pub fn modifier(&self) -> &HpoGroup
Returns a reference to the modifier root terms of the Ontology
See Ontology::set_default_modifier()
for more information
§Examples
use hpo::{HpoTerm, Ontology};
let mut ontology = Ontology::from_binary("tests/example.hpo").unwrap();
assert_eq!(ontology.modifier().len(), 2);
sourcepub fn modifier_mut(&mut self) -> &mut HpoGroup
pub fn modifier_mut(&mut self) -> &mut HpoGroup
Returns a mutable reference to the modifier vector
This is a vector that should contain top-level HpoTermId
s that are
representing modifier terms.
sourcepub fn set_default_modifier(&mut self) -> HpoResult<()>
pub fn set_default_modifier(&mut self) -> HpoResult<()>
Sets the default modifier categories for the Ontology
The default is very opinionated and declares everything a modifier
that is not part of the Phenotypic abnormality
category.
§Errors
This method requires that the root term HP:0000001 | All
is present.
source§impl Ontology
impl Ontology
Methods to add annotations
These methods should rarely (if ever) be used by clients. Calling these functions might disrupt the Ontology and associated terms.
sourcepub fn insert_term<I: Into<HpoTermId>>(&mut self, name: String, id: I)
pub fn insert_term<I: Into<HpoTermId>>(&mut self, name: String, id: I)
Crates and inserts a new term to the ontology
This method does not link the term to its parents or to any annotations
§Examples
use hpo::Ontology;
let mut ontology = Ontology::default();
ontology.insert_term("FooBar".into(), 1u32);
assert_eq!(ontology.len(), 1);
sourcepub fn add_parent<I: Into<HpoTermId> + Copy, J: Into<HpoTermId> + Copy>(
&mut self,
parent_id: I,
child_id: J
)
pub fn add_parent<I: Into<HpoTermId> + Copy, J: Into<HpoTermId> + Copy>( &mut self, parent_id: I, child_id: J )
Add a connection from an HpoTerm
to its parent
This method is called once for every dependency in the Ontology during the initialization.
There should rarely be a need to call this method outside of the ontology building
§Panics
This method will panic if the parent_id
or child_id
is not present in the Ontology
§Examples
use hpo::Ontology;
let mut ontology = Ontology::default();
ontology.insert_term("Foo".into(), 1u32);
ontology.insert_term("Bar".into(), 2u32);
ontology.add_parent(1u32, 2u32);
assert!(ontology.hpo(2u32).unwrap().parent_ids().contains(&1u32.into()));
sourcepub fn create_cache(&mut self)
pub fn create_cache(&mut self)
Crates and caches the all_parents
values for every term
This method can only be called once and afterwards no new terms should be added to the Ontology anymore and no new term-parent connection should be created. Since this method caches the results, rerunning it will not cause a new calculation.
§Examples
use hpo::Ontology;
let mut ontology = Ontology::default();
ontology.insert_term("Root".into(), 1u32);
ontology.insert_term("Foo".into(), 2u32);
ontology.insert_term("Bar".into(), 3u32);
ontology.add_parent(1u32, 2u32);
ontology.add_parent(2u32, 3u32);
// At this point #3 does not have info about grandparents
assert!(!ontology.hpo(3u32).unwrap().all_parent_ids().contains(&1u32.into()));
ontology.create_cache();
assert!(ontology.hpo(3u32).unwrap().all_parent_ids().contains(&1u32.into()));
sourcepub fn add_gene(&mut self, gene_name: &str, gene_id: &str) -> HpoResult<GeneId>
pub fn add_gene(&mut self, gene_name: &str, gene_id: &str) -> HpoResult<GeneId>
Add a gene to the Ontology. and return the GeneId
If the gene does not yet exist, a new Gene
entity is created
and stored in the Ontology.
If the gene already exists in the ontology, it is not added again.
§Note
Adding a gene does not connect it to any HPO terms.
Use Ontology::link_gene_term
for creating connections.
§Errors
If the gene_id
is invalid, an HpoError::ParseIntError
is returned
§Examples
use hpo::Ontology;
let mut ontology = Ontology::default();
assert!(ontology.gene(&1u32.into()).is_none());
ontology.add_gene("Foo", "1");
// Genes can be iterated...
let mut gene_iterator = ontology.genes();
let gene = gene_iterator.next().unwrap();
assert_eq!(gene.name(), "Foo");
assert!(gene_iterator.next().is_none());
// .. or accessed directly
assert!(ontology.gene(&1u32.into()).is_some());
sourcepub fn add_omim_disease(
&mut self,
omim_disease_name: &str,
omim_disease_id: &str
) -> HpoResult<OmimDiseaseId>
pub fn add_omim_disease( &mut self, omim_disease_name: &str, omim_disease_id: &str ) -> HpoResult<OmimDiseaseId>
Add a OMIM disease to the Ontology. and return the OmimDiseaseId
If the disease does not yet exist, a new OmimDisease
entity is
created and stored in the Ontology.
If the disease already exists in the ontology, it is not added again.
§Note
Adding a disease does not connect it to any HPO terms.
Use Ontology::link_omim_disease_term
for creating connections.
§Errors
If the omim_disease_id
is invalid, an HpoError::ParseIntError
is returned
§Examples
use hpo::Ontology;
let mut ontology = Ontology::default();
assert!(ontology.omim_disease(&1u32.into()).is_none());
ontology.add_omim_disease("Foo", "1");
// Diseases can be iterated...
let mut disease_iterator = ontology.omim_diseases();
let omim_disease = disease_iterator.next().unwrap();
assert_eq!(omim_disease.name(), "Foo");
assert!(disease_iterator.next().is_none());
// .. or accessed directly
assert!(ontology.omim_disease(&1u32.into()).is_some());
sourcepub fn link_gene_term<I: Into<HpoTermId>>(
&mut self,
term_id: I,
gene_id: GeneId
) -> HpoResult<()>
pub fn link_gene_term<I: Into<HpoTermId>>( &mut self, term_id: I, gene_id: GeneId ) -> HpoResult<()>
Add the Gene
as annotation to the HpoTerm
The gene will be recursively connected to all parent HpoTerms
as well.
This method does not add the HPO-term to the Gene
, this must be handled
by the client.
§Errors
If the HPO term is not present, an HpoError::DoesNotExist
is returned
§Examples
use hpo::Ontology;
use hpo::annotations::GeneId;
let mut ontology = Ontology::default();
ontology.insert_term("Term-Foo".into(), 1u32);
ontology.add_gene("Foo", "5");
ontology.link_gene_term(1u32, GeneId::from(5u32)).unwrap();
let term = ontology.hpo(1u32).unwrap();
assert_eq!(term.genes().next().unwrap().name(), "Foo");
sourcepub fn link_omim_disease_term<I: Into<HpoTermId>>(
&mut self,
term_id: I,
omim_disease_id: OmimDiseaseId
) -> HpoResult<()>
pub fn link_omim_disease_term<I: Into<HpoTermId>>( &mut self, term_id: I, omim_disease_id: OmimDiseaseId ) -> HpoResult<()>
Add the OmimDisease
as annotation to the HpoTerm
The disease will be recursively connected to all parent HpoTerms
as well.
This method does not add the HPO-term to the OmimDisease
, this
must be handled by the client.
§Errors
If the HPO term is not present, an HpoError
is returned
§Examples
use hpo::Ontology;
use hpo::annotations::OmimDiseaseId;
let mut ontology = Ontology::default();
ontology.insert_term("Term-Foo".into(), 1u32);
ontology.add_omim_disease("Foo", "5");
ontology.link_omim_disease_term(1u32, OmimDiseaseId::from(5u32)).unwrap();
let term = ontology.hpo(1u32).unwrap();
assert_eq!(term.omim_diseases().next().unwrap().name(), "Foo");
sourcepub fn gene_mut(&mut self, gene_id: &GeneId) -> Option<&mut Gene>
pub fn gene_mut(&mut self, gene_id: &GeneId) -> Option<&mut Gene>
Returns a mutable reference to the Gene
of the provided GeneId
If no such gene is present, None
is returned
§Examples
use hpo::Ontology;
let mut ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let mut gene = ontology.gene_mut(&57505u32.into()).unwrap();
assert_eq!(gene.hpo_terms().len(), 10);
gene.add_term(1u32);
assert_eq!(gene.hpo_terms().len(), 11);
sourcepub fn omim_disease_mut(
&mut self,
omim_disease_id: &OmimDiseaseId
) -> Option<&mut OmimDisease>
pub fn omim_disease_mut( &mut self, omim_disease_id: &OmimDiseaseId ) -> Option<&mut OmimDisease>
Returns a mutable reference to the OmimDisease
of the provided OmimDiseaseId
If no such disease is present, None
is returned
§Examples
use hpo::Ontology;
let mut ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let mut disease = ontology.omim_disease_mut(&601495u32.into()).unwrap();
assert_eq!(disease.hpo_terms().len(), 1);
disease.add_term(1u32);
assert_eq!(disease.hpo_terms().len(), 2);
sourcepub fn calculate_information_content(&mut self) -> HpoResult<()>
pub fn calculate_information_content(&mut self) -> HpoResult<()>
Calculates the crate::term::InformationContent
s for every term
This method should only be called after all terms are added, connected and all genes and diseases are linked as well.
It can be called repeatedly, all values are recalculated each time, as long as the Ontology contains at least 1 gene/disease. When no genes/diseases are present, the IC is not calculated nor updated.
§Errors
This method returns an error if there are more Genes or Terms than u16::MAX
because larger numbers can’t be safely converted to f32
§Examples
use hpo::Ontology;
let mut ontology = Ontology::default();
// [all kind of logic to add terms, diseases, genes....]
ontology.calculate_information_content().unwrap();
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Ontology
impl RefUnwindSafe for Ontology
impl Send for Ontology
impl Sync for Ontology
impl Unpin for Ontology
impl UnwindSafe for Ontology
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.