use of org.sbolstandard.core2.Annotation 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);
}
use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.
the class AnnotationOutput method main.
public static void main(String[] args) throws Exception {
String prURI = "http://partsregistry.org/";
String prPrefix = "pr";
SBOLDocument document = new SBOLDocument();
document.setDefaultURIprefix(prURI);
document.setTypesInURIs(true);
document.addNamespace(URI.create(prURI), prPrefix);
ComponentDefinition promoter = document.createComponentDefinition("BBa_J23119", "", new HashSet<URI>(Arrays.asList(URI.create("http://www.biopax.org/release/biopax-level3.owl#DnaRegion"))));
promoter.addRole(SequenceOntology.PROMOTER);
promoter.setName("J23119");
promoter.setDescription("Constitutive promoter");
promoter.createAnnotation(new QName(prURI, "group", prPrefix), "iGEM2006_Berkeley");
promoter.createAnnotation(new QName(prURI, "experience", prPrefix), URI.create("http://parts.igem.org/cgi/partsdb/part_info.cgi?part_name=BBa_J23119"));
Annotation sigmaFactor = new Annotation(QName(prURI, "sigmafactor", prPrefix), "//rnap/prokaryote/ecoli/sigma70");
Annotation regulation = new Annotation(QName(prURI, "regulation", prPrefix), "//regulation/constitutive");
promoter.createAnnotation(new QName(prURI, "information", prPrefix), new QName(prURI, "Information", prPrefix), URI.create("http://partsregistry.org/cd/BBa_J23119/information"), new ArrayList<Annotation>(Arrays.asList(sigmaFactor, regulation)));
SBOLWriter.write(document, (System.out));
}
use of org.sbolstandard.core2.Annotation in project zipkin by openzipkin.
the class JacksonSpanDecoder method parseSpan.
static Span parseSpan(JsonParser jsonParser) throws IOException {
if (!jsonParser.isExpectedStartObjectToken()) {
throw new IOException("Not a valid JSON object, start token: " + jsonParser.currentToken());
}
Span.Builder result = Span.newBuilder();
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jsonParser.currentName();
JsonToken value = jsonParser.nextToken();
if (value == JsonToken.VALUE_NULL) {
continue;
}
switch(fieldName) {
case "traceId":
result.traceId(jsonParser.getValueAsString());
break;
case "parentId":
result.parentId(jsonParser.getValueAsString());
break;
case "id":
result.id(jsonParser.getValueAsString());
break;
case "kind":
result.kind(Span.Kind.valueOf(jsonParser.getValueAsString()));
break;
case "name":
result.name(jsonParser.getValueAsString());
break;
case "timestamp":
result.timestamp(jsonParser.getValueAsLong());
break;
case "duration":
result.duration(jsonParser.getValueAsLong());
break;
case "localEndpoint":
result.localEndpoint(parseEndpoint(jsonParser));
break;
case "remoteEndpoint":
result.remoteEndpoint(parseEndpoint(jsonParser));
break;
case "annotations":
if (!jsonParser.isExpectedStartArrayToken()) {
throw new IOException("Invalid span, expecting annotations array start, got: " + value);
}
while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
Annotation a = parseAnnotation(jsonParser);
result.addAnnotation(a.timestamp(), a.value());
}
break;
case "tags":
if (value != JsonToken.START_OBJECT) {
throw new IOException("Invalid span, expecting tags object, got: " + value);
}
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
result.putTag(jsonParser.currentName(), jsonParser.nextTextValue());
}
break;
case "debug":
result.debug(jsonParser.getBooleanValue());
break;
case "shared":
result.shared(jsonParser.getBooleanValue());
break;
default:
jsonParser.skipChildren();
}
}
return result.build();
}
use of org.sbolstandard.core2.Annotation in project zipkin by openzipkin.
the class V2SpanWriter method write.
@Override
public void write(Span value, WriteBuffer b) {
b.writeAscii("{\"traceId\":\"");
b.writeAscii(value.traceId());
b.writeByte('"');
if (value.parentId() != null) {
b.writeAscii(",\"parentId\":\"");
b.writeAscii(value.parentId());
b.writeByte('"');
}
b.writeAscii(",\"id\":\"");
b.writeAscii(value.id());
b.writeByte('"');
if (value.kind() != null) {
b.writeAscii(",\"kind\":\"");
b.writeAscii(value.kind().toString());
b.writeByte('"');
}
if (value.name() != null) {
b.writeAscii(",\"name\":\"");
b.writeUtf8(jsonEscape(value.name()));
b.writeByte('"');
}
if (value.timestampAsLong() != 0L) {
b.writeAscii(",\"timestamp\":");
b.writeAscii(value.timestampAsLong());
}
if (value.durationAsLong() != 0L) {
b.writeAscii(",\"duration\":");
b.writeAscii(value.durationAsLong());
}
if (value.localEndpoint() != null) {
b.writeAscii(",\"localEndpoint\":");
writeEndpoint(value.localEndpoint(), b, false);
}
if (value.remoteEndpoint() != null) {
b.writeAscii(",\"remoteEndpoint\":");
writeEndpoint(value.remoteEndpoint(), b, false);
}
if (!value.annotations().isEmpty()) {
b.writeAscii(",\"annotations\":");
b.writeByte('[');
for (int i = 0, length = value.annotations().size(); i < length; ) {
Annotation a = value.annotations().get(i++);
writeAnnotation(a.timestamp(), a.value(), null, b);
if (i < length)
b.writeByte(',');
}
b.writeByte(']');
}
if (!value.tags().isEmpty()) {
b.writeAscii(",\"tags\":{");
Iterator<Map.Entry<String, String>> i = value.tags().entrySet().iterator();
while (i.hasNext()) {
Map.Entry<String, String> entry = i.next();
b.writeByte('"');
b.writeUtf8(jsonEscape(entry.getKey()));
b.writeAscii("\":\"");
b.writeUtf8(jsonEscape(entry.getValue()));
b.writeByte('"');
if (i.hasNext())
b.writeByte(',');
}
b.writeByte('}');
}
if (Boolean.TRUE.equals(value.debug())) {
b.writeAscii(",\"debug\":true");
}
if (Boolean.TRUE.equals(value.shared())) {
b.writeAscii(",\"shared\":true");
}
b.writeByte('}');
}
use of org.sbolstandard.core2.Annotation in project zipkin by openzipkin.
the class QueryRequest method test.
/**
* Tests the supplied trace against the current request.
*
* <p>This is used when the backend cannot fully refine a trace query.
*/
public boolean test(List<Span> spans) {
// v2 returns raw spans in any order, get the root's timestamp or the first timestamp
long timestamp = 0L;
for (Span span : spans) {
if (span.timestampAsLong() == 0L)
continue;
if (span.parentId() == null) {
timestamp = span.timestampAsLong();
break;
}
if (timestamp == 0L || timestamp > span.timestampAsLong()) {
timestamp = span.timestampAsLong();
}
}
if (timestamp == 0L || timestamp < (endTs() - lookback()) * 1000 || timestamp > endTs() * 1000) {
return false;
}
boolean testedDuration = minDuration() == null && maxDuration() == null;
String serviceNameToMatch = serviceName();
String remoteServiceNameToMatch = remoteServiceName();
String spanNameToMatch = spanName();
Map<String, String> annotationQueryRemaining = new LinkedHashMap<String, String>(annotationQuery());
for (Span span : spans) {
String localServiceName = span.localServiceName();
// service name, when present, constrains other queries.
if (serviceName() == null || serviceName().equals(localServiceName)) {
serviceNameToMatch = null;
for (Annotation a : span.annotations()) {
if ("".equals(annotationQueryRemaining.get(a.value()))) {
annotationQueryRemaining.remove(a.value());
}
}
for (Map.Entry<String, String> t : span.tags().entrySet()) {
String value = annotationQueryRemaining.get(t.getKey());
if (value == null)
continue;
if (value.isEmpty() || value.equals(t.getValue())) {
annotationQueryRemaining.remove(t.getKey());
}
}
if (remoteServiceNameToMatch != null && remoteServiceNameToMatch.equals(span.remoteServiceName())) {
remoteServiceNameToMatch = null;
}
if (spanNameToMatch != null && spanNameToMatch.equals(span.name())) {
spanNameToMatch = null;
}
if (!testedDuration) {
if (minDuration() != null && maxDuration() != null) {
testedDuration = span.durationAsLong() >= minDuration() && span.durationAsLong() <= maxDuration();
} else if (minDuration() != null) {
testedDuration = span.durationAsLong() >= minDuration();
}
}
}
}
return (serviceName() == null || serviceNameToMatch == null) && remoteServiceNameToMatch == null && spanNameToMatch == null && annotationQueryRemaining.isEmpty() && testedDuration;
}
Aggregations