comparison tools/mira4/mira4.py @ 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 7fcabeeca5df
children 8487d70e82aa
comparison
equal deleted inserted replaced
17:5bbaa930d7fa 18:381aa262c8cb
4 import os 4 import os
5 import sys 5 import sys
6 import subprocess 6 import subprocess
7 import shutil 7 import shutil
8 import time 8 import time
9 import tempfile
9 10
10 #Do we need any PYTHONPATH magic? 11 #Do we need any PYTHONPATH magic?
11 from mira4_make_bam import make_bam 12 from mira4_make_bam import make_bam
12 13
13 WRAPPER_VER = "0.0.1" #Keep in sync with the XML file 14 WRAPPER_VER = "0.0.1" #Keep in sync with the XML file
65 except ValueError: 66 except ValueError:
66 threads = 1 67 threads = 1
67 assert 1 <= threads, threads 68 assert 1 <= threads, threads
68 69
69 70
71 def override_temp(manifest):
72 """Override ``-DI:trt=/tmp`` in manifest with environment variable.
73
74 Currently MIRA 4 does not allow envronment variables like ``$TMP``
75 inside the manifest, which is a problem if you need to override
76 the default at run time.
77
78 The tool XML will ``/tmp`` and we replace that here with
79 ``tempfile.gettempdir()`` which will respect $TMPDIR, $TEMP, $TMP
80 as explained in the Python standard library documentation:
81 http://docs.python.org/2/library/tempfile.html#tempfile.tempdir
82
83 By default MIRA 4 would write its temporary files within the output
84 folder, which is a problem if that is a network drive.
85 """
86 handle = open(manifest, "r")
87 text = handle.read()
88 handle.close()
89
90 #At time of writing, this is at the end of a file,
91 #but could be followed by a space in future...
92 text = text.replace("-DI:trt=/tmp", "-DI:trt=" + tempfile.gettempdir())
93
94 handle = open(manifest, "w")
95 handle.write(text)
96 handle.flush()
97 handle.close()
98
99
70 def log_manifest(manifest): 100 def log_manifest(manifest):
71 """Write the manifest file to stderr.""" 101 """Write the manifest file to stderr."""
72 sys.stderr.write("\n%s\nManifest file\n%s\n" % ("="*60, "="*60)) 102 sys.stderr.write("\n%s\nManifest file\n%s\n" % ("="*60, "="*60))
73 with open(manifest) as h: 103 with open(manifest) as h:
74 for line in h: 104 for line in h:
136 temp = "." 166 temp = "."
137 #name, out_fasta, out_qual, out_ace, out_caf, out_wig, out_log = sys.argv[1:8] 167 #name, out_fasta, out_qual, out_ace, out_caf, out_wig, out_log = sys.argv[1:8]
138 name = "MIRA" 168 name = "MIRA"
139 manifest, out_maf, out_bam, out_fasta, out_log = sys.argv[1:] 169 manifest, out_maf, out_bam, out_fasta, out_log = sys.argv[1:]
140 170
171 override_temp(manifest)
172
141 start_time = time.time() 173 start_time = time.time()
142 #cmd_list =sys.argv[8:] 174 #cmd_list =sys.argv[8:]
143 cmd_list = [mira_binary, "-t", str(threads), manifest] 175 cmd_list = [mira_binary, "-t", str(threads), manifest]
144 cmd = " ".join(cmd_list) 176 cmd = " ".join(cmd_list)
145 177