Mercurial > repos > nick > allele_counts_1
annotate tests/run-tests.py @ 21:1fc7bef38c5f draft default tip
"planemo upload for repository https://github.com/galaxyproject/dunovo commit ac9577f0047ad984b307fe2c4b40e2eb45a0e6e2-dirty"
| author | nick | 
|---|---|
| date | Fri, 03 Apr 2020 19:47:34 +0000 | 
| parents | 44c3abd1b767 | 
| children | 
| rev | line source | 
|---|---|
| 17 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 1 #!/usr/bin/env python3 | 
| 10 | 2 import os | 
| 3 import sys | |
| 4 import subprocess | |
| 5 | |
| 17 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 6 SCRIPT_NAME = 'allele-counts.py' | 
| 10 | 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 | |
| 17 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 20 XML = { | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 21 'tests_start':' <tests>', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 22 'test_start': ' <test>', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 23 'input': ' <param name="input" value="tests/%s" />', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 24 'param': ' <param name="%s" value="%s" />', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 25 'output': ' <output name="output" file="tests/%s" />', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 26 'test_end': ' </test>', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 27 'tests_end': ' </tests>', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 28 } | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 29 PARAMS = { | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 30 '-f':'freq', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 31 '-c':'covg', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 32 '-H':'header', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 33 '-s':'stranded', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 34 '-n':'nofilt', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 35 '-r':'seed', | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 36 } | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 37 PARAM_ARG = { | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 38 '-f':True, | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 39 '-c':True, | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 40 '-H':False, | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 41 '-s':False, | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 42 '-n':False, | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 43 '-r':True, | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 44 } | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 45 | 
| 10 | 46 def main(): | 
| 47 | |
| 17 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 48 do_print_xml = False | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 49 if len(sys.argv) > 1: | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 50 if sys.argv[1] == '-x': | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 51 do_print_xml = True | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 52 else: | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 53 sys.stderr.write("Error: unrecognized option '"+sys.argv[1]+"'\n") | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 54 sys.exit(1) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 55 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 56 test_dir = os.path.dirname(os.path.realpath(__file__)) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 57 script_dir = os.path.relpath(os.path.dirname(test_dir)) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 58 test_dir = os.path.relpath(test_dir) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 59 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 60 if do_print_xml: | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 61 print(XML.get('tests_start')) | 
| 10 | 62 | 
| 63 for dataset in DATASETS: | |
| 17 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 64 infile = os.path.join(test_dir, dataset+IN_EXT) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 65 outfile = os.path.join(test_dir, dataset+OUT_EXT) | 
| 10 | 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) | |
| 17 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 75 if do_print_xml: | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 76 print_xml(infile, outfile, options, XML, PARAMS, PARAM_ARG) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 77 else: | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 78 run_tests(infile, outfile, options, script_dir) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 79 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 80 if do_print_xml: | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 81 print(XML.get('tests_end')) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 82 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 83 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 84 def run_tests(infile, outfile, options, script_dir): | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 85 script_cmd = os.path.join(script_dir, SCRIPT_NAME)+' '+options+' -i '+infile | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 86 bash_cmd = 'diff '+outfile+' <('+script_cmd+')' | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 87 print(script_cmd) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 88 subprocess.call(['bash', '-c', bash_cmd]) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 89 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 90 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 91 def print_xml(infile, outfile, options_str, xml, params, param_arg): | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 92 infile = os.path.basename(infile) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 93 outfile = os.path.basename(outfile) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 94 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 95 options = options_str.split() # on whitespace | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 96 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 97 print(xml.get('test_start')) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 98 print(xml.get('input') % infile) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 99 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 100 # read in options one at a time, print <param> line | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 101 i = 0 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 102 while i < len(options): | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 103 opt = options[i] | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 104 if opt not in params or opt not in param_arg: | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 105 sys.stderr.write("Error: unknown option '"+opt+"' in ARGS list in file "+infile+"\n") | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 106 sys.exit(1) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 107 # takes argument | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 108 if param_arg[opt]: | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 109 i+=1 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 110 arg = options[i] | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 111 print(xml.get('param') % (params[opt], arg)) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 112 # no argument (boolean) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 113 else: | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 114 print(xml.get('param') % (params[opt], 'true')) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 115 i+=1 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 116 | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 117 print(xml.get('output') % outfile) | 
| 
44c3abd1b767
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
 nick parents: 
12diff
changeset | 118 print(xml.get('test_end')) | 
| 10 | 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() | 
