Search in sources :

Example 1 with SequenceAnnotation

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

the class ComponentDefinitionOutput method createComponentDefinitionOutput.

public static SBOLDocument createComponentDefinitionOutput() throws SBOLValidationException {
    String prURI = "http://partsregistry.org/";
    String prPrefix = "pr";
    SBOLDocument document = new SBOLDocument();
    document.setTypesInURIs(true);
    document.addNamespace(URI.create(prURI), prPrefix);
    document.setDefaultURIprefix(prURI);
    Sequence seqpTetR = document.createSequence("BBa_R0040", "", "tccctatcagtgatagagattgacatccctatcagtgatagagatactgagcac", URI.create("http://www.chem.qmul.ac.uk/iubmb/misc/naseq.html"));
    Sequence seqRbs = document.createSequence("BBa_B0034", "", "aaagaggagaaa", URI.create("http://www.chem.qmul.ac.uk/iubmb/misc/naseq.html"));
    Sequence seqCds = document.createSequence("BBa_C0062", "", "atgcttatctgatatgactaaaatggtacattgtgaatattatttactcgcgatcatttatcctcattctatggttaaatctgatatttcaatcctagataattaccctaaaaaatggaggcaatattatgatgacgctaatttaataaaatatgatcctatagtagattattctaactccaatcattcaccaattaattggaatatatttgaaaacaatgctgtaaataaaaaatctccaaatgtaattaaagaagcgaaaacatcaggtcttatcactgggtttagtttccctattcatacggctaacaatggcttcggaatgcttagttttgcacattcagaaaaagacaactatatagatagtttatttttacatgcgtgtatgaacataccattaattgttccttctctagttgataattatcgaaaaataaatatagcaaataataaatcaaacaacgatttaaccaaaagagaaaaagaatgtttagcgtgggcatgcgaaggaaaaagctcttgggatatttcaaaaatattaggttgcagtgagcgtactgtcactttccatttaaccaatgcgcaaatgaaactcaatacaacaaaccgctgccaaagtatttctaaagcaattttaacaggagcaattgattgcccatactttaaaaattaataacactgatagtgctagtgtagatcac", URI.create("http://www.chem.qmul.ac.uk/iubmb/misc/naseq.html"));
    Sequence seqTer = document.createSequence("BBa_B0015", "", "ccaggcatcaaataaaacgaaaggctcagtcgaaagactgggcctttcgttttatctgttgtttgtcggtgaacgctctctactagagtcacactggctcaccttcgggtgggcctttctgcgtttata", URI.create("http://www.chem.qmul.ac.uk/iubmb/misc/naseq.html"));
    Sequence seqPluxR = document.createSequence("BBa_R0062", "", "acctgtaggatcgtacaggtttacgcaagaaaatggtttgttatagtcgaataaa", URI.create("http://www.chem.qmul.ac.uk/iubmb/misc/naseq.html"));
    ComponentDefinition pTetR = document.createComponentDefinition("BBa_R0040", "", new HashSet<URI>(Arrays.asList(ComponentDefinition.DNA)));
    pTetR.addRole(SequenceOntology.PROMOTER);
    pTetR.setName("pTetR");
    pTetR.setDescription("TetR repressible promoter");
    pTetR.addSequence(seqpTetR.getIdentity());
    ComponentDefinition rbs = document.createComponentDefinition("BBa_B0034", "", new HashSet<URI>(Arrays.asList(ComponentDefinition.DNA)));
    rbs.addRole(SequenceOntology.RIBOSOME_ENTRY_SITE);
    rbs.setName("BBa_B0034");
    rbs.setDescription("RBS based on Elowitz repressilator");
    rbs.addSequence(seqRbs.getIdentity());
    ComponentDefinition cds = document.createComponentDefinition("BBa_C0062", "", new HashSet<URI>(Arrays.asList(ComponentDefinition.DNA)));
    cds.addRole(SequenceOntology.CDS);
    cds.setName("luxR");
    cds.setDescription("luxR coding sequence");
    cds.addSequence(seqCds.getIdentity());
    ComponentDefinition ter = document.createComponentDefinition("BBa_B0015", "", new HashSet<URI>(Arrays.asList(ComponentDefinition.DNA)));
    ter.addRole(URI.create("http://identifiers.org/so/SO:0000141"));
    ter.setName("BBa_B0015");
    ter.setDescription("Double terminator");
    ter.addSequence(seqTer.getIdentity());
    ComponentDefinition pluxR = document.createComponentDefinition("BBa_R0062", "", new HashSet<URI>(Arrays.asList(ComponentDefinition.DNA)));
    // 
    pluxR.addRole(SequenceOntology.PROMOTER);
    pluxR.setName("pLuxR");
    pluxR.setDescription("LuxR inducible promoter");
    pluxR.addSequence(seqPluxR.getIdentity());
    ComponentDefinition device = document.createComponentDefinition("BBa_F2620", "", new HashSet<URI>(Arrays.asList(ComponentDefinition.DNA)));
    // biological region
    device.addRole(URI.create("http://identifiers.org/so/SO:00001411"));
    device.setName("BBa_F2620");
    device.setDescription("3OC6HSL -> PoPS Receiver");
    Component comPtetR = device.createComponent("pTetR", AccessType.PUBLIC, pTetR.getIdentity());
    Component comRbs = device.createComponent("rbs", AccessType.PUBLIC, rbs.getIdentity());
    Component comCds = device.createComponent("luxR", AccessType.PUBLIC, cds.getIdentity());
    Component comTer = device.createComponent("ter", AccessType.PUBLIC, ter.getIdentity());
    Component comPluxR = device.createComponent("pLuxR", AccessType.PUBLIC, pluxR.getIdentity());
    int start = 1;
    int end = seqPluxR.getElements().length();
    SequenceAnnotation anno = device.createSequenceAnnotation("anno1", "location1", start, end, OrientationType.INLINE);
    anno.setComponent(comPtetR.getIdentity());
    start = end + 1;
    end = seqRbs.getElements().length() + end + 1;
    SequenceAnnotation anno2 = device.createSequenceAnnotation("anno2", "location2", start, end, OrientationType.INLINE);
    anno2.setComponent(comRbs.getIdentity());
    start = end + 1;
    end = seqCds.getElements().length() + end + 1;
    SequenceAnnotation anno3 = device.createSequenceAnnotation("anno3", "location3", start, end, OrientationType.INLINE);
    anno3.setComponent(comCds.getIdentity());
    start = end + 1;
    end = seqTer.getElements().length() + end + 1;
    SequenceAnnotation anno4 = device.createSequenceAnnotation("anno4", "location4", start, end, OrientationType.INLINE);
    anno4.setComponent(comTer.getIdentity());
    start = end + 1;
    end = seqPluxR.getElements().length() + end + 1;
    SequenceAnnotation anno5 = device.createSequenceAnnotation("anno5", "location5", start, end, OrientationType.INLINE);
    anno5.setComponent(comPluxR.getIdentity());
    return document;
}
Also used : SBOLDocument(org.sbolstandard.core2.SBOLDocument) SequenceAnnotation(org.sbolstandard.core2.SequenceAnnotation) Sequence(org.sbolstandard.core2.Sequence) Component(org.sbolstandard.core2.Component) URI(java.net.URI) ComponentDefinition(org.sbolstandard.core2.ComponentDefinition)

Example 2 with SequenceAnnotation

use of org.sbolstandard.core2.SequenceAnnotation 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;
}
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 3 with SequenceAnnotation

use of org.sbolstandard.core2.SequenceAnnotation 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());
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 4 with SequenceAnnotation

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

the class ComponentDefinition method getImpliedNucleicAcidSequence.

/**
 *  Return the elements of a nucleic acid sequence implied by the hierarchically included components.
 *  <p>
 *  This method first tries to obtain the length of a nucleic acid sequence from the set of sequences referenced by this component definition
 *  that has an {@link Sequence#IUPAC_DNA} encoding. It then iterates through this component defintion's
 *  sequence annotations, and update the length with the ending locations that have a larger value than the current length. It then populates
 *  the elements with this length with unknown bases. This method iterates through this component defintion's sequence annotations to recursively
 *  search for bases implied by the hierarchically included components, and fills the elements with these known bases.
 *
 *  @return the elements of a nucleic sequence implied by the hierarchically included components
 */
public String getImpliedNucleicAcidSequence() {
    URI type = null;
    if (this.getTypes().contains(ComponentDefinition.DNA)) {
        type = ComponentDefinition.DNA;
    } else if (this.getTypes().contains(ComponentDefinition.RNA)) {
        type = ComponentDefinition.RNA;
    } else {
        return null;
    }
    String elements = "";
    int length = 0;
    if (this.getSequenceByEncoding(Sequence.IUPAC_DNA) != null) {
        length = this.getSequenceByEncoding(Sequence.IUPAC_DNA).getElements().length();
    }
    for (SequenceAnnotation sequenceAnnotation : this.getSequenceAnnotations()) {
        for (Location location : sequenceAnnotation.getLocations()) {
            if (location instanceof Range) {
                Range range = (Range) location;
                if (range.getEnd() > length) {
                    length = range.getEnd();
                }
            }
        }
    }
    for (int i = 0; i < length; i++) {
        elements += "N";
    }
    char[] elementsArray = elements.toCharArray();
    for (SequenceAnnotation sequenceAnnotation : this.getSequenceAnnotations()) {
        String subElements = null;
        if (!sequenceAnnotation.isSetComponent())
            continue;
        if (sequenceAnnotation.getComponent().getDefinition() != null) {
            ComponentDefinition compDef = sequenceAnnotation.getComponent().getDefinition();
            if (compDef.getSequenceByEncoding(Sequence.IUPAC_DNA) != null) {
                subElements = compDef.getSequenceByEncoding(Sequence.IUPAC_DNA).getElements();
            } else {
                subElements = compDef.getImpliedNucleicAcidSequence();
            }
            for (Location location : sequenceAnnotation.getLocations()) {
                if (location instanceof Range) {
                    Range range = (Range) location;
                    if (range.isSetOrientation() && range.getOrientation().equals(OrientationType.REVERSECOMPLEMENT)) {
                        subElements = Sequence.reverseComplement(subElements, type);
                    }
                    for (int i = 0; i < subElements.length(); i++) {
                        // TODO: need to deal with when start index out of range
                        elementsArray[(range.getStart() + i) - 1] = subElements.charAt(i);
                    }
                }
            }
        }
    }
    elements = String.valueOf(elementsArray);
    return elements;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 5 with SequenceAnnotation

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

the class ComponentDefinition method createSequenceAnnotation.

/**
 * Creates a child sequence annotation for this component definition with the given arguments,
 * and then adds to this component definition's list of sequence annotations.
 *
 * @param displayId the display ID of the sequence annotation to be created
 * @param location the location of the sequence annotation to be created
 * @return the created sequence annotation
 * @throws SBOLValidationException if any of the following condition is satisfied:
 * <ul>
 * <li>an SBOL validation rule violation occurred in {@link URIcompliance#createCompliantURI(String, String, String)};</li>
 * <li>an SBOL validation rule violation occurred in {@link #createSequenceAnnotation(URI, Set)};</li>
 * <li>an SBOL validation rule violation occurred in {@link SequenceAnnotation#setDisplayId(String)}; or</li>
 * <li>an SBOL validation rule violation occurred in {@link SequenceAnnotation#setVersion(String)}.</li>
 * </ul>
 */
private SequenceAnnotation createSequenceAnnotation(String displayId, Location location) throws SBOLValidationException {
    String URIprefix = this.getPersistentIdentity().toString();
    String version = this.getVersion();
    URI newSequenceAnnotationURI = createCompliantURI(URIprefix, displayId, version);
    Set<Location> locations = new HashSet<>();
    locations.add(location);
    SequenceAnnotation sa = createSequenceAnnotation(newSequenceAnnotationURI, locations);
    sa.setPersistentIdentity(createCompliantURI(URIprefix, displayId, ""));
    sa.setDisplayId(displayId);
    sa.setVersion(version);
    return sa;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) HashSet(java.util.HashSet)

Aggregations

URI (java.net.URI)12 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)11 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)4 QName (javax.xml.namespace.QName)4 Literal (org.sbolstandard.core.datatree.Literal)4 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)4 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)4 Component (org.sbolstandard.core2.Component)3 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)3 SequenceAnnotation (org.sbolstandard.core2.SequenceAnnotation)3 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)2 FunctionalComponent (org.sbolstandard.core2.FunctionalComponent)2 Sequence (org.sbolstandard.core2.Sequence)2 HashMap (java.util.HashMap)1 Set (java.util.Set)1 SBOLDocument (org.sbolstandard.core2.SBOLDocument)1 SBOLValidationException (org.sbolstandard.core2.SBOLValidationException)1