comparison tools/mira3/mira.py @ 12:63ebe9726219 draft default tip

v0.0.11 move dependency to package_mira_3_4_1_1 etc
author peterjc
date Wed, 05 Aug 2015 11:28:05 -0400
parents a2fb1e67bd11
children
comparison
equal deleted inserted replaced
11:e59904c855ae 12:63ebe9726219
7 import shutil 7 import shutil
8 import time 8 import time
9 9
10 WRAPPER_VER = "0.0.5" #Keep in sync with the XML file 10 WRAPPER_VER = "0.0.5" #Keep in sync with the XML file
11 11
12 def stop_err(msg, err=1): 12 def sys_exit(msg, err=1):
13 sys.stderr.write(msg+"\n") 13 sys.stderr.write(msg+"\n")
14 sys.exit(err) 14 sys.exit(err)
15 15
16 16
17 def get_version(): 17 def get_version():
31 return ver.split("\n", 1)[0] 31 return ver.split("\n", 1)[0]
32 32
33 33
34 mira_ver = get_version() 34 mira_ver = get_version()
35 if "V3.4." not in mira_ver: 35 if "V3.4." not in mira_ver:
36 stop_err("This wrapper is for MIRA V3.4, not %s" % mira_ver) 36 sys_exit("This wrapper is for MIRA V3.4, not %s" % mira_ver)
37 if "-v" in sys.argv: 37 if "-v" in sys.argv:
38 print "MIRA wrapper version %s," % WRAPPER_VER 38 print "MIRA wrapper version %s," % WRAPPER_VER
39 print mira_ver 39 print mira_ver
40 sys.exit(0) 40 sys.exit(0)
41 41
42 42
43 def collect_output(temp, name): 43 def collect_output(temp, name):
44 n3 = (temp, name, name, name) 44 n3 = (temp, name, name, name)
45 f = "%s/%s_assembly/%s_d_results" % (temp, name, name) 45 f = "%s/%s_assembly/%s_d_results" % (temp, name, name)
46 if not os.path.isdir(f): 46 if not os.path.isdir(f):
47 stop_err("Missing output folder") 47 sys_exit("Missing output folder")
48 if not os.listdir(f): 48 if not os.listdir(f):
49 stop_err("Empty output folder") 49 sys_exit("Empty output folder")
50 missing = [] 50 missing = []
51 for old, new in [("%s/%s_out.unpadded.fasta" % (f, name), out_fasta), 51 for old, new in [("%s/%s_out.unpadded.fasta" % (f, name), out_fasta),
52 ("%s/%s_out.unpadded.fasta.qual" % (f, name), out_qual), 52 ("%s/%s_out.unpadded.fasta.qual" % (f, name), out_qual),
53 ("%s/%s_out.wig" % (f, name), out_wig), 53 ("%s/%s_out.wig" % (f, name), out_wig),
54 ("%s/%s_out.caf" % (f, name), out_caf), 54 ("%s/%s_out.caf" % (f, name), out_caf),
56 if not os.path.isfile(old): 56 if not os.path.isfile(old):
57 missing.append(os.path.splitext(old)[-1]) 57 missing.append(os.path.splitext(old)[-1])
58 else: 58 else:
59 shutil.move(old, new) 59 shutil.move(old, new)
60 if missing: 60 if missing:
61 stop_err("Missing output files: %s" % ", ".join(missing)) 61 sys_exit("Missing output files: %s" % ", ".join(missing))
62 62
63 def clean_up(temp, name): 63 def clean_up(temp, name):
64 folder = "%s/%s_assembly" % (temp, name) 64 folder = "%s/%s_assembly" % (temp, name)
65 if os.path.isdir(folder): 65 if os.path.isdir(folder):
66 shutil.rmtree(folder) 66 shutil.rmtree(folder)
110 if return_code: 110 if return_code:
111 handle.write("Return error code %i from command:\n" % return_code) 111 handle.write("Return error code %i from command:\n" % return_code)
112 handle.write(cmd + "\n") 112 handle.write(cmd + "\n")
113 handle.close() 113 handle.close()
114 clean_up(temp, name) 114 clean_up(temp, name)
115 stop_err("Return error code %i from command:\n%s" % (return_code, cmd), 115 sys_exit("Return error code %i from command:\n%s" % (return_code, cmd),
116 return_code) 116 return_code)
117 handle.close() 117 handle.close()
118 118
119 #print "Collecting output..." 119 #print "Collecting output..."
120 collect_output(temp, name) 120 collect_output(temp, name)