use crate::sbol2_vocab as v2;
use crate::vocab as v3;
pub(super) fn map_orientation(iri: &str) -> Option<&'static str> {
match iri {
v3::SBOL_INLINE => Some(v2::SBOL2_ORIENTATION_INLINE),
v3::SBOL_REVERSE_COMPLEMENT => Some(v2::SBOL2_ORIENTATION_REVERSE_COMPLEMENT),
_ => None,
}
}
pub(super) fn map_encoding(iri: &str) -> Option<&'static str> {
match iri {
v3::EDAM_IUPAC_DNA_RNA_ENCODING => Some(v2::SBOL2_ENCODING_IUPAC_DNA),
v3::EDAM_IUPAC_PROTEIN_ENCODING => Some(v2::SBOL2_ENCODING_IUPAC_PROTEIN),
"https://identifiers.org/edam:format_1196" => Some(v2::SBOL2_ENCODING_SMILES),
"https://identifiers.org/edam:format_1197" => Some(v2::SBOL2_ENCODING_INCHI),
_ => None,
}
}
pub(super) fn map_biopax_type(iri: &str) -> Option<&'static str> {
match iri {
"https://identifiers.org/SBO:0000251" => Some(v2::BIOPAX_DNA_REGION),
"https://identifiers.org/SBO:0000250" => Some(v2::BIOPAX_RNA_REGION),
"https://identifiers.org/SBO:0000252" => Some(v2::BIOPAX_PROTEIN),
"https://identifiers.org/SBO:0000247" => Some(v2::BIOPAX_SMALL_MOLECULE),
"https://identifiers.org/SBO:0000253" => Some(v2::BIOPAX_COMPLEX),
_ => None,
}
}
pub(super) fn sbo_for_biopax(biopax: &str) -> Option<&'static str> {
match biopax {
v2::BIOPAX_DNA | v2::BIOPAX_DNA_REGION => Some("https://identifiers.org/SBO:0000251"),
v2::BIOPAX_RNA | v2::BIOPAX_RNA_REGION => Some("https://identifiers.org/SBO:0000250"),
v2::BIOPAX_PROTEIN => Some("https://identifiers.org/SBO:0000252"),
v2::BIOPAX_SMALL_MOLECULE => Some("https://identifiers.org/SBO:0000247"),
v2::BIOPAX_COMPLEX => Some("https://identifiers.org/SBO:0000253"),
_ => None,
}
}
pub(super) fn map_restriction(iri: &str) -> Option<String> {
let local = iri.strip_prefix("http://sbols.org/v3#")?;
Some(format!("http://sbols.org/v2#{local}"))
}
pub(super) fn map_restriction_to_refinement(
restriction: &str,
cref_role: CRefPosition,
) -> Option<&'static str> {
match (restriction, cref_role) {
(v3::SBOL_VERIFY_IDENTICAL, _) => Some(v2::SBOL2_REFINEMENT_VERIFY_IDENTICAL),
(v3::SBOL_REPLACES, CRefPosition::Subject) => Some(v2::SBOL2_REFINEMENT_USE_REMOTE),
(v3::SBOL_REPLACES, CRefPosition::Object) => Some(v2::SBOL2_REFINEMENT_USE_LOCAL),
_ => None,
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum CRefPosition {
Subject,
Object,
}
pub(super) fn map_cardinality(iri: &str) -> Option<&'static str> {
match iri {
v3::SBOL_ONE => Some(v2::SBOL2_ONE),
v3::SBOL_ZERO_OR_ONE => Some(v2::SBOL2_ZERO_OR_ONE),
v3::SBOL_ONE_OR_MORE => Some(v2::SBOL2_ONE_OR_MORE),
v3::SBOL_ZERO_OR_MORE => Some(v2::SBOL2_ZERO_OR_MORE),
_ => None,
}
}
pub(super) fn map_strategy(iri: &str) -> Option<&'static str> {
match iri {
v3::SBOL_ENUMERATE => Some(v2::SBOL2_ENUMERATE),
v3::SBOL_SAMPLE => Some(v2::SBOL2_SAMPLE),
_ => None,
}
}
pub(super) fn map_role_integration(iri: &str) -> Option<&'static str> {
match iri {
v3::SBOL_MERGE_ROLES => Some(v2::SBOL2_MERGE_ROLES),
v3::SBOL_OVERRIDE_ROLES => Some(v2::SBOL2_OVERRIDE_ROLES),
_ => None,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn orientation_round_trips() {
assert_eq!(
map_orientation(v3::SBOL_INLINE),
Some(v2::SBOL2_ORIENTATION_INLINE)
);
assert_eq!(
map_orientation(v3::SBOL_REVERSE_COMPLEMENT),
Some(v2::SBOL2_ORIENTATION_REVERSE_COMPLEMENT)
);
assert_eq!(map_orientation("http://example.org/other"), None);
}
#[test]
fn encoding_round_trips() {
assert_eq!(
map_encoding(v3::EDAM_IUPAC_DNA_RNA_ENCODING),
Some(v2::SBOL2_ENCODING_IUPAC_DNA)
);
assert_eq!(
map_encoding(v3::EDAM_IUPAC_PROTEIN_ENCODING),
Some(v2::SBOL2_ENCODING_IUPAC_PROTEIN)
);
}
#[test]
fn sbo_to_biopax_prefers_region_variant() {
assert_eq!(
map_biopax_type("https://identifiers.org/SBO:0000251"),
Some(v2::BIOPAX_DNA_REGION)
);
}
#[test]
fn restriction_namespace_shift() {
assert_eq!(
map_restriction("http://sbols.org/v3#precedes").as_deref(),
Some("http://sbols.org/v2#precedes")
);
assert_eq!(
map_restriction("http://sbols.org/v3#verifyIdentical").as_deref(),
Some("http://sbols.org/v2#verifyIdentical")
);
assert_eq!(map_restriction("http://example.org/other"), None);
}
#[test]
fn refinement_inference_is_position_aware() {
assert_eq!(
map_restriction_to_refinement(v3::SBOL_REPLACES, CRefPosition::Subject),
Some(v2::SBOL2_REFINEMENT_USE_REMOTE)
);
assert_eq!(
map_restriction_to_refinement(v3::SBOL_REPLACES, CRefPosition::Object),
Some(v2::SBOL2_REFINEMENT_USE_LOCAL)
);
assert_eq!(
map_restriction_to_refinement(v3::SBOL_VERIFY_IDENTICAL, CRefPosition::Subject),
Some(v2::SBOL2_REFINEMENT_VERIFY_IDENTICAL)
);
assert_eq!(
map_restriction_to_refinement(v3::SBOL_VERIFY_IDENTICAL, CRefPosition::Object),
Some(v2::SBOL2_REFINEMENT_VERIFY_IDENTICAL)
);
assert_eq!(
map_restriction_to_refinement("http://example.org/other", CRefPosition::Subject),
None
);
}
#[test]
fn cardinality_to_operator() {
assert_eq!(map_cardinality(v3::SBOL_ONE), Some(v2::SBOL2_ONE));
assert_eq!(
map_cardinality(v3::SBOL_ZERO_OR_ONE),
Some(v2::SBOL2_ZERO_OR_ONE)
);
assert_eq!(
map_cardinality(v3::SBOL_ONE_OR_MORE),
Some(v2::SBOL2_ONE_OR_MORE)
);
assert_eq!(
map_cardinality(v3::SBOL_ZERO_OR_MORE),
Some(v2::SBOL2_ZERO_OR_MORE)
);
assert_eq!(map_cardinality("http://example.org/other"), None);
}
#[test]
fn strategy_namespace_shift() {
assert_eq!(map_strategy(v3::SBOL_ENUMERATE), Some(v2::SBOL2_ENUMERATE));
assert_eq!(map_strategy(v3::SBOL_SAMPLE), Some(v2::SBOL2_SAMPLE));
assert_eq!(map_strategy("http://example.org/other"), None);
}
#[test]
fn role_integration_namespace_shift() {
assert_eq!(
map_role_integration(v3::SBOL_MERGE_ROLES),
Some(v2::SBOL2_MERGE_ROLES)
);
assert_eq!(
map_role_integration(v3::SBOL_OVERRIDE_ROLES),
Some(v2::SBOL2_OVERRIDE_ROLES)
);
assert_eq!(map_role_integration("http://example.org/other"), None);
}
}