use of org.sbolstandard.core2.SBOLValidationException 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;
}
use of org.sbolstandard.core2.SBOLValidationException in project libSBOLj by SynBioDex.
the class ComponentDefinition 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 constructors or 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 Component#setDisplayId(String)}</li>
* <li>{@link Component#updateCompliantURI(String, String, String)},</li>
* <li>{@link #addComponent(Component)},</li>
* <li>{@link SequenceConstraint#setDisplayId(String)}</li>
* <li>{@link SequenceConstraint#updateCompliantURI(String, String, String)},</li>
* <li>{@link #addSequenceConstraint(SequenceConstraint)},</li>
* <li>{@link SequenceAnnotation#setDisplayId(String)}</li>
* <li>{@link SequenceAnnotation#updateCompliantURI(String, String, String)}, or</li>
* <li>{@link #addSequenceAnnotation(SequenceAnnotation)},</li>
* </ul>
*/
@Override
ComponentDefinition copy(String URIprefix, String displayId, String version) throws SBOLValidationException {
ComponentDefinition 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 (Component component : cloned.getComponents()) {
if (!component.isSetDisplayId())
component.setDisplayId("component" + ++count);
component.updateCompliantURI(cloned.getPersistentIdentity().toString(), component.getDisplayId(), version);
cloned.removeChildSafely(component, cloned.components);
cloned.addComponent(component);
}
count = 0;
for (SequenceConstraint sequenceConstraint : cloned.getSequenceConstraints()) {
if (!sequenceConstraint.isSetDisplayId())
sequenceConstraint.setDisplayId("sequenceConstraint" + ++count);
sequenceConstraint.updateCompliantURI(cloned.getPersistentIdentity().toString(), sequenceConstraint.getDisplayId(), version);
cloned.removeChildSafely(sequenceConstraint, cloned.sequenceConstraints);
cloned.addSequenceConstraint(sequenceConstraint);
}
count = 0;
for (SequenceAnnotation sequenceAnnotation : cloned.getSequenceAnnotations()) {
if (!sequenceAnnotation.isSetDisplayId())
sequenceAnnotation.setDisplayId("sequenceAnnotation" + ++count);
sequenceAnnotation.updateCompliantURI(cloned.getPersistentIdentity().toString(), sequenceAnnotation.getDisplayId(), version);
cloned.removeChildSafely(sequenceAnnotation, cloned.sequenceAnnotations);
cloned.addSequenceAnnotation(sequenceAnnotation);
}
return cloned;
}
use of org.sbolstandard.core2.SBOLValidationException in project libSBOLj by SynBioDex.
the class VariableComponent method addVariant.
/**
* Adds the given variant to the list of variants.
*
* @param uriPrefix
* URI prefix for variant
* @param displayId
* display id for variant
* @param version
* version for variant
* @throws SBOLValidationException if the following SBOL validation rule was violated:
*/
public void addVariant(String uriPrefix, String displayId, String version) throws SBOLValidationException {
URI uri = URIcompliance.createCompliantURI(uriPrefix, displayId, version);
ComponentDefinition componentDefinition = this.getSBOLDocument().getComponentDefinition(uri);
addVariant(componentDefinition.getIdentity());
}
use of org.sbolstandard.core2.SBOLValidationException in project libSBOLj by SynBioDex.
the class VariableComponent method addVariantCollection.
/**
* Adds the given variant collection to the list of variant collections.
*
* @param uriPrefix
* URI prefix for variant collection
* @param displayId
* display id for variant collection
* @param version
* version for variant collection
* @throws SBOLValidationException if the following SBOL validation rule was violated:
*/
public void addVariantCollection(String uriPrefix, String displayId, String version) throws SBOLValidationException {
URI uri = URIcompliance.createCompliantURI(uriPrefix, displayId, version);
Collection collection = this.getSBOLDocument().getCollection(uri);
addVariantCollection(collection.getIdentity());
}
use of org.sbolstandard.core2.SBOLValidationException 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);
}
}
Aggregations