use sbol::constants::{SBO_DNA, SO_PROMOTER};
use sbol::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let design_ns = "https://example.org/design";
let parts_ns = "https://example.org/parts";
let promoter = Component::builder(parts_ns, "j23119")?
.types([SBO_DNA])
.add_component_role(SO_PROMOTER)
.name("J23119 constitutive promoter")
.build()?;
let parts = Document::from_objects(vec![SbolObject::Component(promoter.clone())])?;
let mut device = Component::builder(design_ns, "device")?
.types([SBO_DNA])
.name("Promoter-driven device")
.build()?;
let sub = SubComponent::new(&device.identity, "promoter", promoter.identity.clone())?;
device.features.push(sub.identity.clone());
let design = Document::from_objects(vec![
SbolObject::Component(device),
SbolObject::SubComponent(sub.clone()),
])?;
match sub.definition(&design) {
Err(ReferenceError::NotFound(iri)) => {
println!("within design alone: NotFound({iri}) — expected\n");
}
other => panic!("unexpected single-document outcome: {other:?}"),
}
let scope = DocumentSet::from_documents([&design, &parts])?;
let definition = sub.definition(&scope)?;
println!(
"design SubComponent `{}` resolves to Component `{}` from the parts library",
sub.identity, definition.identity,
);
if let Some(name) = definition.name() {
println!(" name: {name}");
}
println!(" types: {:?}", definition.types);
println!(" roles: {:?}", definition.roles);
Ok(())
}