use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.
the class SBOLReader method parseParticipation.
/**
* @param participation
* @return
* @throws SBOLValidationException if either of the following conditions is satisfied:
* <ul>
* <li>any of the following SBOL validation rules was violated:
* 10203, 10204, 10206, 10208, 10212, 10213, 11906, 12002, 12004; or
*</li>
* <li>an SBOL validation rule violation occurred in the following constructor or methods:
* <ul>
* <li>{@link Participation#Participation(URI, URI, Set)},</li>
* <li>{@link Participation#setDisplayId(String)},</li>
* <li>{@link Participation#setVersion(String)},</li>
* <li>{@link Participation#setWasDerivedFrom(URI)}, or</li>
* <li>{@link Identified#setAnnotations(List)}.</li>
* </ul>
* </li>
* </ul>
*/
private static Participation parseParticipation(NestedDocument<QName> participation) throws SBOLValidationException {
// URIcompliance.extractDisplayId(participation.getIdentity());
String displayId = null;
String name = null;
String description = null;
// URI.create(URIcompliance.extractPersistentId(participation.getIdentity()));
URI persistentIdentity = null;
String version = null;
Set<URI> roles = new HashSet<>();
URI participant = null;
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
List<Annotation> annotations = new ArrayList<>();
for (NamedProperty<QName> namedProperty : participation.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", participation.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", participation.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", participation.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", participation.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", participation.getIdentity());
}
description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
} else if (namedProperty.getName().equals(Sbol2Terms.Participation.role)) {
if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-12004", participation.getIdentity());
}
roles.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getName().equals(Sbol2Terms.Participation.hasParticipant)) {
if (!(namedProperty.getValue() instanceof Literal) || participant != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-12002", participation.getIdentity());
}
participant = URI.create(((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", participation.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", participation.getIdentity());
}
wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else {
annotations.add(new Annotation(namedProperty));
}
}
Participation p = new Participation(participation.getIdentity(), participant, roles);
if (displayId != null)
p.setDisplayId(displayId);
if (name != null)
p.setName(name);
if (description != null)
p.setDescription(description);
if (persistentIdentity != null)
p.setPersistentIdentity(persistentIdentity);
if (version != null)
p.setVersion(version);
p.setWasDerivedFroms(wasDerivedFroms);
p.setWasGeneratedBys(wasGeneratedBys);
if (!annotations.isEmpty())
p.setAnnotations(annotations);
return p;
}
use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.
the class SBOLReader method parseMapsTo.
/**
* @param mapsTo
* @param inModule
* @return
* @throws SBOLValidationException if either of the following conditions is satisfied:
* <ul>
* <li>any of the following SBOL validation rules was violated:
* 10203, 10204, 10206, 10208, 10212, 10213, 10606, 10802, 10805, 10810, 11706; or
*</li>
* <li>an SBOL validation rule violation occurred in the following constructor or methods:
* <ul>
* <li>{@link MapsTo#MapsTo(URI, RefinementType, URI, URI)},</li>
* <li>{@link MapsTo#setDisplayId(String)},</li>
* <li>{@link MapsTo#setVersion(String)},</li>
* <li>{@link MapsTo#setWasDerivedFrom(URI)}, or</li>
* <li>{@link Identified#setAnnotations(List)}.</li>
* </ul>
* </li>
* </ul>
*/
private static MapsTo parseMapsTo(NestedDocument<QName> mapsTo, boolean inModule) throws SBOLValidationException {
// URIcompliance.extractDisplayId(mapsTo.getIdentity());
String displayId = null;
String name = null;
String description = null;
// URI.create(URIcompliance.extractPersistentId(mapsTo.getIdentity()));
URI persistentIdentity = null;
String version = null;
URI remote = null;
RefinementType refinement = null;
URI local = null;
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
List<Annotation> annotations = new ArrayList<>();
for (NamedProperty<QName> namedProperty : mapsTo.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", mapsTo.getIdentity());
}
persistentIdentity = URI.create(((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", mapsTo.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", mapsTo.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", mapsTo.getIdentity());
}
description = ((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", mapsTo.getIdentity());
}
version = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
} else if (namedProperty.getName().equals(Sbol2Terms.MapsTo.refinement)) {
if (!(namedProperty.getValue() instanceof Literal) || refinement != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-10810", mapsTo.getIdentity());
}
String refinementStr = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
if (!refinementStr.startsWith("http://sbols.org/v2#")) {
System.err.println("Warning: namespace for refinement types should be http://sbols.org/v2#");
refinementStr = "http://sbols.org/v2#" + refinementStr;
}
try {
refinement = RefinementType.convertToRefinementType(URI.create(refinementStr));
} catch (SBOLValidationException e) {
throw new SBOLValidationException("sbol-10810", mapsTo.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.MapsTo.hasRemote)) {
if (!(namedProperty.getValue() instanceof Literal) || remote != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-10805", mapsTo.getIdentity());
}
remote = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
} else if (namedProperty.getName().equals(Sbol2Terms.MapsTo.hasLocal)) {
if (!(namedProperty.getValue() instanceof Literal) || local != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-10802", mapsTo.getIdentity());
}
local = URI.create(((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", mapsTo.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", mapsTo.getIdentity());
}
wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else {
annotations.add(new Annotation(namedProperty));
}
}
MapsTo map = new MapsTo(mapsTo.getIdentity(), refinement, local, remote);
if (displayId != null)
map.setDisplayId(displayId);
if (name != null)
map.setName(name);
if (description != null)
map.setDescription(description);
if (persistentIdentity != null)
map.setPersistentIdentity(persistentIdentity);
if (version != null)
map.setVersion(version);
map.setWasDerivedFroms(wasDerivedFroms);
map.setWasGeneratedBys(wasGeneratedBys);
if (!annotations.isEmpty())
map.setAnnotations(annotations);
return map;
}
use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.
the class AnnotationTest method test_toString.
@Test
public void test_toString() throws SBOLValidationException {
Annotation CD_annot = gRNA_b_gene.createAnnotation(new QName(prURI, "protein", "pr"), true);
// System.out.println(CD_annot.toString());
assertTrue(CD_annot.toString().contains("value=" + true));
}
use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.
the class ModuleDefinitionOutput method addSubComponents.
private static void addSubComponents(SBOLDocument document, ComponentDefinition componentDef, List<ComponentDefinition> subComponents) throws Exception {
int i = 1;
int start = 0;
int end = 0;
for (ComponentDefinition subComponent : subComponents) {
Component component = componentDef.createComponent(subComponent.getDisplayId(), AccessType.PUBLIC, subComponent.getIdentity());
start = end + 1;
end = start + getSequenceLength(document, subComponent);
SequenceAnnotation annotation = componentDef.createSequenceAnnotation("anno" + i, "location" + i, start, end, OrientationType.INLINE);
annotation.setComponent(component.getIdentity());
i++;
}
}
use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.
the class ModuleDefinitionOutput method getSequenceLength.
private static int getSequenceLength(SBOLDocument document, ComponentDefinition componentDef) throws Exception {
if (componentDef.getSequences() != null && componentDef.getSequences().size() > 0) {
Sequence sequence = componentDef.getSequences().iterator().next();
return sequence.getElements().length();
} else {
int total = 0;
for (SequenceAnnotation annotation : componentDef.getSequenceAnnotations()) {
if (annotation.getComponent() != null) {
Component component = annotation.getComponent();
ComponentDefinition subComponentDef = component.getDefinition();
total = total + getSequenceLength(document, subComponentDef);
} else {
throw new Exception("Can't get sequence length for an incomplete design");
}
}
return total;
}
}
Aggregations