Search in sources :

Example 6 with MapsTo

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

the class Component method copy.

void copy(Component component) throws SBOLValidationException {
    ((ComponentInstance) this).copy((ComponentInstance) component);
    if (!component.getMapsTos().isEmpty()) {
        for (MapsTo mapsTo : component.getMapsTos()) {
            String displayId = URIcompliance.findDisplayId(mapsTo);
            String localDisplayId = URIcompliance.findDisplayId(mapsTo.getLocal());
            MapsTo newMapsTo = this.createMapsTo(displayId, mapsTo.getRefinement(), localDisplayId, mapsTo.getRemoteURI());
            newMapsTo.copy(mapsTo);
        }
    }
    for (URI role : component.getRoles()) {
        this.addRole(URI.create(role.toString()));
    }
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 7 with MapsTo

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

the class Component method createMapsTo.

/**
 * Creates a child mapsTo for this component with the given arguments, and then adds it to its list of mapsTos.
 * <p>
 * This method creates compliant local and remote URIs first.
 * The compliant local URI is created with this component's persistent identity URI, followed by
 * the given local component's display ID, followed by this component's version.
 * The compliant remote URI is created following the same pattern.
 * It then calls {@link #createMapsTo(String, RefinementType, URI, URI)} with the given mapsTo's display ID, its refinement type,
 * and the created compliant local and remote components' URIs.
 * <p>
 * This method calls {@link ComponentDefinition#createComponent(String, AccessType, String, String)} to automatically
 * create a local component with the given display ID of referenced local component definition,
 * {@link AccessType#PUBLIC}, and an empty version string, if all of the following conditions are satisfied:
 * <ul>
 * <li>the associated SBOLDocument instance for this component is not {@code null};</li>
 * <li>if default components should be automatically created when not present in the associated SBOLDocument instance,
 * i.e., {@link SBOLDocument#isCreateDefaults} returns {@code true};</li>
 * <li>if this component's parent ComponentDefinition instance exists; and</li>
 * <li>if this component's parent ComponentDefinition instance does not already have a component
 * with the created compliant local URI.</li>
 * </ul>
 * This automatically created created component has the same display ID as its referenced component definition.
 *
 * @param displayId the display ID of the mapsTo to be created
 * @param refinement the relationship between the local and remote components
 * @param localId the display ID of the local component
 * @param remoteId the display ID of the remote component
 * @return the created mapsTo
 * @throws SBOLValidationException if any of the following condition is satisfied:
 * <ul>
 * <li>if either of the following SBOL validation rules was violated: 10204, 10206;</li>
 * <li>an SBOL validation exception occurred in {@link ComponentDefinition#createComponent(String, AccessType, String, String)}; or</li>
 * <li>an SBOL validation exception occurred in {@link #createMapsTo(String, RefinementType, URI, URI)}.</li>
 * </ul>
 */
public MapsTo createMapsTo(String displayId, RefinementType refinement, String localId, String remoteId) throws SBOLValidationException {
    URI localURI = URIcompliance.createCompliantURI(componentDefinition.getPersistentIdentity().toString(), localId, componentDefinition.getVersion());
    if (this.getSBOLDocument() != null && this.getSBOLDocument().isCreateDefaults() && componentDefinition != null && componentDefinition.getComponent(localURI) == null) {
        componentDefinition.createComponent(localId, AccessType.PUBLIC, localId, "");
    }
    URI remoteURI = URIcompliance.createCompliantURI(getDefinition().getPersistentIdentity().toString(), remoteId, getDefinition().getVersion());
    return createMapsTo(displayId, refinement, localURI, remoteURI);
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 8 with MapsTo

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

the class SBOLDocument method updateReferences.

// TODO: need to update persistentIdentities too
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 (ComponentDefinition componentDefinition : getComponentDefinitions()) {
        updateReferences(componentDefinition, uriMap);
        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 (SequenceAnnotation sa : componentDefinition.getSequenceAnnotations()) {
            for (Location loc : sa.getLocations()) {
                updateReferences(loc, uriMap);
            }
            updateReferences(sa, uriMap);
        }
        for (SequenceConstraint sc : componentDefinition.getSequenceConstraints()) {
            updateReferences(sc, uriMap);
        }
        for (URI sequenceURI : componentDefinition.getSequenceURIs()) {
            if (uriMap.get(sequenceURI) != null) {
                componentDefinition.removeSequence(sequenceURI);
                componentDefinition.addSequence(uriMap.get(sequenceURI));
            }
        }
    }
    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()) {
        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()) {
            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 9 with MapsTo

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

the class Module method createMapsTo.

/**
 * Creates a child mapsTo for this module with the given arguments, and then adds it to its list of mapsTos.
 * <p>
 * This method creates a compliant URI for the mapsTo to be created. It starts with this module's persistent
 * identity, followed by the mapsTo's display ID, and ends with this module's version.
 *
 * @param displayId the display ID of the mapsTo to be created
 * @param refinement the relationship between the local and remote components
 * @param local the identity URI of the local functional component
 * @param remote the identity URI of the remote functional component
 * @return the created mapsTo
 * @throws SBOLValidationException if any of the following SBOL validation rules was violated:
 * 10201, 10202, 10204, 10206, 10802, 10803, 10804, 10805, 10807, 10808, 10809, 10811, 11609.
 */
public MapsTo createMapsTo(String displayId, RefinementType refinement, URI local, URI remote) throws SBOLValidationException {
    String parentPersistentIdStr = this.getPersistentIdentity().toString();
    String version = this.getVersion();
    URI newMapsToURI = createCompliantURI(parentPersistentIdStr, displayId, version);
    MapsTo m = createMapsTo(newMapsToURI, refinement, local, remote);
    m.setPersistentIdentity(createCompliantURI(parentPersistentIdStr, displayId, ""));
    m.setDisplayId(displayId);
    m.setVersion(version);
    return m;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 10 with MapsTo

use of org.sbolstandard.core2.MapsTo 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)

Aggregations

URI (java.net.URI)12 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)12 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 QName (javax.xml.namespace.QName)4 Literal (org.sbolstandard.core.datatree.Literal)4 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)4 Test (org.junit.Test)3 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)3 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)3 MapsTo (org.sbolstandard.core2.MapsTo)3 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)1 FunctionalComponent (org.sbolstandard.core2.FunctionalComponent)1 ModuleDefinition (org.sbolstandard.core2.ModuleDefinition)1 SBOLDocument (org.sbolstandard.core2.SBOLDocument)1