use of org.sbolstandard.core2.Cut in project libSBOLj by SynBioDex.
the class SequenceAnnotation method addCut.
/**
* Creates a cut with the given arguments and then adds it to this sequence annotation's
* list of locations.
* <p>
* This method first creates a compliant URI for the cut to be created.
* It starts with this sequence annotation's persistent identity URI,
* followed by the given display ID, and ends an empty string for version.
*
* @param displayId the display ID for the cut to be created
* @param at the at property for the cut to be created
* @param orientation the orientation type
* @return the created cut
* @throws SBOLValidationException if any of the following SBOL validation rules was violated:
* 10201, 10202, 10204, 10206, 11202.
*/
public Cut addCut(String displayId, int at, OrientationType orientation) throws SBOLValidationException {
URI identity = createCompliantURI(this.getPersistentIdentity().toString(), displayId, this.getVersion());
Cut cut = new Cut(identity, at);
cut.setPersistentIdentity(createCompliantURI(this.getPersistentIdentity().toString(), displayId, ""));
cut.setDisplayId(displayId);
cut.setVersion(this.getVersion());
cut.setOrientation(orientation);
addLocation(cut);
return cut;
}
use of org.sbolstandard.core2.Cut in project libSBOLj by SynBioDex.
the class SequenceAnnotation method copy.
void copy(SequenceAnnotation sequenceAnnotation) throws SBOLValidationException {
((Identified) this).copy((Identified) sequenceAnnotation);
for (Location location : sequenceAnnotation.getLocations()) {
String displayId = URIcompliance.findDisplayId(location);
if (location instanceof Range) {
Range range = (Range) location;
Range newRange;
if (range.isSetOrientation()) {
newRange = this.addRange(displayId, range.getStart(), range.getEnd(), range.getOrientation());
} else {
newRange = this.addRange(displayId, range.getStart(), range.getEnd());
}
newRange.copy(range);
} else if (location instanceof Cut) {
Cut cut = (Cut) location;
Cut newCut;
if (cut.isSetOrientation()) {
newCut = this.addCut(displayId, cut.getAt(), cut.getOrientation());
} else {
newCut = this.addCut(displayId, cut.getAt());
}
newCut.copy(cut);
} else if (location instanceof GenericLocation) {
GenericLocation genericLocation = (GenericLocation) location;
GenericLocation newGenericLocation;
if (genericLocation.isSetOrientation()) {
newGenericLocation = this.addGenericLocation(displayId, genericLocation.getOrientation());
} else {
newGenericLocation = this.addGenericLocation(displayId);
}
newGenericLocation.copy(genericLocation);
}
}
Location location = this.getLocation("DUMMY__LOCATION");
if (location != null) {
this.removeLocation(location);
}
if (sequenceAnnotation.isSetComponent()) {
String componentDisplayId = URIcompliance.findDisplayId(sequenceAnnotation.getComponent());
this.setComponent(componentDisplayId);
}
this.roles = new HashSet<>();
for (URI role : sequenceAnnotation.getRoles()) {
this.addRole(URI.create(role.toString()));
}
}
use of org.sbolstandard.core2.Cut in project libSBOLj by SynBioDex.
the class SequenceAnnotation method addCut.
/**
* Creates a cut with the given arguments and then adds it to this sequence annotation's
* list of locations.
* <p>
* This method first creates a compliant URI for the cut to be created.
* It starts with this sequence annotation's persistent identity URI,
* followed by the given display ID, and ends an empty string for version.
*
* @param displayId the display ID for the cut to be created
* @param at the at property for the cut to be created
* @return the created cut
* @throws SBOLValidationException if any of the following SBOL validation rules was violated:
* 10201, 10202, 10204, 10206, 11202.
*/
public Cut addCut(String displayId, int at) throws SBOLValidationException {
URI identity = createCompliantURI(this.getPersistentIdentity().toString(), displayId, this.getVersion());
Cut cut = new Cut(identity, at);
cut.setPersistentIdentity(createCompliantURI(this.getPersistentIdentity().toString(), displayId, ""));
cut.setDisplayId(displayId);
cut.setVersion(this.getVersion());
addLocation(cut);
return cut;
}
use of org.sbolstandard.core2.Cut in project libSBOLj by SynBioDex.
the class SBOLReader method parseCut.
/**
* @param typeCut
* @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,
* 11002, 11202; or
*</li>
* <li>an SBOL validation rule violation occurred in the following constructor or methods:
* <ul>
* <li>{@link Cut#Cut(URI, int)},</li>
* <li>{@link Cut#setDisplayId(String)},</li>
* <li>{@link Cut#setVersion(String)},</li>
* <li>{@link Cut#setWasDerivedFrom(URI)}, or</li>
* <li>{@link Identified#setAnnotations(List)}.</li>
* </ul>
* </li>
* </ul>
*/
private static Cut parseCut(NestedDocument<QName> typeCut) throws SBOLValidationException {
// URIcompliance.extractDisplayId(typeCut.getIdentity());
String displayId = null;
String name = null;
String description = null;
// URI.create(URIcompliance.extractPersistentId(typeCut.getIdentity()));
URI persistentIdentity = null;
Integer at = null;
URI orientation = null;
String version = null;
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
List<Annotation> annotations = new ArrayList<>();
for (NamedProperty<QName> namedProperty : typeCut.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", typeCut.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", typeCut.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", typeCut.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", typeCut.getIdentity());
}
description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
} else if (namedProperty.getName().equals(Sbol2Terms.Cut.at)) {
if (!(namedProperty.getValue() instanceof Literal) || at != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
throw new SBOLValidationException("sbol-11202", typeCut.getIdentity());
}
String temp = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
// at = Integer.parseInt(temp);
try {
at = Integer.parseInt(temp);
} catch (NumberFormatException e) {
throw new SBOLValidationException("sbol-11202", typeCut.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.Cut.orientation)) {
if (!(namedProperty.getValue() instanceof Literal) || orientation != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-11002", typeCut.getIdentity());
}
orientation = 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", typeCut.getIdentity());
}
version = ((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", typeCut.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", typeCut.getIdentity());
}
wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else {
annotations.add(new Annotation(namedProperty));
}
}
if (at == null) {
throw new SBOLValidationException("Cut requires at property.");
}
Cut c = new Cut(typeCut.getIdentity(), at);
if (persistentIdentity != null)
c.setPersistentIdentity(persistentIdentity);
if (displayId != null)
c.setDisplayId(displayId);
if (name != null)
c.setName(name);
if (description != null)
c.setDescription(description);
if (orientation != null)
try {
c.setOrientation(OrientationType.convertToOrientationType(orientation));
} catch (SBOLValidationException e) {
throw new SBOLValidationException("sbol-11002", c);
}
if (version != null)
c.setVersion(version);
c.setWasDerivedFroms(wasDerivedFroms);
c.setWasGeneratedBys(wasGeneratedBys);
if (!annotations.isEmpty())
c.setAnnotations(annotations);
return c;
}
use of org.sbolstandard.core2.Cut in project libSBOLj by SynBioDex.
the class Provenance_SpecifyBuildOperations method specifyCutOperation.
/**
* specifies to perform a cut operation in order to linearize a vector using a restriction enzyme
*
* @throws Exception
*/
public static void specifyCutOperation() throws Exception {
// instantiate a document
SBOLDocument document = new SBOLDocument();
document.setDefaultURIprefix(BUILD_PREFIX);
ComponentDefinition vector = document.createComponentDefinition("vector", VECTOR_PLASMID);
vector.setName("vector");
ComponentDefinition enzyme = document.createComponentDefinition("restriction_enzyme", RESTRICTION_ENZYME);
enzyme.setName("restriction_enzyme");
// Create the generic top level entity for the cut operation
Activity activity = document.createActivity("cut_" + vector.getName() + "_with_" + enzyme.getName());
activity.setName("cut(" + vector.getName() + ", " + enzyme.getName() + ")");
// Create the qualifiedUsage annotation to describe the inputs of the cut operation
activity.createUsage("vector", vector.getIdentity()).addRole(VECTOR_PLASMID);
activity.createUsage("enzyme", enzyme.getIdentity()).addRole(RESTRICTION_ENZYME);
// the result of the cut operation
ComponentDefinition linearized_vector = document.createComponentDefinition("linearized_vector", LINEAR_DOUBLE_STRANDED_DNA);
linearized_vector.setName("linearized_vector");
linearized_vector.addWasGeneratedBy(activity.getIdentity());
// serialize the document to a file
SBOLWriter.write(document, System.out);
}
Aggregations