# HG changeset patch # User peterjc # Date 1395747470 14400 # Node ID 381aa262c8cbe926ea2006cf3ff778b3da3f7b12 # Parent 5bbaa930d7fa66f24de97dc93f1544af766c10ff Uploaded v0.0.2 preview 10, override /tmp via environment variable diff -r 5bbaa930d7fa -r 381aa262c8cb tools/mira4/README.rst --- 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``. ======= ====================================================================== diff -r 5bbaa930d7fa -r 381aa262c8cb tools/mira4/mira4.py --- 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] diff -r 5bbaa930d7fa -r 381aa262c8cb tools/mira4/mira4_bait.xml --- 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 @@ - + Filter reads using kmer matches mirabait @@ -31,16 +31,8 @@ help="How many k-mer matches do you want per read? Minimum one" /> - - - - - - - - - - + diff -r 5bbaa930d7fa -r 381aa262c8cb tools/mira4/mira4_de_novo.xml --- 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 diff -r 5bbaa930d7fa -r 381aa262c8cb tools/mira4/mira4_mapping.xml --- 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 #------------------------------------------------------------------------------ diff -r 5bbaa930d7fa -r 381aa262c8cb tools/mira4/tool_dependencies.xml --- 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 @@ - +