use of org.sbolstandard.core2.Activity 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.core2.Activity in project libSBOLj by SynBioDex.
the class Activity method copy.
/* (non-Javadoc)
* @see org.sbolstandard.core2.abstract_classes.TopLevel#copy(java.lang.String, java.lang.String, java.lang.String)
*/
/**
* @throws SBOLValidationException if an SBOL validation rule violation occurred in
* any of the following methods:
* <ul>
* <li>{@link #deepCopy()},</li>
* <li>{@link URIcompliance#createCompliantURI(String, String, String)},</li>
* <li>{@link #setDisplayId(String)},</li>
* <li>{@link #setVersion(String)},</li>
* <li>{@link #setWasDerivedFrom(URI)}, or</li>
* <li>{@link #setIdentity(URI)}.</li>
* </ul>
*/
@Override
Activity copy(String URIprefix, String displayId, String version) throws SBOLValidationException {
Activity cloned = this.deepCopy();
cloned.setPersistentIdentity(createCompliantURI(URIprefix, displayId, ""));
cloned.setDisplayId(displayId);
cloned.setVersion(version);
URI newIdentity = createCompliantURI(URIprefix, displayId, version);
if (!this.getIdentity().equals(newIdentity)) {
cloned.addWasDerivedFrom(this.getIdentity());
} else {
cloned.setWasDerivedFroms(this.getWasDerivedFroms());
}
cloned.setIdentity(newIdentity);
return cloned;
}
use of org.sbolstandard.core2.Activity in project libSBOLj by SynBioDex.
the class SBOLReader method parseActivity.
@SuppressWarnings("unchecked")
private static Activity parseActivity(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
String displayId = null;
String name = null;
String description = null;
URI persistentIdentity = null;
String version = null;
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
Set<URI> attachments = new HashSet<>();
DateTime startedAtTime = null;
DateTime endedAtTime = null;
Set<URI> wasInformedBys = new HashSet<>();
Set<Association> qualifiedAssociations = new HashSet<>();
Set<Usage> qualifiedUsages = new HashSet<>();
List<Annotation> annotations = new ArrayList<>();
for (NamedProperty<QName> namedProperty : topLevel.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", topLevel.getIdentity());
}
persistentIdentity = 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", topLevel.getIdentity());
}
version = ((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();
} 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 if (namedProperty.getName().equals(Sbol2Terms.Identified.wasDerivedFrom)) {
if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-10208", topLevel.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", topLevel.getIdentity());
}
wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getName().equals(Sbol2Terms.TopLevel.hasAttachment)) {
if (namedProperty.getValue() instanceof Literal) {
if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
}
attachments.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getValue() instanceof IdentifiableDocument) {
if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.Attachment.Attachment)) {
Attachment attachment = parseAttachment(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue());
attachments.add(attachment.getIdentity());
} else {
throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
}
} else {
throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.Activity.startedAtTime)) {
if (!(namedProperty.getValue() instanceof Literal) || startedAtTime != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
throw new SBOLValidationException("sbol-12402", topLevel.getIdentity());
}
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
try {
startedAtTime = fmt.parseDateTime(((Literal<QName>) namedProperty.getValue()).getValue().toString());
} catch (IllegalArgumentException e) {
throw new SBOLValidationException("sbol-12402", topLevel.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.Activity.endedAtTime)) {
if (!(namedProperty.getValue() instanceof Literal) || endedAtTime != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
throw new SBOLValidationException("sbol-12403", topLevel.getIdentity());
}
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
try {
endedAtTime = fmt.parseDateTime(((Literal<QName>) namedProperty.getValue()).getValue().toString());
} catch (IllegalArgumentException e) {
throw new SBOLValidationException("sbol-12403", topLevel.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.Activity.wasInformedBy)) {
if (namedProperty.getValue() instanceof Literal) {
if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
throw new SBOLValidationException("sbol-12406", topLevel.getIdentity());
}
wasInformedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else if (namedProperty.getValue() instanceof IdentifiableDocument) {
if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.Activity.Activity)) {
Activity activity = parseActivity(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
wasInformedBys.add(activity.getIdentity());
} else {
throw new SBOLValidationException("sbol-12406", topLevel.getIdentity());
}
} else {
throw new SBOLValidationException("sbol-12406", topLevel.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.Activity.qualifiedAssociation)) {
if (namedProperty.getValue() instanceof NestedDocument) {
NestedDocument<QName> nestedDocument = ((NestedDocument<QName>) namedProperty.getValue());
if (nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.Association.Association)) {
throw new SBOLValidationException("sbol-12404", topLevel.getIdentity());
}
qualifiedAssociations.add(parseAssociation(SBOLDoc, ((NestedDocument<QName>) namedProperty.getValue()), nested));
} else {
URI uri = (URI) ((Literal<QName>) namedProperty.getValue()).getValue();
NestedDocument<QName> nestedDocument = nested.get(uri);
if (nestedDocument == null || nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.Association.Association)) {
throw new SBOLValidationException("sbol-12404", topLevel.getIdentity());
}
qualifiedAssociations.add(parseAssociation(SBOLDoc, nestedDocument, nested));
}
} else if (namedProperty.getName().equals(Sbol2Terms.Activity.qualifiedUsage)) {
if (namedProperty.getValue() instanceof NestedDocument) {
NestedDocument<QName> nestedDocument = ((NestedDocument<QName>) namedProperty.getValue());
if (nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.Usage.Usage)) {
throw new SBOLValidationException("sbol-12405", topLevel.getIdentity());
}
qualifiedUsages.add(parseUsage(SBOLDoc, ((NestedDocument<QName>) namedProperty.getValue()), nested));
} else {
URI uri = (URI) ((Literal<QName>) namedProperty.getValue()).getValue();
NestedDocument<QName> nestedDocument = nested.get(uri);
if (nestedDocument == null || nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.Usage.Usage)) {
throw new SBOLValidationException("sbol-12405", topLevel.getIdentity());
}
qualifiedUsages.add(parseUsage(SBOLDoc, nestedDocument, nested));
}
} else {
annotations.add(new Annotation(namedProperty));
}
}
// GenericTopLevel t = SBOLDoc.createGenericTopLevel(topLevel.getIdentity(), topLevel.getType());
Activity t = new Activity(topLevel.getIdentity());
if (persistentIdentity != null)
t.setPersistentIdentity(persistentIdentity);
if (version != null)
t.setVersion(version);
if (displayId != null)
t.setDisplayId(displayId);
if (name != null)
t.setName(name);
if (description != null)
t.setDescription(description);
t.setWasDerivedFroms(wasDerivedFroms);
t.setWasGeneratedBys(wasGeneratedBys);
if (!annotations.isEmpty())
t.setAnnotations(annotations);
if (startedAtTime != null)
t.setStartedAtTime(startedAtTime);
if (endedAtTime != null)
t.setEndedAtTime(endedAtTime);
if (!qualifiedAssociations.isEmpty())
t.setAssociations(qualifiedAssociations);
if (!qualifiedUsages.isEmpty())
t.setUsages(qualifiedUsages);
if (!wasInformedBys.isEmpty())
t.setWasInformedBys(wasInformedBys);
if (!attachments.isEmpty())
t.setAttachments(attachments);
Activity oldA = SBOLDoc.getActivity(topLevel.getIdentity());
if (oldA == null) {
SBOLDoc.addActivity(t);
} else {
if (!t.equals(oldA)) {
throw new SBOLValidationException("sbol-10202", t);
}
}
return t;
}
use of org.sbolstandard.core2.Activity in project libSBOLj by SynBioDex.
the class SBOLDocument method updateReferences.
// TODO: need to update persistentIdentities too
private void updateReferences(HashMap<URI, URI> uriMap) throws SBOLValidationException {
for (TopLevel topLevel : getTopLevels()) {
for (URI wasDerivedFrom : topLevel.getWasDerivedFroms()) {
if (uriMap.get(wasDerivedFrom) != null) {
topLevel.removeWasDerivedFrom(wasDerivedFrom);
topLevel.addWasDerivedFrom(uriMap.get(wasDerivedFrom));
}
}
for (URI wasGeneratedBy : topLevel.getWasGeneratedBys()) {
if (uriMap.get(wasGeneratedBy) != null) {
topLevel.removeWasGeneratedBy(wasGeneratedBy);
topLevel.addWasGeneratedBy(uriMap.get(wasGeneratedBy));
}
}
for (URI attachmentURI : topLevel.getAttachmentURIs()) {
if (uriMap.get(attachmentURI) != null) {
topLevel.removeAttachment(attachmentURI);
topLevel.addAttachment(uriMap.get(attachmentURI));
}
}
}
for (Collection collection : getCollections()) {
for (URI memberURI : collection.getMemberURIs()) {
if (uriMap.get(memberURI) != null) {
collection.removeMember(memberURI);
collection.addMember(uriMap.get(memberURI));
}
}
updateReferences(collection, uriMap);
}
for (ComponentDefinition componentDefinition : getComponentDefinitions()) {
updateReferences(componentDefinition, uriMap);
for (Component component : componentDefinition.getComponents()) {
if (uriMap.get(component.getDefinitionURI()) != null) {
component.setDefinition(uriMap.get(component.getDefinitionURI()));
for (MapsTo mapsTo : component.getMapsTos()) {
ComponentDefinition cd = getComponentDefinition(component.getDefinitionURI());
if (cd != null) {
String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
mapsTo.setRemote(newURI);
}
}
}
updateReferences(component, uriMap);
for (MapsTo mapsTo : component.getMapsTos()) {
updateReferences(mapsTo, uriMap);
}
}
for (SequenceAnnotation sa : componentDefinition.getSequenceAnnotations()) {
for (Location loc : sa.getLocations()) {
updateReferences(loc, uriMap);
}
updateReferences(sa, uriMap);
}
for (SequenceConstraint sc : componentDefinition.getSequenceConstraints()) {
updateReferences(sc, uriMap);
}
for (URI sequenceURI : componentDefinition.getSequenceURIs()) {
if (uriMap.get(sequenceURI) != null) {
componentDefinition.removeSequence(sequenceURI);
componentDefinition.addSequence(uriMap.get(sequenceURI));
}
}
}
for (ModuleDefinition moduleDefinition : getModuleDefinitions()) {
updateReferences(moduleDefinition, uriMap);
for (FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
if (uriMap.get(functionalComponent.getDefinitionURI()) != null) {
functionalComponent.setDefinition(uriMap.get(functionalComponent.getDefinitionURI()));
for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
ComponentDefinition cd = getComponentDefinition(functionalComponent.getDefinitionURI());
if (cd != null) {
String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
mapsTo.setRemote(newURI);
}
}
}
updateReferences(functionalComponent, uriMap);
for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
updateReferences(mapsTo, uriMap);
}
}
for (Module module : moduleDefinition.getModules()) {
if (uriMap.get(module.getDefinitionURI()) != null) {
module.setDefinition(uriMap.get(module.getDefinitionURI()));
for (MapsTo mapsTo : module.getMapsTos()) {
ModuleDefinition md = getModuleDefinition(module.getDefinitionURI());
if (md != null) {
String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
URI newURI = URIcompliance.createCompliantURI(md.getPersistentIdentity().toString(), displayId, md.getVersion());
mapsTo.setRemote(newURI);
}
}
}
updateReferences(module, uriMap);
for (MapsTo mapsTo : module.getMapsTos()) {
updateReferences(mapsTo, uriMap);
}
}
for (Interaction interaction : moduleDefinition.getInteractions()) {
updateReferences(interaction, uriMap);
for (Participation participation : interaction.getParticipations()) {
updateReferences(participation, uriMap);
}
}
for (URI modelURI : moduleDefinition.getModelURIs()) {
if (uriMap.get(modelURI) != null) {
moduleDefinition.removeModel(modelURI);
moduleDefinition.addModel(uriMap.get(modelURI));
}
}
}
for (Model model : getModels()) {
updateReferences(model, uriMap);
}
for (Sequence sequence : getSequences()) {
updateReferences(sequence, uriMap);
}
for (Attachment attachment : getAttachments()) {
updateReferences(attachment, uriMap);
}
for (Implementation implementation : getImplementations()) {
if (implementation.isSetBuilt()) {
URI built = implementation.getBuiltURI();
if (uriMap.get(built) != null) {
implementation.setBuilt(uriMap.get(built));
}
}
updateReferences(implementation, uriMap);
}
for (GenericTopLevel genericTopLevel : getGenericTopLevels()) {
updateReferences(genericTopLevel, uriMap);
}
for (CombinatorialDerivation combinatorialDerivation : getCombinatorialDerivations()) {
updateReferences(combinatorialDerivation, uriMap);
if (uriMap.get(combinatorialDerivation.getTemplateURI()) != null) {
combinatorialDerivation.setTemplate(uriMap.get(combinatorialDerivation.getTemplateURI()));
ComponentDefinition cd = getComponentDefinition(combinatorialDerivation.getTemplateURI());
if (cd != null) {
for (VariableComponent variableComponent : combinatorialDerivation.getVariableComponents()) {
String displayId = URIcompliance.extractDisplayId(variableComponent.getVariableURI());
URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
variableComponent.setVariable(newURI);
}
}
}
for (VariableComponent variableComponent : combinatorialDerivation.getVariableComponents()) {
updateReferences(variableComponent, uriMap);
}
}
for (Activity activity : getActivities()) {
updateReferences(activity, uriMap);
for (Association association : activity.getAssociations()) {
if (uriMap.get(association.getAgentURI()) != null) {
association.setAgent(uriMap.get(association.getAgentURI()));
}
if (uriMap.get(association.getPlanURI()) != null) {
association.setPlan(uriMap.get(association.getPlanURI()));
}
updateReferences(association, uriMap);
}
for (Usage usage : activity.getUsages()) {
if (uriMap.get(usage.getEntityURI()) != null) {
usage.setEntity(uriMap.get(usage.getEntityURI()));
}
updateReferences(usage, uriMap);
}
}
for (Agent agent : getAgents()) {
updateReferences(agent, uriMap);
}
for (Plan plan : getPlans()) {
updateReferences(plan, uriMap);
}
}
use of org.sbolstandard.core2.Activity in project ORCID-Source by ORCID.
the class Api2_0_LastModifiedDatesHelper method calculateLastModified.
public static void calculateLastModified(ActivitiesContainer actContainerV2) {
if (actContainerV2 != null) {
Collection<? extends Activity> activities = actContainerV2.retrieveActivities();
if (activities != null && !activities.isEmpty()) {
Iterator<? extends Activity> activitiesIterator = activities.iterator();
XMLGregorianCalendar latest = activitiesIterator.next().getLastModifiedDate().getValue();
while (activitiesIterator.hasNext()) {
Activity activity = activitiesIterator.next();
if (latest.compare(activity.getLastModifiedDate().getValue()) == -1) {
latest = activity.getLastModifiedDate().getValue();
}
}
actContainerV2.setLastModifiedDate(new LastModifiedDate(latest));
}
}
}
Aggregations