Search in sources :

Example 41 with Annotation

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;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) Literal(org.sbolstandard.core.datatree.Literal) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) HashSet(java.util.HashSet)

Example 42 with Annotation

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;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 43 with Annotation

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));
}
Also used : QName(javax.xml.namespace.QName) Annotation(org.sbolstandard.core2.Annotation) Test(org.junit.Test)

Example 44 with Annotation

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++;
    }
}
Also used : SequenceAnnotation(org.sbolstandard.core2.SequenceAnnotation) Component(org.sbolstandard.core2.Component) FunctionalComponent(org.sbolstandard.core2.FunctionalComponent) ComponentDefinition(org.sbolstandard.core2.ComponentDefinition)

Example 45 with Annotation

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;
    }
}
Also used : SequenceAnnotation(org.sbolstandard.core2.SequenceAnnotation) Sequence(org.sbolstandard.core2.Sequence) Component(org.sbolstandard.core2.Component) FunctionalComponent(org.sbolstandard.core2.FunctionalComponent) SBOLValidationException(org.sbolstandard.core2.SBOLValidationException) ComponentDefinition(org.sbolstandard.core2.ComponentDefinition)

Aggregations

URI (java.net.URI)33 QName (javax.xml.namespace.QName)33 ArrayList (java.util.ArrayList)31 HashSet (java.util.HashSet)31 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)31 Literal (org.sbolstandard.core.datatree.Literal)30 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)30 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)17 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)13 Annotation (zipkin2.Annotation)11 Map (java.util.Map)8 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)7 SBOLDocument (org.sbolstandard.core2.SBOLDocument)5 Endpoint (zipkin2.Endpoint)5 Activity (org.sbolstandard.core2.Activity)4 LinkedHashMap (java.util.LinkedHashMap)3 Test (org.junit.Test)3 Annotation (org.sbolstandard.core2.Annotation)3 Span (zipkin2.Span)3 JsonToken (com.fasterxml.jackson.core.JsonToken)2