Search in sources :

Example 46 with SBOLDocument

use of org.sbolstandard.core2.SBOLDocument in project libSBOLj by SynBioDex.

the class SBOLReader method parseUsage.

private static Usage parseUsage(SBOLDocument SBOLDoc, NestedDocument<QName> usage, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
    String displayId = null;
    String name = null;
    String description = null;
    URI persistentIdentity = null;
    String version = null;
    URI entityURI = null;
    Set<URI> roles = new HashSet<>();
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : usage.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", usage.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", usage.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", usage.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", usage.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", usage.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", usage.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", usage.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Usage.role)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-12502", usage.getIdentity());
            }
            roles.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Usage.entity)) {
            if (!(namedProperty.getValue() instanceof Literal) || entityURI != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-12502", usage.getIdentity());
            }
            entityURI = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Usage u = new Usage(usage.getIdentity(), entityURI);
    if (persistentIdentity != null)
        u.setPersistentIdentity(persistentIdentity);
    if (version != null)
        u.setVersion(version);
    if (displayId != null)
        u.setDisplayId(displayId);
    if (name != null)
        u.setName(name);
    if (description != null)
        u.setDescription(description);
    u.setWasDerivedFroms(wasDerivedFroms);
    u.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        u.setAnnotations(annotations);
    if (!roles.isEmpty())
        u.setRoles(roles);
    return u;
}
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 47 with SBOLDocument

use of org.sbolstandard.core2.SBOLDocument in project libSBOLj by SynBioDex.

the class SBOLReader method parseCollectionV1.

/**
 * @param SBOLDoc
 * @param topLevel
 * @return
 * @throws SBOLConversionException
 * @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 Collection#Collection(URI)},</li>
 * 		<li>{@link Collection#setVersion(String)},</li>
 * 		<li>{@link Collection#setWasDerivedFrom(URI)},</li>
 * 		<li>{@link Collection#setDisplayId(String)},</li>
 * 		<li>{@link Collection#setMembers(Set)},</li>
 * 		<li>{@link Identified#setAnnotations(List)}, or</li>
 * 		<li>{@link SBOLDocument#addCollection(Collection)}; or</li>
 * 	</ul>
 * </li>
 * <li>the following SBOL validation rule was violated: 10202.</li>
 * </ul>
 */
private static Collection parseCollectionV1(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel) throws SBOLValidationException, SBOLConversionException {
    URI identity = topLevel.getIdentity();
    URI persistentIdentity = null;
    String displayId = null;
    String name = null;
    String description = null;
    Set<URI> members = new HashSet<>();
    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.Collection.displayId)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10204", topLevel.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
            displayId = URIcompliance.fixDisplayId(displayId);
            if (URIPrefix != null) {
                identity = createCompliantURI(URIPrefix, TopLevel.COLLECTION, displayId, version, typesInURI);
                persistentIdentity = createCompliantURI(URIPrefix, TopLevel.COLLECTION, displayId, "", typesInURI);
            }
        } else if (namedProperty.getName().equals(Sbol1Terms.Collection.name)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((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(Sbol1Terms.Collection.description)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((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(Sbol1Terms.Collection.component)) {
            if (namedProperty.getValue() instanceof Literal) {
                members.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
            } else {
                members.add(parseDnaComponentV1(SBOLDoc, (NestedDocument<QName>) namedProperty.getValue()).getIdentity());
            }
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    // Collection c = SBOLDoc.createCollection(identity);
    Collection c = new Collection(identity);
    if (persistentIdentity != null) {
        c.setPersistentIdentity(persistentIdentity);
        c.setVersion(version);
    }
    if (identity != topLevel.getIdentity())
        c.addWasDerivedFrom(topLevel.getIdentity());
    if (displayId != null)
        c.setDisplayId(displayId);
    if (name != null)
        c.setName(name);
    if (description != null)
        c.setDescription(description);
    if (!members.isEmpty())
        c.setMembers(members);
    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;
}
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) NestedDocument(org.sbolstandard.core.datatree.NestedDocument) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 48 with SBOLDocument

use of org.sbolstandard.core2.SBOLDocument in project libSBOLj by SynBioDex.

the class SBOLReader method parseAssociation.

private static Association parseAssociation(SBOLDocument SBOLDoc, NestedDocument<QName> association, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
    String displayId = null;
    String name = null;
    String description = null;
    URI persistentIdentity = null;
    String version = null;
    Set<URI> roles = new HashSet<>();
    URI planURI = null;
    URI agentURI = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : association.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", association.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", association.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", association.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", association.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", association.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", association.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", association.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Association.role)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-12602", association.getIdentity());
            }
            roles.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Association.agent)) {
            if (!(namedProperty.getValue() instanceof Literal) || agentURI != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-12605", association.getIdentity());
            }
            agentURI = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.Association.plan)) {
            if (!(namedProperty.getValue() instanceof Literal) || planURI != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-12603", association.getIdentity());
            }
            planURI = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Association a = new Association(association.getIdentity(), agentURI);
    if (persistentIdentity != null)
        a.setPersistentIdentity(persistentIdentity);
    if (version != null)
        a.setVersion(version);
    if (displayId != null)
        a.setDisplayId(displayId);
    if (name != null)
        a.setName(name);
    if (description != null)
        a.setDescription(description);
    a.setWasDerivedFroms(wasDerivedFroms);
    a.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        a.setAnnotations(annotations);
    if (!roles.isEmpty())
        a.setRoles(roles);
    if (planURI != null)
        a.setPlan(planURI);
    return a;
}
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 49 with SBOLDocument

use of org.sbolstandard.core2.SBOLDocument in project libSBOLj by SynBioDex.

the class ComponentDefinition method createSequenceConstraint.

/**
 * Creates a child sequence constraint for this component definition with the given arguments,
 * and then adds to this component definition's list of sequence constraints.
 * <p>
 * Creation of a sequence constraint requires URIs of a subject component and an object component.
 * This method creates compliant URIs for them respectively. The subject component compliant URI is created with this
 * component defintion's persistent identity URI, followed by the given subject component's display ID,
 * followed by this component's version. The object component compliant URI is created similarly.
 * This method then calls {@link #createSequenceConstraint(String, RestrictionType, URI, URI)} to create
 * the sequence constraint.
 * <p>
 * This method automatically creates a subject component if all of the following conditions are satisfied:
 * <ul>
 * <li>the associated SBOLDocument, i.e., the SBOLDocument instance hosting this component definition, is not {@code null};</li>
 * <li>if default components should be automatically created when not present for the associated SBOLDocument instance,
 * i.e., {@link SBOLDocument#isCreateDefaults} returns {@code true}; and</li>
 * <li>if this component definition does not already have a component with the created compliant subject component URI.</li>
 * </ul>
 * An object component is automatically created if the similar set of conditions hold.
 *
 * @param displayId the display ID of the sequence constraint to be created
 * @param restriction the structural restriction of the subject and object components
 * @param subjectId the display ID of the subject component
 * @param objectId the display ID of the object component
 * @return the created sequence constraint
 * @throws SBOLValidationException if any of the following condition is satisfied:
 * <ul>
 * <li>if any of the following SBOL validation rules was violated:
 * 10201, 10202, 10204, 10206, 10602, 10604, 10605, 10607, 10803; or</li>
 * <li>an SBOL validation rule violation occurred in {@link #createSequenceConstraint(String, RestrictionType, URI, URI)}.</li>
 * </ul>
 */
public SequenceConstraint createSequenceConstraint(String displayId, RestrictionType restriction, String subjectId, String objectId) throws SBOLValidationException {
    URI subjectURI = URIcompliance.createCompliantURI(this.getPersistentIdentity().toString(), subjectId, this.getVersion());
    if (this.getSBOLDocument() != null && this.getSBOLDocument().isCreateDefaults() && this.getComponent(subjectURI) == null) {
        this.createComponent(subjectId, AccessType.PUBLIC, subjectId, "");
    }
    URI objectURI = URIcompliance.createCompliantURI(this.getPersistentIdentity().toString(), objectId, this.getVersion());
    if (this.getSBOLDocument() != null && this.getSBOLDocument().isCreateDefaults() && this.getComponent(objectURI) == null) {
        this.createComponent(objectId, AccessType.PUBLIC, objectId, "");
    }
    return createSequenceConstraint(displayId, restriction, subjectURI, objectURI);
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 50 with SBOLDocument

use of org.sbolstandard.core2.SBOLDocument in project libSBOLj by SynBioDex.

the class Module method createMapsTo.

/**
 * Creates a child mapsTo for this module 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 module's persistent identity URI, followed by
 * the given local module's display ID, followed by this module'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 functional components' URIs.
 * <p>
 * This method calls {@link ModuleDefinition#createFunctionalComponent(String, AccessType, String, String, DirectionType)}
 * to automatically create a local functional component with the given display ID of referenced local component definition,
 * {@link AccessType#PUBLIC}, an empty version string, and {@link DirectionType#INOUT}, if all of the following conditions are satisfied:
 * <ul>
 * <li>the associated SBOLDocument instance for this module is not {@code null};</li>
 * <li>if default functional 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 module's parent ModuleDefinition instance exists; and</li>
 * <li>if this module's parent ModuleDefinition instance does not already have a functional component
 * with the created compliant local URI.</li>
 * </ul>
 * This automatically created created functional 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 functional component
 * @param remoteId the display ID of the remote functional 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 ModuleDefinition#createFunctionalComponent(String, AccessType, String, String, DirectionType)}; 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(moduleDefinition.getPersistentIdentity().toString(), localId, moduleDefinition.getVersion());
    if (this.getSBOLDocument() != null && this.getSBOLDocument().isCreateDefaults() && moduleDefinition != null && moduleDefinition.getFunctionalComponent(localURI) == null) {
        moduleDefinition.createFunctionalComponent(localId, AccessType.PUBLIC, localId, "", DirectionType.INOUT);
    }
    URI remoteURI = URIcompliance.createCompliantURI(getDefinition().getPersistentIdentity().toString(), remoteId, getDefinition().getVersion());
    return createMapsTo(displayId, refinement, localURI, remoteURI);
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Aggregations

SBOLDocument (org.sbolstandard.core2.SBOLDocument)44 URI (java.net.URI)39 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)27 QName (javax.xml.namespace.QName)26 ArrayList (java.util.ArrayList)23 HashSet (java.util.HashSet)23 Literal (org.sbolstandard.core.datatree.Literal)22 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)22 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)20 Before (org.junit.Before)17 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)17 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)11 Sequence (org.sbolstandard.core2.Sequence)8 ModuleDefinition (org.sbolstandard.core2.ModuleDefinition)7 FunctionalComponent (org.sbolstandard.core2.FunctionalComponent)6 Activity (org.sbolstandard.core2.Activity)5 Component (org.sbolstandard.core2.Component)4 GenericTopLevel (org.sbolstandard.core2.GenericTopLevel)3 Interaction (org.sbolstandard.core2.Interaction)3 Module (org.sbolstandard.core2.Module)3