use of org.sbolstandard.core2.Sequence in project libSBOLj by SynBioDex.
the class GettingStartedExample method main.
public static void main(String[] args) throws IOException, SBOLValidationException, SBOLConversionException {
String prURI = "http://partsregistry.org/";
String prPrefix = "pr";
String myersLabURI = "http://www.async.ece.utah.edu/";
String myersLabPrefix = "myersLab";
SBOLDocument document = new SBOLDocument();
document.setDefaultURIprefix(prURI);
document.setTypesInURIs(true);
document.setComplete(true);
document.setCreateDefaults(true);
document.addNamespace(URI.create(prURI), prPrefix);
document.addNamespace(URI.create(myersLabURI), myersLabPrefix);
// Creating a Top-level SBOL Data Object
HashSet<URI> types = new HashSet<URI>(Arrays.asList(ComponentDefinition.DNA, URI.create("http://identifiers.org/chebi/CHEBI:4705")));
ComponentDefinition TetR_promoter = document.createComponentDefinition("BBa_R0040", types);
ComponentDefinition LacI_repressor = document.createComponentDefinition("BBa_C0012", types);
ComponentDefinition pIKELeftCassette = document.createComponentDefinition("pIKELeftCassette", types);
Sequence seq_187 = document.createSequence("partseq_187", "tccctatcagtgatagagattgacatccctatcagtgatagagatactgagcac", Sequence.IUPAC_DNA);
String element2 = "atggtgaatgtgaaaccagtaacgttatacgatgtcgcagagtatgccggtgtc" + "tcttatcagaccgtttcccgcgtggtgaaccaggccagccacgtttctgcgaaaacgcggga" + "aaaagtggaagcggcgatggcggagctgaattacattcccaaccgcgtggcacaacaactgg" + "cgggcaaacagtcgttgctgattggcgttgccacctccagtctggccctgcacgcgccgtcg" + "caaattgtcgcggcgattaaatctcgcgccgatcaactgggtgccagcgtggtggtgtcgat" + "ggtagaacgaagcggcgtcgaagcctgtaaagcggcggtgcacaatcttctcgcgcaacgcg" + "tcagtgggctgatcattaactatccgctggatgaccaggatgccattgctgtggaagctgcc" + "tgcactaatgttccggcgttatttcttgatgtctctgaccagacacccatcaacagtattat" + "tttctcccatgaagacggtacgcgactgggcgtggagcatctggtcgcattgggtcaccagc" + "aaatcgcgctgttagcgggcccattaagttctgtctcggcgcgtctgcgtctggctggctgg" + "cataaatatctcactcgcaatcaaattcagccgatagcggaacgggaaggcgactggagtgc" + "catgtccggttttcaacaaaccatgcaaatgctgaatgagggcatcgttcccactgcgatgc" + "tggttgccaacgatcagatggcgctgggcgcaatgcgcgccattaccgagtccgggctgcgc" + "gttggtgcggatatctcggtagtgggatacgacgataccgaagacagctcatgttatatccc" + "gccgttaaccaccatcaaacaggattttcgcctgctggggcaaaccagcgtggaccgcttgc" + "tgcaactctctcagggccaggcggtgaagggcaatcagctgttgcccgtctcactggtgaaa" + "agaaaaaccaccctggcgcccaatacgcaaaccgcctctccccgcgcgttggccgattcatt" + "aatgcagctggcacgacaggtttcccgactggaaagcgggcaggctgcaaacgacgaaaact" + "acgctttagtagcttaataa";
Sequence seq_153 = document.createSequence("partseq_153", element2, Sequence.IUPAC_DNA);
// Setting and editing optional fields
TetR_promoter.setName("p(tetR)");
LacI_repressor.setName("lacI");
TetR_promoter.setDescription("TetR repressible promoter");
LacI_repressor.setDescription("lacI repressor from E. coli (+LVA)");
if (TetR_promoter.isSetName()) {
TetR_promoter.unsetName();
}
TetR_promoter.setName("p(tetR)");
TetR_promoter.addRole(SequenceOntology.PROMOTER);
LacI_repressor.addRole(SequenceOntology.CDS);
URI TetR_promoter_role2 = URI.create("http://identifiers.org/so/SO:0000613");
TetR_promoter.addRole(TetR_promoter_role2);
if (TetR_promoter.containsRole(TetR_promoter_role2)) {
TetR_promoter.removeRole(TetR_promoter_role2);
}
TetR_promoter.clearRoles();
if (!TetR_promoter.getRoles().isEmpty()) {
System.out.println("TetR_promoter set is not empty");
}
TetR_promoter.setRoles(new HashSet<URI>(Arrays.asList(SequenceOntology.PROMOTER)));
// Creating and editing references
TetR_promoter.addSequence(seq_187);
LacI_repressor.addSequence(seq_153);
pIKELeftCassette.addSequence(seq_187);
pIKELeftCassette.clearSequences();
// Adding the sequence below causes an exception because it cannot be found
// pIKELeftCassette.addSequence(URI.create("http://partsregistry.org/seq/partseq_154"));
// Creating Annotations
TetR_promoter.createAnnotation(new QName(prURI, "experience", prPrefix), URI.create("http://parts.igem.org/Part:BBa_R0040"));
// Creating Generic TopLevel Object
GenericTopLevel datasheet = document.createGenericTopLevel("datasheet", "1.0", new QName(myersLabURI, "datasheet", myersLabPrefix));
datasheet.setName("Datasheet for Custom Parameters");
datasheet.createAnnotation(new QName(myersLabURI, "characterizationData", myersLabPrefix), URI.create(myersLabURI + "/measurement/Part:BBa_R0040"));
datasheet.createAnnotation(new QName(myersLabURI, "transcriptionRate", myersLabPrefix), "0.75");
TetR_promoter.createAnnotation(new QName(myersLabURI, "datasheet", myersLabPrefix), datasheet.getIdentity());
// Creating and editing Child Objects
// For pIKELeftCassette, create sequence constraint that says BBa_R0040 precedes BBa_C0012.
// Note that with CreateDefaults that components get created automatically.
// The position of the subject Component MUST precede that of the object Component.
pIKELeftCassette.createSequenceConstraint("pIKELeftCassette_sc", RestrictionType.PRECEDES, TetR_promoter.getDisplayId(), LacI_repressor.getDisplayId());
if (pIKELeftCassette.getComponent("BBa_R0040") == null) {
System.out.println("TetR_promoter component is missing");
}
if (pIKELeftCassette.getComponent("BBa_C0012") == null) {
System.out.println("LacI_repressor component is missing");
}
// Removing the subject component below causes an exception.
// pIKELeftCassette.removeComponent(pIKELeftCassette.getComponent("BBa_R0040"));
// Copying objects
ComponentDefinition TetR_promoter_copy = (ComponentDefinition) document.createCopy(TetR_promoter, "BBa_K137046");
Sequence seq = document.createSequence("seq_K137046", "gtgctcagtatctctatcactgatagggatgtcaatctctatcactgatagggactctagtatat" + "aaacgcagaaaggcccacccgaaggtgagccagtgtgactctagtagagagcgttcaccgaca" + "aacaacagataaaacgaaaggc", Sequence.IUPAC_DNA);
TetR_promoter_copy.addSequence(seq);
SBOLWriter.write(document, "GettingStartedExample.rdf");
writeThenRead(document);
}
use of org.sbolstandard.core2.Sequence 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;
}
use of org.sbolstandard.core2.Sequence in project libSBOLj by SynBioDex.
the class SequenceTest method test_deep_copy.
@Test
public void test_deep_copy() throws SBOLValidationException {
Sequence gen_seq = doc.createSequence("CRa_U6_seq", CRa_U6_seq, Sequence.IUPAC_DNA);
Sequence copy_seq = (Sequence) doc.createCopy(gen_seq, "copy_seq");
// assertTrue(copy_seq.equals(gen_seq));
assertTrue(copy_seq.getElements().equals(CRa_U6_seq));
}
use of org.sbolstandard.core2.Sequence in project libSBOLj by SynBioDex.
the class SBOLReader method parseDnaSequenceV1.
/**
* @param SBOLDoc
* @param topLevel
* @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, String, boolean)},</li>
* <li>{@link Sequence#Sequence(URI, String, URI)},</li>
* <li>{@link Sequence#setVersion(String)},</li>
* <li>{@link Sequence#setWasDerivedFrom(URI)},</li>
* <li>{@link Sequence#setDisplayId(String)},</li>
* <li>{@link Identified#setAnnotations(List)},</li>
* <li>{@link Sequence#setIdentity(URI)}, or </li>
* <li>{@link SBOLDocument#addSequence(Sequence)}; or</li>
* </ul>
* </li>
* <li>any of the following SBOL validation rules was violated: 10202, 10204, 10212, 10213.</li>
* </ul>
*/
private static Sequence parseDnaSequenceV1(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel) throws SBOLValidationException {
String elements = null;
String displayId = null;
String name = null;
String description = null;
URI identity = topLevel.getIdentity();
URI persistentIdentity = topLevel.getIdentity();
URI encoding = Sequence.IUPAC_DNA;
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.DNASequence.nucleotides)) {
elements = ((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();
if (URIPrefix != null) {
identity = createCompliantURI(URIPrefix, TopLevel.SEQUENCE, displayId, version, typesInURI);
}
} 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 {
annotations.add(new Annotation(namedProperty));
}
}
Sequence sequence = new Sequence(identity, elements, encoding);
if (persistentIdentity != null) {
sequence.setPersistentIdentity(persistentIdentity);
sequence.setVersion(version);
}
if (identity != topLevel.getIdentity())
sequence.addWasDerivedFrom(topLevel.getIdentity());
if (displayId != null)
sequence.setDisplayId(displayId);
if (name != null)
sequence.setName(name);
if (description != null)
sequence.setDescription(description);
if (!annotations.isEmpty())
sequence.setAnnotations(annotations);
Sequence oldS = SBOLDoc.getSequence(identity);
if (oldS == null) {
SBOLDoc.addSequence(sequence);
} else if (sequence.getWasDerivedFroms().size() > 0 && oldS.getWasDerivedFroms().size() > 0 && !sequence.getWasDerivedFroms().equals(oldS.getWasDerivedFroms())) {
URI wasDerivedFrom = (URI) sequence.getWasDerivedFroms().toArray()[0];
Set<TopLevel> topLevels = SBOLDoc.getByWasDerivedFrom(wasDerivedFrom);
for (TopLevel top : topLevels) {
if (top instanceof Sequence) {
return (Sequence) top;
}
}
do {
displayId = displayId + "_";
identity = createCompliantURI(URIPrefix, TopLevel.SEQUENCE, displayId, version, typesInURI);
persistentIdentity = createCompliantURI(URIPrefix, TopLevel.SEQUENCE, displayId, "", typesInURI);
} while (SBOLDoc.getSequence(identity) != null);
sequence.setIdentity(identity);
sequence.setDisplayId(displayId);
sequence.setPersistentIdentity(persistentIdentity);
SBOLDoc.addSequence(sequence);
} else if (dropObjectsWithDuplicateURIs) {
return oldS;
} else {
if (!sequence.equals(oldS)) {
throw new SBOLValidationException("sbol-10202", sequence);
}
}
return sequence;
}
use of org.sbolstandard.core2.Sequence 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;
}
Aggregations