Struct hpo::Ontology

source ·
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 HpoTerms, Genes and OmimDiseases.

§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

  1. Download the standard annotation data from Jax HPO itself. Then use Ontology::from_standard to load the data. You need the following files:

  2. 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:

  1. construct an empty Ontology Ontology::default
  2. Add all terms Ontology::insert_term
  3. Connect terms to their parents Ontology::add_parent
  4. Cache all parent, child and grandparent connections Ontology::create_cache
  5. Add genes and diseases to the ontology
  6. Calculate the information content Ontology::calculate_information_content

§Layout

The Ontology contains all terms and all associated genes and diseases. HpoTerms 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 (Genes, OmimDiseases) 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 HpoTerms.

§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 Genes and OmimDiseases will only contain links to direct HpoTerms. The annotations are not transitiv.

erDiagram ONTOLOGY ||--|{ HPOTERM : contains HPOTERM ||--|{ HPOTERM : is_a HPOTERM }|--o{ DISEASE : phenotype_of HPOTERM }|--o{ GENE : phenotype_of HPOTERM { str name HpoTermId id HpoTerms parents HpoTerms children Genes genes OmimDiseases omim_diseases } DISEASE { str name OmimDiseaseId id HpoGroup hpo_terms } GENE { str name GeneId id HpoGroup hpo_terms }

§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.

classDiagram class Ontology { into_iter() } class HpoTerm{ - HpoTermId id - &Ontology parents() HpoTerms parent_ids() HpoGroup all_parent_ids() HpoGroup children() HpoTerms children_ids() HpoTerms common_ancestors() Combine union_ancestors() Combine many-more() } class HpoGroup { - Set~HpoTermId~ into_iter() terms() } class HpoSet { - HpoGroup - &Ontology similarity(...) f32 information_content() } class HpoTermId { - u32: id } class `ontology::Iter` { next() HpoTerm } class `term::Iter` { next() HpoTerm } class `group::Iter` { next() HpoTermId } class Combine { - HpoGroup into_iter() } Ontology ..|> `ontology::Iter`: hpos() HpoSet ..|> `term::Iter`: iter() HpoGroup ..|> `group::Iter`: iter() HpoGroup ..|> `term::Iter`: terms() Combine ..|> `term::Iter`: iter() `ontology::Iter` --o HpoGroup: collect() `ontology::Iter` --* HpoTerm: iterates() `term::Iter` --* HpoTerm: iterates() `term::Iter` --o HpoGroup: collect() `group::Iter` --* HpoTermId: iterates() `group::Iter` --o HpoGroup: collect() HpoTerm ..|> HpoGroup: parent_ids()/children_ids() HpoTerm ..|> `term::Iter`: parents()/children() HpoTerm ..|> `Combine`: ..._ancestors()

§Example ontology

For all examples and tests in this documentation, we’re using the following small subset of the full Ontology:

graph TD HP:0011017["HP:0011017
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

Public API of the Ontology

Those methods are all safe to use

source

pub fn from_standard(folder: &str) -> HpoResult<Self>

Initialize the Ontology from data provided by Jax HPO

You must download:

and then specify the folder where the data is stored.

§Errors

This method can fail for various reasons:

§Note

Since version 0.9.0 this method will not load genes transitively. That means only directly linked HpoTerms 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");
source

pub fn from_standard_transitive(folder: &str) -> HpoResult<Self>

Initialize the Ontology from data provided by Jax HPO

You must download:

and then specify the folder where the data is stored.

§Errors

This method can fail for various reasons:

§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");
source

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");
source

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 failed
  • Ontology::add_genes_from_bytes failed
  • Ontology::add_omim_disease_from_bytes failed
  • add_terms_from_bytes failed
  • add_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");
source

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

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);
source

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

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

pub fn hpos(&self) -> Iter<'_>

Returns an Iterator of all HpoTerms from the Ontology

§Examples
use hpo::Ontology;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
for term in ontology.hpos() {
    println!("{}", term.name());
}
source

pub fn gene(&self, gene_id: &GeneId) -> Option<&Gene>

Returns a reference to the Gene of the provided GeneId

If no such gene is present, None is returned

§Examples
use hpo::Ontology;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let gene = ontology.gene(&57505u32.into()).unwrap();
assert_eq!(gene.name(), "AARS2");
source

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

Genes 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());
source

pub fn genes(&self) -> Values<'_, GeneId, Gene>

Returns an Iterator of all Genes 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 gene in ontology.genes() {
    println!("{}", gene.name());
}
source

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");
source

pub fn omim_diseases(&self) -> Values<'_, OmimDiseaseId, OmimDisease>

Returns an Iterator of all OmimDiseases 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());
}
source

pub fn omim_diseases_by_name<'a>( &'a self, substring: &'a str ) -> OmimDiseaseFilter<'_>

Returns an Iterator of all OmimDiseases 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());
 }
source

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");
source

pub fn hpo_version(&self) -> String

Returns the Jax-Ontology release version

e.g. 2023-03-13

source

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);
source

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);
source

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

source

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

source

pub fn categories(&self) -> &HpoGroup

Returns a reference to the categories of the Ontology

Categories are top-level HpoTermIds used for categorizing individual HpoTerms.

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);
source

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 HpoTermIds used for categorizing individual HpoTerms.

See Ontology::set_default_categories()

source

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.

source

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);
source

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 HpoTermIds that are representing modifier terms.

See Ontology::set_default_modifier()

source

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

pub fn iter(&self) -> Iter<'_>

Iterates HpoTerms

source§

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.

source

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);
source

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

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

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

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

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");

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");
source

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);
source

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);
source

pub fn calculate_information_content(&mut self) -> HpoResult<()>

Calculates the crate::term::InformationContents 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§

source§

impl Clone for Ontology

source§

fn clone(&self) -> Ontology

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Ontology

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Ontology

source§

fn default() -> Ontology

Returns the “default value” for a type. Read more
source§

impl<'a> IntoIterator for &'a Ontology

§

type Item = HpoTerm<'a>

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more