Mercurial > repos > nick > allele_counts_1
comparison tests/run-tests.py @ 12:97b772e3a0f1
Uploaded tarball.
| author | nick |
|---|---|
| date | Tue, 10 Sep 2013 13:14:07 -0400 |
| parents | 566e42c97532 |
| children | 44c3abd1b767 |
comparison
equal
deleted
inserted
replaced
| 11:566e42c97532 | 12:97b772e3a0f1 |
|---|---|
| 14 ] | 14 ] |
| 15 IN_EXT = '.vcf.in' | 15 IN_EXT = '.vcf.in' |
| 16 OUT_EXT = '.csv.out' | 16 OUT_EXT = '.csv.out' |
| 17 ARGS_KEY = '##comment="ARGS=' | 17 ARGS_KEY = '##comment="ARGS=' |
| 18 | 18 |
| 19 XML = { | |
| 20 'tests_start':' <tests>', | |
| 21 'test_start': ' <test>', | |
| 22 'input': ' <param name="input" value="tests/%s" />', | |
| 23 'param': ' <param name="%s" value="%s" />', | |
| 24 'output': ' <output name="output" file="tests/%s" />', | |
| 25 'test_end': ' </test>', | |
| 26 'tests_end': ' </tests>', | |
| 27 } | |
| 28 PARAMS = { | |
| 29 '-f':'freq', | |
| 30 '-c':'covg', | |
| 31 '-H':'header', | |
| 32 '-s':'stranded', | |
| 33 '-n':'nofilt', | |
| 34 '-r':'seed', | |
| 35 } | |
| 36 PARAM_ARG = { | |
| 37 '-f':True, | |
| 38 '-c':True, | |
| 39 '-H':False, | |
| 40 '-s':False, | |
| 41 '-n':False, | |
| 42 '-r':True, | |
| 43 } | |
| 44 | |
| 45 def main(): | 19 def main(): |
| 46 | |
| 47 do_print_xml = False | |
| 48 if len(sys.argv) > 1: | |
| 49 if sys.argv[1] == '-x': | |
| 50 do_print_xml = True | |
| 51 else: | |
| 52 sys.stderr.write("Error: unrecognized option '"+sys.argv[1]+"'\n") | |
| 53 sys.exit(1) | |
| 54 | 20 |
| 55 test_dir = os.path.dirname(os.path.relpath(sys.argv[0])) | 21 test_dir = os.path.dirname(os.path.relpath(sys.argv[0])) |
| 56 if test_dir: | 22 if test_dir: |
| 57 test_dir += os.sep | 23 test_dir += os.sep |
| 58 | |
| 59 if do_print_xml: | |
| 60 print XML.get('tests_start') | |
| 61 | 24 |
| 62 for dataset in DATASETS: | 25 for dataset in DATASETS: |
| 63 infile = test_dir+dataset+IN_EXT | 26 infile = test_dir+dataset+IN_EXT |
| 64 outfile = test_dir+dataset+OUT_EXT | 27 outfile = test_dir+dataset+OUT_EXT |
| 65 | 28 |
| 69 if not os.path.exists(outfile): | 32 if not os.path.exists(outfile): |
| 70 sys.stderr.write("Error: file not found: "+outfile+"\n") | 33 sys.stderr.write("Error: file not found: "+outfile+"\n") |
| 71 continue | 34 continue |
| 72 | 35 |
| 73 options = read_options(infile) | 36 options = read_options(infile) |
| 74 if do_print_xml: | 37 script_cmd = 'allele-counts.py '+options+' -i '+infile |
| 75 print_xml(infile, outfile, options, XML, PARAMS, PARAM_ARG) | 38 bash_cmd = 'diff '+outfile+' <('+script_cmd+')' |
| 76 else: | 39 # print infile+":" |
| 77 run_tests(infile, outfile, options) | 40 print script_cmd |
| 78 | 41 subprocess.call(['bash', '-c', bash_cmd]) |
| 79 if do_print_xml: | |
| 80 print XML.get('tests_end') | |
| 81 | |
| 82 | |
| 83 def run_tests(infile, outfile, options): | |
| 84 script_cmd = 'allele-counts.py '+options+' -i '+infile | |
| 85 bash_cmd = 'diff '+outfile+' <('+script_cmd+')' | |
| 86 print script_cmd | |
| 87 subprocess.call(['bash', '-c', bash_cmd]) | |
| 88 | |
| 89 | |
| 90 def print_xml(infile, outfile, options_str, xml, params, param_arg): | |
| 91 infile = os.path.basename(infile) | |
| 92 outfile = os.path.basename(outfile) | |
| 93 | |
| 94 options = options_str.split() # on whitespace | |
| 95 | |
| 96 print xml.get('test_start') | |
| 97 print xml.get('input') % infile | |
| 98 | |
| 99 i = 0 | |
| 100 while i < len(options): | |
| 101 opt = options[i] | |
| 102 if not params.has_key(opt) or not param_arg.has_key(opt): | |
| 103 sys.stderr.write("Error: unknown option '"+opt+"' in ARGS list in file " | |
| 104 +infile+"\n") | |
| 105 sys.exit(1) | |
| 106 if param_arg[opt]: | |
| 107 i+=1 | |
| 108 arg = options[i] | |
| 109 print xml.get('param') % (params[opt], arg) | |
| 110 else: | |
| 111 print xml.get('param') % (params[opt], opt) | |
| 112 i+=1 | |
| 113 | |
| 114 print xml.get('output') % outfile | |
| 115 print xml.get('test_end') | |
| 116 | 42 |
| 117 | 43 |
| 118 def read_options(infile): | 44 def read_options(infile): |
| 119 with open(infile, 'r') as infilehandle: | 45 with open(infile, 'r') as infilehandle: |
| 120 for line in infilehandle: | 46 for line in infilehandle: |
