Search in sources :

Example 6 with FunctionalComponent

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

the class ModuleDefinition method createFunctionalComponent.

/**
 * Creates a child functional component for this module definition with the given arguments, and then adds to this
 * module definition's list of functional components.
 * <p>
 * This method creates a compliant URI for the functional component to be created. It starts with
 * this component defintion's persistent identity, followed by the given functional component's display ID,
 * and ends with this module definition's version.
 *
 * @param displayId the display ID of the functional component to be created
 * @param access the access property of the functional component to be created
 * @param definitionURI the identity URI of the component definition referenced by the functional component to be created
 * @param direction the direction property of the functional component to be created
 * @return the created functional component
 * @throws SBOLValidationException if any of the following SBOL validation rules was violated:
 * 10201, 10202, 10204, 10206, 10602, 10604, 10607, 11802, 10804.
 */
public FunctionalComponent createFunctionalComponent(String displayId, AccessType access, URI definitionURI, DirectionType direction) throws SBOLValidationException {
    if (this.getSBOLDocument() != null && this.getSBOLDocument().isComplete()) {
        if (this.getSBOLDocument().getComponentDefinition(definitionURI) == null) {
            throw new SBOLValidationException("sbol-10604", this);
        }
    }
    String URIprefix = this.getPersistentIdentity().toString();
    String version = this.getVersion();
    URI functionalComponentURI = createCompliantURI(URIprefix, displayId, version);
    FunctionalComponent fc = createFunctionalComponent(functionalComponentURI, access, definitionURI, direction);
    fc.setPersistentIdentity(createCompliantURI(URIprefix, displayId, ""));
    fc.setDisplayId(displayId);
    fc.setVersion(version);
    return fc;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 7 with FunctionalComponent

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

the class ModuleDefinition method flattenRecurse.

/**
 * @return flattened ModuleDefinition
 * @throws SBOLValidationException if either of the following condition is satisfied:
 * <ul>
 * <li>The following SBOL validation rule was violated: 10811; or</li>
 *
 * <li>if an SBOL validation rule violation occurred in any of the following methods:</li>
 *	 <ul>
 *     	<li>{@link #deepCopy()},</li>
 * 		<li>{@link #flattenRecurse()},</li>
 * 		<li>{@link FunctionalComponent#setDefinition(URI)},</li>
 * 		<li>{@link FunctionalComponent#deepCopy()},</li>
 * 		<li>{@link FunctionalComponent#updateCompliantURI(String, String, String)},</li>
 * 		<li>{@link #addFunctionalComponent(FunctionalComponent)},</li>
 * 		<li>{@link Participation#setParticipant(URI)},</li>
 * 		<li>{@link #addInteraction(Interaction)}, or</li>
 * 		<li>{@link Interaction#deepCopy()}.</li>
 * 	</ul>
 * </ul>
 */
private ModuleDefinition flattenRecurse() throws SBOLValidationException {
    ModuleDefinition flatModuleDefinition = this.deepCopy();
    for (Module module : this.getModules()) {
        ModuleDefinition flatModule = module.getDefinition().flattenRecurse();
        for (FunctionalComponent fc : flatModule.getFunctionalComponents()) {
            boolean foundIt = false;
            URI oldURI = fc.getIdentity();
            URI newURI = null;
            for (MapsTo mapsTo : module.getMapsTos()) {
                if (mapsTo.getRemoteURI().equals(fc.getIdentity())) {
                    newURI = mapsTo.getLocalURI();
                    FunctionalComponent topFc = flatModuleDefinition.getFunctionalComponent(newURI);
                    if (mapsTo.getRefinement() == RefinementType.USEREMOTE) {
                        topFc.setDefinition(fc.getDefinitionURI());
                    } else if (mapsTo.getRefinement() == RefinementType.VERIFYIDENTICAL) {
                        if (!topFc.getDefinitionURI().equals(fc.getDefinitionURI())) {
                            // + "' are not identical.");
                            throw new SBOLValidationException("sbol-10811", mapsTo);
                        }
                    } else if (mapsTo.getRefinement() == RefinementType.MERGE) {
                    // TODO: merge?
                    }
                    foundIt = true;
                    break;
                }
            }
            if (!foundIt) {
                FunctionalComponent newFC = fc.deepCopy();
                newFC.updateCompliantURI(this.getPersistentIdentity().toString(), module.getDisplayId() + "__" + fc.getDisplayId(), this.getVersion());
                newURI = newFC.getIdentity();
                flatModuleDefinition.addFunctionalComponent(newFC);
            }
            for (Interaction i : flatModule.getInteractions()) {
                for (Participation p : i.getParticipations()) {
                    if (p.getParticipantURI().equals(oldURI)) {
                        p.setParticipant(newURI);
                    }
                }
            }
        }
        for (Interaction i : flatModule.getInteractions()) {
            flatModuleDefinition.addInteraction(i.deepCopy());
        }
    }
    flatModuleDefinition.clearModules();
    return flatModuleDefinition;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 8 with FunctionalComponent

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

the class SBOLDocument method updateReferences.

// TODO: need to update persistentIdentities too
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 (ComponentDefinition componentDefinition : getComponentDefinitions()) {
        updateReferences(componentDefinition, originalIdentity, 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 (SequenceAnnotation sa : componentDefinition.getSequenceAnnotations()) {
            for (Location loc : sa.getLocations()) {
                updateReferences(loc, originalIdentity, newIdentity);
            }
            updateReferences(sa, originalIdentity, newIdentity);
        }
        for (SequenceConstraint sc : componentDefinition.getSequenceConstraints()) {
            updateReferences(sc, originalIdentity, newIdentity);
        }
        for (URI sequenceURI : componentDefinition.getSequenceURIs()) {
            if (sequenceURI.equals(originalIdentity)) {
                componentDefinition.removeSequence(originalIdentity);
                componentDefinition.addSequence(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()) {
        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()) {
            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)

Example 9 with FunctionalComponent

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

the class ModuleDefinition 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 one 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)},</li>
 * <li>{@link #setIdentity(URI)},</li>
 * <li>{@link FunctionalComponent#setDisplayId(String)}</li>
 * <li>{@link FunctionalComponent#updateCompliantURI(String, String, String)},</li>
 * <li>{@link #addFunctionalComponent(FunctionalComponent)},</li>
 * <li>{@link Module#setDisplayId(String)}</li>
 * <li>{@link Module#updateCompliantURI(String, String, String)},</li>
 * <li>{@link #addModule(Module)},</li>
 * <li>{@link Interaction#setDisplayId(String)},</li>
 * <li>{@link Interaction#updateCompliantURI(String, String, String)}, or</li>
 * <li>{@link #addInteraction(Interaction)}.</li>
 * </ul>
 */
@Override
ModuleDefinition copy(String URIprefix, String displayId, String version) throws SBOLValidationException {
    ModuleDefinition 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);
    int count = 0;
    for (FunctionalComponent component : cloned.getFunctionalComponents()) {
        if (!component.isSetDisplayId())
            component.setDisplayId("functionalComponent" + ++count);
        component.updateCompliantURI(cloned.getPersistentIdentity().toString(), component.getDisplayId(), version);
        cloned.removeChildSafely(component, cloned.functionalComponents);
        cloned.addFunctionalComponent(component);
    }
    count = 0;
    for (Module module : cloned.getModules()) {
        if (!module.isSetDisplayId())
            module.setDisplayId("module" + ++count);
        module.updateCompliantURI(cloned.getPersistentIdentity().toString(), module.getDisplayId(), version);
        cloned.removeChildSafely(module, cloned.modules);
        cloned.addModule(module);
    }
    count = 0;
    for (Interaction interaction : cloned.getInteractions()) {
        if (!interaction.isSetDisplayId())
            interaction.setDisplayId("interaction" + ++count);
        interaction.updateCompliantURI(cloned.getPersistentIdentity().toString(), interaction.getDisplayId(), version);
        cloned.removeChildSafely(interaction, cloned.interactions);
        cloned.addInteraction(interaction);
    }
    return cloned;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 10 with FunctionalComponent

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

the class ModuleDefinition method copy.

void copy(ModuleDefinition moduleDefinition) throws SBOLValidationException {
    ((TopLevel) this).copy((TopLevel) moduleDefinition);
    for (URI role : moduleDefinition.getRoles()) {
        this.addRole(role);
    }
    for (FunctionalComponent component : moduleDefinition.getFunctionalComponents()) {
        String displayId = URIcompliance.findDisplayId(component);
        FunctionalComponent newComponent = this.createFunctionalComponent(displayId, component.getAccess(), component.getDefinitionURI(), component.getDirection());
        newComponent.copy(component);
    }
    for (Module subModule : moduleDefinition.getModules()) {
        String displayId = URIcompliance.findDisplayId(subModule);
        Module newModule = this.createModule(displayId, subModule.getDefinitionURI());
        newModule.copy(subModule);
    }
    for (Interaction interaction : moduleDefinition.getInteractions()) {
        String displayId = URIcompliance.findDisplayId(interaction);
        Interaction newInteraction = this.createInteraction(displayId, interaction.getTypes());
        newInteraction.copy(interaction);
    }
    this.setModels(moduleDefinition.getModelURIs());
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Aggregations

URI (java.net.URI)10 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)8 FunctionalComponent (org.sbolstandard.core2.FunctionalComponent)4 ModuleDefinition (org.sbolstandard.core2.ModuleDefinition)3 SBOLDocument (org.sbolstandard.core2.SBOLDocument)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 QName (javax.xml.namespace.QName)2 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)2 Literal (org.sbolstandard.core.datatree.Literal)2 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)2 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)2 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)2 Interaction (org.sbolstandard.core2.Interaction)2 Model (org.sbolstandard.core2.Model)1 Module (org.sbolstandard.core2.Module)1 Participation (org.sbolstandard.core2.Participation)1