Skip to content

Commit

Permalink
structured version
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Jun 11, 2023
1 parent 4c99f41 commit 747a60b
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 39 deletions.
24 changes: 24 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,27 @@ impl FromStr for ScoreCombiner {
.ok_or(anyhow::anyhow!("unknown score combiner: {}", s))

Check warning on line 240 in src/common.rs

View check run for this annotation

Codecov / codecov/patch

src/common.rs#L237-L240

Added lines #L237 - L240 were not covered by tests
}
}

/// The version of `viguno` package.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

/// Version information that is returned by the HTTP server.
#[derive(serde::Serialize, serde::Deserialize, Default, Debug, Clone)]
pub struct Version {
/// Version of the HPO.
pub hpo: String,
/// Version of the `viguno` package.
pub viguno: String,
}

impl Version {
/// Construct a new version.
///
/// The viguno version is filed automatically.
pub fn new(hpo: &str) -> Self {
Self {
hpo: hpo.to_string(),
viguno: VERSION.to_string(),
}
}
}
33 changes: 16 additions & 17 deletions src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use hpo::{annotations::AnnotationId, term::HpoGroup, HpoTermId, Ontology};
use crate::algos::phenomizer;
use crate::pbs::simulation::SimulationResults;
use crate::query::query_result::TermDetails;
use crate::simulate::VERSION;

/// Command line arguments for `query` command.
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -52,7 +51,9 @@ pub mod query_result {
use super::HpoTerm;

/// Struct for storing gene information in the result.
#[derive(serde::Serialize, serde::Deserialize, PartialEq, Eq, PartialOrd, Ord, Debug, Clone)]
#[derive(
serde::Serialize, serde::Deserialize, PartialEq, Eq, PartialOrd, Ord, Debug, Clone,
)]
pub struct Gene {
/// The NCBI gene ID.
pub entrez_id: u32,
Expand All @@ -72,10 +73,8 @@ pub mod query_result {
/// Result container data structure.
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
pub struct Container {
/// Version of the HPO.
pub hpo_version: String,
/// Version of the `viguno` package.
pub viguno_version: String,
/// Version information.
pub version: crate::common::Version,
/// The original query records.
pub query: Query,
/// The resulting records for the scored genes.
Expand Down Expand Up @@ -131,6 +130,7 @@ pub mod query_result {
/// In the case that a term or database lookup fails.
#[allow(clippy::cast_possible_truncation)]
#[allow(clippy::cast_precision_loss)]
#[allow(clippy::too_many_lines)]
pub fn run_query(
patient: &HpoGroup,
genes: &Vec<&hpo::annotations::Gene>,
Expand All @@ -144,20 +144,19 @@ pub fn run_query(
let num_terms = std::cmp::min(10, patient.len());
let query = query_result::Query {
terms: patient
.iter()
.map(|t| {
let term = hpo.hpo(t).expect("could not resolve HPO term");
HpoTerm {
term_id: term.id().to_string(),
term_name: Some(term.name().to_string()),
}
})
.collect(),
.iter()
.map(|t| {
let term = hpo.hpo(t).expect("could not resolve HPO term");
HpoTerm {
term_id: term.id().to_string(),
term_name: Some(term.name().to_string()),
}
})
.collect(),
genes: Vec::new(),
};
let mut result = query_result::Container {
hpo_version: hpo.hpo_version(),
viguno_version: VERSION.to_string(),
version: crate::common::Version::new(&hpo.hpo_version()),
query,
result: Vec::new(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
source: src/server/actix_server/hpo_sim/term_gene.rs
expression: "&run_query(\"/hpo/sim/term-gene?terms=HP:0010442,HP:0000347&gene_ids=23483,7273\").await?"
---
hpo_version: 2023-04-05
viguno_version: 0.1.0
version:
hpo: 2023-04-05
viguno: 0.1.0
query:
terms:
- term_id: "HP:0000347"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
source: src/server/actix_server/hpo_sim/term_gene.rs
expression: "&run_query(\"/hpo/sim/term-gene?terms=HP:0010442,HP:0000347&gene_symbols=TGDS,TTN\").await?"
---
hpo_version: 2023-04-05
viguno_version: 0.1.0
version:
hpo: 2023-04-05
viguno: 0.1.0
query:
terms:
- term_id: "HP:0000347"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
source: src/server/actix_server/hpo_sim/term_term.rs
expression: "&run_query(\"/hpo/sim/term-term?lhs=HP:0010442&rhs=HP:0001780\").await?"
---
hpo_version: 2023-04-05
viguno_version: 0.1.0
version:
hpo: 2023-04-05
viguno: 0.1.0
query:
lhs:
- "HP:0010442"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
source: src/server/actix_server/hpo_sim/term_term.rs
expression: "&run_query(\"/hpo/sim/term-term?lhs=HP:0010442,HP:0000347&rhs=HP:0001780,HP:0000252\").await?"
---
hpo_version: 2023-04-05
viguno_version: 0.1.0
version:
hpo: 2023-04-05
viguno: 0.1.0
query:
lhs:
- "HP:0010442"
Expand Down
14 changes: 4 additions & 10 deletions src/server/actix_server/hpo_sim/term_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ use hpo::{
};
use itertools::Itertools;

use crate::common::{to_pairwise_sim, IcBasedOn, ScoreCombiner, SimilarityMethod};
use crate::server::{actix_server::CustomError, WebServerData};
use crate::{
common::{to_pairwise_sim, IcBasedOn, ScoreCombiner, SimilarityMethod},
simulate::VERSION,
};

/// Parameters for `handle`.
///
Expand Down Expand Up @@ -66,10 +63,8 @@ pub struct ResponseQuery {
/// Result container.
#[derive(serde::Serialize, serde::Deserialize, Default, Debug, Clone)]
pub struct Container {
/// Version of the HPO.
pub hpo_version: String,
/// Version of the `viguno` package.
pub viguno_version: String,
/// Version information.
pub version: crate::common::Version,
/// The original query records.
pub query: ResponseQuery,
/// The resulting records for the scored genes.
Expand Down Expand Up @@ -146,8 +141,7 @@ async fn handle(
} = query.into_inner();

let result = Container {
hpo_version: data.ontology.hpo_version().to_string(),
viguno_version: VERSION.to_string(),
version: crate::common::Version::new(&data.ontology.hpo_version()),
query: ResponseQuery {
lhs,
rhs,
Expand Down
5 changes: 1 addition & 4 deletions src/simulate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ use crate::{
pbs::simulation::SimulationResults,
};

/// The version of `viguno` package.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

/// Command line arguments for Viguno.
#[derive(Parser, Debug)]
#[command(author, version, about = "Prepare values for Viguno", long_about = None)]
Expand Down Expand Up @@ -247,7 +244,7 @@ pub fn run(args_common: &crate::common::Args, args: &Args) -> Result<(), anyhow:
.cf_handle("meta")
.ok_or(anyhow::anyhow!("column family meta not found"))?;
db.put_cf(&cf_meta, "hpo-version", ontology.hpo_version())?;
db.put_cf(&cf_meta, "app-version", VERSION)?;
db.put_cf(&cf_meta, "app-version", crate::common::VERSION)?;
tracing::info!("...done opening RocksDB in {:?}", before_rocksdb.elapsed());

tracing::info!("Running simulations...");
Expand Down

0 comments on commit 747a60b

Please sign in to comment.