Search in sources :

Example 11 with Sequence

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

the class ComponentDefinition method createSequenceAnnotation.

/**
 * Creates a child sequence annotation for this component definition with the given arguments,
 * and then adds to this component definition's list of sequence annotations.
 *
 * @param displayId the display ID of the sequence annotation to be created
 * @param location the location of the sequence annotation to be created
 * @return the created sequence annotation
 * @throws SBOLValidationException if any of the following condition is satisfied:
 * <ul>
 * <li>an SBOL validation rule violation occurred in {@link URIcompliance#createCompliantURI(String, String, String)};</li>
 * <li>an SBOL validation rule violation occurred in {@link #createSequenceAnnotation(URI, Set)};</li>
 * <li>an SBOL validation rule violation occurred in {@link SequenceAnnotation#setDisplayId(String)}; or</li>
 * <li>an SBOL validation rule violation occurred in {@link SequenceAnnotation#setVersion(String)}.</li>
 * </ul>
 */
private SequenceAnnotation createSequenceAnnotation(String displayId, Location location) throws SBOLValidationException {
    String URIprefix = this.getPersistentIdentity().toString();
    String version = this.getVersion();
    URI newSequenceAnnotationURI = createCompliantURI(URIprefix, displayId, version);
    Set<Location> locations = new HashSet<>();
    locations.add(location);
    SequenceAnnotation sa = createSequenceAnnotation(newSequenceAnnotationURI, locations);
    sa.setPersistentIdentity(createCompliantURI(URIprefix, displayId, ""));
    sa.setDisplayId(displayId);
    sa.setVersion(version);
    return sa;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) HashSet(java.util.HashSet)

Example 12 with Sequence

use of org.sbolstandard.core2.Sequence 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 13 with Sequence

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

the class SequenceAnnotation method addCut.

/**
 * Creates a cut with the given arguments and then adds it to this sequence annotation's
 * list of locations.
 * <p>
 * This method first creates a compliant URI for the cut to be created.
 * It starts with this sequence annotation's persistent identity URI,
 * followed by the given display ID, and ends an empty string for version.
 *
 * @param displayId the display ID for the cut to be created
 * @param at the at property for the cut to be created
 * @param orientation the orientation type
 * @return the created cut
 * @throws SBOLValidationException if any of the following SBOL validation rules was violated:
 * 10201, 10202, 10204, 10206, 11202.
 */
public Cut addCut(String displayId, int at, OrientationType orientation) throws SBOLValidationException {
    URI identity = createCompliantURI(this.getPersistentIdentity().toString(), displayId, this.getVersion());
    Cut cut = new Cut(identity, at);
    cut.setPersistentIdentity(createCompliantURI(this.getPersistentIdentity().toString(), displayId, ""));
    cut.setDisplayId(displayId);
    cut.setVersion(this.getVersion());
    cut.setOrientation(orientation);
    addLocation(cut);
    return cut;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 14 with Sequence

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

the class SequenceAnnotation method addCut.

/**
 * Creates a cut with the given arguments and then adds it to this sequence annotation's
 * list of locations.
 * <p>
 * This method first creates a compliant URI for the cut to be created.
 * It starts with this sequence annotation's persistent identity URI,
 * followed by the given display ID, and ends an empty string for version.
 *
 * @param displayId the display ID for the cut to be created
 * @param at the at property for the cut to be created
 * @return the created cut
 * @throws SBOLValidationException if any of the following SBOL validation rules was violated:
 * 10201, 10202, 10204, 10206, 11202.
 */
public Cut addCut(String displayId, int at) throws SBOLValidationException {
    URI identity = createCompliantURI(this.getPersistentIdentity().toString(), displayId, this.getVersion());
    Cut cut = new Cut(identity, at);
    cut.setPersistentIdentity(createCompliantURI(this.getPersistentIdentity().toString(), displayId, ""));
    cut.setDisplayId(displayId);
    cut.setVersion(this.getVersion());
    addLocation(cut);
    return cut;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 15 with Sequence

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

the class SequenceAnnotation method addGenericLocation.

/**
 * Creates a generic location with the given arguments and then adds it to this sequence annotation's
 * list of locations.
 * <p>
 * This method first creates a compliant URI for the generic location to be created.
 * It starts with this sequence annotation's persistent identity URI,
 * followed by the given display ID, and ends an empty string for version.
 *
 * @param displayId the display ID for the generic location to be created
 * @return the created generic location instance
 * @throws SBOLValidationException if any of the following SBOL validation rules was violated:
 * 10201, 10202, 10204, 10206.
 */
public GenericLocation addGenericLocation(String displayId) throws SBOLValidationException {
    URI identity = createCompliantURI(this.getPersistentIdentity().toString(), displayId, this.getVersion());
    GenericLocation genericLocation = new GenericLocation(identity);
    genericLocation.setPersistentIdentity(createCompliantURI(this.getPersistentIdentity().toString(), displayId, ""));
    genericLocation.setDisplayId(displayId);
    genericLocation.setVersion(this.getVersion());
    addLocation(genericLocation);
    return genericLocation;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Aggregations

URI (java.net.URI)21 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)15 Sequence (org.sbolstandard.core2.Sequence)9 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)8 SBOLDocument (org.sbolstandard.core2.SBOLDocument)8 QName (javax.xml.namespace.QName)6 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)4 SEQUENCE (org.mozilla.jss.asn1.SEQUENCE)4 BMPString (org.mozilla.jss.asn1.BMPString)3 SET (org.mozilla.jss.asn1.SET)3 Literal (org.sbolstandard.core.datatree.Literal)3 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)3 AMPassword (com.sun.identity.security.keystore.AMPassword)2 MessageDigest (java.security.MessageDigest)2 Test (org.junit.Test)2 ASN1Value (org.mozilla.jss.asn1.ASN1Value)2 OCTET_STRING (org.mozilla.jss.asn1.OCTET_STRING)2 AuthenticatedSafes (org.mozilla.jss.pkcs12.AuthenticatedSafes)2 PFX (org.mozilla.jss.pkcs12.PFX)2