use crate::{f32_from_usize, HpoResult};
#[derive(Default, Debug, Clone)]
pub struct InformationContent {
gene: f32,
omim: f32,
orpha: f32,
custom: f32,
}
impl InformationContent {
pub fn gene(&self) -> f32 {
self.gene
}
pub fn gene_mut(&mut self) -> &mut f32 {
&mut self.gene
}
pub fn omim_disease(&self) -> f32 {
self.omim
}
pub fn omim_disease_mut(&mut self) -> &mut f32 {
&mut self.omim
}
pub fn orpha_disease(&self) -> f32 {
self.orpha
}
pub fn orpha_disease_mut(&mut self) -> &mut f32 {
&mut self.orpha
}
pub fn get_kind(&self, kind: &InformationContentKind) -> f32 {
match kind {
InformationContentKind::Gene => self.gene(),
InformationContentKind::Omim => self.omim_disease(),
InformationContentKind::Orpha => self.orpha_disease(),
InformationContentKind::Custom => self.custom(),
}
}
fn calculate(total: usize, current: usize) -> HpoResult<f32> {
if total == 0 || current == 0 {
return Ok(0.0);
}
let total = f32_from_usize(total)?;
let current = f32_from_usize(current)?;
Ok(-(current / total).ln())
}
pub fn set_gene(&mut self, total: usize, current: usize) -> HpoResult<()> {
self.gene = Self::calculate(total, current)?;
Ok(())
}
pub fn set_omim_disease(&mut self, total: usize, current: usize) -> HpoResult<()> {
self.omim = Self::calculate(total, current)?;
Ok(())
}
pub fn set_orpha_disease(&mut self, total: usize, current: usize) -> HpoResult<()> {
self.orpha = Self::calculate(total, current)?;
Ok(())
}
pub fn custom(&self) -> f32 {
self.custom
}
pub fn custom_mut(&mut self) -> &mut f32 {
&mut self.custom
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum InformationContentKind {
Gene,
Omim,
Orpha,
Custom,
}