Skip to content

Commit

Permalink
Add a condition_details vec to OntAnnotationDetail
Browse files Browse the repository at this point in the history
Show we can show the condition details on the website.

Refs pombase/website#2029
  • Loading branch information
kimrutherford committed Nov 13, 2023
1 parent d0daf85 commit 372f13d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/pombase/data_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet, BTreeMap};
use std::collections::{HashMap, HashSet, BTreeMap, BTreeSet};

use std::fmt::Display;
use std::fmt;
Expand Down Expand Up @@ -754,6 +754,8 @@ pub struct OntAnnotationDetail {
pub genotype_background: Option<FlexStr>,
#[serde(skip_serializing_if="HashSet::is_empty", default)]
pub conditions: HashSet<TermId>,
#[serde(skip_serializing_if="BTreeSet::is_empty", default)]
pub condition_details: BTreeSet<(TermId, Option<String>)>,
#[serde(skip_serializing_if="Option::is_none")]
pub date: Option<FlexStr>,
#[serde(skip_serializing_if="Option::is_none")]
Expand Down
33 changes: 33 additions & 0 deletions src/pombase/web/data_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,27 @@ fn set_has_protein_features(genes: &mut UniquenameGeneMap, protein_view_data: &H
}
}


lazy_static! {
static ref CONDITION_DETAIL_RE: Regex =
Regex::new(r"^([A-Z][\w]+:\d\d\d+)(?:\((.+)\))?$").unwrap();
}

// parse something like "FYECO:0000005(32C)" or "FYECO:0000329(2% (v/v))" into a term ID
// and a String containers the details from the brackets
// parse "FYECO:0000005" into (TermId, None)
fn parse_condition_with_detail(condition_string: &str) -> (TermId, Option<String>) {
let captures = CONDITION_DETAIL_RE.captures(condition_string).unwrap();

let term_id = captures.get(1).as_ref().unwrap().as_str().into();

if let Some(detail) = captures.get(2) {
(term_id, Some(detail.as_str().into()))
} else {
(term_id, None)
}
}

impl <'a> WebDataBuild<'a> {
pub fn new(raw: &'a Raw,
domain_data: &'a HashMap<UniprotIdentifier, UniprotResult>,
Expand Down Expand Up @@ -3776,6 +3797,7 @@ phenotypes, so just the first part of this extension will be used:
let publication = &feature_cvterm.publication;
let mut extra_props: HashMap<FlexStr, FlexStr> = HashMap::new();
let mut conditions: HashSet<TermId> = HashSet::new();
let mut condition_details: BTreeSet<(TermId, Option<String>)> = BTreeSet::new();
let mut withs: HashSet<WithFromValue> = HashSet::new();
let mut froms: HashSet<WithFromValue> = HashSet::new();
let mut qualifiers: Vec<Qualifier> = vec![];
Expand Down Expand Up @@ -3838,6 +3860,16 @@ phenotypes, so just the first part of this extension will be used:
value, feature.uniquename, termid);
}
},
"condition_detail" =>
if let Some(ref value) = prop.value {
if value.contains(':') {
let parsed_value = parse_condition_with_detail(value);
condition_details.insert(parsed_value);
} else {
eprintln!(r#"ignoring condition that doesn't contain a term ID "{}" (from annotation of {} with {})"#,
value, feature.uniquename, termid);
}
},
"qualifier" =>
if let Some(value) = prop.value.clone() {
qualifiers.push(value);
Expand Down Expand Up @@ -3998,6 +4030,7 @@ phenotypes, so just the first part of this extension will be used:
evidence,
eco_evidence,
conditions,
condition_details,
extension,
date,
assigned_by,
Expand Down
8 changes: 6 additions & 2 deletions tests/test_data_build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use std::collections::{HashMap, HashSet, BTreeSet};
use std::iter::FromIterator;

use std::cmp::Ordering;
Expand Down Expand Up @@ -402,6 +402,9 @@ fn make_one_detail(id: i32, gene_uniquename: &str, reference_uniquename: &str,
maybe_genotype_uniquename: Option<&str>, evidence: &str,
extension: Vec<ExtPart>,
conditions: HashSet<TermId>) -> OntAnnotationDetail {
let condition_details: BTreeSet<_> =
conditions.iter().map(|cond| (cond.clone(), None)).collect();

OntAnnotationDetail {
id: id,
genes: vec![gene_uniquename.into()],
Expand All @@ -419,7 +422,8 @@ fn make_one_detail(id: i32, gene_uniquename: &str, reference_uniquename: &str,
qualifiers: vec![],
extension: extension,
gene_ex_props: None,
conditions: conditions,
conditions,
condition_details,
assigned_by: Some("PomBase".to_shared_str()),
throughput: Some(Throughput::HighThroughput),
}
Expand Down

0 comments on commit 372f13d

Please sign in to comment.