Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/catplus-common/src/graph/namespaces/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace! {
Observation,
optimizationType,
order,
Peak,
peak,
PeakList,
Plate,
ProcessedDataDocument,
Expand Down
7 changes: 7 additions & 0 deletions src/catplus-common/src/graph/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use sophia_api::{
term::{bnode_id::BnodeId, SimpleTerm},
};
use uuid::Uuid;
use crate::graph::namespaces::cat_resource;

pub fn generate_bnode_term() -> SimpleTerm<'static> {
let identifier = Uuid::new_v4().to_string();
Expand All @@ -20,3 +21,9 @@ pub(crate) fn hash_identifier(identifier: &str) -> String {
let result = hasher.finalize();
general_purpose::URL_SAFE_NO_PAD.encode(result)
}

pub fn generate_resource_identifier_uri(resource_id: String) -> SimpleTerm<'static> {
let mut uri = cat_resource::ns.clone().as_str().to_owned();
uri.push_str(&hash_identifier(&resource_id));
IriRef::new_unchecked(uri).try_into_term().expect("Failed to convert to SimpleTerm")
}
35 changes: 9 additions & 26 deletions src/catplus-common/src/models/agilent.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
graph::{
insert_into::{InsertIntoGraph, Link},
namespaces::{allodc, allores, allorole, cat, cat_resource, obo, purl, qb, qudt},
utils::hash_identifier,
namespaces::{allodc, allores, allorole, cat, obo, purl, qb, qudt},
utils::generate_resource_identifier_uri,
},
models::{core::PeakList, enums::Unit},
models::{core::PeakList, enums::Unit}
};

use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -100,9 +100,6 @@ impl InsertIntoGraph for MeasurementAggregateDocument {
pub struct MeasurementDocument {
#[serde(rename = "measurement identifier")]
pub measurement_identifier: String,
// TO-DO: needs further definition to be integrated
// #[serde(rename = "chromatography column document")]
// pub chromatography_column_document: ChromatographyColumnDocument,
#[serde(rename = "device control aggregate document")]
pub device_control_aggregate_document: DeviceSystemDocument,
#[serde(rename = "sample document")]
Expand Down Expand Up @@ -148,23 +145,6 @@ impl InsertIntoGraph for MeasurementDocument {
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ChromatographyColumnDocument {}

impl InsertIntoGraph for ChromatographyColumnDocument {
fn insert_into(&self, graph: &mut LightGraph, iri: SimpleTerm) -> anyhow::Result<()> {
for (pred, value) in
[(rdf::type_, &cat::ChromatographyColumnDocument.as_simple() as &dyn InsertIntoGraph)]
{
value.attach_into(
graph,
Link { source_iri: iri.clone(), pred: pred.as_simple(), target_iri: None },
)?;
}
Ok(())
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct DeviceSystemDocument {
#[serde(alias = "device document", alias = "device control document")]
Expand Down Expand Up @@ -215,9 +195,7 @@ pub struct DeviceDocument {
impl InsertIntoGraph for DeviceDocument {
fn get_uri(&self) -> SimpleTerm<'static> {
// build URI based on self.device_identifier
let mut uri = cat_resource::ns.clone().as_str().to_owned();
uri.push_str(&hash_identifier(&self.device_identifier));
IriRef::new_unchecked(uri).try_into_term().unwrap()
generate_resource_identifier_uri(self.device_identifier.clone())
}

fn insert_into(&self, graph: &mut LightGraph, iri: SimpleTerm) -> anyhow::Result<()> {
Expand Down Expand Up @@ -296,6 +274,11 @@ pub struct AgilentProduct {
}

impl InsertIntoGraph for AgilentProduct {
fn get_uri(&self) -> SimpleTerm<'static> {
//same as in synth.rs set_product_uri function
//same as in bravo.rs get_uri function for BravoProduct
generate_resource_identifier_uri(self.product_identifier.clone())
}
fn insert_into(&self, graph: &mut LightGraph, iri: SimpleTerm) -> anyhow::Result<()> {
for (pred, value) in [
(rdf::type_, &cat::Product.as_simple() as &dyn InsertIntoGraph),
Expand Down
13 changes: 10 additions & 3 deletions src/catplus-common/src/models/bravo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
graph::{
insert_into::{InsertIntoGraph, Link},
namespaces::{alloprop, alloqual, allores, cat, purl},
utils::generate_resource_identifier_uri,
},
models::{
core::{Chemical, Observation, Plate, Well},
Expand All @@ -13,6 +14,7 @@ use serde::{Deserialize, Serialize};
use sophia::{
api::ns::{rdf, xsd},
inmem::graph::LightGraph,
iri::IriRef,
};
use sophia_api::term::{SimpleTerm, Term};

Expand Down Expand Up @@ -60,7 +62,7 @@ pub struct BravoAction {
pub start_duration: Option<Observation>,
pub ending_duration: Option<Observation>,
pub order: Option<String>,
pub product_identification: ProductIdentification,
pub product_identification: BravoProduct,
}

impl InsertIntoGraph for BravoAction {
Expand Down Expand Up @@ -191,14 +193,19 @@ impl InsertIntoGraph for BravoWell {

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProductIdentification {
pub struct BravoProduct {
#[serde(rename = "sampleID")]
pub sample_id: String,
// Peak identifier is added on the action, not on the product
pub peak_identifier: String,
}

impl InsertIntoGraph for ProductIdentification {
impl InsertIntoGraph for BravoProduct {
fn get_uri(&self) -> SimpleTerm<'static> {
//same as in synth.rs set_product_uri function
//same as in agilent.rs get_uri function for AgilentProduct
generate_resource_identifier_uri(self.sample_id.clone())
}
fn insert_into(&self, graph: &mut LightGraph, iri: SimpleTerm) -> anyhow::Result<()> {
for (pred, value) in [
(rdf::type_, &cat::Product.as_simple() as &dyn InsertIntoGraph),
Expand Down
16 changes: 15 additions & 1 deletion src/catplus-common/src/models/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,27 @@ impl InsertIntoGraph for PeakList {
fn insert_into(&self, graph: &mut LightGraph, iri: SimpleTerm) -> anyhow::Result<()> {
for (pred, value) in [
(rdf::type_, &cat::PeakList.as_simple() as &dyn InsertIntoGraph),
(cat::Peak, &self.peak),
(cat::peak, &self.peak),
] {
value.attach_into(
graph,
Link { source_iri: iri.clone(), pred: pred.as_simple(), target_iri: None },
)?;
}
let product = cat::Product.as_simple();
let rdf_type = rdf::type_.as_simple();

let product_object = graph.triples().filter_map(Result::ok).find_map(|[s, p, o]| {
if *p == rdf_type && *o == product {
Some(s.clone())
} else {
None
}
});

if let Some(subject) = product_object {
graph.insert(iri.clone(), cat::hasProduct.as_simple(), subject)?;
}
Ok(())
}
}
Expand Down
21 changes: 13 additions & 8 deletions src/catplus-common/src/models/synth.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
graph::{
insert_into::{InsertIntoGraph, Link},
namespaces::{alloproc, alloprop, alloqual, allores, cat, cat_resource, purl, qudt},
utils::hash_identifier,
namespaces::{alloproc, alloprop, alloqual, allores, cat, purl, qudt},
utils::generate_resource_identifier_uri,
},
models::{
core::{Chemical, Observation, Plate},
Expand Down Expand Up @@ -31,13 +31,17 @@ pub struct SynthBatch {
pub actions: Vec<SynthAction>,
}

fn set_product_uri(product_id: String) -> SimpleTerm<'static> {
Comment thread
vancauwe marked this conversation as resolved.
//same as in agilent.rs get_uri function for AgilentProduct
//same as in bravo.rs get_uri function for BravoProduct
generate_resource_identifier_uri(product_id.clone())
}

impl InsertIntoGraph for SynthBatch {
fn get_uri(&self) -> SimpleTerm<'static> {
// build URI based on self.batch_id
let mut uri = cat_resource::ns.clone().as_str().to_owned();
uri.push_str(&hash_identifier(&self.batch_id));
IriRef::new_unchecked(uri).try_into_term().unwrap()
}
generate_resource_identifier_uri(self.batch_id.clone())
}

fn insert_into(&self, graph: &mut LightGraph, iri: SimpleTerm) -> anyhow::Result<()> {
for (pred, value) in [
Expand All @@ -64,7 +68,8 @@ impl InsertIntoGraph for SynthBatch {
// Create the product_id from container_id and position
let product_id =
format!("{}-{}", &well.has_plate.container_id, well.position);
Comment thread
vancauwe marked this conversation as resolved.
let new_product_uri = well.get_uri();
//let new_product_uri = well.get_uri();
let new_product_uri = set_product_uri(product_id.clone());
for (pred, value) in [
(
rdf::type_,
Expand Down Expand Up @@ -169,7 +174,7 @@ impl InsertIntoGraph for SynthAction {
(allores::AFR_0001606, &self.method_name.as_simple()),
(allores::AFR_0001723, &self.equipment_name.as_simple()),
(cat::subEquipmentName, &self.sub_equipment_name.as_simple()),
(cat::speedInRPM, &self.speed_shaker),
(alloprop::AFX_0000211, &self.speed_shaker),
(cat::temperatureTumbleStirrer, &self.temperature_tumble_stirrer),
(alloprop::AFX_0000211, &self.speed_tumble_stirrer),
(cat::vacuum, &self.vacuum),
Expand Down
Loading