changeset 18:381aa262c8cb draft

Uploaded v0.0.2 preview 10, override /tmp via environment variable
author peterjc
date Tue, 25 Mar 2014 07:37:50 -0400
parents 5bbaa930d7fa
children 8487d70e82aa
files tools/mira4/README.rst tools/mira4/mira4.py tools/mira4/mira4_bait.xml tools/mira4/mira4_de_novo.xml tools/mira4/mira4_mapping.xml tools/mira4/tool_dependencies.xml
diffstat 6 files changed, 42 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/tools/mira4/README.rst	Mon Mar 03 11:49:21 2014 -0500
+++ b/tools/mira4/README.rst	Tue Mar 25 07:37:50 2014 -0400
@@ -86,6 +86,10 @@
 v0.0.1  - Initial version (prototype for MIRA 4.0 RC4, based on wrapper for v3.4)
 v0.0.2  - Include BAM output (using ``miraconvert`` and ``samtools``).
         - Updated to target MIRA 4.0
+        - Simplified XML to apply input format to output data.
+        - Sets temporary folder at run time to respect environment variables
+          (``$TMPDIR``, ``$TEMP``, or ``$TMP`` in that order). This was
+          previously hard coded as ``/tmp``.
 ======= ======================================================================
 
 
--- a/tools/mira4/mira4.py	Mon Mar 03 11:49:21 2014 -0500
+++ b/tools/mira4/mira4.py	Tue Mar 25 07:37:50 2014 -0400
@@ -6,6 +6,7 @@
 import subprocess
 import shutil
 import time
+import tempfile
 
 #Do we need any PYTHONPATH magic?
 from mira4_make_bam import make_bam
@@ -67,6 +68,35 @@
 assert 1 <= threads, threads
 
 
+def override_temp(manifest):
+    """Override ``-DI:trt=/tmp`` in manifest with environment variable.
+
+    Currently MIRA 4 does not allow envronment variables like ``$TMP``
+    inside the manifest, which is a problem if you need to override
+    the default at run time.
+
+    The tool XML will ``/tmp`` and we replace that here with
+    ``tempfile.gettempdir()`` which will respect $TMPDIR, $TEMP, $TMP
+    as explained in the Python standard library documentation:
+    http://docs.python.org/2/library/tempfile.html#tempfile.tempdir
+
+    By default MIRA 4 would write its temporary files within the output
+    folder, which is a problem if that is a network drive.
+    """
+    handle = open(manifest, "r")
+    text = handle.read()
+    handle.close()
+
+    #At time of writing, this is at the end of a file,
+    #but could be followed by a space in future...
+    text = text.replace("-DI:trt=/tmp", "-DI:trt=" + tempfile.gettempdir())
+
+    handle = open(manifest, "w")
+    handle.write(text)
+    handle.flush()
+    handle.close()
+
+
 def log_manifest(manifest):
     """Write the manifest file to stderr."""
     sys.stderr.write("\n%s\nManifest file\n%s\n" % ("="*60, "="*60))
@@ -138,6 +168,8 @@
 name = "MIRA"
 manifest, out_maf, out_bam, out_fasta, out_log = sys.argv[1:]
 
+override_temp(manifest)
+
 start_time = time.time()
 #cmd_list =sys.argv[8:]
 cmd_list = [mira_binary, "-t", str(threads), manifest]
--- a/tools/mira4/mira4_bait.xml	Mon Mar 03 11:49:21 2014 -0500
+++ b/tools/mira4/mira4_bait.xml	Tue Mar 25 07:37:50 2014 -0400
@@ -1,4 +1,4 @@
-<tool id="mira_4_0_bait" name="MIRA v4.0 mirabait" version="0.0.1">
+<tool id="mira_4_0_bait" name="MIRA v4.0 mirabait" version="0.0.2">
     <description>Filter reads using kmer matches</description>
     <requirements>
         <requirement type="binary">mirabait</requirement>
@@ -31,16 +31,8 @@
                help="How many k-mer matches do you want per read? Minimum one" />
     </inputs>
     <outputs>
-        <data name="output_reads" format="fasta" label="$input_reads.name #if str($output_choice)=='pos' then 'matching' else 'excluding matches to' # $bait_file.name">
-            <!-- TODO - Replace this with format="input:input_reads" if/when that works -->
-            <change_format>
-                <when input_dataset="input_reads" attribute="extension" value="fastq" format="fastq" />
-                <when input_dataset="input_reads" attribute="extension" value="fastqsanger" format="fastqsanger" />
-                <when input_dataset="input_reads" attribute="extension" value="fastqsolexa" format="fastqsolexa" />
-                <when input_dataset="input_reads" attribute="extension" value="fastqillumina" format="fastqillumina" />
-                <when input_dataset="input_reads" attribute="extension" value="fastqcssanger" format="fastqcssanger" />
-            </change_format>
-        </data>
+        <data name="output_reads" format="input" metadata_source="input_reads"
+	      label="$input_reads.name #if str($output_choice)=='pos' then 'matching' else 'excluding matches to' # $bait_file.name"/>
     </outputs>
     <tests>
         <test>
--- a/tools/mira4/mira4_de_novo.xml	Mon Mar 03 11:49:21 2014 -0500
+++ b/tools/mira4/mira4_de_novo.xml	Tue Mar 25 07:37:50 2014 -0400
@@ -94,6 +94,7 @@
 ##
 ## -DI:trt is short for -DIRECTORY:tmp_redirected_to and should
 ## point to a local hard drive (not something like NFS on network).
+## We replace /tmp with an environment variable via mira4.py
 
 #for $rg in $read_group
 
--- a/tools/mira4/mira4_mapping.xml	Mon Mar 03 11:49:21 2014 -0500
+++ b/tools/mira4/mira4_mapping.xml	Tue Mar 25 07:37:50 2014 -0400
@@ -92,6 +92,7 @@
 ##
 ## -DI:trt is short for -DIRECTORY:tmp_redirected_to and should
 ## point to a local hard drive (not something like NFS on network).
+## We replace /tmp with an environment variable via mira4.py
 
 ##This bar goes into the manifest as a comment line
 #------------------------------------------------------------------------------
--- a/tools/mira4/tool_dependencies.xml	Mon Mar 03 11:49:21 2014 -0500
+++ b/tools/mira4/tool_dependencies.xml	Tue Mar 25 07:37:50 2014 -0400
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <tool_dependency>
     <package name="samtools" version="0.1.19">
-        <repository changeset_revision="54195f1d4b0f" name="package_samtools_0_1_19" owner="iuc" toolshed="http://testtoolshed.g2.bx.psu.edu" />
+        <repository changeset_revision="36aa94676939" name="package_samtools_0_1_19" owner="iuc" toolshed="http://testtoolshed.g2.bx.psu.edu" />
     </package>
     <package name="MIRA" version="4.0">
         <install version="1.0">