Repository 'mira_assembler'
hg clone https://toolshed.g2.bx.psu.edu/repos/peterjc/mira_assembler

Changeset 3:298f5c1d9521 (2011-06-21)
Previous changeset 2:73263d5c2c9f (2011-06-21) Next changeset 4:117cce3296af (2011-12-21)
Commit message:
Uploaded v0.0.2 of the wrapper, which improves capture of the stdout/stderr log file from MIRA.
modified:
tools/sr_assembly/mira.py
tools/sr_assembly/mira.txt
tools/sr_assembly/mira.xml
b
diff -r 73263d5c2c9f -r 298f5c1d9521 tools/sr_assembly/mira.py
--- a/tools/sr_assembly/mira.py Tue Jun 21 09:48:11 2011 -0400
+++ b/tools/sr_assembly/mira.py Tue Jun 21 09:50:32 2011 -0400
[
@@ -31,16 +31,21 @@
 
 def collect_output(temp, name):
     n3 = (temp, name, name, name)
-    tcs_to_tabular("%s/%s_assembly/%s_d_results/%s_out.tcs" % n3, out_tcs)
-    for old, new in [("%s/%s_assembly/%s_d_results/%s_out.unpadded.fasta" % n3, out_fasta),
-                     ("%s/%s_assembly/%s_d_results/%s_out.unpadded.fasta.qual" % n3, out_qual),
-                     ("%s/%s_assembly/%s_d_results/%s_out.wig" % n3, out_wig),
-                     ("%s/%s_assembly/%s_d_results/%s_out.caf" % n3, out_caf),
-                     ("%s/%s_assembly/%s_d_results/%s_out.ace" % n3, out_ace)]:
+    f = "%s/%s_assembly/%s_d_results" % (temp, name, name)
+    if not os.path.isdir(f):
+        stop_err("Missing output folder")
+    if not os.listdir(f):
+        stop_err("Empty output folder")
+    for old, new in [("%s/%s_out.unpadded.fasta" % (f, name), out_fasta),
+                     ("%s/%s_out.unpadded.fasta.qual" % (f, name), out_qual),
+                     ("%s/%s_out.wig" % (f, name), out_wig),
+                     ("%s/%s_out.caf" % (f, name), out_caf),
+                     ("%s/%s_out.ace" % (f, name), out_ace)]:
         if not os.path.isfile(old):
             stop_err("Missing %s output file" % os.path.splitext(old)[-1])
         else:
             shutil.move(old, new)
+    tcs_to_tabular("%s/%s_assembly/%s_d_results/%s_out.tcs" % n3, out_tcs)
 
 def clean_up(temp, name):
     folder = "%s/%s_assembly" % (temp, name)
@@ -48,22 +53,44 @@
         shutil.rmtree(folder)
 
 #TODO - Run MIRA in /tmp or a configurable directory?
+#Currently Galaxy puts us somewhere safe like:
+#/opt/galaxy-dist/database/job_working_directory/846/
 temp = "."
 name, out_fasta, out_qual, out_tcs, out_ace, out_caf, out_wig, out_log = sys.argv[1:9]
+
 start_time = time.time()
+cmd = " ".join(sys.argv[9:])
+
+assert os.path.isdir(temp)
+d = "%s_assembly" % name
+assert not os.path.isdir(d)
 try:
-    cmd = " ".join(sys.argv[9:])
+    #Check path access
+    os.mkdir(d)
+except Exception, err:
+    sys.stderr.write("Error making directory %s\n%s" % (d, err))
+    sys.exit(1)
+
+#print os.path.abspath(".")
+#print cmd
+
+handle = open(out_log, "w")
+try:
+    #Run MIRA
     child = subprocess.Popen(sys.argv[9:],
-                             stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+                             stdout=handle,
+                             stderr=subprocess.STDOUT)
 except Exception, err:
     sys.stderr.write("Error invoking command:\n%s\n\n%s\n" % (cmd, err))
+    #TODO - call clean up?
+    handle.write("Error invoking command:\n%s\n\n%s\n" % (cmd, err))
+    handle.close()
     sys.exit(1)
 #Use .communicate as can get deadlocks with .wait(),
 stdout, stderr = child.communicate()
+assert not stdout and not stderr #Should be empty as sent to handle
 run_time = time.time() - start_time
 return_code = child.returncode
-handle = open(out_log, "w")
-handle.write(stdout)
 handle.write("\n\nMIRA took %0.2f minutes\n" % (run_time / 60.0))
 print "MIRA took %0.2f minutes" % (run_time / 60.0)
 if return_code:
b
diff -r 73263d5c2c9f -r 298f5c1d9521 tools/sr_assembly/mira.txt
--- a/tools/sr_assembly/mira.txt Tue Jun 21 09:48:11 2011 -0400
+++ b/tools/sr_assembly/mira.txt Tue Jun 21 09:50:32 2011 -0400
b
@@ -34,6 +34,7 @@
 =======
 
 v0.0.1 - Initial version (working prototype)
+v0.0.2 - Improve capture of stdout/stderr (should see it as it runs)
 
 
 Developers
b
diff -r 73263d5c2c9f -r 298f5c1d9521 tools/sr_assembly/mira.xml
--- a/tools/sr_assembly/mira.xml Tue Jun 21 09:48:11 2011 -0400
+++ b/tools/sr_assembly/mira.xml Tue Jun 21 09:50:32 2011 -0400
b
@@ -1,4 +1,4 @@
-<tool id="mira_assembler" name="Assemble with MIRA" version="0.0.1">
+<tool id="mira_assembler" name="Assemble with MIRA" version="0.0.2">
     <description>Takes Sanger, Roche, and Illumina data</description>
  <command interpreter="python">mira.py mira $out_fasta $out_qual $out_tcs $out_ace $out_caf $out_wig $out_log
 ##Give the wrapper script list of output filenames, then the mira command...