use std::collections::HashMap;
use mzdata::params::Value;
use crate::{
mzspeclib::{Attribute, AttributeValue, Attributes, Id, merge_attributes},
term,
};
#[derive(Clone, Debug, PartialEq)]
pub struct Interpretation {
pub id: Id,
pub probability: Option<f64>,
pub attributes: Attributes,
pub analyte_refs: Vec<Id>,
pub members: HashMap<Id, Attributes>,
}
impl Default for Interpretation {
fn default() -> Self {
Self {
id: 0,
probability: None,
attributes: vec![Vec::new(); 1],
analyte_refs: Vec::new(),
members: HashMap::new(),
}
}
}
impl Interpretation {
pub fn attributes(&self) -> Attributes {
let mut attributes = vec![Vec::new(); 1];
if !self.analyte_refs.is_empty() {
attributes[0].push(Attribute::new(
term!(MS:1003163|analyte mixture members),
AttributeValue::List(
self.analyte_refs
.iter()
.map(|v| Value::Int(i64::from(*v)))
.collect(),
),
));
}
if let Some(probability) = self.probability {
attributes[0].push(Attribute::new(
term!(MS:1002357|PSM-level probability),
Value::Float(probability),
));
}
merge_attributes(&mut attributes, &self.attributes);
attributes
}
}