001package org.biopax.paxtools.query.wrapperL3undirected;
002
003import org.biopax.paxtools.model.BioPAXElement;
004import org.biopax.paxtools.model.level3.*;
005import org.biopax.paxtools.query.model.AbstractNode;
006import org.biopax.paxtools.query.model.Edge;
007import org.biopax.paxtools.query.model.Graph;
008import org.biopax.paxtools.query.model.Node;
009
010/**
011 * Wrapper for Interaction class, excluding Control objects.
012 *
013 * @author Ozgun Babur
014 */
015public class InteractionWrapper extends EventWrapper
016{
017        /**
018         * Wrapped Interaction.
019         */
020        private Interaction interaction;
021
022        /**
023         * Constructor with the Interaction and the owner graph.
024         * @param interaction Interaction to wrap
025         * @param graph Owner graph
026         */
027        protected InteractionWrapper(Interaction interaction, GraphL3Undirected graph)
028        {
029                super(graph);
030
031                if (interaction instanceof Control) throw new IllegalArgumentException("Control objects " +
032                        "should be wrapped with ControlWrapper.");
033
034                this.interaction = interaction;
035        }
036
037        /**
038         * Binds to participants and controllers.
039         */
040        @Override
041        public void initUpstream()
042        {
043                for (Entity entity : interaction.getParticipant())
044                {
045                        addToUpstream(entity, getGraph());
046                }
047                for (Control control : interaction.getControlledOf())
048                {
049                        addToUpstream(control, getGraph());
050                }
051        }
052
053        /**
054         * Binds to participants and controllers.
055         */
056        @Override
057        public void initDownstream()
058        {
059                for (Entity entity : interaction.getParticipant())
060                {
061                        addToDownstream(entity, getGraph());
062                }
063                for (Control control : interaction.getControlledOf())
064                {
065                        addToDownstream(control, getGraph());
066                }
067        }
068
069        /**
070         * Being a transcription is not relevant in the undirected context.
071         * @return false
072         */
073        @Override
074        public boolean isTranscription()
075        {
076                return false;
077        }
078
079        /**
080         * Binds the given PhysicalEntity to the downstream.
081         * @param pe PhysicalEntity to bind
082         * @param graph Owner graph
083         */
084        protected void addToDownstream(BioPAXElement pe, Graph graph)
085        {
086                AbstractNode node = (AbstractNode) graph.getGraphObject(pe);
087
088                if (node != null)
089                {
090                        EdgeL3 edge = new EdgeL3(this, node, graph);
091                        edge.setTranscription(true);
092
093                        node.getUpstreamNoInit().add(edge);
094                        this.getDownstreamNoInit().add(edge);
095                }
096        }
097
098        /**
099         * Binds the given element to the upstream.
100         * @param ele Element to bind
101         * @param graph Owner graph
102         */
103        protected void addToUpstream(BioPAXElement ele, org.biopax.paxtools.query.model.Graph graph)
104        {
105                AbstractNode node = (AbstractNode) graph.getGraphObject(ele);
106                if (node != null)
107                {
108                        Edge edge = new EdgeL3(node, this, graph);
109
110                        node.getDownstreamNoInit().add(edge);
111                        this.getUpstreamNoInit().add(edge);
112                }
113        }
114
115        /**
116         * Uses RDF ID of TemplateReaction as key.
117         * @return RDF ID of TemplateReaction
118         */
119        public String getKey()
120        {
121                return interaction.getRDFId();
122        }
123
124        /**
125         * Gets the wrapped TemplateReaction
126         * @return The wrapped TemplateReaction
127         */
128        public Interaction getInteraction()
129        {
130                return interaction;
131        }
132}