001package org.biopax.paxtools.query.wrapperL3undirected; 002 003import org.biopax.paxtools.model.BioPAXElement; 004import org.biopax.paxtools.model.level3.*; 005import org.biopax.paxtools.model.level3.Process; 006import org.biopax.paxtools.query.model.AbstractNode; 007import org.biopax.paxtools.query.model.Edge; 008import org.biopax.paxtools.query.model.Graph; 009import org.biopax.paxtools.query.model.Node; 010 011import java.util.Collection; 012import java.util.Collections; 013 014/** 015 * Wrapper for the Control class. 016 * 017 * @author Ozgun Babur 018 */ 019public class ControlWrapper extends AbstractNode 020{ 021 /** 022 * Wrapped control. 023 */ 024 protected Control ctrl; 025 026 /** 027 * Sign of the control. 028 */ 029 protected int sign; 030 031 /** 032 * Flag to indicate if this control is related to a transcription. 033 */ 034 protected boolean transcription; 035 036 /** 037 * Constructor with the Control and the owner graph. 038 * @param ctrl Control to be wrapped 039 * @param graph Owner graph 040 */ 041 protected ControlWrapper(Control ctrl, Graph graph) 042 { 043 super(graph); 044 this.ctrl = ctrl; 045 this.transcription = false; 046 } 047 048 /** 049 * Control is not a breadth node. 050 * @return False 051 */ 052 public boolean isBreadthNode() 053 { 054 return false; 055 } 056 057 /** 058 * @return Sign of the Control 059 */ 060 public int getSign() 061 { 062 return sign; 063 } 064 065 /** 066 * Controls are not ubiquitous molecules. 067 * @return False 068 */ 069 public boolean isUbique() 070 { 071 return false; 072 } 073 074 /** 075 * RDF ID of the Control is its key. 076 * @return Key 077 */ 078 public String getKey() 079 { 080 return ctrl.getRDFId(); 081 } 082 083 /** 084 * Extracts the sign and the type of the Control. 085 */ 086 @Override 087 public void init() 088 { 089 ControlType type = ctrl.getControlType(); 090 091 if (type != null && type.toString().startsWith("I")) 092 { 093 sign = NEGATIVE; 094 } 095 else 096 { 097 sign = POSITIVE; 098 } 099 100 if (ctrl instanceof TemplateReactionRegulation) 101 transcription = true; 102 } 103 104 /** 105 * Puts the wrapper of the parameter element to the upstream of this Control. 106 * @param element to put at upstream 107 */ 108 private void bindUpstream(BioPAXElement element) 109 { 110 AbstractNode node = (AbstractNode) graph.getGraphObject(element); 111 112 if (node != null) 113 { 114 Edge edge = new EdgeL3(node, this, graph); 115 node.getDownstreamNoInit().add(edge); 116 this.getUpstreamNoInit().add(edge); 117 } 118 } 119 120 /** 121 * Puts the wrapper of the parameter element to the upstream of this Control. 122 * @param element to put at upstream 123 */ 124 private void bindDownstream(BioPAXElement element) 125 { 126 AbstractNode node = (AbstractNode) graph.getGraphObject(element); 127 128 if (node != null) 129 { 130 Edge edge = new EdgeL3(this, node, graph); 131 this.getDownstreamNoInit().add(edge); 132 node.getUpstreamNoInit().add(edge); 133 } 134 } 135 136 /** 137 * Binds the controller and other Controls that controls this control. 138 */ 139 @Override 140 public void initUpstream() 141 { 142 for (Controller controller : ctrl.getController()) 143 { 144 if (controller instanceof Pathway) continue; 145 146 PhysicalEntity pe = (PhysicalEntity) controller; 147 bindUpstream(pe); 148 } 149 150 for (Control control : ctrl.getControlledOf()) 151 { 152 bindUpstream(control); 153 } 154 155 for (Process prc : ctrl.getControlled()) 156 { 157 if (prc instanceof Interaction) 158 { 159 bindUpstream(prc); 160 } 161 } 162 } 163 164 /** 165 * Binds the controlled objects. 166 */ 167 @Override 168 public void initDownstream() 169 { 170 for (Controller controller : ctrl.getController()) 171 { 172 if (controller instanceof Pathway) continue; 173 174 PhysicalEntity pe = (PhysicalEntity) controller; 175 bindDownstream(pe); 176 } 177 178 for (Control control : ctrl.getControlledOf()) 179 { 180 bindDownstream(control); 181 } 182 183 for (Process prc : ctrl.getControlled()) 184 { 185 if (prc instanceof Interaction) 186 { 187 bindDownstream(prc); 188 } 189 } 190 } 191 192 /** 193 * Gets the wrapped Control. 194 * @return The Control 195 */ 196 public Control getControl() 197 { 198 return ctrl; 199 } 200 201 /** 202 * Control cannot have an equivalent. 203 * @return Empty set 204 */ 205 @Override 206 public Collection<Node> getUpperEquivalent() 207 { 208 return Collections.emptySet(); 209 } 210 211 /** 212 * Control cannot have an equivalent. 213 * @return Empty set 214 */ 215 @Override 216 public Collection<Node> getLowerEquivalent() 217 { 218 return Collections.emptySet(); 219 } 220 221 /** 222 * @return whether this Control is related to a transcription event 223 */ 224 public boolean isTranscription() 225 { 226 return transcription; 227 } 228 229 /** 230 * Make or not make this control related to a transcription. 231 * @param transcription whether this Control is related to a transcription 232 */ 233 public void setTranscription(boolean transcription) 234 { 235 this.transcription = transcription; 236 } 237}