Debian Codegraph @

hmmer/easel/miniapps/esl-shuffle.itest.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # Integrated tests of esl-shuffle miniapp
4 #
5 # Usage: ./esl-shuffle.itest.py <builddir> <srcdir> <tmpfile_prefix>
6 # Example: ./esl-shuffle.itest.py .. .. tmpfoo
7 #
8 # SRE, Sat 07 Jul 2018 [Woodland Lodge, Titusville PA]
9 # supersedes esl-shuffle.itest.pl
10 #
11 import sys
12 import os
13 import subprocess
14
15 if len(sys.argv) != 4:
16 sys.exit('usage: esl-shuffle.itest.py <builddir> <srcdir> <tmppfx>')
17
18 builddir = sys.argv[1]
19 srcdir = sys.argv[2]
20 tmppfx = sys.argv[3]
21
22 if not os.path.isfile('{0}/miniapps/esl-shuffle'.format(builddir)):
23 sys.exit('FAIL: no esl-shuffle program in {0}'.format(builddir))
24 errmsg = 'FAIL: esl-shuffle.itest.py integration test failed'
25
26
27 # <tmppfx>.sto is a test alignment file
28 #
29 with open('{0}.sto'.format(tmppfx), 'w') as f:
30 print(
31 """# STOCKHOLM 1.0
32
33 seq1 ACDEFGHIKLMNPQRSTVWY
34 seq2 ACDEFGHIKLMNPQRSTVWY
35 seq3 ACDEFGHIKLMNPQRSTVWY
36 seq4 ACDEFGHIKLMNPQRSTVWY
37 seq5 ACDEFGHIKLMNPQRSTVWY
38 //
39 """, end='', file=f)
40
41 # <tmppfx>.fa is a test sequence file
42 with open('{0}.fa'.format(tmppfx), 'w') as f:
43 print(
44 """>seq1
45 ACDEFGHIKLMNPQRSTVWY
46 >seq2
47 ACACACACACACACACACAC
48 >seq3
49 WYWYWYWYWYWYWYWYWYWY
50 """, end='', file=f)
51
52
53 # Use of --seed makes shuffled outputs reproducible, regressable.
54 # Until you change the RNG again, anyway. If you do that, all these
55 # regressions need to change.
56 #
57 try:
58 output = subprocess.check_output([ '{}/miniapps/esl-shuffle'.format(builddir), '--seed', '42', '{}.fa'.format(tmppfx) ],
59 stderr=subprocess.STDOUT, universal_newlines=True)
60 except:
61 sys.exit(errmsg)
62
63 lines = output.splitlines()
64 if len(lines) != 6: sys.exit(errmsg)
65 if (lines[0] != '>seq1-shuffled' or
66 lines[1] != 'TIGEYHFWCKVSALQNPDRM' or
67 lines[2] != '>seq2-shuffled' or
68 lines[3] != 'CACAAAACCCACCAACAACC' or
69 lines[4] != '>seq3-shuffled' or
70 lines[5] != 'WWYYWWYWWYYWYYWYYWYW'): sys.exit(errmsg)
71
72 # We had bugs in the -N option at one point. This test exercises the
73 # bugs.
74 #
75 try:
76 output = subprocess.check_output([ '{}/miniapps/esl-shuffle'.format(builddir), '--seed', '42', '-N', '2', '{}.fa'.format(tmppfx) ],
77 stderr=subprocess.STDOUT, universal_newlines=True)
78 except:
79 sys.exit(errmsg)
80
81 lines = output.splitlines()
82 if len(lines) != 12: sys.exit(errmsg)
83 if (lines[2] != '>seq1-shuffled-1' or
84 lines[3] != 'NTEPDRFIQYKLCMWVHAGS'): sys.exit(errmsg);
85
86 # Easel iss #24 was a silly, untested failure of esl-shuffle -A
87 #
88 try:
89 output = subprocess.check_output([ '{}/miniapps/esl-shuffle'.format(builddir), '--seed', '42', '-A', '{}.sto'.format(tmppfx) ],
90 stderr=subprocess.STDOUT, universal_newlines=True)
91 except:
92 sys.exit(errmsg)
93
94 lines = output.splitlines()
95 if len(lines) != 9: sys.exit(errmsg)
96 if (lines[3] != 'seq1 TIGEYHFWCKVSALQNPDRM'): sys.exit(errmsg)
97
98 print('ok')
99
100 os.remove('{0}.sto'.format(tmppfx))
101 os.remove('{0}.fa'.format(tmppfx))
102 sys.exit(0)