pub struct HpoSet<'a> { /* private fields */ }
Expand description
A set of unique HPO terms
It provides several convinience functions to operate on a set of terms.
A typical use-case for an HpoSet
is to record the clinical information
of a patient. You can compare the aggregated information of the patient
with other patients, genes or dieases.
As in a set, each term can only appear once.
§Examples
use hpo::term::InformationContentKind;
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
use hpo::similarity::{Builtins, StandardCombiner};
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
// create one set
let mut hpos = HpoGroup::new();
hpos.insert(707u32);
hpos.insert(12639u32);
hpos.insert(12638u32);
hpos.insert(818u32);
hpos.insert(2715u32);
let set = HpoSet::new(&ontology, hpos);
assert_eq!(set.len(), 5);
// create another set
let mut hpos_2 = HpoGroup::new();
hpos_2.insert(100547u32);
hpos_2.insert(12638u32);
hpos_2.insert(864u32);
hpos_2.insert(25454u32);
let set_2 = HpoSet::new(&ontology, hpos_2);
assert_eq!(set_2.len(), 4);
let similarity = set.similarity(
&set_2,
Builtins::GraphIc(InformationContentKind::Omim),
StandardCombiner::default()
);
assert_eq!(similarity, 0.8177036);
Implementations§
source§impl<'a> HpoSet<'a>
impl<'a> HpoSet<'a>
sourcepub fn new(ontology: &'a Ontology, group: HpoGroup) -> Self
pub fn new(ontology: &'a Ontology, group: HpoGroup) -> Self
Constructs an HpoSet
§Examples
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let mut hpos = HpoGroup::new();
hpos.insert(707u32);
hpos.insert(12639u32);
hpos.insert(12638u32);
hpos.insert(818u32);
hpos.insert(2715u32);
let set = HpoSet::new(&ontology, hpos);
assert_eq!(set.len(), 5);
sourcepub fn child_nodes(&self) -> Self
pub fn child_nodes(&self) -> Self
Returns a new HpoSet
that contains only the child-most terms
This means that it only contains terms that don’t have a child term present in the set.
§Examples
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let mut hpos = HpoGroup::new();
hpos.insert(707u32);
hpos.insert(12639u32);
hpos.insert(12638u32);
hpos.insert(818u32);
hpos.insert(2715u32);
let mut set = HpoSet::new(&ontology, hpos);
assert_eq!(set.len(), 5);
let children = set.child_nodes();
assert_eq!(children.len(), 4);
§Panics
TODO
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of terms in the set
§Examples
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let mut hpos = HpoGroup::new();
hpos.insert(707u32);
hpos.insert(12639u32);
hpos.insert(12638u32);
hpos.insert(818u32);
hpos.insert(2715u32);
let set = HpoSet::new(&ontology, hpos);
assert_eq!(set.len(), 5);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no terms in the set
§Examples
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let hpos = HpoGroup::new();
let set = HpoSet::new(&ontology, hpos);
assert!(set.is_empty());
sourcepub fn remove_modifier(&mut self)
pub fn remove_modifier(&mut self)
Removes all modifier terms in-place
§Examples
use hpo::{Ontology, HpoSet};
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let mut set: HpoSet = method_that_returns_an_hposet(&ontology);
assert_eq!(set.len(), 5);
set.remove_modifier();
assert_eq!(set.len(), 3);
sourcepub fn without_modifier(&self) -> Self
pub fn without_modifier(&self) -> Self
Returns a new set without modifier terms
§Examples
use hpo::{Ontology, HpoSet};
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let set_1: HpoSet = method_that_returns_an_hposet(&ontology);
assert_eq!(set_1.len(), 5);
let set_2 = set_1.without_modifier();
assert_eq!(set_2.len(), 3);
for term in set_1.iter() {
if !set_2.contains(&term.id()) {
println!("Modifier: {} | {}", term.id(), term.name());
}
}
// "HP:0000007 | Autosomal recessive inheritance"
// "HP:0003581 | Adult onset"
sourcepub fn remove_obsolete(&mut self)
pub fn remove_obsolete(&mut self)
Removes all obsolete terms in-place
§Panics
When an HpoTermId
of the set is not part of the Ontology
§Examples
The example Ontology does not contain obsolete terms, so this example does not show an actual effect.
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let mut set: HpoSet = method_that_returns_an_hposet(&ontology);
assert_eq!(set.len(), 5);
set.remove_obsolete();
assert_eq!(set.len(), 5);
sourcepub fn without_obsolete(&self) -> Self
pub fn without_obsolete(&self) -> Self
Returns a new set without obsolete terms
§Panics
When an HpoTermId
of the set is not part of the Ontology
§Examples
The example Ontology does not contain obsolete terms, so this example does not show an actual effect.
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let set: HpoSet = method_that_returns_an_hposet(&ontology);
assert_eq!(set.len(), 5);
let new_set = set.without_obsolete();
assert_eq!(new_set.len(), 5);
sourcepub fn with_replaced_obsolete(&self) -> Self
pub fn with_replaced_obsolete(&self) -> Self
Returns a new set where obsolete terms are replaced
All terms with a replaced_by
attribute are replaced accordingly.
See HpoTerm::replaced_by
for more information
§Panics
When an HpoTermId
of the set is not part of the Ontology
§Examples
The example Ontology does not contain replacement terms, so this example does not show an actual effect.
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let set: HpoSet = method_that_returns_an_hposet(&ontology);
assert_eq!(set.len(), 5);
let new_set = set.with_replaced_obsolete();
assert_eq!(new_set.len(), 5);
sourcepub fn replace_obsolete(&mut self)
pub fn replace_obsolete(&mut self)
Replaces obsolete terms in-place
All terms with a replaced_by
attribute are replaced accordingly.
See HpoTerm::replaced_by
for more information
§Panics
When an HpoTermId
of the set is not part of the Ontology
§Examples
The example Ontology does not contain replacement terms, so this example does not show an actual effect.
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let mut set: HpoSet = method_that_returns_an_hposet(&ontology);
assert_eq!(set.len(), 5);
set.replace_obsolete();
assert_eq!(set.len(), 5);
sourcepub fn gene_ids(&self) -> Genes
pub fn gene_ids(&self) -> Genes
Returns all crate::annotations::GeneId
s that are associated to the set
§Panics
When an HpoTermId
of the set is not part of the Ontology
§Examples
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let mut hpos = HpoGroup::new();
hpos.insert(12639u32);
hpos.insert(818u32);
let set = HpoSet::new(&ontology, hpos);
// `ABCD1 (HGNC:215)` is linked to `HP:0012639`
assert!(set.gene_ids().contains(&215u32.into()));
sourcepub fn omim_disease_ids(&self) -> OmimDiseases
pub fn omim_disease_ids(&self) -> OmimDiseases
Returns all crate::annotations::OmimDiseaseId
s that are associated to the set
§Panics
When an HpoTermId
of the set is not part of the Ontology
§Examples
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let mut hpos = HpoGroup::new();
hpos.insert(12639u32);
hpos.insert(818u32);
let set = HpoSet::new(&ontology, hpos);
// `Microphthalmia, syndromic 6 (OMIM:607932)` is linked to `HP:0012639`
assert!(set.omim_disease_ids().contains(&607932u32.into()));
sourcepub fn categories(&self) -> HashMap<HpoTermId, usize>
pub fn categories(&self) -> HashMap<HpoTermId, usize>
Returns the counts of all categories in the set
§Examples
use hpo::{Ontology, HpoSet, HpoTermId};
use hpo::term::HpoGroup;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let mut hpos = HpoGroup::new();
hpos.insert(12285u32); // Abnormal hypothalamus physiology
hpos.insert(12639u32); // Abnormal nervous system morphology
hpos.insert(12638u32); // Abnormal nervous system physiology
hpos.insert(12648u32); // Decreased inflammatory response
hpos.insert(3581u32); // Adult onset
hpos.insert(7u32); // Autosomal recessive inheritance
let set: HpoSet = HpoSet::new(&ontology, hpos);
let cats = set.categories();
assert_eq!(cats.get(&HpoTermId::from_u32(5)).unwrap(), &1);
assert_eq!(cats.get(&HpoTermId::from_u32(707)).unwrap(), &3);
assert_eq!(cats.get(&HpoTermId::from_u32(818)).unwrap(), &1);
assert_eq!(cats.get(&HpoTermId::from_u32(2715)).unwrap(), &1);
assert_eq!(cats.get(&HpoTermId::from_u32(12823)).unwrap(), &1);
sourcepub fn information_content(&self) -> HpoResult<InformationContent>
pub fn information_content(&self) -> HpoResult<InformationContent>
Calculates and returns the aggregated InformationContent
of the set
The InformationContent
is not cached internally, so this operation
is not cheap
§Errors
- When the ontology or set have more than
u16::MAX
genes or diseases
§Panics
- When an
HpoTermId
of the set is not part of the Ontology
§Examples
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let mut hpos = HpoGroup::new();
hpos.insert(707u32);
hpos.insert(12639u32);
hpos.insert(12638u32);
hpos.insert(818u32);
hpos.insert(2715u32);
let set = HpoSet::new(&ontology, hpos);
assert_eq!(set.information_content().unwrap().gene(), 0.14216587);
sourcepub fn similarity<S: Similarity, C: SimilarityCombiner>(
&self,
other: &HpoSet<'_>,
similarity: S,
combiner: C
) -> f32
pub fn similarity<S: Similarity, C: SimilarityCombiner>( &self, other: &HpoSet<'_>, similarity: S, combiner: C ) -> f32
Calculates the similarity to another HpoSet
§Examples
use hpo::term::InformationContentKind;
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
use hpo::similarity::{Builtins, StandardCombiner};
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
// create one set
let mut hpos = HpoGroup::new();
hpos.insert(707u32);
hpos.insert(12639u32);
hpos.insert(12638u32);
hpos.insert(818u32);
hpos.insert(2715u32);
let set = HpoSet::new(&ontology, hpos);
// create another set
let mut hpos_2 = HpoGroup::new();
hpos_2.insert(100547u32);
hpos_2.insert(12638u32);
hpos_2.insert(864u32);
hpos_2.insert(25454u32);
let set_2 = HpoSet::new(&ontology, hpos_2);
let similarity = set.similarity(
&set_2,
Builtins::GraphIc(InformationContentKind::Omim),
StandardCombiner::default()
);
assert_eq!(similarity, 0.8177036);
sourcepub fn iter(&self) -> Iter<'_> ⓘ
pub fn iter(&self) -> Iter<'_> ⓘ
Returns an Iterator of HpoTerm
§Examples
use hpo::term::InformationContentKind;
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
use hpo::similarity::{Builtins, StandardCombiner};
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
// create one set
let mut hpos = HpoGroup::new();
hpos.insert(707u32);
hpos.insert(12639u32);
let set = HpoSet::new(&ontology, hpos);
let mut iter = set.iter();
assert!(iter.next().is_some());
assert!(iter.next().is_some());
assert!(iter.next().is_none());
sourcepub fn contains(&self, id: &HpoTermId) -> bool
pub fn contains(&self, id: &HpoTermId) -> bool
Returns true if the set contains a term with the HpoTermId
§Examples
use hpo::term::InformationContentKind;
use hpo::{Ontology, HpoSet};
use hpo::term::HpoGroup;
use hpo::similarity::{Builtins, StandardCombiner};
let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
// create one set
let mut hpos = HpoGroup::new();
hpos.insert(707u32);
hpos.insert(12639u32);
let set = HpoSet::new(&ontology, hpos);
assert!(set.contains(&707u32.into()));
assert!(!set.contains(&66666u32.into()));
Trait Implementations§
source§impl<'b, 'a> Extend<HpoTerm<'b>> for HpoSet<'a>
impl<'b, 'a> Extend<HpoTerm<'b>> for HpoSet<'a>
source§fn extend<T: IntoIterator<Item = HpoTerm<'b>>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = HpoTerm<'b>>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Auto Trait Implementations§
impl<'a> Freeze for HpoSet<'a>
impl<'a> RefUnwindSafe for HpoSet<'a>
impl<'a> Send for HpoSet<'a>
impl<'a> Sync for HpoSet<'a>
impl<'a> Unpin for HpoSet<'a>
impl<'a> UnwindSafe for HpoSet<'a>
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.