1#![deny(clippy::pedantic)]
2#![allow(clippy::must_use_candidate)]
3#![allow(clippy::module_name_repetitions)]
4#![warn(missing_docs)]
5#![doc = include_str!("../README.md")]
6
7use core::fmt::Debug;
8use std::num::ParseIntError;
9use thiserror::Error;
10
11pub mod annotations;
12pub mod matrix;
13mod ontology;
14mod parser;
15mod set;
16pub mod similarity;
17pub mod stats;
18pub mod term;
19pub mod utils;
20
21pub use ontology::builder;
22pub use ontology::comparison;
23pub use ontology::Ontology;
24pub use set::HpoSet;
25#[doc(inline)]
26pub use term::{HpoTerm, HpoTermId};
27
28const DEFAULT_NUM_PARENTS: usize = 10;
29const DEFAULT_NUM_ALL_PARENTS: usize = 30;
30const DEFAULT_NUM_GENES: usize = 50;
31const DEFAULT_NUM_OMIM: usize = 20;
32const DEFAULT_NUM_ORPHA: usize = 20;
33const MAX_HPO_ID_INTEGER: usize = 10_000_000;
34
35const OBO_FILENAME: &str = "hp.obo";
36const GENE_FILENAME: &str = "phenotype_to_genes.txt";
37const GENE_TO_PHENO_FILENAME: &str = "genes_to_phenotype.txt";
38const DISEASE_FILENAME: &str = "phenotype.hpoa";
39
40pub const PHENOTYPE_ID: HpoTermId = HpoTermId::from_u32(118);
42
43#[derive(Error, Debug)]
44pub enum HpoError {
46 #[error("not implemented")]
48 NotImplemented,
49 #[error("term does not exist")]
51 DoesNotExist,
52 #[error("unable to parse Integer")]
54 ParseIntError,
55 #[error("unable to parse binary data")]
57 ParseBinaryError,
58 #[error("cannot open file {0}")]
60 CannotOpenFile(String),
61 #[error("cannot convert int to float")]
63 TryFromIntError(#[from] std::num::TryFromIntError),
64 #[error("invalid input data: {0}")]
66 InvalidInput(String),
67}
68
69impl From<ParseIntError> for HpoError {
70 fn from(_: ParseIntError) -> Self {
71 HpoError::ParseIntError
72 }
73}
74
75pub type HpoResult<T> = Result<T, HpoError>;
77
78fn u32_from_bytes(bytes: &[u8]) -> u32 {
86 u32::from_be_bytes([bytes[0], bytes[1], bytes[2], bytes[3]])
87}
88
89fn f32_from_usize(n: usize) -> HpoResult<f32> {
90 let intermediate: u16 = n.try_into()?;
91 Ok(intermediate.into())
92}