Struct hpo::HpoSet

source ·
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>

source

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

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

source

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

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

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

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

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

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

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

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

pub fn gene_ids(&self) -> Genes

Returns all crate::annotations::GeneIds 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()));
source

pub fn omim_disease_ids(&self) -> OmimDiseases

Returns all crate::annotations::OmimDiseaseIds 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()));
source

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

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

pub fn get(&self, index: usize) -> Option<HpoTerm<'a>>

Returns the HpoTerm at the given index

§Panics
  • When an HpoTermId of the set is not part of the Ontology
source

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

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

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>

source§

fn extend<T: IntoIterator<Item = HpoTerm<'b>>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> IntoIterator for &'a HpoSet<'a>

§

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§

§

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> 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, 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