-
Notifications
You must be signed in to change notification settings - Fork 4
/
ContactNetworkNode.py
executable file
·281 lines (242 loc) · 6.8 KB
/
ContactNetworkNode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#! /usr/bin/env python3
'''
Niema Moshiri 2016
"ContactNetworkNode" module
'''
import abc
class ContactNetworkNode(metaclass=abc.ABCMeta):
'''
Abstract class defining a ``ContactNetworkNode'' object
Methods
-------
add_virus(virus)
Add ``virus'' to this ``ContactNetworkNode'' (NOT for infection, but for
viral evolution! Should be at current time)
cite()
Return citation string (or None)
get_attribute()
Return the attribute(s) of this ``ContactNetworkNode'' object
get_contact_network()
Return the ``ContactNetwork'' object this node is in
get_first_infection_time()
Returns the first time this node was infected (or None if never)
get_infections_from()
Return a list of infection(s) (this_node,v) as (time, v) tuples
get_infections_to()
Return a list of infection(s) (u,this_node) as (time, virus) tuples
get_name()
Return the name of this ``ContactNetworkNode'' object
infect(time, virus)
Infect this ``ContactNetworkNode'' object with ``virus'' at ``time''
init()
Initialize the module (if need be)
is_infected()
Return True if this node is infected, otherwise False
num_infections()
Return the number of infections
remove_virus(virus)
Remove ``virus'' from this ``ContactNetworkNode'' (should be at current
time)
uninfect()
Remove all viruses from this ``ContactNetworkNode''
viruses()
Iterate over the viruses that exist in this ``ContactNetworkNode''
object at the current time
'''
@staticmethod
@abc.abstractmethod
def init():
'''
Initialize the module (if need be)
'''
pass
@staticmethod
@abc.abstractmethod
def cite():
'''
Return citation string (or None)
Returns
-------
citation : str
The citation string (or None)
'''
pass
@abc.abstractmethod
def __eq__(self, other):
'''
Overridden equality check
'''
pass
@abc.abstractmethod
def __ne__(self, other):
'''
Overridden not equals check
'''
pass
@abc.abstractmethod
def __lt__(self, other):
'''
Overridden less than check
'''
pass
@abc.abstractmethod
def __gt__(self, other):
'''
Overridden greater than check
'''
pass
@abc.abstractmethod
def __le__(self, other):
'''
Overridden less than or equal to check
'''
pass
@abc.abstractmethod
def __ge__(self, other):
'''
Overridden greater than or equal to check
'''
pass
@abc.abstractmethod
def __hash__(self):
'''
Overridden hash function
'''
pass
@abc.abstractmethod
def __str__(self):
'''
Overridden string function
'''
pass
@abc.abstractmethod
def get_name(self):
'''
Return the name of this ``ContactNetworkNode'' object
Returns
-------
name : str
The name of this ``ContactNetworkNode'' object
'''
pass
@abc.abstractmethod
def get_attribute(self):
'''
Return the attribute(s) of this ``ContactNetworkNode'' object
Returns
-------
attribute : str
The attribute(s) of this ``ContactNetworkNode'' object
'''
pass
@abc.abstractmethod
def get_contact_network(self):
'''
Returns the ``ContactNetwork'' object this node is in
Returns
-------
contact_network : ContactNetwork
The ``ContactNetwork'' object this node is in
'''
pass
@abc.abstractmethod
def get_first_infection_time(self):
'''
Returns the first time this node was infected (or None if never)
Returns
-------
time : float
The first time this node was infected (or None if never)
'''
pass
@abc.abstractmethod
def get_infections_from(self):
'''
Return the infections from this ``ContactNetworkNode'' object. If
only one infection, the list will contain a single element.
Returns
-------
infections : list of (float, TreeNode) tuples
The infections of this ``ContactNetworkNode'' object as
(time, virus) tuples
'''
pass
@abc.abstractmethod
def get_infections_to(self):
'''
Return the infections to this ``ContactNetworkNode'' object. If
only one infection, the list will contain a single element.
Returns
-------
infections : list of (float, TreeNode) tuples
The infections of this ``ContactNetworkNode'' object as
(time, virus) tuples
'''
pass
@abc.abstractmethod
def num_infections(self):
'''
Return the number of infections of this ``ContactNetworkNode'' object.
Returns
-------
num_infections : int
The number of infections of this ``ContactNetworkNode'' object.
'''
pass
@abc.abstractmethod
def infect(self, time, sequence):
'''
Infect this ``ContactNetworkNode'' object with ``sequence'' at ``time''.
Will create the initial ``Tree'' for this infection as well.
Parameters
----------
time : float
The time of infection
sequence : str
The infecting virus sequence
'''
pass
@abc.abstractmethod
def is_infected(self):
'''
Return True if this node is infected, otherwise False
Returns
-------
infected : bool
True if this node is infected, otherwise False
'''
pass
@abc.abstractmethod
def add_virus(self, virus):
'''
Add ``virus'' to this ``ContactNetworkNode'' (NOT for infection, but for
viral evolution! Should be at current time)
Parameters
----------
virus : TreeNode
The virus to add to this node (should be at current time)
'''
pass
@abc.abstractmethod
def remove_virus(self, virus):
'''
Return ``virus'' from this node
Parameters
----------
virus : TreeNode
The virus to remove from this node (should be at current time)
'''
pass
@abc.abstractmethod
def uninfect(self):
'''
Remove all viruses from this ``ContactNetworkNode''
'''
pass
@abc.abstractmethod
def viruses(self):
'''
Iterate over the viruses that exist in this ``ContactNetworkNode''
object at the current time
'''
pass