comparison tools/mira3/mira.py @ 22:a5a3460fafa6 draft

planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira3/ commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
author peterjc
date Wed, 10 Feb 2016 09:07:29 -0500
parents f74bc0420db4
children 83a94a5038a7
comparison
equal deleted inserted replaced
21:fc18dbea2963 22:a5a3460fafa6
6 import subprocess 6 import subprocess
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
12 def sys_exit(msg, err=1):
13 sys.stderr.write(msg+"\n")
14 sys.exit(err)
15 11
16 12
17 def get_version(): 13 def get_version():
18 """Run MIRA to find its version number""" 14 """Run MIRA to find its version number"""
19 # At the commend line I would use: mira -v | head -n 1 15 # At the commend line I would use: mira -v | head -n 1
31 return ver.split("\n", 1)[0] 27 return ver.split("\n", 1)[0]
32 28
33 29
34 mira_ver = get_version() 30 mira_ver = get_version()
35 if "V3.4." not in mira_ver: 31 if "V3.4." not in mira_ver:
36 sys_exit("This wrapper is for MIRA V3.4, not %s" % mira_ver) 32 sys.exit("This wrapper is for MIRA V3.4, not %s" % mira_ver)
37 if "-v" in sys.argv: 33 if "-v" in sys.argv:
38 print "MIRA wrapper version %s," % WRAPPER_VER 34 print "MIRA wrapper version %s," % WRAPPER_VER
39 print mira_ver 35 print mira_ver
40 sys.exit(0) 36 sys.exit(0)
41 37
42 38
43 def collect_output(temp, name): 39 def collect_output(temp, name):
44 n3 = (temp, name, name, name) 40 n3 = (temp, name, name, name)
45 f = "%s/%s_assembly/%s_d_results" % (temp, name, name) 41 f = "%s/%s_assembly/%s_d_results" % (temp, name, name)
46 if not os.path.isdir(f): 42 if not os.path.isdir(f):
47 sys_exit("Missing output folder") 43 sys.exit("Missing output folder")
48 if not os.listdir(f): 44 if not os.listdir(f):
49 sys_exit("Empty output folder") 45 sys.exit("Empty output folder")
50 missing = [] 46 missing = []
51 for old, new in [("%s/%s_out.unpadded.fasta" % (f, name), out_fasta), 47 for old, new in [("%s/%s_out.unpadded.fasta" % (f, name), out_fasta),
52 ("%s/%s_out.unpadded.fasta.qual" % (f, name), out_qual), 48 ("%s/%s_out.unpadded.fasta.qual" % (f, name), out_qual),
53 ("%s/%s_out.wig" % (f, name), out_wig), 49 ("%s/%s_out.wig" % (f, name), out_wig),
54 ("%s/%s_out.caf" % (f, name), out_caf), 50 ("%s/%s_out.caf" % (f, name), out_caf),
56 if not os.path.isfile(old): 52 if not os.path.isfile(old):
57 missing.append(os.path.splitext(old)[-1]) 53 missing.append(os.path.splitext(old)[-1])
58 else: 54 else:
59 shutil.move(old, new) 55 shutil.move(old, new)
60 if missing: 56 if missing:
61 sys_exit("Missing output files: %s" % ", ".join(missing)) 57 sys.exit("Missing output files: %s" % ", ".join(missing))
62 58
63 def clean_up(temp, name): 59 def clean_up(temp, name):
64 folder = "%s/%s_assembly" % (temp, name) 60 folder = "%s/%s_assembly" % (temp, name)
65 if os.path.isdir(folder): 61 if os.path.isdir(folder):
66 shutil.rmtree(folder) 62 shutil.rmtree(folder)
110 if return_code: 106 if return_code:
111 handle.write("Return error code %i from command:\n" % return_code) 107 handle.write("Return error code %i from command:\n" % return_code)
112 handle.write(cmd + "\n") 108 handle.write(cmd + "\n")
113 handle.close() 109 handle.close()
114 clean_up(temp, name) 110 clean_up(temp, name)
115 sys_exit("Return error code %i from command:\n%s" % (return_code, cmd), 111 sys.stderr.write("Return error code %i from command:\n" % return_code)
116 return_code) 112 sys.stderr.write(cmd + "\n")
113 sys.exit(return_code)
117 handle.close() 114 handle.close()
118 115
119 #print "Collecting output..." 116 #print "Collecting output..."
120 collect_output(temp, name) 117 collect_output(temp, name)
121 118