-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing_queries.py
635 lines (412 loc) · 19.7 KB
/
testing_queries.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
import settings
import logging
import coloredlogs
from intermine.webservice import Service
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
coloredlogs.install(level='DEBUG')
logging.getLogger('intermine').setLevel(logging.INFO)
logging.getLogger('JSONIterator').setLevel(logging.INFO)
logging.getLogger('Model').setLevel(logging.INFO)
def assert_result(query_number, number_of_rows, expected_result, model):
try:
assert len(number_of_rows) == expected_result
logger.info('Query #' + query_number + ' ' + model + ' PASSED. Returned ' + str(len(number_of_rows)))
return 'Query #' + query_number + ' ' + model + ' PASSED. Returned ' + str(len(number_of_rows))
except Exception as e:
logger.info(str(e))
# settings.to_check.append(('query_' + str(query_number), model))
logger.warning('Query #' + query_number + ' ' + model + ' FAILED. Expected ' + str(expected_result) + ' returned ' + str(len(number_of_rows)))
return 'Query #' + query_number + ' ' + model + ' FAILED. Expected ' + str(expected_result) + ' returned ' + str(len(number_of_rows))
def assert_greater(query_number, number_of_rows, minimum, model):
try:
assert len(number_of_rows) >= minimum
logger.info('Query #' + query_number + ' ' + model + ' PASSED. Returned ' + str(len(number_of_rows)))
return 'Query #' + query_number + ' PASSED. Returned ' + str(len(number_of_rows))
except Exception as e:
logger.info(str(e))
# settings.to_check.append(('query_' + str(query_number), model))
logger.warning('Query #' + query_number + ' FAILED. Expected ' + str(minimum) + ' returned ' + str(len(number_of_rows)))
return 'Query #' + query_number + ' ' + model + ' FAILED. Expected ' + str(minimum) + ' returned ' + str(len(number_of_rows))
def save_txt_file(my_class, rows):
output_file = open('to_remove_' + my_class + '.txt', 'a+')
for row in rows:
output_file.write(row['primaryIdentifier'] + '\n')
output_file.close()
def query_01(service, save_file=False):
query = service.new_query('Gene')
query.add_view('primaryIdentifier', 'secondaryIdentifier', 'symbol', 'organism.name')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('primaryIdentifier', 'NOT LIKE', 'WBGene*', code='B')
if save_file:
save_txt_file('gene', query.rows())
logger.info('File saved')
return assert_result('01', query.rows(), 0, 'Gene')
def query_02(service, save_file=False):
query = service.new_query('Gene')
query.add_view('primaryIdentifier', 'secondaryIdentifier', 'symbol', 'organism.name')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('symbol', 'IS NULL', code='B')
if save_file:
save_txt_file('gene', query.rows())
logger.info('File saved')
return assert_result('02', query.rows(), 0, 'Gene')
def query_03(service, save_file=False):
query = service.new_query('Gene')
query.add_view('primaryIdentifier', 'secondaryIdentifier', 'symbol', 'organism.name')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('primaryIdentifier', 'IS NULL', code='B')
if save_file:
save_txt_file('gene', query.rows())
logger.info('File saved')
return assert_result('03', query.rows(), 0, 'Gene')
def query_04(service, save_file=False):
query = service.new_query('Transcript')
query.add_view('primaryIdentifier', 'symbol', 'organism.name')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('chromosome', 'IS NULL', code='B')
if save_file:
save_txt_file('transcript', query.rows())
logger.info('File saved')
return assert_result('04', query.rows(), 0, 'Transcript')
def query_05(service, save_file=False):
query = service.new_query('CDS')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('primaryIdentifier', 'CONTAINS', '2L52.1a', code='A')
if save_file:
save_txt_file('cds', query.rows())
logger.info('File saved')
return assert_result('05', query.rows(), 1, 'CDS')
def query_06(service, save_file=False):
query = service.new_query('Transcript')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('primaryIdentifier', 'CONTAINS', 'B0207.4', code='B')
query.add_constraint('symbol', 'CONTAINS', 'B0207.4', code='A')
query.set_logic('A or B')
if save_file:
save_txt_file('transcript', query.rows())
logger.info('File saved')
return assert_result('06', query.rows(), 2, 'Transcript')
def query_07(service, save_file=False):
query = service.new_query('Allele')
query.add_view('primaryIdentifier', 'gene.primaryIdentifier', 'gene.secondaryIdentifier')
query.add_constraint('primaryIdentifier', '=', 'WBVar01498288', code='A')
if save_file:
save_txt_file('allele', query.rows())
logger.info('File saved')
return assert_result('07', query.rows(), 76, 'Allele')
def query_08(service, save_file=False):
query = service.new_query('Gene')
query.add_view('primaryIdentifier', 'secondaryIdentifier', 'symbol')
query.add_constraint('secondaryIdentifier', 'CONTAINS', 'WBGene', code='A')
if save_file:
save_txt_file('gene', query.rows())
logger.info('File saved')
return assert_result('08', query.rows(), 0, 'Gene')
def query_09(service, save_file=False):
query = service.new_query('Gene')
query.add_view('primaryIdentifier', 'secondaryIdentifier', 'symbol')
query.add_constraint('symbol', 'CONTAINS', 'WBGene', code='A')
if save_file:
save_txt_file('gene', query.rows())
logger.info('File saved')
return assert_result('09', query.rows(), 0, 'Gene')
def query_10(service, save_file=False):
query = service.new_query('Transcript')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('primaryIdentifier', 'NOT LIKE', 'Transcript:*', code='A')
if save_file:
save_txt_file('transcript', query.rows())
logger.info('File saved')
return assert_result('10', query.rows(), 0, 'Transcript')
def query_11(service, save_file=False):
query = service.new_query('CDS')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('primaryIdentifier', 'NOT LIKE', 'CDS:*', code='A')
if save_file:
save_txt_file('cds', query.rows())
logger.info('File saved')
return assert_result('11', query.rows(), 0, 'CDS')
def query_12(service, save_file=False):
query = service.new_query('Gene')
query.add_view('primaryIdentifier', 'secondaryIdentifier', 'symbol')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('CDSs', 'IS NOT NULL', code='B')
if save_file:
save_txt_file('gene', query.rows())
logger.info('File saved')
return assert_greater('12', query.rows(), 19984, 'Gene')
def query_13(service, save_file=False):
query = service.new_query('CDS')
query.add_view('primaryIdentifier', 'symbol', 'sequence.length')
query.add_constraint('symbol', '=', 'ZC416.4', code='A')
for row in query.rows():
try:
assert (row['length'] >= 999)
return 'Query #13' + ' PASSED. Returned ' + str(row['length'])
except Exception as e:
logger.info(e)
return 'Query #13' + ' FAILED. Returned ' + str(row['length'])
def query_14(service, save_file=False):
query = service.new_query('Gene')
query.add_view('primaryIdentifier', 'secondaryIdentifier', 'symbol', 'length')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('length', 'IS NOT NULL', code='B')
if save_file:
save_txt_file('gene', query.rows())
logger.info('File saved')
return assert_greater('14', query.rows(), 46500, 'Gene')
def query_15(service, save_file=False):
query = service.new_query('Gene')
query.add_view('primaryIdentifier', 'secondaryIdentifier', 'symbol')
query.add_constraint('organism', 'IS NULL', code='A')
if save_file:
save_txt_file('gene', query.rows())
logger.info('File saved')
return assert_result('15', query.rows(), 0, 'Gene')
def query_16(service, save_file=False):
query = service.new_query('CDS')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('gene', 'IS NULL', code='B')
if save_file:
save_txt_file('cds', query.rows())
logger.info('File saved')
return assert_result('16', query.rows(), 0, 'CDS')
def query_17(service, save_file=False):
query = service.new_query('Transcript')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('gene', 'IS NULL', code='B')
if save_file:
save_txt_file('transcript', query.rows())
logger.info('File saved')
return assert_result('17', query.rows(), 0, 'Transcript')
def query_18(service, save_file=False):
query = service.new_query('CDS')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('protein', 'IS NULL', code='B')
if save_file:
save_txt_file('cds', query.rows())
logger.info('File saved')
return assert_result('18', query.rows(), 0, 'CDS')
def query_19(service, save_file=False):
query = service.new_query('CDS')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('transcripts', 'IS NULL', code='B')
if save_file:
save_txt_file('cds', query.rows())
logger.info('File saved')
return assert_result('19', query.rows(), 0, 'CDS')
def query_20(service, save_file=False):
query = service.new_query('Transcript')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('CDSs', 'IS NOT NULL', code='A')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='B')
if save_file:
save_txt_file('transcript', query.rows())
logger.info('File saved')
return assert_greater('20', query.rows(), 31000, 'Transcript')
def query_21(service, save_file=False):
query = service.new_query('Protein')
query.add_view('primaryAccession', 'primaryIdentifier', 'secondaryIdentifier', 'symbol')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('primaryAccession', 'NOT LIKE', 'CE*', code='B')
if save_file:
save_txt_file('protein', query.rows())
logger.info('File saved')
return assert_result('21', query.rows(), 0, 'Protein')
def query_22(service, save_file=False):
query = service.new_query('Protein')
query.add_view('primaryAccession', 'primaryIdentifier', 'secondaryIdentifier', 'symbol')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('primaryIdentifier', 'NOT LIKE', 'CE*', code='B')
if save_file:
save_txt_file('protein', query.rows())
logger.info('File saved')
return assert_result('22', query.rows(), 0, 'Protein')
def query_23(service, save_file=False):
query = service.new_query('Protein')
query.add_view('primaryAccession', 'primaryIdentifier', 'secondaryIdentifier', 'symbol')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('CDSs', 'IS NULL', code='B')
if save_file:
save_txt_file('protein', query.rows())
logger.info('File saved')
return assert_result('23', query.rows(), 0, 'Protein')
def query_24(service, save_file=False):
query = service.new_query('Protein')
query.add_view('primaryAccession', 'primaryIdentifier', 'secondaryIdentifier', 'symbol')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('sequence', 'IS NULL', code='B')
if save_file:
save_txt_file('protein', query.rows())
logger.info('File saved')
return assert_result('24', query.rows(), 0, 'Protein')
def query_25(service, save_file=False):
query = service.new_query('CDS')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('organism', 'IS NULL', code='A')
if save_file:
save_txt_file('cds', query.rows())
logger.info('File saved')
return assert_result('25', query.rows(), 0, 'CDS')
def query_26(service, save_file=False):
query = service.new_query('Transcript')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('organism', 'IS NULL', code='A')
if save_file:
save_txt_file('transcript', query.rows())
logger.info('File saved')
return assert_result('26', query.rows(), 0, 'Transcript')
def query_27(service, save_file=False):
query = service.new_query('Protein')
query.add_view('primaryAccession', 'primaryIdentifier', 'secondaryIdentifier', 'symbol')
query.add_sort_order('Protein.primaryIdentifier', 'ASC')
query.add_constraint('primaryIdentifier', 'IS NULL', code='A')
if save_file:
save_txt_file('protein', query.rows())
logger.info('File saved')
return assert_result('27', query.rows(), 0, 'Protein')
def query_28(service, save_file=False):
query = service.new_query('Allele')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('symbol', '=', 'e1370', code='A')
if save_file:
save_txt_file('allele', query.rows())
logger.info('File saved')
return assert_result('28', query.rows(), 1, 'Allele')
def query_29(service, save_file=False):
query = service.new_query('CDS')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('primaryIdentifier', 'LIKE', 'CDS:CDS:*', code='A')
if save_file:
save_txt_file('cds', query.rows())
logger.info('File saved')
return assert_result('29', query.rows(), 0, 'CDS')
def query_30(service, save_file=False):
query = service.new_query('MRNA')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
query.add_constraint('gene', 'IS NULL', code='B')
if save_file:
save_txt_file('mrna', query.rows())
logger.info('File saved')
return assert_result('30', query.rows(), 0, 'MRNA')
def query_31(service, save_file=False):
query = service.new_query('MRNA')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('organism', 'IS NULL', code='A')
if save_file:
save_txt_file('mrna', query.rows())
logger.info('File saved')
return assert_result('31', query.rows(), 0, 'MRNA')
def query_32(service, save_file=False):
query = service.new_query('MRNA')
query.add_view('primaryIdentifier', 'symbol')
query.add_constraint('CDSs', 'IS NULL', code='A')
if save_file:
save_txt_file('mrna', query.rows())
logger.info('File saved')
return assert_result('32', query.rows(), 0, 'MRNA')
def query_33(service, save_file=False):
query = service.new_query('Protein')
query.add_view('primaryIdentifier', 'CDSs.primaryIdentifier', 'CDSs.symbol')
query.add_constraint('primaryIdentifier', '=', 'CE46852', code='A')
if save_file:
save_txt_file('protein', query.rows())
logger.info('File saved')
return assert_result('33', query.rows(), 1, 'PROTEIN')
def query_34(service, save_file=False):
query = service.new_query('CDS')
query.add_view('primaryIdentifier', 'symbol', 'protein.primaryIdentifier')
query.add_constraint('protein.primaryIdentifier', '=', 'CE46852', code='A')
if save_file:
save_txt_file('cds', query.rows())
logger.info('File saved')
return assert_result('34', query.rows(), 1, 'CDS')
def query_35(service, save_file=False):
query = service.new_query('Organism')
query.add_view('name', 'taxonId')
query.add_constraint('name', 'IS NULL', code='A')
if save_file:
save_txt_file('organism', query.rows())
logger.info('File saved')
return assert_result('35', query.rows(), 0, 'Organism')
def query_36(service, save_file=False):
query = service.new_query('Organism')
query.add_view('name', 'taxonId')
print('Query #36')
result = {}
for row in query.rows():
result[row['name']] = row['taxonId']
to_return = 'Query #36<br>'
for i in result:
print('\t' + i + '\t' + str(result[i]))
to_return += ' ' + i + ' ' + str(result[i]) + '<br>'
return to_return
def query_37(service, save_file=False):
query = service.new_query('Chromosome')
query.add_view('primaryIdentifier', 'organism.name')
query.add_constraint('organism.name', '=', 'Caenorhabditis elegans', code='A')
print('Query #37')
result = {}
for row in query.rows():
result[row['primaryIdentifier']] = row['organism.name']
to_return = 'Query #37<br>'
for i in result:
try:
print('\t' + i + '\t' + str(result[i]))
to_return += ' ' + i + ' ' + str(result[i]) + '<br>'
except Exception as e:
logger.info(e)
print('\t' + i)
to_return += '\t' + i
return to_return
def query_38(service, save_file=False):
query = service.new_query('Allele')
query.add_view('primaryIdentifier', 'symbol', 'phenotype.identifier', 'phenotype.name')
query.add_constraint('primaryIdentifier', '=', 'WBVar00143949', code='A')
if save_file:
save_txt_file('allele', query.rows())
logger.info('File saved')
return assert_result('38', query.rows(), 94, 'Allele')
def query_39(service, save_file=False):
query = service.new_query('ExpressionPattern')
query.add_view('primaryIdentifier', 'genes.primaryIdentifier', 'genes.secondaryIdentifier', 'genes.symbol')
query.add_constraint('primaryIdentifier', '=', 'Expr3417', code='A')
if save_file:
save_txt_file('expression_pattern', query.rows())
logger.info('File saved')
return assert_result('39', query.rows(), 47, 'ExpressionPattern')
def query_40(service, save_file=False):
query = service.new_query('Gene')
query.add_view('primaryIdentifier', 'secondaryIdentifier', 'symbol', 'allele.primaryIdentifier', 'allele.symbol')
query.add_constraint('symbol', '=', 'cdk-4', code='A')
query.add_constraint('allele.primaryIdentifier', '=', 'WBVar02146689', code='B')
if save_file:
save_txt_file('gene', query.rows())
logger.info('File saved')
return assert_result('40', query.rows(), 1, 'Gene')
def query_41(service, save_file=False):
query = service.new_query('AnatomyTerm')
query.add_view('primaryIdentifier', 'name', 'synonym', 'definition')
query.add_constraint('definition', 'CONTAINS', 'CDATA', code='A')
if save_file:
save_txt_file('anatomy_term', query.rows())
logger.info('File saved')
return assert_result('41', query.rows(), 0, 'AnatomyTerm')
# print('\nTesting complete')
# print('These queries need to be checked: {0}'.format(', '.join(to_check)))
# if __name__ == '__main__':
# service = Service('http://im-dev1.wormbase.org/tools/wormmine/service')
# def inner():
# for x in dir(testing_queries):
# item = getattr(testing_queries, x)
# print(item)
# if callable(item):
# if not item.__name__ in ['assert_result', 'Service', 'assert_greater', 'save_txt_file']:
# time.sleep(1)
# print '%s<br/>\n' % item(service)