-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbar_utils.py
More file actions
286 lines (259 loc) · 8.2 KB
/
bar_utils.py
File metadata and controls
286 lines (259 loc) · 8.2 KB
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
282
283
284
285
286
import re
import redis
import os
class BARUtils:
@staticmethod
def error_exit(msg):
"""Exit if failed
:param msg: message to pass on failure
:return:
"""
result = {"wasSuccessful": False, "error": msg}
return result
@staticmethod
def success_exit(msg):
"""Output if success
:param msg: the actual data the needs to be output
:return:
"""
result = {"wasSuccessful": True, "data": msg}
return result
@staticmethod
def is_arabidopsis_gene_valid(gene):
"""This function verifies if Arabidopsis gene is valid
:param gene:
:return:
"""
if re.search(r"^At[12345cm]g\d{5}.?\d?$", gene, re.I):
return True
else:
return False
@staticmethod
def is_grape_gene_valid(gene):
"""This function verifies if grape gene is valid: VIT_00s0120g00060
:param gene:
:return:
"""
if re.search(r"^VIT_\d{0,3}\D\d{0,5}g\d{0,6}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_poplar_gene_valid(gene):
"""This function verifies if Poplar v3 gene is valid
:param gene:
:return: True if valid
"""
if re.search(r"^POTRI\.\d{3}g\d{6}.?\d{0,3}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_rice_gene_valid(gene, isoform_id=False):
"""This function verifies if rice gene is valid
:param gene:
:param isoform_id: True if you want to verifiy isoform ID
:return: True if valid
"""
if isoform_id and re.search(r"^LOC_Os\d{2}g\d{5}\.\d{1,2}$", gene, re.I):
return True
elif isoform_id is False and re.search(r"^LOC_Os\d{2}g\d{5}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_tomato_gene_valid(gene, isoform_id=False):
"""This function verifies if ITAG Solyc gene is valid
:param gene:
:param isoform_id: True if you want to verifiy isoform ID
:return: True if valid
"""
if isoform_id and re.search(r"^Solyc\d\dg\d{6}\.\d\.\d$", gene, re.I):
return True
elif isoform_id is False and re.search(r"^Solyc\d\dg\d{6}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_cannabis_gene_valid(gene):
"""This function verifies if cannabis gene is valid: AGQN03000001
:param gene:
:return: True if valid
"""
if gene and re.search(r"^AGQN\d{0,10}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_canola_gene_valid(gene):
"""This function verifies if canola gene (BnaC07g42830D) is valid
:param gene:
:return:
"""
if re.search(r"^Bna[AC]\d{2}g\d{5}[A-D]?$", gene, re.I):
return True
else:
return False
@staticmethod
def is_arachis_gene_valid(gene):
"""This function verifies if arachis gene is valid: Adur10000_comp0_c0_seq1
:param gene:
:return: True if valid
"""
if gene and re.search(r"^Adur\d{1,10}_comp\d{1,3}_\D{1,3}\d{1,3}_seq\d{1,5}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_brassica_rapa_gene_valid(gene):
"""This function verifies if Brassica rapa gene is valid: BraA01g000010
:param gene:
:return: True if valid
"""
if gene and re.search(r"^BraA.{1,4}g\d{1,9}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_soybean_gene_valid(gene):
"""This function verifies if soybean gene is valid: Glyma06g47400
:param gene:
:return: True if valid
"""
if gene and re.search(r"^((Glyma\d{1,3}g\d{1,6}\.?\d?)|(Glyma\.\d{1,3}g\d{1,8}))$", gene, re.I):
return True
else:
return False
@staticmethod
def is_maize_gene_valid(gene):
"""This function verifies if maize gene is valid: Zm00001d046170
:param gene:
:return: True if valid
"""
if gene and re.search(
r"^(AC[0-9]{6}\.[0-9]{1}_FG[0-9]{3})|(AC[0-9]{6}\.[0-9]{1}_FGT[0-9]{3})|(GRMZM(2|5)G[0-9]{6})|(GRMZM(2|5)G[0-9]{6}_T[0-9]{2})|(Zm\d+d\d+)$",
gene,
re.I,
):
return True
else:
return False
@staticmethod
def is_sorghum_gene_valid(gene):
"""This function verifies if Arabidopsis gene is valid
:param gene:
:return:
"""
if re.search(r"^(Sobic.\d{0,5}G\d{0,10}|Sobic.K\d{0,10})$", gene, re.I):
return True
else:
return False
@staticmethod
def is_kalanchoe_gene_valid(gene):
"""This function verifies if Kalanchoe gene is valid
:param gene:
:return:
"""
if re.search(r"^Kaladp\d{1,10}s\d{1,10}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_phelipanche_gene_valid(gene):
"""This function verifies if phelipanche gene (OrAeBC5_9992.10) is valid
:param gene:
:return:
"""
if re.search(r"^OrAeBC5_\d{1,6}\.\d{1,3}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_physcomitrella_gene_valid(gene):
"""This function verifies if physcomitrella gene (Pp1s9_70V6.1) is valid
:param gene:
:return:
"""
if re.search(r"^Pp1s\d{1,8}_\d{1,8}V6\.\d{1,3}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_selaginella_gene_valid(gene):
"""This function verifies if selaginella gene (Smo402070) is valid
:param gene:
:return:
"""
if re.search(r"^Smo\d{1,8}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_strawberry_gene_valid(gene):
"""This function verifies if strawberry gene (FvH4_1g00010) is valid
:param gene:
:return:
"""
if re.search(r"^FvH4_\d{1,3}g\d{1,8}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_striga_gene_valid(gene):
"""This function verifies if striga gene (StHeBC3_9993.10) is valid
:param gene:
:return:
"""
if re.search(r"^StHeBC3_\d{1,6}\.\d{1,5}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_triphysaria_gene_valid(gene):
"""This function verifies if triphysaria gene (TrVeBC3_9999.18) is valid
:param gene:
:return:
"""
if re.search(r"^TrVeBC3_\d{1,6}\.\d{1,3}$", gene, re.I):
return True
else:
return False
@staticmethod
def is_integer(data):
"""Check if the input is at max ten figure number.
:param data: int number
:return: True if a number
"""
if re.search(r"^\d{1,10}$", data):
return True
else:
return False
@staticmethod
def is_gaia_alias(data):
"""Check if the input is a valid gaia alias.
:param data
:return: True if valid gaia alias
"""
if re.search(r"^[a-z0-9_]{1,50}$", data, re.I):
return True
else:
return False
@staticmethod
def format_poplar(poplar_gene):
"""Format Poplar gene ID to be Potri.016G107900, i.e. capitalized P and G
:param poplar_gene: gene id
:return: String
"""
return poplar_gene.translate(str.maketrans("pOTRIg", "PotriG"))
@staticmethod
def connect_redis():
"""This function connects to redis
:returns: redis connection
"""
if os.environ.get("BAR"):
r = redis.Redis(
host=os.environ.get("BAR_REDIS_HOST"), port=6379, password=os.environ.get("BAR_REDIS_PASSWORD")
)
else:
r = redis.Redis(host="localhost")
return r