Search in sources :

Example 1 with Plan

use of org.sbolstandard.core2.Plan in project libSBOLj by SynBioDex.

the class SBOLDocument method updateReferences.

private void updateReferences(HashMap<URI, URI> uriMap) throws SBOLValidationException {
    for (TopLevel topLevel : getTopLevels()) {
        for (URI wasDerivedFrom : topLevel.getWasDerivedFroms()) {
            if (uriMap.get(wasDerivedFrom) != null) {
                topLevel.removeWasDerivedFrom(wasDerivedFrom);
                topLevel.addWasDerivedFrom(uriMap.get(wasDerivedFrom));
            }
        }
        for (URI wasGeneratedBy : topLevel.getWasGeneratedBys()) {
            if (uriMap.get(wasGeneratedBy) != null) {
                topLevel.removeWasGeneratedBy(wasGeneratedBy);
                topLevel.addWasGeneratedBy(uriMap.get(wasGeneratedBy));
            }
        }
        for (URI attachmentURI : topLevel.getAttachmentURIs()) {
            if (uriMap.get(attachmentURI) != null) {
                topLevel.removeAttachment(attachmentURI);
                topLevel.addAttachment(uriMap.get(attachmentURI));
            }
        }
    }
    for (Collection collection : getCollections()) {
        for (URI memberURI : collection.getMemberURIs()) {
            if (uriMap.get(memberURI) != null) {
                collection.removeMember(memberURI);
                collection.addMember(uriMap.get(memberURI));
            }
        }
        updateReferences(collection, uriMap);
    }
    for (Experiment experiment : getExperiments()) {
        for (URI experimentalDatumURI : experiment.getExperimentalDataURIs()) {
            if (uriMap.get(experimentalDatumURI) != null) {
                experiment.removeExperimentalData(experimentalDatumURI);
                experiment.addExperimentalData(uriMap.get(experimentalDatumURI));
            }
        }
        updateReferences(experiment, uriMap);
    }
    for (ComponentDefinition componentDefinition : getComponentDefinitions()) {
        updateReferences(componentDefinition, uriMap);
        for (URI sequenceURI : componentDefinition.getSequenceURIs()) {
            if (uriMap.get(sequenceURI) != null) {
                componentDefinition.removeSequence(sequenceURI);
                componentDefinition.addSequence(uriMap.get(sequenceURI));
            }
        }
        for (Component component : componentDefinition.getComponents()) {
            if (uriMap.get(component.getDefinitionURI()) != null) {
                component.setDefinition(uriMap.get(component.getDefinitionURI()));
                for (MapsTo mapsTo : component.getMapsTos()) {
                    ComponentDefinition cd = getComponentDefinition(component.getDefinitionURI());
                    if (cd != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(component, uriMap);
            for (MapsTo mapsTo : component.getMapsTos()) {
                updateReferences(mapsTo, uriMap);
            }
            for (Location sourceLocation : component.getSourceLocations()) {
                if (sourceLocation.isSetSequence() && uriMap.get(sourceLocation.getSequenceURI()) != null) {
                    sourceLocation.setSequence(uriMap.get(sourceLocation.getSequenceURI()));
                }
            }
        }
        for (SequenceAnnotation sa : componentDefinition.getSequenceAnnotations()) {
            for (Location loc : sa.getLocations()) {
                if (loc.isSetSequence() && uriMap.get(loc.getSequenceURI()) != null) {
                    loc.setSequence(uriMap.get(loc.getSequenceURI()));
                }
                updateReferences(loc, uriMap);
            }
            updateReferences(sa, uriMap);
        }
        for (SequenceConstraint sc : componentDefinition.getSequenceConstraints()) {
            updateReferences(sc, uriMap);
        }
    }
    for (ModuleDefinition moduleDefinition : getModuleDefinitions()) {
        updateReferences(moduleDefinition, uriMap);
        for (FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
            if (uriMap.get(functionalComponent.getDefinitionURI()) != null) {
                functionalComponent.setDefinition(uriMap.get(functionalComponent.getDefinitionURI()));
                for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
                    ComponentDefinition cd = getComponentDefinition(functionalComponent.getDefinitionURI());
                    if (cd != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(functionalComponent, uriMap);
            for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
                updateReferences(mapsTo, uriMap);
            }
        }
        for (Module module : moduleDefinition.getModules()) {
            if (uriMap.get(module.getDefinitionURI()) != null) {
                module.setDefinition(uriMap.get(module.getDefinitionURI()));
                for (MapsTo mapsTo : module.getMapsTos()) {
                    ModuleDefinition md = getModuleDefinition(module.getDefinitionURI());
                    if (md != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(md.getPersistentIdentity().toString(), displayId, md.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(module, uriMap);
            for (MapsTo mapsTo : module.getMapsTos()) {
                updateReferences(mapsTo, uriMap);
            }
        }
        for (Interaction interaction : moduleDefinition.getInteractions()) {
            updateReferences(interaction, uriMap);
            for (Participation participation : interaction.getParticipations()) {
                updateReferences(participation, uriMap);
            }
        }
        for (URI modelURI : moduleDefinition.getModelURIs()) {
            if (uriMap.get(modelURI) != null) {
                moduleDefinition.removeModel(modelURI);
                moduleDefinition.addModel(uriMap.get(modelURI));
            }
        }
    }
    for (Model model : getModels()) {
        if (uriMap.get(model.getSource()) != null) {
            model.setSource(uriMap.get(model.getSource()));
        }
        updateReferences(model, uriMap);
    }
    for (Sequence sequence : getSequences()) {
        updateReferences(sequence, uriMap);
    }
    for (Attachment attachment : getAttachments()) {
        updateReferences(attachment, uriMap);
    }
    for (Implementation implementation : getImplementations()) {
        if (implementation.isSetBuilt()) {
            URI built = implementation.getBuiltURI();
            if (uriMap.get(built) != null) {
                implementation.setBuilt(uriMap.get(built));
            }
        }
        updateReferences(implementation, uriMap);
    }
    for (GenericTopLevel genericTopLevel : getGenericTopLevels()) {
        updateReferences(genericTopLevel, uriMap);
    }
    for (CombinatorialDerivation combinatorialDerivation : getCombinatorialDerivations()) {
        updateReferences(combinatorialDerivation, uriMap);
        if (uriMap.get(combinatorialDerivation.getTemplateURI()) != null) {
            combinatorialDerivation.setTemplate(uriMap.get(combinatorialDerivation.getTemplateURI()));
            ComponentDefinition cd = getComponentDefinition(combinatorialDerivation.getTemplateURI());
            if (cd != null) {
                for (VariableComponent variableComponent : combinatorialDerivation.getVariableComponents()) {
                    String displayId = URIcompliance.extractDisplayId(variableComponent.getVariableURI());
                    URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                    variableComponent.setVariable(newURI);
                }
            }
        }
        for (VariableComponent variableComponent : combinatorialDerivation.getVariableComponents()) {
            for (URI variantURI : variableComponent.getVariantURIs()) {
                if (uriMap.get(variantURI) != null) {
                    variableComponent.removeVariant(variantURI);
                    variableComponent.addVariant(uriMap.get(variantURI));
                }
            }
            for (URI variantCollectionURI : variableComponent.getVariantCollectionURIs()) {
                if (uriMap.get(variantCollectionURI) != null) {
                    variableComponent.removeVariantCollection(variantCollectionURI);
                    variableComponent.addVariantCollection(uriMap.get(variantCollectionURI));
                }
            }
            for (URI variantDerivationURI : variableComponent.getVariantDerivationURIs()) {
                if (uriMap.get(variantDerivationURI) != null) {
                    variableComponent.removeVariantDerivation(variantDerivationURI);
                    variableComponent.addVariantDerivation(uriMap.get(variantDerivationURI));
                }
            }
            updateReferences(variableComponent, uriMap);
        }
    }
    for (Activity activity : getActivities()) {
        updateReferences(activity, uriMap);
        for (Association association : activity.getAssociations()) {
            if (uriMap.get(association.getAgentURI()) != null) {
                association.setAgent(uriMap.get(association.getAgentURI()));
            }
            if (uriMap.get(association.getPlanURI()) != null) {
                association.setPlan(uriMap.get(association.getPlanURI()));
            }
            updateReferences(association, uriMap);
        }
        for (Usage usage : activity.getUsages()) {
            if (uriMap.get(usage.getEntityURI()) != null) {
                usage.setEntity(uriMap.get(usage.getEntityURI()));
            }
            updateReferences(usage, uriMap);
        }
    }
    for (Agent agent : getAgents()) {
        updateReferences(agent, uriMap);
    }
    for (Plan plan : getPlans()) {
        updateReferences(plan, uriMap);
    }
}
Also used : URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI)

Example 2 with Plan

use of org.sbolstandard.core2.Plan in project libSBOLj by SynBioDex.

the class SBOLReader method parsePlan.

@SuppressWarnings("unchecked")
private static Plan parsePlan(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel) throws SBOLValidationException {
    String displayId = null;
    String name = null;
    String description = null;
    URI persistentIdentity = null;
    String version = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    Set<URI> attachments = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : topLevel.getProperties()) {
        if (namedProperty.getName().equals(Sbol2Terms.Identified.persistentIdentity)) {
            if (!(namedProperty.getValue() instanceof Literal) || persistentIdentity != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10203", topLevel.getIdentity());
            }
            persistentIdentity = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.version)) {
            if (!(namedProperty.getValue() instanceof Literal) || version != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10206", topLevel.getIdentity());
            }
            version = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.displayId)) {
            if (!(namedProperty.getValue() instanceof Literal) || displayId != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10204", topLevel.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.title)) {
            if (!(namedProperty.getValue() instanceof Literal) || name != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10212", topLevel.getIdentity());
            }
            name = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.description)) {
            if (!(namedProperty.getValue() instanceof Literal) || description != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10213", topLevel.getIdentity());
            }
            description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasDerivedFrom)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10208", topLevel.getIdentity());
            }
            wasDerivedFroms.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasGeneratedBy)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10221", topLevel.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.TopLevel.hasAttachment)) {
            if (namedProperty.getValue() instanceof Literal) {
                if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
                    throw new SBOLValidationException("sbol-10306", topLevel.getIdentity());
                }
                attachments.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
            } else if (namedProperty.getValue() instanceof IdentifiableDocument) {
                if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.Attachment.Attachment)) {
                    Attachment attachment = parseAttachment(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue());
                    attachments.add(attachment.getIdentity());
                } else {
                    throw new SBOLValidationException("sbol-10306", topLevel.getIdentity());
                }
            } else {
                throw new SBOLValidationException("sbol-10306", topLevel.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Description.type) && ((Literal<QName>) namedProperty.getValue()).getValue().toString().equals(Sbol2Terms.Plan.Plan.getNamespaceURI() + Sbol2Terms.Plan.Plan.getLocalPart())) {
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Plan t = new Plan(topLevel.getIdentity());
    if (persistentIdentity != null)
        t.setPersistentIdentity(persistentIdentity);
    if (version != null)
        t.setVersion(version);
    if (displayId != null)
        t.setDisplayId(displayId);
    if (name != null)
        t.setName(name);
    if (description != null)
        t.setDescription(description);
    t.setWasDerivedFroms(wasDerivedFroms);
    t.setWasGeneratedBys(wasGeneratedBys);
    t.setAttachments(attachments);
    if (!annotations.isEmpty())
        t.setAnnotations(annotations);
    Plan oldA = SBOLDoc.getPlan(topLevel.getIdentity());
    if (oldA == null) {
        SBOLDoc.addPlan(t);
    } else {
        if (!t.equals(oldA)) {
            throw new SBOLValidationException("sbol-10202", t);
        }
    }
    return t;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) IdentifiableDocument(org.sbolstandard.core.datatree.IdentifiableDocument) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 3 with Plan

use of org.sbolstandard.core2.Plan in project libSBOLj by SynBioDex.

the class SBOLWorkshop2018 method main.

public static void main(String[] args) throws SBOLValidationException, IOException, SBOLConversionException, SynBioHubException {
    /* Getting a Device from an SBOL Compliant XML */
    // Start a new SBOL Document to hold the device
    SBOLDocument doc = new SBOLDocument();
    doc.setCreateDefaults(true);
    // Set your Homespace. All new SBOL objects will be created in this namespace
    String my_namespace = "http://my_namespace.org/";
    doc.setDefaultURIprefix(my_namespace);
    // Create a new device
    ComponentDefinition my_device = doc.createComponentDefinition("my_device", version, ComponentDefinition.DNA_REGION);
    System.out.println(my_device.getIdentity());
    System.out.println("");
    // Load some genetic parts taken from the Cello paper
    // TODO: need to fill in path
    SBOLDocument cello_parts = SBOLReader.read("/Users/myers/Downloads/parts.xml");
    System.out.println(len(cello_parts));
    printCounts(cello_parts);
    System.out.println("");
    // componentDefinitions and sequences
    for (TopLevel topLevel : cello_parts.getTopLevels()) {
        System.out.println(topLevel.getIdentity());
    }
    System.out.println("");
    // Import these objects into your Document
    doc.createCopy(cello_parts);
    for (TopLevel topLevel : doc.getTopLevels()) {
        System.out.println(topLevel.getIdentity());
    }
    System.out.println("");
    // Retrieve an object from the Document using its uniform resource identifier (URI)
    Collection promoter_collection = doc.getCollection(URI.create("http://examples.org/Collection/promoters/1"));
    // A Collection contains a list of URI references to objects, not the object themselves
    for (TopLevel topLevel : promoter_collection.getMembers()) {
        System.out.println(topLevel.getIdentity());
    }
    System.out.println("");
    // Retrieve a component, using its full URI
    ComponentDefinition promoter = doc.getComponentDefinition(URI.create("http://examples.org/ComponentDefinition/pPhlF/1"));
    // Review the BioPAX and Sequence Ontology terms that describe this component
    System.out.println(promoter.getTypes());
    System.out.println(promoter.getRoles());
    System.out.println("");
    /* Getting a Device from Synbiohub */
    // Start an interface to the part shop
    SynBioHubFrontend part_shop = new SynBioHubFrontend("https://synbiohub.org");
    // Search for records from the interlab study
    ArrayList<IdentifiedMetadata> records = part_shop.getMatchingComponentDefinitionMetadata("interlab", null, null, null, 0, 50);
    for (IdentifiedMetadata record : records) {
        System.out.println(record.getDisplayId() + ": " + record.getUri());
    }
    System.out.println("");
    // Import the medium device into the user's Document
    doc.createCopy(part_shop.getSBOL(URI.create("https://synbiohub.org/public/iGEM_2016_interlab/Medium_2016Interlab/1")));
    // Explore the new parts
    for (TopLevel topLevel : doc.getTopLevels()) {
        System.out.println(topLevel.getClass().getSimpleName() + ": " + topLevel.getIdentity());
    }
    System.out.println("");
    /* Extracting a ComponentDefinition from a Pre-existing Device */
    // Extract the medium strength promoter
    ComponentDefinition medium_strength_promoter = doc.getComponentDefinition(URI.create("https://synbiohub.org/public/igem/BBa_J23106/1"));
    // Get parts for a new circuit
    ComponentDefinition rbs = doc.getComponentDefinition(URI.create("http://examples.org/ComponentDefinition/Q2/1"));
    ComponentDefinition cds = doc.getComponentDefinition(URI.create("http://examples.org/ComponentDefinition/LuxR/1"));
    ComponentDefinition terminator = doc.getComponentDefinition(URI.create("http://examples.org/ComponentDefinition/ECK120010818/1"));
    // Assemble a new gene
    my_device.createSequenceConstraint("constraint1", RestrictionType.PRECEDES, medium_strength_promoter.getIdentity(), rbs.getIdentity());
    my_device.createSequenceConstraint("constraint2", RestrictionType.PRECEDES, rbs.getIdentity(), cds.getIdentity());
    my_device.createSequenceConstraint("constraint3", RestrictionType.PRECEDES, cds.getIdentity(), terminator.getIdentity());
    // Annotate the target construct with a Sequence Ontology term
    my_device.addRole(SequenceOntology.ENGINEERED_REGION);
    // Explore the newly assembled gene
    for (Component component : my_device.getComponents()) {
        System.out.println(component.getDisplayId());
    }
    System.out.println("");
    compile(doc, my_device);
    Sequence seq = my_device.getSequenceByEncoding(Sequence.IUPAC_DNA);
    System.out.println(seq.getElements());
    System.out.println("");
    /* Managing a Design-Build-Test-Learn workflow */
    Activity workflow_step_1 = doc.createActivity("build_1", version);
    Activity workflow_step_2 = doc.createActivity("build_2", version);
    Activity workflow_step_3 = doc.createActivity("test_1", version);
    Activity workflow_step_4 = doc.createActivity("analysis_1", version);
    Plan workflow_step_1_plan = doc.createPlan("gibson_assembly", version);
    Plan workflow_step_2_plan = doc.createPlan("transformation", version);
    Plan workflow_step_3_plan = doc.createPlan("promoter_characterization", version);
    Plan workflow_step_4_plan = doc.createPlan("parameter_optimization", version);
    workflow_step_1.createAssociation("association", URI.create("mailto:jdoe@my_namespace.org")).setPlan(workflow_step_1_plan.getIdentity());
    workflow_step_2.createAssociation("association", URI.create("mailto:jdoe@my_namespace.org")).setPlan(workflow_step_2_plan.getIdentity());
    workflow_step_3.createAssociation("association", URI.create("http://sys-bio.org/plate_reader_1")).setPlan(workflow_step_3_plan.getIdentity());
    workflow_step_4.createAssociation("association", URI.create("http://tellurium.analogmachine.org")).setPlan(workflow_step_4_plan.getIdentity());
    Implementation gibson_mix = doc.createImplementation("gibson_mix", version);
    gibson_mix.setBuilt(my_device);
    gibson_mix.addWasGeneratedBy(workflow_step_1.getIdentity());
    workflow_step_1.createUsage("usage", my_device.getIdentity());
    Collection clones = doc.createCollection("clones", version);
    Implementation clone1 = doc.createImplementation("clone1", version);
    clone1.setBuilt(my_device);
    clones.addMember(clone1.getIdentity());
    Implementation clone2 = doc.createImplementation("clone2", version);
    clone2.setBuilt(my_device);
    clones.addMember(clone2.getIdentity());
    Implementation clone3 = doc.createImplementation("clone3", version);
    clone3.setBuilt(my_device);
    clones.addMember(clone3.getIdentity());
    clones.addWasGeneratedBy(workflow_step_2.getIdentity());
    workflow_step_2.createUsage("usage", gibson_mix.getIdentity());
    Collection experiment1 = doc.createCollection("experiment1", version);
    experiment1.addWasGeneratedBy(workflow_step_3.getIdentity());
    workflow_step_3.createUsage("usage", clones.getIdentity());
    Collection analysis1 = doc.createCollection("analysis1", version);
    analysis1.addWasGeneratedBy(workflow_step_4.getIdentity());
    workflow_step_4.createUsage("usage", experiment1.getIdentity());
    // Validate the Document
    SBOLValidate.validateSBOL(doc, false, false, false);
    for (String error : SBOLValidate.getErrors()) {
        System.out.println(error);
    }
    System.out.println(analysis1.getIdentity());
    System.out.println("");
    /* Uploading the Device back to SynBioHub */
    // TODO: Need to provide your credentials
    String user_name = "myers";
    String password = "MaWen69!";
    part_shop.login(user_name, password);
    // Upon submission, the Document will be converted to a Collection with the following properties
    // The new Collection will have a URI that conforms to the following pattern:
    // https://synbiohub.org/user/<USERNAME>/<DOC.DISPLAYID>/<DOC.DISPLAYID>_collection
    String displayId = "my_device";
    String name = "my device";
    String description = "a description of the cassette";
    part_shop.createCollection(displayId, version, name, description, "", true, doc);
    // TODO: need to fill in your path
    String attachment_path = "/Users/myers/Downloads/results.txt";
    // Attach raw experimental data to the Test object here. Note the pattern
    URI test_uri = URI.create("https://synbiohub.org/user/" + user_name + "/" + displayId + "/experiment1/1");
    part_shop.attachFile(test_uri, attachment_path);
    // Attach processed experimental data here
    // TODO: need to fill in your path
    String other_attachement_path = "/Users/myers/Downloads/results.txt";
    URI analysis_uri = URI.create("https://synbiohub.org/user/" + user_name + "/" + displayId + "/analysis1/1");
    part_shop.attachFile(analysis_uri, other_attachement_path);
    System.out.println("Successfully uploaded");
}
Also used : SBOLDocument(org.sbolstandard.core2.SBOLDocument) Activity(org.sbolstandard.core2.Activity) Sequence(org.sbolstandard.core2.Sequence) Plan(org.sbolstandard.core2.Plan) URI(java.net.URI) Implementation(org.sbolstandard.core2.Implementation) Collection(org.sbolstandard.core2.Collection) TopLevel(org.sbolstandard.core2.TopLevel) SynBioHubFrontend(org.synbiohub.frontend.SynBioHubFrontend) Component(org.sbolstandard.core2.Component) IdentifiedMetadata(org.synbiohub.frontend.IdentifiedMetadata) ComponentDefinition(org.sbolstandard.core2.ComponentDefinition)

Example 4 with Plan

use of org.sbolstandard.core2.Plan in project libSBOLj by SynBioDex.

the class Plan method copy.

/* (non-Javadoc)
	 * @see org.sbolstandard.core2.abstract_classes.TopLevel#copy(java.lang.String, java.lang.String, java.lang.String)
	 */
/**
 * @throws SBOLValidationException if an SBOL validation rule violation occurred in
 * any of the following methods:
 * <ul>
 * <li>{@link #deepCopy()},</li>
 * <li>{@link URIcompliance#createCompliantURI(String, String, String)},</li>
 * <li>{@link #setDisplayId(String)},</li>
 * <li>{@link #setVersion(String)},</li>
 * <li>{@link #setWasDerivedFrom(URI)}, or</li>
 * <li>{@link #setIdentity(URI)}.</li>
 * </ul>
 */
@Override
Plan copy(String URIprefix, String displayId, String version) throws SBOLValidationException {
    Plan cloned = this.deepCopy();
    cloned.setPersistentIdentity(createCompliantURI(URIprefix, displayId, ""));
    cloned.setDisplayId(displayId);
    cloned.setVersion(version);
    URI newIdentity = createCompliantURI(URIprefix, displayId, version);
    if (!this.getIdentity().equals(newIdentity)) {
        cloned.addWasDerivedFrom(this.getIdentity());
    } else {
        cloned.setWasDerivedFroms(this.getWasDerivedFroms());
    }
    cloned.setIdentity(newIdentity);
    return cloned;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 5 with Plan

use of org.sbolstandard.core2.Plan in project libSBOLj by SynBioDex.

the class SBOLDocument method updateReferences.

private void updateReferences(URI originalIdentity, URI newIdentity) throws SBOLValidationException {
    for (TopLevel topLevel : getTopLevels()) {
        for (URI wasDerivedFrom : topLevel.getWasDerivedFroms()) {
            if (wasDerivedFrom.equals(originalIdentity)) {
                topLevel.removeWasDerivedFrom(originalIdentity);
                topLevel.addWasDerivedFrom(newIdentity);
            }
        }
        for (URI wasGeneratedBy : topLevel.getWasGeneratedBys()) {
            if (wasGeneratedBy.equals(originalIdentity)) {
                topLevel.removeWasGeneratedBy(originalIdentity);
                topLevel.addWasGeneratedBy(newIdentity);
            }
        }
        for (URI attachmentURI : topLevel.getAttachmentURIs()) {
            if (attachmentURI.equals(originalIdentity)) {
                topLevel.removeAttachment(originalIdentity);
                topLevel.addAttachment(newIdentity);
            }
        }
    }
    for (Collection collection : getCollections()) {
        for (URI memberURI : collection.getMemberURIs()) {
            if (memberURI.equals(originalIdentity)) {
                collection.removeMember(originalIdentity);
                collection.addMember(newIdentity);
            }
        }
        updateReferences(collection, originalIdentity, newIdentity);
    }
    for (Experiment experiment : getExperiments()) {
        for (URI experimentalDataURI : experiment.getExperimentalDataURIs()) {
            if (experimentalDataURI.equals(originalIdentity)) {
                experiment.removeExperimentalData(originalIdentity);
                experiment.addExperimentalData(newIdentity);
            }
        }
        updateReferences(experiment, originalIdentity, newIdentity);
    }
    for (ComponentDefinition componentDefinition : getComponentDefinitions()) {
        updateReferences(componentDefinition, originalIdentity, newIdentity);
        for (URI sequenceURI : componentDefinition.getSequenceURIs()) {
            if (sequenceURI.equals(originalIdentity)) {
                componentDefinition.removeSequence(originalIdentity);
                componentDefinition.addSequence(newIdentity);
            }
        }
        for (Component component : componentDefinition.getComponents()) {
            if (component.getDefinitionURI().equals(originalIdentity)) {
                component.setDefinition(newIdentity);
                for (MapsTo mapsTo : component.getMapsTos()) {
                    ComponentDefinition cd = getComponentDefinition(newIdentity);
                    if (cd != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(component, originalIdentity, newIdentity);
            for (MapsTo mapsTo : component.getMapsTos()) {
                updateReferences(mapsTo, originalIdentity, newIdentity);
            }
            for (Location sourceLocation : component.getSourceLocations()) {
                if (sourceLocation.isSetSequence() && sourceLocation.getSequenceURI().equals(originalIdentity)) {
                    sourceLocation.setSequence(newIdentity);
                }
            }
        }
        for (SequenceAnnotation sa : componentDefinition.getSequenceAnnotations()) {
            for (Location loc : sa.getLocations()) {
                if (loc.isSetSequence() && loc.getSequenceURI().equals(originalIdentity)) {
                    loc.setSequence(newIdentity);
                }
                updateReferences(loc, originalIdentity, newIdentity);
            }
            updateReferences(sa, originalIdentity, newIdentity);
        }
        for (SequenceConstraint sc : componentDefinition.getSequenceConstraints()) {
            updateReferences(sc, originalIdentity, newIdentity);
        }
    }
    for (ModuleDefinition moduleDefinition : getModuleDefinitions()) {
        updateReferences(moduleDefinition, originalIdentity, newIdentity);
        for (FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
            if (functionalComponent.getDefinitionURI().equals(originalIdentity)) {
                functionalComponent.setDefinition(newIdentity);
                for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
                    ComponentDefinition cd = getComponentDefinition(newIdentity);
                    if (cd != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(functionalComponent, originalIdentity, newIdentity);
            for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
                updateReferences(mapsTo, originalIdentity, newIdentity);
            }
        }
        for (Module module : moduleDefinition.getModules()) {
            if (module.getDefinitionURI().equals(originalIdentity)) {
                module.setDefinition(newIdentity);
                for (MapsTo mapsTo : module.getMapsTos()) {
                    ModuleDefinition md = getModuleDefinition(newIdentity);
                    if (md != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(md.getPersistentIdentity().toString(), displayId, md.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(module, originalIdentity, newIdentity);
            for (MapsTo mapsTo : module.getMapsTos()) {
                updateReferences(mapsTo, originalIdentity, newIdentity);
            }
        }
        for (Interaction interaction : moduleDefinition.getInteractions()) {
            updateReferences(interaction, originalIdentity, newIdentity);
            for (Participation participation : interaction.getParticipations()) {
                updateReferences(participation, originalIdentity, newIdentity);
            }
        }
        for (URI modelURI : moduleDefinition.getModelURIs()) {
            if (modelURI.equals(originalIdentity)) {
                moduleDefinition.removeModel(originalIdentity);
                moduleDefinition.addModel(newIdentity);
            }
        }
    }
    for (Model model : getModels()) {
        if (model.getSource().equals(originalIdentity)) {
            model.setSource(newIdentity);
        }
        updateReferences(model, originalIdentity, newIdentity);
    }
    for (Attachment attachment : getAttachments()) {
        updateReferences(attachment, originalIdentity, newIdentity);
    }
    for (Implementation implementation : getImplementations()) {
        if (implementation.isSetBuilt() && implementation.getBuiltURI().equals(originalIdentity)) {
            implementation.setBuilt(newIdentity);
        }
        updateReferences(implementation, originalIdentity, newIdentity);
    }
    for (Sequence sequence : getSequences()) {
        updateReferences(sequence, originalIdentity, newIdentity);
    }
    for (GenericTopLevel genericTopLevel : getGenericTopLevels()) {
        updateReferences(genericTopLevel, originalIdentity, newIdentity);
    }
    for (CombinatorialDerivation combinatorialDerivation : getCombinatorialDerivations()) {
        updateReferences(combinatorialDerivation, originalIdentity, newIdentity);
        if (combinatorialDerivation.getTemplateURI().equals(originalIdentity)) {
            combinatorialDerivation.setTemplate(newIdentity);
            ComponentDefinition cd = getComponentDefinition(newIdentity);
            if (cd != null) {
                for (VariableComponent variableComponent : combinatorialDerivation.getVariableComponents()) {
                    String displayId = URIcompliance.extractDisplayId(variableComponent.getVariableURI());
                    URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                    variableComponent.setVariable(newURI);
                }
            }
        }
        for (VariableComponent variableComponent : combinatorialDerivation.getVariableComponents()) {
            for (URI variantURI : variableComponent.getVariantURIs()) {
                if (variantURI.equals(originalIdentity)) {
                    variableComponent.removeVariant(variantURI);
                    variableComponent.addVariant(newIdentity);
                }
            }
            for (URI variantCollectionURI : variableComponent.getVariantCollectionURIs()) {
                if (variantCollectionURI.equals(originalIdentity)) {
                    variableComponent.removeVariantCollection(variantCollectionURI);
                    variableComponent.addVariantCollection(newIdentity);
                }
            }
            for (URI variantDerivationURI : variableComponent.getVariantDerivationURIs()) {
                if (variantDerivationURI.equals(originalIdentity)) {
                    variableComponent.removeVariantDerivation(variantDerivationURI);
                    variableComponent.addVariantDerivation(newIdentity);
                }
            }
            updateReferences(variableComponent, originalIdentity, newIdentity);
        }
    }
    for (Activity activity : getActivities()) {
        updateReferences(activity, originalIdentity, newIdentity);
        for (Association association : activity.getAssociations()) {
            if (association.getAgentURI().equals(originalIdentity)) {
                association.setAgent(newIdentity);
            }
            if (association.isSetPlan() && association.getPlanURI().equals(originalIdentity)) {
                association.setPlan(newIdentity);
            }
            updateReferences(association, originalIdentity, newIdentity);
        }
        for (Usage usage : activity.getUsages()) {
            if (usage.getEntityURI().equals(originalIdentity)) {
                usage.setEntity(newIdentity);
            }
            updateReferences(usage, originalIdentity, newIdentity);
        }
    }
    for (Agent agent : getAgents()) {
        updateReferences(agent, originalIdentity, newIdentity);
    }
    for (Plan plan : getPlans()) {
        updateReferences(plan, originalIdentity, newIdentity);
    }
}
Also used : URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI)

Aggregations

URI (java.net.URI)5 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)4 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)1 Literal (org.sbolstandard.core.datatree.Literal)1 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)1 Activity (org.sbolstandard.core2.Activity)1 Collection (org.sbolstandard.core2.Collection)1 Component (org.sbolstandard.core2.Component)1 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)1 Implementation (org.sbolstandard.core2.Implementation)1 Plan (org.sbolstandard.core2.Plan)1 SBOLDocument (org.sbolstandard.core2.SBOLDocument)1 Sequence (org.sbolstandard.core2.Sequence)1 TopLevel (org.sbolstandard.core2.TopLevel)1 IdentifiedMetadata (org.synbiohub.frontend.IdentifiedMetadata)1 SynBioHubFrontend (org.synbiohub.frontend.SynBioHubFrontend)1