annotate tools/mira4/mira4.py @ 4:df86ed992a1b draft

Uploaded preview 4, lots of work on mapping
author peterjc
date Fri, 11 Oct 2013 04:28:45 -0400
parents 32f693f6e741
children ffefb87bd414
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
1 #!/usr/bin/env python
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
2 """A simple wrapper script to call MIRA and collect its output.
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
3 """
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
4 import os
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
5 import sys
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
6 import subprocess
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
7 import shutil
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
8 import time
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
9
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
10 WRAPPER_VER = "0.0.1" #Keep in sync with the XML file
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
11
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
12 def stop_err(msg, err=1):
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
13 sys.stderr.write(msg+"\n")
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
14 sys.exit(err)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
15
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
16
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
17 def get_version(mira_binary):
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
18 """Run MIRA to find its version number"""
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
19 # At the commend line I would use: mira -v | head -n 1
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
20 # however there is some pipe error when doing that here.
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
21 cmd = [mira_binary, "-v"]
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
22 try:
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
23 child = subprocess.Popen(cmd,
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
24 stdout=subprocess.PIPE,
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
25 stderr=subprocess.STDOUT)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
26 except Exception, err:
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
27 sys.stderr.write("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err))
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
28 sys.exit(1)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
29 ver, tmp = child.communicate()
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
30 del child
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
31 return ver.split("\n", 1)[0]
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
32
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
33
4
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
34 os.environ["PATH"] = "/mnt/galaxy/downloads/mira_4.0rc3_linux-gnu_x86_64_static/bin/:%s" % os.environ["PATH"]
0
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
35 mira_binary = "mira"
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
36 mira_ver = get_version(mira_binary)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
37 if not mira_ver.strip().startswith("4.0"):
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
38 stop_err("This wrapper is for MIRA V4.0, not:\n%s" % mira_ver)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
39 if "-v" in sys.argv:
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
40 print "MIRA wrapper version %s," % WRAPPER_VER
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
41 print mira_ver
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
42 sys.exit(0)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
43
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
44
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
45 def log_manifest(manifest):
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
46 """Write the manifest file to stderr."""
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
47 sys.stderr.write("\n%s\nManifest file\n%s\n" % ("="*60, "="*60))
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
48 with open(manifest) as h:
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
49 for line in h:
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
50 sys.stderr.write(line)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
51 sys.stderr.write("\n%s\nEnd of manifest\n%s\n" % ("="*60, "="*60))
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
52
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
53
4
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
54 def collect_output(temp, name, handle):
0
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
55 n3 = (temp, name, name, name)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
56 f = "%s/%s_assembly/%s_d_results" % (temp, name, name)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
57 if not os.path.isdir(f):
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
58 log_manifest(manifest)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
59 stop_err("Missing output folder")
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
60 if not os.listdir(f):
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
61 log_manifest(manifest)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
62 stop_err("Empty output folder")
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
63 missing = []
4
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
64
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
65 old_maf = "%s/%s_out.maf" % (f, name)
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
66 if not os.path.isfile(old_maf):
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
67 #Triggered extractLargeContigs.sh?
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
68 old_maf = "%s/%s_LargeContigs_out.maf" % (f, name)
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
69
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
70 #De novo or single strain mapping,
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
71 old_fasta = "%s/%s_out.unpadded.fasta" % (f, name)
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
72 if not os.path.isfile(old_fasta):
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
73 #Mapping (currently StrainX versus reference)
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
74 old_fasta = "%s/%s_out_StrainX.unpadded.fasta" % (f, name)
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
75 if not os.path.isfile(old_fasta):
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
76 #Triggered extractLargeContigs.sh?
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
77 old_fasta = "%s/%s_LargeContigs_out.fasta" % (f, name)
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
78
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
79 missing = False
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
80 for old, new in [(old_maf, out_maf),
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
81 (old_fasta, out_fasta)]:
0
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
82 if not os.path.isfile(old):
4
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
83 missing = True
0
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
84 else:
4
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
85 handle.write("Capturing %s\n" % old)
0
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
86 shutil.move(old, new)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
87 if missing:
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
88 log_manifest(manifest)
4
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
89 sys.stderr.write("Contents of %r:\n" % f)
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
90 for filename in sorted(os.listdir(f)):
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
91 sys.stderr.write("%s\n" % filename)
0
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
92
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
93 def clean_up(temp, name):
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
94 folder = "%s/%s_assembly" % (temp, name)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
95 if os.path.isdir(folder):
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
96 shutil.rmtree(folder)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
97
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
98 #TODO - Run MIRA in /tmp or a configurable directory?
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
99 #Currently Galaxy puts us somewhere safe like:
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
100 #/opt/galaxy-dist/database/job_working_directory/846/
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
101 temp = "."
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
102 #name, out_fasta, out_qual, out_ace, out_caf, out_wig, out_log = sys.argv[1:8]
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
103 name = "MIRA"
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
104 manifest, out_maf, out_fasta, out_log = sys.argv[1:5]
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
105
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
106 start_time = time.time()
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
107 #cmd_list =sys.argv[8:]
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
108 cmd_list = [mira_binary, manifest]
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
109 cmd = " ".join(cmd_list)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
110
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
111 assert os.path.isdir(temp)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
112 d = "%s_assembly" % name
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
113 assert not os.path.isdir(d), "Path %s already exists" % d
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
114 try:
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
115 #Check path access
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
116 os.mkdir(d)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
117 except Exception, err:
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
118 log_manifest(manifest)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
119 sys.stderr.write("Error making directory %s\n%s" % (d, err))
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
120 sys.exit(1)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
121
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
122 #print os.path.abspath(".")
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
123 #print cmd
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
124
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
125 handle = open(out_log, "w")
4
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
126 handle.write("======================== MIRA manifest (instructions) ========================\n")
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
127 m = open(manifest, "rU")
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
128 for line in m:
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
129 handle.write(line)
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
130 m.close()
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
131 del m
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
132 handle.write("\n")
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
133 handle.write("============================ Starting MIRA now ===============================\n")
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
134 handle.flush()
0
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
135 try:
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
136 #Run MIRA
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
137 child = subprocess.Popen(cmd_list,
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
138 stdout=handle,
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
139 stderr=subprocess.STDOUT)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
140 except Exception, err:
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
141 log_manifest(manifest)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
142 sys.stderr.write("Error invoking command:\n%s\n\n%s\n" % (cmd, err))
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
143 #TODO - call clean up?
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
144 handle.write("Error invoking command:\n%s\n\n%s\n" % (cmd, err))
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
145 handle.close()
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
146 sys.exit(1)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
147 #Use .communicate as can get deadlocks with .wait(),
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
148 stdout, stderr = child.communicate()
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
149 assert not stdout and not stderr #Should be empty as sent to handle
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
150 run_time = time.time() - start_time
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
151 return_code = child.returncode
4
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
152 handle.write("\n")
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
153 handle.write("============================ MIRA has finished ===============================\n")
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
154 handle.write("MIRA took %0.2f hours\n" % (run_time / 3600.0))
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
155 print "MIRA took %0.2f hours" % (run_time / 3600.0)
0
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
156 if return_code:
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
157 handle.write("Return error code %i from command:\n" % return_code)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
158 handle.write(cmd + "\n")
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
159 handle.close()
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
160 clean_up(temp, name)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
161 log_manifest(manifest)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
162 stop_err("Return error code %i from command:\n%s" % (return_code, cmd),
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
163 return_code)
4
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
164 handle.flush()
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
165
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
166 if os.path.isfile("MIRA_assembly/MIRA_d_results/ec.log"):
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
167 handle.write("\n")
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
168 handle.write("====================== Extract Large Contigs failed ==========================\n")
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
169 e = open("MIRA_assembly/MIRA_d_results/ec.log", "rU")
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
170 for line in e:
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
171 handle.write(line)
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
172 e.close()
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
173 handle.write("============================ (end of ec.log) =================================\n")
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
174 handle.flush()
0
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
175
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
176 #print "Collecting output..."
4
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
177 collect_output(temp, name, handle)
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
178
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
179 if os.path.isfile("MIRA_assembly/MIRA_d_results/ec.log"):
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
180 #Treat as an error, but doing this AFTER collect_output
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
181 sys.stderr.write("Extract Large Contigs failed\n")
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
182 handle.write("Extract Large Contigs failed\n")
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
183 handle.close()
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
184 sys.exit(1)
0
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
185
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
186 #print "Cleaning up..."
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
187 clean_up(temp, name)
32f693f6e741 Uploaded v0.0.1 preview0, very much a work in progress, primarily checking mira_datatypes dependency
peterjc
parents:
diff changeset
188
4
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
189 handle.close()
df86ed992a1b Uploaded preview 4, lots of work on mapping
peterjc
parents: 0
diff changeset
190 print("Done")