use of org.sbolstandard.core.datatree.Literal in project libSBOLj by SynBioDex.
the class SBOLReader method parseActivity.
@SuppressWarnings("unchecked")
private static Activity parseActivity(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
String displayId = null;
String name = null;
String description = null;
URI persistentIdentity = null;
String version = null;
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
Set<URI> attachments = new HashSet<>();
DateTime startedAtTime = null;
DateTime endedAtTime = null;
Set<URI> wasInformedBys = new HashSet<>();
Set<Association> qualifiedAssociations = new HashSet<>();
Set<Usage> qualifiedUsages = 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.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 if (namedProperty.getName().equals(Sbol2Terms.Activity.startedAtTime)) {
if (!(namedProperty.getValue() instanceof Literal) || startedAtTime != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
throw new SBOLValidationException("sbol-12402", topLevel.getIdentity());
}
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
try {
startedAtTime = fmt.parseDateTime(((Literal<QName>) namedProperty.getValue()).getValue().toString());
} catch (IllegalArgumentException e) {
throw new SBOLValidationException("sbol-12402", topLevel.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.Activity.endedAtTime)) {
if (!(namedProperty.getValue() instanceof Literal) || endedAtTime != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
throw new SBOLValidationException("sbol-12403", topLevel.getIdentity());
}
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
try {
endedAtTime = fmt.parseDateTime(((Literal<QName>) namedProperty.getValue()).getValue().toString());
} catch (IllegalArgumentException e) {
throw new SBOLValidationException("sbol-12403", topLevel.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.Activity.wasInformedBy)) {
if (namedProperty.getValue() instanceof Literal) {
if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
throw new SBOLValidationException("sbol-12406", topLevel.getIdentity());
}
wasInformedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getValue() instanceof IdentifiableDocument) {
if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.Activity.Activity)) {
Activity activity = parseActivity(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
wasInformedBys.add(activity.getIdentity());
} else {
throw new SBOLValidationException("sbol-12406", topLevel.getIdentity());
}
} else {
throw new SBOLValidationException("sbol-12406", topLevel.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.Activity.qualifiedAssociation)) {
if (namedProperty.getValue() instanceof NestedDocument) {
NestedDocument<QName> nestedDocument = ((NestedDocument<QName>) namedProperty.getValue());
if (nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.Association.Association)) {
throw new SBOLValidationException("sbol-12404", topLevel.getIdentity());
}
qualifiedAssociations.add(parseAssociation(SBOLDoc, ((NestedDocument<QName>) namedProperty.getValue()), nested));
} else {
URI uri = (URI) ((Literal<QName>) namedProperty.getValue()).getValue();
NestedDocument<QName> nestedDocument = nested.get(uri);
if (nestedDocument == null || nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.Association.Association)) {
throw new SBOLValidationException("sbol-12404", topLevel.getIdentity());
}
qualifiedAssociations.add(parseAssociation(SBOLDoc, nestedDocument, nested));
}
} else if (namedProperty.getName().equals(Sbol2Terms.Activity.qualifiedUsage)) {
if (namedProperty.getValue() instanceof NestedDocument) {
NestedDocument<QName> nestedDocument = ((NestedDocument<QName>) namedProperty.getValue());
if (nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.Usage.Usage)) {
throw new SBOLValidationException("sbol-12405", topLevel.getIdentity());
}
qualifiedUsages.add(parseUsage(SBOLDoc, ((NestedDocument<QName>) namedProperty.getValue()), nested));
} else {
URI uri = (URI) ((Literal<QName>) namedProperty.getValue()).getValue();
NestedDocument<QName> nestedDocument = nested.get(uri);
if (nestedDocument == null || nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.Usage.Usage)) {
throw new SBOLValidationException("sbol-12405", topLevel.getIdentity());
}
qualifiedUsages.add(parseUsage(SBOLDoc, nestedDocument, nested));
}
} else {
annotations.add(new Annotation(namedProperty));
}
}
// GenericTopLevel t = SBOLDoc.createGenericTopLevel(topLevel.getIdentity(), topLevel.getType());
Activity t = new Activity(topLevel.getIdentity());
if (persistentIdentity != null)
t.setPersistentIdentity(persistentIdentity);
if (version != null)
t.setVersion(version);
if (displayId != null)
t.setDisplayId(displayId);
if (name != null)
t.setName(name);
if (description != null)
t.setDescription(description);
t.setWasDerivedFroms(wasDerivedFroms);
t.setWasGeneratedBys(wasGeneratedBys);
if (!annotations.isEmpty())
t.setAnnotations(annotations);
if (startedAtTime != null)
t.setStartedAtTime(startedAtTime);
if (endedAtTime != null)
t.setEndedAtTime(endedAtTime);
if (!qualifiedAssociations.isEmpty())
t.setAssociations(qualifiedAssociations);
if (!qualifiedUsages.isEmpty())
t.setUsages(qualifiedUsages);
if (!wasInformedBys.isEmpty())
t.setWasInformedBys(wasInformedBys);
if (!attachments.isEmpty())
t.setAttachments(attachments);
Activity oldA = SBOLDoc.getActivity(topLevel.getIdentity());
if (oldA == null) {
SBOLDoc.addActivity(t);
} else {
if (!t.equals(oldA)) {
throw new SBOLValidationException("sbol-10202", t);
}
}
return t;
}
use of org.sbolstandard.core.datatree.Literal in project libSBOLj by SynBioDex.
the class SBOLReader method parsePlan.
@SuppressWarnings("unchecked")
private static Plan parsePlan(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel) throws SBOLValidationException {
String displayId = null;
String name = null;
String description = null;
URI persistentIdentity = null;
String version = null;
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
Set<URI> attachments = 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.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));
}
}
Plan t = new Plan(topLevel.getIdentity());
if (persistentIdentity != null)
t.setPersistentIdentity(persistentIdentity);
if (version != null)
t.setVersion(version);
if (displayId != null)
t.setDisplayId(displayId);
if (name != null)
t.setName(name);
if (description != null)
t.setDescription(description);
t.setWasDerivedFroms(wasDerivedFroms);
t.setWasGeneratedBys(wasGeneratedBys);
t.setAttachments(attachments);
if (!annotations.isEmpty())
t.setAnnotations(annotations);
Plan oldA = SBOLDoc.getPlan(topLevel.getIdentity());
if (oldA == null) {
SBOLDoc.addPlan(t);
} else {
if (!t.equals(oldA)) {
throw new SBOLValidationException("sbol-10202", t);
}
}
return t;
}
use of org.sbolstandard.core.datatree.Literal in project libSBOLj by SynBioDex.
the class SBOLReader method parseImplementation.
/**
* @param SBOLDoc
* @param topLevel
* @param nested
* @return
*/
@SuppressWarnings("unchecked")
private static Implementation parseImplementation(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;
URI built = null;
String version = null;
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
Set<URI> attachments = new HashSet<>();
List<Annotation> annotations = new ArrayList<>();
for (NamedProperty<QName> namedProperty : topLevel.getProperties()) {
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.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.Implementation.built)) {
if (namedProperty.getValue() instanceof Literal) {
if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
throw new SBOLValidationException("sbol-13102", topLevel.getIdentity());
}
built = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
} else if (namedProperty.getValue() instanceof IdentifiableDocument) {
if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.ModuleDefinition.ModuleDefinition)) {
ModuleDefinition md = parseModuleDefinition(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
built = md.getIdentity();
} else if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.ComponentDefinition.ComponentDefinition)) {
ComponentDefinition md = parseComponentDefinition(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
built = md.getIdentity();
} else {
throw new SBOLValidationException("sbol-13102", topLevel.getIdentity());
}
} else {
throw new SBOLValidationException("sbol-13102", topLevel.getIdentity());
}
} 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.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.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 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 {
annotations.add(new Annotation(namedProperty));
}
}
Implementation i = new Implementation(topLevel.getIdentity());
if (displayId != null)
i.setDisplayId(displayId);
if (persistentIdentity != null)
i.setPersistentIdentity(persistentIdentity);
if (name != null)
i.setName(name);
if (description != null)
i.setDescription(description);
if (!annotations.isEmpty())
i.setAnnotations(annotations);
if (version != null)
i.setVersion(version);
if (built != null)
i.setBuilt(built);
i.setWasDerivedFroms(wasDerivedFroms);
i.setWasGeneratedBys(wasGeneratedBys);
i.setAttachments(attachments);
Implementation oldI = SBOLDoc.getImplementation(topLevel.getIdentity());
if (oldI == null) {
SBOLDoc.addImplementation(i);
} else {
if (!i.equals(oldI)) {
throw new SBOLValidationException("sbol-10202", i);
}
}
return i;
}
use of org.sbolstandard.core.datatree.Literal in project libSBOLj by SynBioDex.
the class SBOLReader method parseSequenceAnnotationV1.
/**
* @param SBOLDoc
* @param sequenceAnnotation
* @param precedePairs
* @param parentURI
* @param sa_num
* @param instantiatedComponents
* @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)}, </li>
* <li>{@link #parseDnaComponentV1(SBOLDocument, IdentifiableDocument)}, </li>
* <li>{@link Range#Range(URI, int, int)}, </li>
* <li>{@link Range#setDisplayId(String)}, </li>
* <li>{@link Range#setVersion(String)}, </li>
* <li>{@link GenericLocation#GenericLocation(URI)}, </li>
* <li>{@link SequenceAnnotation#SequenceAnnotation(URI, Set)}, </li>
* <li>{@link SequenceAnnotation#setDisplayId(String)}, </li>
* <li>{@link SequenceAnnotation#setVersion(String)}, </li>
* <li>{@link SequenceAnnotation#setWasDerivedFrom(URI)}, </li>
* <li>{@link SequenceAnnotation#setComponent(URI)}, or </li>
* <li>{@link SequenceAnnotation#setAnnotations(List)}; or</li>
* </ul>
* </li>
* <li>the following SBOL validation rule was violated: 11002.</li>
* </ul>
* @throws SBOLConversionException
*/
private static SequenceAnnotation parseSequenceAnnotationV1(SBOLDocument SBOLDoc, NestedDocument<QName> sequenceAnnotation, List<SBOLPair> precedePairs, String parentURI, int sa_num, Set<String> instantiatedComponents) throws SBOLValidationException, SBOLConversionException {
Integer start = null;
Integer end = null;
String strand = null;
URI componentURI = null;
URI identity = sequenceAnnotation.getIdentity();
String persIdentity = sequenceAnnotation.getIdentity().toString();
List<Annotation> annotations = new ArrayList<>();
if (URIPrefix != null) {
persIdentity = createCompliantURI(parentURI, "annotation" + sa_num, "").toString();
identity = createCompliantURI(parentURI, "annotation" + sa_num, version);
}
if (!sequenceAnnotation.getType().equals(Sbol1Terms.SequenceAnnotations.SequenceAnnotation)) {
throw new SBOLConversionException("QName has to be" + Sbol1Terms.SequenceAnnotations.SequenceAnnotation.toString());
}
for (NamedProperty<QName> namedProperty : sequenceAnnotation.getProperties()) {
if (namedProperty.getName().equals(Sbol1Terms.SequenceAnnotations.bioStart)) {
if (!(namedProperty.getValue() instanceof Literal) || start != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
throw new SBOLValidationException("sbol-11102", sequenceAnnotation.getIdentity());
}
String temp = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
start = Integer.parseInt(temp);
} else if (namedProperty.getName().equals(Sbol1Terms.SequenceAnnotations.bioEnd)) {
if (!(namedProperty.getValue() instanceof Literal) || end != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
throw new SBOLValidationException("sbol-11103", sequenceAnnotation.getIdentity());
}
String temp2 = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
end = Integer.parseInt(temp2);
} else if (namedProperty.getName().equals(Sbol1Terms.SequenceAnnotations.strand)) {
if (!(namedProperty.getValue() instanceof Literal) || strand != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
throw new SBOLValidationException("sbol-11002", sequenceAnnotation.getIdentity());
}
strand = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
} else if (namedProperty.getName().equals(Sbol1Terms.SequenceAnnotations.subComponent)) {
if (componentURI != null) {
throw new SBOLValidationException("sbol-10904", sequenceAnnotation.getIdentity());
}
if (namedProperty.getValue() instanceof NestedDocument) {
componentURI = parseDnaComponentV1(SBOLDoc, (NestedDocument<QName>) namedProperty.getValue()).getIdentity();
} else {
if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-10904", sequenceAnnotation.getIdentity());
}
componentURI = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
}
} else if (namedProperty.getName().equals(Sbol1Terms.SequenceAnnotations.precedes)) {
URI left = sequenceAnnotation.getIdentity();
URI right = null;
if (namedProperty.getValue() instanceof NestedDocument) {
// TODO: need to check if ++sa_num here okay
right = parseSequenceAnnotationV1(SBOLDoc, (NestedDocument<QName>) namedProperty.getValue(), precedePairs, parentURI, ++sa_num, instantiatedComponents).getIdentity();
} else {
if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-11404", sequenceAnnotation.getIdentity());
}
right = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
}
SBOLPair pair = new SBOLPair(left, right);
precedePairs.add(pair);
} else {
annotations.add(new Annotation(namedProperty));
}
}
String componentDisplayId = URIcompliance.extractDisplayId(componentURI);
String displayId = "annotation" + sa_num;
if (compliant && componentDisplayId != null && !instantiatedComponents.contains(componentDisplayId)) {
identity = createCompliantURI(parentURI, componentDisplayId + "_annotation", version);
persIdentity = createCompliantURI(parentURI, componentDisplayId + "_annotation", "").toString();
displayId = componentDisplayId + "_annotation";
}
// Note: Do not create a seqAnnotation if Location is empty
Location location = null;
if (// create SequenceAnnotation & Component
start != null && end != null) {
URI range_identity = createCompliantURI(persIdentity, "range", version);
location = new Range(range_identity, start, end);
if (!persIdentity.equals("")) {
location.setPersistentIdentity(createCompliantURI(persIdentity, "range", ""));
location.setDisplayId("range");
location.setVersion(version);
}
if (strand != null) {
if (strand.equals("+")) {
location.setOrientation(OrientationType.INLINE);
} else if (strand.equals("-")) {
location.setOrientation(OrientationType.REVERSECOMPLEMENT);
}
}
} else {
URI dummyGenericLoc_id = createCompliantURI(persIdentity, "genericLocation", version);
location = new GenericLocation(dummyGenericLoc_id);
if (!persIdentity.equals("")) {
location.setPersistentIdentity(createCompliantURI(persIdentity, "genericLocation", ""));
location.setDisplayId("genericLocation");
location.setVersion(version);
}
if (strand != null) {
if (strand.equals("+")) {
location.setOrientation(OrientationType.INLINE);
} else if (strand.equals("-")) {
location.setOrientation(OrientationType.REVERSECOMPLEMENT);
}
}
}
Set<Location> locations = new HashSet<>();
locations.add(location);
SequenceAnnotation s = new SequenceAnnotation(identity, locations);
if (!persIdentity.equals("")) {
s.setPersistentIdentity(URI.create(persIdentity));
s.setDisplayId(displayId);
s.setVersion(version);
}
if (identity != sequenceAnnotation.getIdentity())
s.addWasDerivedFrom(sequenceAnnotation.getIdentity());
if (componentURI != null)
s.setComponent(componentURI);
if (!annotations.isEmpty())
s.setAnnotations(annotations);
return s;
}
use of org.sbolstandard.core.datatree.Literal in project libSBOLj by SynBioDex.
the class SBOLReader method parseAgent.
@SuppressWarnings("unchecked")
private static Agent parseAgent(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel) throws SBOLValidationException {
String displayId = null;
String name = null;
String description = null;
URI persistentIdentity = null;
String version = null;
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
Set<URI> attachments = 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.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));
}
}
Agent t = new Agent(topLevel.getIdentity());
if (persistentIdentity != null)
t.setPersistentIdentity(persistentIdentity);
if (version != null)
t.setVersion(version);
if (displayId != null)
t.setDisplayId(displayId);
if (name != null)
t.setName(name);
if (description != null)
t.setDescription(description);
t.setWasDerivedFroms(wasDerivedFroms);
t.setWasGeneratedBys(wasGeneratedBys);
t.setAttachments(attachments);
if (!annotations.isEmpty())
t.setAnnotations(annotations);
Agent oldA = SBOLDoc.getAgent(topLevel.getIdentity());
if (oldA == null) {
SBOLDoc.addAgent(t);
} else {
if (!t.equals(oldA)) {
throw new SBOLValidationException("sbol-10202", t);
}
}
return t;
}
Aggregations