Mercurial > repos > nick > allele_counts
annotate tests/run-tests.py @ 9:6cc488e11544 draft
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
author | nick |
---|---|
date | Tue, 31 Mar 2020 05:09:12 -0400 |
parents | 411adeff1eec |
children |
rev | line source |
---|---|
9
6cc488e11544
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
nick
parents:
8
diff
changeset
|
1 #!/usr/bin/env python3 |
5 | 2 import os |
3 import sys | |
4 import subprocess | |
5 | |
8
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
6 SCRIPT_NAME = 'allele-counts.py' |
5 | 7 DATASETS = [ |
8 'artificial', | |
9 'artificial-samples', | |
10 'artificial-nofilt', | |
11 'real', | |
12 'real-mit', | |
13 'real-mit-s', | |
14 'real-nofilt', | |
15 ] | |
16 IN_EXT = '.vcf.in' | |
17 OUT_EXT = '.csv.out' | |
18 ARGS_KEY = '##comment="ARGS=' | |
19 | |
8
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
20 XML = { |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
21 'tests_start':' <tests>', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
22 'test_start': ' <test>', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
23 'input': ' <param name="input" value="tests/%s" />', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
24 'param': ' <param name="%s" value="%s" />', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
25 'output': ' <output name="output" file="tests/%s" />', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
26 'test_end': ' </test>', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
27 'tests_end': ' </tests>', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
28 } |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
29 PARAMS = { |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
30 '-f':'freq', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
31 '-c':'covg', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
32 '-H':'header', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
33 '-s':'stranded', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
34 '-n':'nofilt', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
35 '-r':'seed', |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
36 } |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
37 PARAM_ARG = { |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
38 '-f':True, |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
39 '-c':True, |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
40 '-H':False, |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
41 '-s':False, |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
42 '-n':False, |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
43 '-r':True, |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
44 } |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
45 |
5 | 46 def main(): |
47 | |
8
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
48 do_print_xml = False |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
49 if len(sys.argv) > 1: |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
50 if sys.argv[1] == '-x': |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
51 do_print_xml = True |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
52 else: |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
53 sys.stderr.write("Error: unrecognized option '"+sys.argv[1]+"'\n") |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
54 sys.exit(1) |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
55 |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
56 test_dir = os.path.dirname(os.path.realpath(__file__)) |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
57 script_dir = os.path.relpath(os.path.dirname(test_dir)) |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
58 test_dir = os.path.relpath(test_dir) |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
59 |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
60 if do_print_xml: |
9
6cc488e11544
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
nick
parents:
8
diff
changeset
|
61 print(XML.get('tests_start')) |
5 | 62 |
63 for dataset in DATASETS: | |
8
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
64 infile = os.path.join(test_dir, dataset+IN_EXT) |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
65 outfile = os.path.join(test_dir, dataset+OUT_EXT) |
5 | 66 |
67 if not os.path.exists(infile): | |
68 sys.stderr.write("Error: file not found: "+infile+"\n") | |
69 continue | |
70 if not os.path.exists(outfile): | |
71 sys.stderr.write("Error: file not found: "+outfile+"\n") | |
72 continue | |
73 | |
74 options = read_options(infile) | |
8
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
75 if do_print_xml: |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
76 print_xml(infile, outfile, options, XML, PARAMS, PARAM_ARG) |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
77 else: |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
78 run_tests(infile, outfile, options, script_dir) |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
79 |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
80 if do_print_xml: |
9
6cc488e11544
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
nick
parents:
8
diff
changeset
|
81 print(XML.get('tests_end')) |
8
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
82 |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
83 |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
84 def run_tests(infile, outfile, options, script_dir): |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
85 script_cmd = os.path.join(script_dir, SCRIPT_NAME)+' '+options+' -i '+infile |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
86 bash_cmd = 'diff '+outfile+' <('+script_cmd+')' |
9
6cc488e11544
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
nick
parents:
8
diff
changeset
|
87 print(script_cmd) |
8
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
88 subprocess.call(['bash', '-c', bash_cmd]) |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
89 |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
90 |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
91 def print_xml(infile, outfile, options_str, xml, params, param_arg): |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
92 infile = os.path.basename(infile) |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
93 outfile = os.path.basename(outfile) |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
94 |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
95 options = options_str.split() # on whitespace |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
96 |
9
6cc488e11544
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
nick
parents:
8
diff
changeset
|
97 print(xml.get('test_start')) |
6cc488e11544
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
nick
parents:
8
diff
changeset
|
98 print(xml.get('input') % infile) |
8
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
99 |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
100 # read in options one at a time, print <param> line |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
101 i = 0 |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
102 while i < len(options): |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
103 opt = options[i] |
9
6cc488e11544
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
nick
parents:
8
diff
changeset
|
104 if opt not in params or opt not in param_arg: |
6cc488e11544
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
nick
parents:
8
diff
changeset
|
105 sys.stderr.write("Error: unknown option '"+opt+"' in ARGS list in file "+infile+"\n") |
8
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
106 sys.exit(1) |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
107 # takes argument |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
108 if param_arg[opt]: |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
109 i+=1 |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
110 arg = options[i] |
9
6cc488e11544
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
nick
parents:
8
diff
changeset
|
111 print(xml.get('param') % (params[opt], arg)) |
8
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
112 # no argument (boolean) |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
113 else: |
9
6cc488e11544
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
nick
parents:
8
diff
changeset
|
114 print(xml.get('param') % (params[opt], 'true')) |
8
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
115 i+=1 |
411adeff1eec
Handle "." sample columns, update tests to work with BIAS column.
nick
parents:
5
diff
changeset
|
116 |
9
6cc488e11544
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
nick
parents:
8
diff
changeset
|
117 print(xml.get('output') % outfile) |
6cc488e11544
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
nick
parents:
8
diff
changeset
|
118 print(xml.get('test_end')) |
5 | 119 |
120 | |
121 def read_options(infile): | |
122 with open(infile, 'r') as infilehandle: | |
123 for line in infilehandle: | |
124 line.strip() | |
125 if ARGS_KEY == line[:len(ARGS_KEY)]: | |
126 return line[len(ARGS_KEY):-2] | |
127 return '' | |
128 | |
129 | |
130 if __name__ == '__main__': | |
131 main() |