use of org.sbolstandard.core2.Location in project libSBOLj by SynBioDex.
the class SBOLDocument method updateReferences.
// TODO: need to update persistentIdentities too
private void updateReferences(URI originalIdentity, URI newIdentity) throws SBOLValidationException {
for (TopLevel topLevel : getTopLevels()) {
for (URI wasDerivedFrom : topLevel.getWasDerivedFroms()) {
if (wasDerivedFrom.equals(originalIdentity)) {
topLevel.removeWasDerivedFrom(originalIdentity);
topLevel.addWasDerivedFrom(newIdentity);
}
}
for (URI wasGeneratedBy : topLevel.getWasGeneratedBys()) {
if (wasGeneratedBy.equals(originalIdentity)) {
topLevel.removeWasGeneratedBy(originalIdentity);
topLevel.addWasGeneratedBy(newIdentity);
}
}
for (URI attachmentURI : topLevel.getAttachmentURIs()) {
if (attachmentURI.equals(originalIdentity)) {
topLevel.removeAttachment(originalIdentity);
topLevel.addAttachment(newIdentity);
}
}
}
for (Collection collection : getCollections()) {
for (URI memberURI : collection.getMemberURIs()) {
if (memberURI.equals(originalIdentity)) {
collection.removeMember(originalIdentity);
collection.addMember(newIdentity);
}
}
updateReferences(collection, originalIdentity, newIdentity);
}
for (ComponentDefinition componentDefinition : getComponentDefinitions()) {
updateReferences(componentDefinition, originalIdentity, newIdentity);
for (Component component : componentDefinition.getComponents()) {
if (component.getDefinitionURI().equals(originalIdentity)) {
component.setDefinition(newIdentity);
for (MapsTo mapsTo : component.getMapsTos()) {
ComponentDefinition cd = getComponentDefinition(newIdentity);
if (cd != null) {
String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
mapsTo.setRemote(newURI);
}
}
}
updateReferences(component, originalIdentity, newIdentity);
for (MapsTo mapsTo : component.getMapsTos()) {
updateReferences(mapsTo, originalIdentity, newIdentity);
}
}
for (SequenceAnnotation sa : componentDefinition.getSequenceAnnotations()) {
for (Location loc : sa.getLocations()) {
updateReferences(loc, originalIdentity, newIdentity);
}
updateReferences(sa, originalIdentity, newIdentity);
}
for (SequenceConstraint sc : componentDefinition.getSequenceConstraints()) {
updateReferences(sc, originalIdentity, newIdentity);
}
for (URI sequenceURI : componentDefinition.getSequenceURIs()) {
if (sequenceURI.equals(originalIdentity)) {
componentDefinition.removeSequence(originalIdentity);
componentDefinition.addSequence(newIdentity);
}
}
}
for (ModuleDefinition moduleDefinition : getModuleDefinitions()) {
updateReferences(moduleDefinition, originalIdentity, newIdentity);
for (FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
if (functionalComponent.getDefinitionURI().equals(originalIdentity)) {
functionalComponent.setDefinition(newIdentity);
for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
ComponentDefinition cd = getComponentDefinition(newIdentity);
if (cd != null) {
String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
mapsTo.setRemote(newURI);
}
}
}
updateReferences(functionalComponent, originalIdentity, newIdentity);
for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
updateReferences(mapsTo, originalIdentity, newIdentity);
}
}
for (Module module : moduleDefinition.getModules()) {
if (module.getDefinitionURI().equals(originalIdentity)) {
module.setDefinition(newIdentity);
for (MapsTo mapsTo : module.getMapsTos()) {
ModuleDefinition md = getModuleDefinition(newIdentity);
if (md != null) {
String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
URI newURI = URIcompliance.createCompliantURI(md.getPersistentIdentity().toString(), displayId, md.getVersion());
mapsTo.setRemote(newURI);
}
}
}
updateReferences(module, originalIdentity, newIdentity);
for (MapsTo mapsTo : module.getMapsTos()) {
updateReferences(mapsTo, originalIdentity, newIdentity);
}
}
for (Interaction interaction : moduleDefinition.getInteractions()) {
updateReferences(interaction, originalIdentity, newIdentity);
for (Participation participation : interaction.getParticipations()) {
updateReferences(participation, originalIdentity, newIdentity);
}
}
for (URI modelURI : moduleDefinition.getModelURIs()) {
if (modelURI.equals(originalIdentity)) {
moduleDefinition.removeModel(originalIdentity);
moduleDefinition.addModel(newIdentity);
}
}
}
for (Model model : getModels()) {
updateReferences(model, originalIdentity, newIdentity);
}
for (Attachment attachment : getAttachments()) {
updateReferences(attachment, originalIdentity, newIdentity);
}
for (Implementation implementation : getImplementations()) {
if (implementation.isSetBuilt() && implementation.getBuiltURI().equals(originalIdentity)) {
implementation.setBuilt(newIdentity);
}
updateReferences(implementation, originalIdentity, newIdentity);
}
for (Sequence sequence : getSequences()) {
updateReferences(sequence, originalIdentity, newIdentity);
}
for (GenericTopLevel genericTopLevel : getGenericTopLevels()) {
updateReferences(genericTopLevel, originalIdentity, newIdentity);
}
for (CombinatorialDerivation combinatorialDerivation : getCombinatorialDerivations()) {
updateReferences(combinatorialDerivation, originalIdentity, newIdentity);
if (combinatorialDerivation.getTemplateURI().equals(originalIdentity)) {
combinatorialDerivation.setTemplate(newIdentity);
ComponentDefinition cd = getComponentDefinition(newIdentity);
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, originalIdentity, newIdentity);
}
}
for (Activity activity : getActivities()) {
updateReferences(activity, originalIdentity, newIdentity);
for (Association association : activity.getAssociations()) {
if (association.getAgentURI().equals(originalIdentity)) {
association.setAgent(newIdentity);
}
if (association.isSetPlan() && association.getPlanURI().equals(originalIdentity)) {
association.setPlan(newIdentity);
}
updateReferences(association, originalIdentity, newIdentity);
}
for (Usage usage : activity.getUsages()) {
if (usage.getEntityURI().equals(originalIdentity)) {
usage.setEntity(newIdentity);
}
updateReferences(usage, originalIdentity, newIdentity);
}
}
for (Agent agent : getAgents()) {
updateReferences(agent, originalIdentity, newIdentity);
}
for (Plan plan : getPlans()) {
updateReferences(plan, originalIdentity, newIdentity);
}
}
use of org.sbolstandard.core2.Location in project libSBOLj by SynBioDex.
the class ModuleDefinitionOutput method addSubComponents.
private static void addSubComponents(SBOLDocument document, ComponentDefinition componentDef, List<ComponentDefinition> subComponents) throws Exception {
int i = 1;
int start = 0;
int end = 0;
for (ComponentDefinition subComponent : subComponents) {
Component component = componentDef.createComponent(subComponent.getDisplayId(), AccessType.PUBLIC, subComponent.getIdentity());
start = end + 1;
end = start + getSequenceLength(document, subComponent);
SequenceAnnotation annotation = componentDef.createSequenceAnnotation("anno" + i, "location" + i, start, end, OrientationType.INLINE);
annotation.setComponent(component.getIdentity());
i++;
}
}
use of org.sbolstandard.core2.Location in project libSBOLj by SynBioDex.
the class SequenceAnnotationTest method test_locationMethods.
@Test
public void test_locationMethods() throws SBOLValidationException {
Cut promoter_cut = promoter_SA.addCut("promoter_cut", 1);
assertTrue(gRNA_b_gene.getSequenceAnnotation("promoter_SA").getLocation("promoter_cut").equals(promoter_cut));
promoter_cut.unsetOrientation();
assertNull(promoter_cut.getOrientation());
Location test = promoter_cut;
assertNotNull(test.toString());
Cut terminator_cut = terminator_SA.addCut("terminator_cut", 100);
assertTrue(gRNA_b_gene.getSequenceAnnotation("terminator_SA").getLocation("terminator_cut").equals(terminator_cut));
Cut gene_cut = gene_SA.addCut("gene_cut", 50, OrientationType.INLINE);
assertTrue(gRNA_b_gene.getSequenceAnnotation("gene_SA").getLocation("gene_cut").equals(gene_cut));
gene_SA.removeLocation(gene_cut);
assertNull(gene_SA.getLocation("gene_cut"));
Range gene_range = gene_SA.addRange("gene_range", 50, 99);
assertTrue(gRNA_b_gene.getSequenceAnnotation("gene_SA").getLocation("gene_range").equals(gene_range));
gene_range.unsetOrientation();
assertNull(gene_range.getOrientation());
promoter_SA.removeLocation(promoter_cut);
assertNull(promoter_SA.getLocation(promoter_cut.getIdentity()));
GenericLocation promoter_glocation = promoter_SA.addGenericLocation("promoter_glocation");
assertTrue(gRNA_b_gene.getSequenceAnnotation("promoter_SA").getLocation("promoter_glocation").equals(promoter_glocation));
terminator_SA.removeLocation(terminator_cut);
assertNull(terminator_SA.getLocation("terminator_cut"));
GenericLocation terminator_glocation = terminator_SA.addGenericLocation("terminator_glocation", OrientationType.INLINE);
assertTrue(gRNA_b_gene.getSequenceAnnotation("terminator_SA").getLocation("terminator_glocation").equals(terminator_glocation));
}
use of org.sbolstandard.core2.Location in project libSBOLj by SynBioDex.
the class SequenceAnnotationTest method test_LocToString.
/*
*
* move to Location Test class
*/
@Test
public void test_LocToString() throws SBOLValidationException {
Location test = promoter_SA.addGenericLocation("promoter_cut");
assertTrue(test.toString().length() != 0);
assertNotNull(test.toString());
assertTrue(test.toString().contains("identity="));
assertTrue(test.toString().contains("displayId="));
assertTrue(!test.toString().contains("description="));
assertTrue(!test.toString().contains("orientation="));
assertTrue(!test.toString().contains("name="));
}
use of org.sbolstandard.core2.Location in project libSBOLj by SynBioDex.
the class SequenceAnnotation method addGenericLocation.
/**
* Creates a generic location 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 generic location 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 generic location to be created
* @param orientation the orientation type
* @return the created generic location instance
* @throws SBOLValidationException if any of the following SBOL validation rules was violated:
* 10201, 10202, 10204, 10206.
*/
public GenericLocation addGenericLocation(String displayId, OrientationType orientation) throws SBOLValidationException {
URI identity = createCompliantURI(this.getPersistentIdentity().toString(), displayId, this.getVersion());
GenericLocation genericLocation = new GenericLocation(identity);
genericLocation.setPersistentIdentity(createCompliantURI(this.getPersistentIdentity().toString(), displayId, ""));
genericLocation.setDisplayId(displayId);
genericLocation.setVersion(this.getVersion());
genericLocation.setOrientation(orientation);
addLocation(genericLocation);
return genericLocation;
}
Aggregations