hpo/
term.rs

1//! [`HpoTerm`]s are the main building block of the Ontology.
2//!  Each term is a descendent (child) of at least one other term
3//! (except for the root term `HP:0000001 | All`). The relationship
4//! is modeled bi-drectionally in `hpo`, so that every term also has
5//! one or several `children` (except for all leaf terms).
6//!
7//! At the same time, terms are associated with diseases by describing a part
8//! of their phenotypical representation. They are also associated with genes
9//! when the gene is relevant for the phenotype or associated disease. The
10//! association to genes and diseases are inversely "inherited" to a term's parent
11//! terms (and subsequently their parents as well).
12//!
13//! Each term is identified by a unique [`HpoTermId`].
14//!
15use crate::Ontology;
16use core::fmt::Debug;
17
18pub mod group;
19mod hpoterm;
20mod hpotermid;
21mod information_content;
22pub(crate) mod internal;
23
24pub use group::HpoGroup;
25pub use hpoterm::HpoTerm;
26pub use hpotermid::HpoTermId;
27pub use information_content::{InformationContent, InformationContentKind};
28
29/// [`HpoTerm`] iterator
30pub struct Iter<'a> {
31    group_iter: group::Iter<'a>,
32    ontology: &'a Ontology,
33}
34
35impl<'a> Iter<'a> {
36    pub(crate) fn new(group_iter: group::Iter<'a>, ontology: &'a Ontology) -> Self {
37        Self {
38            group_iter,
39            ontology,
40        }
41    }
42}
43
44impl<'a> Iterator for Iter<'a> {
45    type Item = HpoTerm<'a>;
46    fn next(&mut self) -> Option<Self::Item> {
47        match self.group_iter.next() {
48            Some(term) => {
49                let term = self
50                    .ontology
51                    .get(term)
52                    .unwrap_or_else(|| panic!("Invalid HPO-Term: {term}"));
53                Some(HpoTerm::new(self.ontology, term))
54            }
55            None => None,
56        }
57    }
58}
59
60impl Debug for Iter<'_> {
61    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62        write!(f, "Iter<HpoTerm>")
63    }
64}