use of org.sbolstandard.core.datatree.NamespaceBinding in project libSBOLj by SynBioDex.
the class Provenance_StrainDerivation method main.
public static void main(String[] args) throws Exception {
NamespaceBinding myAppNs = NamespaceBinding("http://myapp.com/", "myapp");
SBOLDocument document = new SBOLDocument();
document.addNamespace(URI.create(myAppNs.getNamespaceURI()), myAppNs.getPrefix());
document.setDefaultURIprefix(myAppNs.getNamespaceURI());
ComponentDefinition b168 = getCds(document, "bsubtilis168", "Bacillus subtilis 168");
ComponentDefinition b3610 = getCds(document, "bsubtilisncimb3610", "Bacillus subtilis NCIMB 3610");
b168.addWasDerivedFrom(b3610.getIdentity());
// Create the agent definition to represent X-ray
Agent agent = document.createAgent("x_ray");
agent.setName("X-ray");
// Create the generic top level entity for the X-ray mutagenesis activity
Activity activity = document.createActivity("xraymutagenesis");
activity.setName("X-ray mutagenesis");
// Create the qualifiedUsage annotation to describe the use of the parent strain
activity.createUsage("usage", b3610.getIdentity()).addRole(URI.create("http://sbols.org/v2#source"));
// Create the qualifiedAssociation annotation to describe the use of the agent used in the activity
activity.createAssociation("association", agent.getIdentity()).addRole(myAppNs.namespacedUri("mutagen"));
b168.addWasGeneratedBy(activity.getIdentity());
SBOLWriter.write(document, System.out);
}
use of org.sbolstandard.core.datatree.NamespaceBinding in project libSBOLj by SynBioDex.
the class Provenance_CodonOptimization method main.
public static void main(String[] args) throws Exception {
NamespaceBinding myAppNs = NamespaceBinding("http://myapp.com/", "myapp");
SBOLDocument document = new SBOLDocument();
document.addNamespace(URI.create(myAppNs.getNamespaceURI()), myAppNs.getPrefix());
document.setDefaultURIprefix(myAppNs.getNamespaceURI());
ComponentDefinition optimizedCds = getCds(document, "codon_optimized", "Codon optimised CDS");
ComponentDefinition sourceCds = getCds(document, "non_codon_optimized", "Non Codon optimised CDS");
optimizedCds.addWasDerivedFrom(sourceCds.getIdentity());
// Create the agent definition for the codon optimization software
Agent agent = document.createAgent("codon_optimization_software");
agent.setName("Codon Optimization Software");
// Create the generic top level entity for the codon optimization activity
Activity activity = document.createActivity("codon_optimization_activity");
activity.setName("Codon Optimization Activity");
// Create the qualifiedUsage annotation to describe the use of the non codon optimized CDS component
activity.createUsage("usage", sourceCds.getIdentity()).addRole(URI.create("http://sbols.org/v2#source"));
// Create the qualifiedAssociation annotation to describe the use of the software agent used in the activity
activity.createAssociation("association", agent.getIdentity()).addRole(myAppNs.namespacedUri("codonoptimiser"));
optimizedCds.addWasGeneratedBy(activity.getIdentity());
SBOLWriter.write(document, System.out);
}
use of org.sbolstandard.core.datatree.NamespaceBinding in project libSBOLj by SynBioDex.
the class SBOLReader method read.
/**
* @param SBOLDoc
* @param in
* @param fileType
* @throws SBOLValidationException if either of the following conditions is satisfied:
* <ul>
* <li>If {@link #keepGoing} was set to {@code false}, and an SBOL validation rule violation occurred in
* any of the following methods:
* <ul>
* <li>{@link FASTA#read(SBOLDocument, String, String, String, URI)},</li>
* <li>{@link GenBank#read(SBOLDocument, String, String)},</li>
* <li>{@link #readJSON(Reader)}, </li>
* <li>{@link #readRDF(Reader)}, </li>
* <li>{@link #readTurtle(Reader)}, </li>
* <li>{@link #getSBOLVersion(DocumentRoot)}, or</li>
* <li>{@link #readV1(SBOLDocument, DocumentRoot)}; or</li>
* </ul></li>
* <li>an SBOL validation rule violation occurred in {@link #readTopLevelDocs(SBOLDocument, DocumentRoot)}.</li>
* </ul>
* @throws IOException see {@link IOException}
* @throws SBOLConversionException
*/
static void read(SBOLDocument SBOLDoc, InputStream in, String fileType) throws SBOLValidationException, IOException, SBOLConversionException {
compliant = SBOLDoc.isCompliant();
Scanner scanner = new Scanner(in, "UTF-8");
String inputStreamString;
try {
inputStreamString = scanner.useDelimiter("\\A").next();
} catch (NoSuchElementException e) {
scanner.close();
throw new SBOLConversionException("File is empty.");
}
clearErrors();
DocumentRoot<QName> document = null;
try {
if (SBOLReader.isFastaString(inputStreamString)) {
SBOLDoc.setCreateDefaults(true);
SBOLDoc.setCompliant(true);
if (URIPrefix == null) {
scanner.close();
throw new SBOLConversionException("No URI prefix has been provided.");
}
SBOLDoc.setDefaultURIprefix(URIPrefix);
FASTA.read(SBOLDoc, inputStreamString, URIPrefix, version, defaultSequenceEncoding);
scanner.close();
return;
} else if (SBOLReader.isGenBankString(inputStreamString)) {
SBOLDoc.setCreateDefaults(true);
SBOLDoc.setCompliant(true);
if (URIPrefix == null) {
scanner.close();
throw new SBOLConversionException("No URI prefix has been provided.");
}
SBOLDoc.setDefaultURIprefix(URIPrefix);
GenBank.read(SBOLDoc, inputStreamString, URIPrefix, version);
scanner.close();
return;
} else if (fileType.equals(SBOLDocument.JSON)) {
document = readJSON(new StringReader(inputStreamString));
} else if (fileType.equals(SBOLDocument.TURTLE)) {
document = readTurtle(new StringReader(inputStreamString));
} else {
document = readRDF(new StringReader(inputStreamString));
}
if (getSBOLVersion(document).equals(SBOLVERSION1)) {
scanner.close();
readV1(SBOLDoc, document);
return;
}
} catch (SBOLValidationException e) {
if (keepGoing) {
errors.add(e.getMessage());
return;
} else {
throw new SBOLValidationException(e);
}
}
for (NamespaceBinding n : document.getNamespaceBindings()) {
if (SBOLDoc.getNamespace(URI.create(n.getNamespaceURI())) == null) {
if (n.getPrefix() == null) {
SBOLDoc.addNamespaceBinding(NamespaceBinding(n.getNamespaceURI(), ""));
} else {
SBOLDoc.addNamespaceBinding(NamespaceBinding(n.getNamespaceURI(), n.getPrefix()));
}
}
}
readTopLevelDocs(SBOLDoc, document);
scanner.close();
SBOLValidate.clearErrors();
SBOLValidate.validateCompliance(SBOLDoc);
if (SBOLValidate.getNumErrors() > 0) {
SBOLDoc.setCompliant(false);
}
}
use of org.sbolstandard.core.datatree.NamespaceBinding in project libSBOLj by SynBioDex.
the class SBOLReader method readV1.
/**
* @param SBOLDoc
* @param document
* @return
* @throws SBOLValidationException if an SBOL validation rule violation occurred in {@link #readTopLevelDocsV1(SBOLDocument, DocumentRoot)}.
* @throws SBOLConversionException
*/
private static SBOLDocument readV1(SBOLDocument SBOLDoc, DocumentRoot<QName> document) throws SBOLValidationException, SBOLConversionException {
for (NamespaceBinding n : document.getNamespaceBindings()) {
if (n.getNamespaceURI().equals(Sbol1Terms.sbol1.getNamespaceURI())) {
SBOLDoc.addNamespaceBinding(NamespaceBinding(Sbol2Terms.sbol2.getNamespaceURI(), Sbol2Terms.sbol2.getPrefix()));
} else {
if (SBOLDoc.getNamespace(URI.create(n.getNamespaceURI())) == null) {
SBOLDoc.addNamespaceBinding(NamespaceBinding(n.getNamespaceURI(), n.getPrefix()));
}
}
}
SBOLDoc.addNamespaceBinding(NamespaceBinding(Sbol2Terms.prov.getNamespaceURI(), Sbol2Terms.prov.getPrefix()));
readTopLevelDocsV1(SBOLDoc, document);
SBOLValidate.clearErrors();
SBOLValidate.validateCompliance(SBOLDoc);
if (SBOLValidate.getNumErrors() > 0) {
SBOLDoc.setCompliant(false);
}
return SBOLDoc;
}
use of org.sbolstandard.core.datatree.NamespaceBinding in project libSBOLj by SynBioDex.
the class SBOLReader method getSBOLVersion.
/**
* @param document
* @return
* @throws SBOLValidationException if either of the following SBOL validation rules was violated:
* 10101, 10102.
*/
private static String getSBOLVersion(DocumentRoot<QName> document) throws SBOLValidationException {
boolean foundRDF = false;
boolean foundSBOL1 = false;
boolean foundSBOL2 = false;
for (NamespaceBinding n : document.getNamespaceBindings()) {
if (n.getNamespaceURI().equals(Sbol1Terms.rdf.getNamespaceURI()))
foundRDF = true;
if (n.getNamespaceURI().equals(Sbol1Terms.sbol1.getNamespaceURI()))
foundSBOL1 = true;
if (n.getNamespaceURI().equals(Sbol2Terms.sbol2.getNamespaceURI()))
foundSBOL2 = true;
}
if (foundSBOL2) {
if (!foundRDF) {
throw new SBOLValidationException("sbol-10102");
}
return SBOLVERSION2;
} else if (foundSBOL1) {
if (!foundRDF) {
throw new SBOLValidationException("sbol-10102");
}
return SBOLVERSION1;
} else {
throw new SBOLValidationException("sbol-10101");
}
}
Aggregations