Search in sources :

Example 1 with Participation

use of org.sbolstandard.core2.Participation in project libSBOLj by SynBioDex.

the class ModuleDefinitionOutput method createInverter.

private static void createInverter(SBOLDocument document, ModuleDefinition moduleDef, ComponentDefinition promoter, ComponentDefinition TF) throws Exception {
    FunctionalComponent laciInverterModuleDef_promoter = moduleDef.createFunctionalComponent("promoter", AccessType.PUBLIC, promoter.getIdentity(), DirectionType.INOUT);
    FunctionalComponent laciInverterModuleDef_TF = moduleDef.createFunctionalComponent("TF", AccessType.PUBLIC, TF.getIdentity(), DirectionType.INOUT);
    Interaction interaction = moduleDef.createInteraction("LacI_pLacI", new HashSet<URI>(Arrays.asList(toURI(Terms.interactionTypes.transcriptionalRepression))));
    Participation participation = interaction.createParticipation(promoter.getDisplayId(), laciInverterModuleDef_promoter.getIdentity(), toURI(Terms.participantRoles.promoter));
    Participation participation2 = interaction.createParticipation(TF.getDisplayId(), laciInverterModuleDef_TF.getIdentity(), toURI(Terms.participantRoles.inhibitor));
}
Also used : Participation(org.sbolstandard.core2.Participation) Interaction(org.sbolstandard.core2.Interaction) FunctionalComponent(org.sbolstandard.core2.FunctionalComponent) URI(java.net.URI)

Example 2 with Participation

use of org.sbolstandard.core2.Participation in project libSBOLj by SynBioDex.

the class InteractionTest method test_RoleAndParticpantMethods.

@Test
public void test_RoleAndParticpantMethods() throws SBOLValidationException {
    Interaction TetR_Interaction = TetRInverter_MD.createInteraction("TetR_Interaction", SystemsBiologyOntology.NON_COVALENT_BINDING);
    Participation TetR_part = TetR_Interaction.createParticipation("TetR", "TetR", SystemsBiologyOntology.PRODUCT);
    assertTrue(TetR_Interaction.containsType(SystemsBiologyOntology.NON_COVALENT_BINDING));
    assertTrue(TetR_Interaction.addType(SystemsBiologyOntology.ABSOLUTE_STIMULATION));
    assertTrue(TetR_Interaction.getTypes().size() == 2);
    assertTrue(TetR_Interaction.removeType(SystemsBiologyOntology.NON_COVALENT_BINDING));
    assertTrue(TetR_Interaction.getTypes().size() == 1);
    assertTrue(TetR_Interaction.getParticipation(TetR_part.getIdentity()).equals(TetR_part));
    assertTrue(TetR_Interaction.getParticipations().size() == 1);
    assertTrue(TetR_Interaction.removeParticipation(TetR_part));
    assertTrue(TetR_Interaction.getParticipations().size() == 0);
    assertFalse(TetR_Interaction.removeType(SystemsBiologyOntology.NON_COVALENT_BINDING));
}
Also used : Participation(org.sbolstandard.core2.Participation) Interaction(org.sbolstandard.core2.Interaction) Test(org.junit.Test)

Example 3 with Participation

use of org.sbolstandard.core2.Participation in project libSBOLj by SynBioDex.

the class ParticipationTest method test_ParticipantMethods.

@Test
public void test_ParticipantMethods() throws SBOLValidationException {
    TetR.addRole(SystemsBiologyOntology.INHIBITOR);
    Interaction TetR_Interaction = TetRInverter_MD.createInteraction("TetR_Interaction", SystemsBiologyOntology.NON_COVALENT_BINDING);
    Participation TetR_part = TetR_Interaction.createParticipation("TetR", "TetR", SystemsBiologyOntology.PRODUCT);
    assertTrue(TetR_Interaction.getParticipation("TetR").equals(TetR_part));
    assertTrue(TetR_part.addRole(SystemsBiologyOntology.COMPETITIVE_INHIBITOR));
    assertTrue(TetR_part.containsRole(SystemsBiologyOntology.COMPETITIVE_INHIBITOR));
    assertTrue(TetR_part.getRoles().size() == 2);
    assertTrue(TetR_part.removeRole(SystemsBiologyOntology.COMPETITIVE_INHIBITOR));
    assertFalse(TetR_part.containsRole(SystemsBiologyOntology.COMPETITIVE_INHIBITOR));
    assertTrue(TetR_part.getParticipantDefinition().getIdentity().equals(TetR.getIdentity()));
    assertTrue(TetR_part.getParticipant().getIdentity().equals(TetRInverter_MD.getFunctionalComponent("TetR").getIdentity()));
    assertNotNull(TetR_part);
}
Also used : Participation(org.sbolstandard.core2.Participation) Interaction(org.sbolstandard.core2.Interaction) Test(org.junit.Test)

Example 4 with Participation

use of org.sbolstandard.core2.Participation in project libSBOLj by SynBioDex.

the class SBOLReader method parseInteraction.

/**
 * @param interaction
 * @param nested
 * @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, 11605, 11902; or
 *</li>
 * <li>an SBOL validation rule violation occurred in the following constructor or methods:
 * 	<ul>
 * 		<li>{@link #parseParticipation(NestedDocument)},</li>
 * 		<li>{@link Interaction#Interaction(URI, Set)},</li>
 * 		<li>{@link Interaction#setParticipations(Set)}, </li>
 * 		<li>{@link Interaction#setDisplayId(String)}, </li>
 * 		<li>{@link Interaction#setVersion(String)}, </li>
 * 		<li>{@link Interaction#setWasDerivedFrom(URI)}, or</li>
 * 		<li>{@link Identified#setAnnotations(List)}. </li>
 * 	</ul>
 * </li>
 * </ul>
 */
private static Interaction parseInteraction(NestedDocument<QName> interaction, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(interaction.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(interaction.getIdentity()));
    URI persistentIdentity = null;
    String version = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    Set<URI> type = new HashSet<>();
    Set<Participation> participations = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : interaction.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", interaction.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", interaction.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", interaction.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Interaction.type)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-11902", interaction.getIdentity());
            }
            type.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Interaction.hasParticipations)) {
            if (namedProperty.getValue() instanceof NestedDocument) {
                NestedDocument<QName> nestedDocument = ((NestedDocument<QName>) namedProperty.getValue());
                if (nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.Participation.Participation)) {
                    throw new SBOLValidationException("sbol-11906", interaction.getIdentity());
                }
                participations.add(parseParticipation(((NestedDocument<QName>) namedProperty.getValue())));
            } 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.Participation.Participation)) {
                    throw new SBOLValidationException("sbol-11906", interaction.getIdentity());
                }
                participations.add(parseParticipation(nested.get(uri)));
            }
        } 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", interaction.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", interaction.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", interaction.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", interaction.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Interaction i = new Interaction(interaction.getIdentity(), type);
    if (!participations.isEmpty())
        i.setParticipations(participations);
    if (persistentIdentity != null)
        i.setPersistentIdentity(persistentIdentity);
    if (version != null)
        i.setVersion(version);
    if (displayId != null)
        i.setDisplayId(displayId);
    if (name != null)
        i.setName(name);
    if (description != null)
        i.setDescription(description);
    i.setWasDerivedFroms(wasDerivedFroms);
    i.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        i.setAnnotations(annotations);
    return i;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) NestedDocument(org.sbolstandard.core.datatree.NestedDocument) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 5 with Participation

use of org.sbolstandard.core2.Participation 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);
    }
}
Also used : URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI)

Aggregations

URI (java.net.URI)6 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)5 Interaction (org.sbolstandard.core2.Interaction)3 Participation (org.sbolstandard.core2.Participation)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 QName (javax.xml.namespace.QName)2 Test (org.junit.Test)2 Literal (org.sbolstandard.core.datatree.Literal)2 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)2 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)1 FunctionalComponent (org.sbolstandard.core2.FunctionalComponent)1