1 """@namespace IMP.spatiotemporal.graphNode
2 Defines the graphNode class. Each node corresponds to a snapshot model.
3 Nodes can be connected to create spatiotemporal models.
10 """A class to represent a node in a spatiotemporal process.
12 Each graphNode contains a list of it's component subcoplexes,
13 an array of scores, a time index and a list of pointers to nodes
14 to which edges coming from this node point.
27 self._expected_subcomplexes = []
30 """String representation of a graphNode
32 return (
"graphNode(" +
",".join([str(self._time), str(self._label)])
36 expected_subcomplexes):
37 """Function that initiates a graph node with specific time, label,
38 and expected_subcomplexes. Scores and components are extracted from
39 files named scorestr and subcomplexstr respectively. Returns a single
42 @param time: string, time point in the stepwise temporal process
43 @param label: string, a number label for the graphNode
44 @param scorestr: string, trailing characters at the end of the file
45 with scores for each stage of the spatiotemporal model
46 @param subcomplexstr: string, trailing characters after the subcomplex
47 file, which is a list of subcomplexes included in the given
49 @param expected_subcomplexes: list of all possible subcomplex strings
60 scores_fn = label +
'_' + time + scorestr
61 if os.path.exists(scores_fn):
62 scores = np.loadtxt(scores_fn)
64 raise Exception(
"Error!!! Unable to find scores file: "
65 + scores_fn +
'\nClosing...')
68 if len(expected_subcomplexes) > 0:
69 with open(label +
'_' + time + subcomplexstr,
"r") as fh:
70 included_prots = fh.read().splitlines()
73 included_prots, label + '_' + time + subcomplexstr)
77 """Set an index to label node's identity.
82 """Return the node's index.
88 """Set an index to label node's identity.
93 """Return the node's index.
98 """Return the weight of the node. A weight refers in this case to the
99 sum score of the scores list.
101 return sum(self._scores)
104 """Return a list of subcomplexes in this node's representation.
106 return self._components
109 """Set the list of subcomplex components.
111 Should be one of the standard used components.
114 if sc
not in self._expected_subcomplexes:
115 raise Exception(
"Error!!! Did not recognize the subcomplex "
116 "name " + sc +
" from config file: " + fn)
118 self._components = scs
121 """Set the list of possible subcomplex components.
122 Should include all possible components across the entire
125 self._expected_subcomplexes = expected_subcomplexes
128 """Add a directed edge to the node.
130 Expects a graphNode object.
133 if not isinstance(edge, graphNode):
134 raise TypeError(
"Object " + str(edge) +
" is not a graphNode")
137 self._edges.add(edge)
140 """Return the list of edges for this node.
150 """Return the time associated with this node.
155 """Set the score data for this node.
157 Expects an list of floats which represent the total score array.
159 self._scores = scores
162 """Update the score list by appending score.
165 if not isinstance(score, float):
166 raise TypeError(
"add_score expects a float but got a "
169 self._scores.append(score)
172 """Return the scores array.
177 def draw_edge(nodeA, nodeB, spatio_temporal_rule):
179 Draws an edge between graphNode objects nodeA and nodeB. If
180 spatio_temporal_rule, node will only be drawn if the components of nodeA
181 are a subset of the components of nodeB.
182 If spatio_temporal_rule: determines if an edge should be drawn if Node A
183 comes immediately before node B in time and if node B contains node A's
184 components as a subset.
185 Else: draws an edge between nodeA and nodeB regardless.
187 @param nodeA: first graphNode object
188 @param nodeB: second graphNode object
189 @param spatio_temporal_rule: Boolean, whether to consider composition
194 assert isinstance(nodeA, graphNode), str(nodeA) +
" is not a graphNode."
195 assert isinstance(nodeB, graphNode), str(nodeB) +
" is not a graphNode."
198 if spatio_temporal_rule:
199 if frozenset(nodeA.get_subcomplex_components()).issubset(
200 set(nodeB.get_subcomplex_components())):
201 nodeA.add_edge(nodeB)
203 nodeA.add_edge(nodeB)
def set_scores
Set the score data for this node.
def get_edges
Return the list of edges for this node.
def get_index
Return the node's index.
def init_graphNode
Function that initiates a graph node with specific time, label, and expected_subcomplexes.
def set_subcomplex_components
Set the list of subcomplex components.
def __repr__
String representation of a graphNode.
def get_subcomplex_components
Return a list of subcomplexes in this node's representation.
def set_label
Set an index to label node's identity.
def add_score
Update the score list by appending score.
def set_expected_subcomplexes
Set the list of possible subcomplex components.
def get_scores
Return the scores array.
def add_edge
Add a directed edge to the node.
def set_index
Set an index to label node's identity.
def get_weight
Return the weight of the node.
def get_label
Return the node's index.
def get_time
Return the time associated with this node.
The general base class for IMP exceptions.
def set_time
Set the time.
def draw_edge
Draws an edge between graphNode objects nodeA and nodeB.
def __init__
Initialize a node.