use of org.sbolstandard.core2.SBOLValidationException in project libSBOLj by SynBioDex.
the class SBOLReader method parseDnaSequenceV1.
/**
* @param SBOLDoc
* @param topLevel
* @return
* @throws SBOLValidationException if either of the following conditions is satisfied:
* <ul>
* <li>if an SBOL validation rule violation occurred in any of the following constructors or methods:
* <ul>
* <li>{@link URIcompliance#createCompliantURI(String, String, String, String, boolean)},</li>
* <li>{@link Sequence#Sequence(URI, String, URI)},</li>
* <li>{@link Sequence#setVersion(String)},</li>
* <li>{@link Sequence#setWasDerivedFrom(URI)},</li>
* <li>{@link Sequence#setDisplayId(String)},</li>
* <li>{@link Identified#setAnnotations(List)},</li>
* <li>{@link Sequence#setIdentity(URI)}, or </li>
* <li>{@link SBOLDocument#addSequence(Sequence)}; or</li>
* </ul>
* </li>
* <li>any of the following SBOL validation rules was violated: 10202, 10204, 10212, 10213.</li>
* </ul>
*/
private static Sequence parseDnaSequenceV1(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel) throws SBOLValidationException {
String elements = null;
String displayId = null;
String name = null;
String description = null;
URI identity = topLevel.getIdentity();
URI persistentIdentity = topLevel.getIdentity();
URI encoding = Sequence.IUPAC_DNA;
List<Annotation> annotations = new ArrayList<>();
if (URIPrefix != null) {
displayId = URIcompliance.findDisplayId(topLevel.getIdentity().toString());
identity = createCompliantURI(URIPrefix, TopLevel.SEQUENCE, displayId, version, typesInURI);
persistentIdentity = createCompliantURI(URIPrefix, TopLevel.SEQUENCE, displayId, "", typesInURI);
}
for (NamedProperty<QName> namedProperty : topLevel.getProperties()) {
if (namedProperty.getName().equals(Sbol1Terms.DNASequence.nucleotides)) {
elements = ((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();
if (URIPrefix != null) {
identity = createCompliantURI(URIPrefix, TopLevel.SEQUENCE, displayId, version, typesInURI);
}
} 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 {
annotations.add(new Annotation(namedProperty));
}
}
Sequence sequence = new Sequence(identity, elements, encoding);
if (persistentIdentity != null) {
sequence.setPersistentIdentity(persistentIdentity);
sequence.setVersion(version);
}
if (identity != topLevel.getIdentity())
sequence.addWasDerivedFrom(topLevel.getIdentity());
if (displayId != null)
sequence.setDisplayId(displayId);
if (name != null)
sequence.setName(name);
if (description != null)
sequence.setDescription(description);
if (!annotations.isEmpty())
sequence.setAnnotations(annotations);
Sequence oldS = SBOLDoc.getSequence(identity);
if (oldS == null) {
SBOLDoc.addSequence(sequence);
} else if (sequence.getWasDerivedFroms().size() > 0 && oldS.getWasDerivedFroms().size() > 0 && !sequence.getWasDerivedFroms().equals(oldS.getWasDerivedFroms())) {
URI wasDerivedFrom = (URI) sequence.getWasDerivedFroms().toArray()[0];
Set<TopLevel> topLevels = SBOLDoc.getByWasDerivedFrom(wasDerivedFrom);
for (TopLevel top : topLevels) {
if (top instanceof Sequence) {
return (Sequence) top;
}
}
do {
displayId = displayId + "_";
identity = createCompliantURI(URIPrefix, TopLevel.SEQUENCE, displayId, version, typesInURI);
persistentIdentity = createCompliantURI(URIPrefix, TopLevel.SEQUENCE, displayId, "", typesInURI);
} while (SBOLDoc.getSequence(identity) != null);
sequence.setIdentity(identity);
sequence.setDisplayId(displayId);
sequence.setPersistentIdentity(persistentIdentity);
SBOLDoc.addSequence(sequence);
} else if (dropObjectsWithDuplicateURIs) {
return oldS;
} else {
if (!sequence.equals(oldS)) {
throw new SBOLValidationException("sbol-10202", sequence);
}
}
return sequence;
}
use of org.sbolstandard.core2.SBOLValidationException in project libSBOLj by SynBioDex.
the class SBOLReader method parseCollection.
/**
* @param SBOLDoc
* @param topLevel
* @return
* @throws SBOLValidationException if either of the following conditions is satisfied:
* <ul>
* <li>any of the following SBOL validation rules was violated:
* 10202, 10203, 10204, 10206, 10208, 10212, 10213, 12102; or</li>
* <li>an SBOL validation rule violation occurred in the following constructor or methods:
* <ul>
* <li>{@link Collection#Collection(URI)}, </li>
* <li>{@link Collection#setDisplayId(String)}, </li>
* <li>{@link Collection#setVersion(String)}, </li>
* <li>{@link Collection#setMembers(Set)}, </li>
* <li>{@link Collection#setWasDerivedFrom(URI)}, </li>
* <li>{@link Identified#setAnnotations(List)}, or</li>
* <li>{@link SBOLDocument#addCollection(Collection)}.</li>
* </ul>
* </li>
* </ul>
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Collection parseCollection(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
// URIcompliance.extractDisplayId(topLevel.getIdentity());
String displayId = null;
String name = null;
String description = null;
// URI.create(URIcompliance.extractPersistentId(topLevel.getIdentity()));
URI persistentIdentity = null;
String version = null;
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
Set<URI> attachments = new HashSet<>();
Set<URI> members = 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.Collection.hasMembers)) {
if (namedProperty.getValue() instanceof Literal) {
if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
throw new SBOLValidationException("sbol-12102", topLevel.getIdentity());
}
members.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getValue() instanceof NestedDocument) {
if (((IdentifiableDocument) namedProperty).getType().equals(Sbol2Terms.Collection.Collection))
parseCollection(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.ModuleDefinition.ModuleDefinition))
parseModuleDefinition(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Model.Model))
parseModel(SBOLDoc, (IdentifiableDocument) namedProperty);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Sequence.Sequence))
parseSequence(SBOLDoc, (IdentifiableDocument) namedProperty);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.ComponentDefinition.ComponentDefinition))
parseComponentDefinition(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.CombinatorialDerivation.CombinatorialDerivation))
parseCombinatorialDerivation(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Implementation.Implementation))
parseImplementation(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Attachment.Attachment))
parseAttachment(SBOLDoc, (IdentifiableDocument) namedProperty);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Activity.Activity))
parseActivity(SBOLDoc, (IdentifiableDocument) namedProperty, nested);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Agent.Agent))
parseAgent(SBOLDoc, (IdentifiableDocument) namedProperty);
else if (((IdentifiableDocument) namedProperty).equals(Sbol2Terms.Plan.Plan))
parsePlan(SBOLDoc, (IdentifiableDocument) namedProperty);
else
parseGenericTopLevel(SBOLDoc, (IdentifiableDocument) namedProperty);
} else {
throw new SBOLValidationException("sbol-12102", topLevel.getIdentity());
}
} 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-XXXXX", 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-XXXXX", topLevel.getIdentity());
}
} else {
throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
}
} else {
annotations.add(new Annotation(namedProperty));
}
}
Collection c = new Collection(topLevel.getIdentity());
if (displayId != null)
c.setDisplayId(displayId);
if (version != null)
c.setVersion(version);
if (persistentIdentity != null)
c.setPersistentIdentity(persistentIdentity);
if (!members.isEmpty())
c.setMembers(members);
if (name != null)
c.setName(name);
if (description != null)
c.setDescription(description);
c.setWasDerivedFroms(wasDerivedFroms);
c.setWasGeneratedBys(wasGeneratedBys);
c.setAttachments(attachments);
if (!annotations.isEmpty())
c.setAnnotations(annotations);
Collection oldC = SBOLDoc.getCollection(topLevel.getIdentity());
if (oldC == null) {
SBOLDoc.addCollection(c);
} else {
if (!c.equals(oldC)) {
throw new SBOLValidationException("sbol-10202", c);
}
}
return c;
}
use of org.sbolstandard.core2.SBOLValidationException 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()));
}
}
use of org.sbolstandard.core2.SBOLValidationException 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);
}
use of org.sbolstandard.core2.SBOLValidationException in project libSBOLj by SynBioDex.
the class ComponentDefinition method copy.
void copy(ComponentDefinition componentDefinition) throws SBOLValidationException {
((TopLevel) this).copy((TopLevel) componentDefinition);
for (URI role : componentDefinition.getRoles()) {
this.addRole(URI.create(role.toString()));
}
for (Component component : componentDefinition.getComponents()) {
String displayId = URIcompliance.findDisplayId(component);
Component newComponent = this.createComponent(displayId, component.getAccess(), component.getDefinitionURI());
newComponent.copy(component);
}
for (SequenceConstraint sequenceConstraint : componentDefinition.getSequenceConstraints()) {
String displayId = URIcompliance.findDisplayId(sequenceConstraint);
String subjectDisplayId = URIcompliance.findDisplayId(sequenceConstraint.getSubject());
String objectDisplayId = URIcompliance.findDisplayId(sequenceConstraint.getObject());
SequenceConstraint newSequenceConstraint = this.createSequenceConstraint(displayId, sequenceConstraint.getRestriction(), subjectDisplayId, objectDisplayId);
newSequenceConstraint.copy(sequenceConstraint);
}
for (SequenceAnnotation sequenceAnnotation : componentDefinition.getSequenceAnnotations()) {
String displayId = URIcompliance.findDisplayId(sequenceAnnotation);
SequenceAnnotation newSequenceAnnotation = this.createSequenceAnnotation(displayId, "DUMMY__LOCATION");
newSequenceAnnotation.copy(sequenceAnnotation);
}
this.setSequences(componentDefinition.getSequenceURIs());
}
Aggregations