comparison tools/effectiveT3/effectiveT3.py @ 9:512530020360 draft

v0.0.18 Internal changes to command line handling
author peterjc
date Tue, 16 May 2017 09:17:17 -0400
parents 60a9b3f760cc
children a46d7861c32c
comparison
equal deleted inserted replaced
8:60a9b3f760cc 9:512530020360
9 9
10 It then calls the standalone Effective T3 v1.0.1 program (not the 10 It then calls the standalone Effective T3 v1.0.1 program (not the
11 webservice), and reformats the semi-colon separated output into 11 webservice), and reformats the semi-colon separated output into
12 tab separated output for use in Galaxy. 12 tab separated output for use in Galaxy.
13 """ 13 """
14 import sys
15 import os 14 import os
16 import subprocess 15 import subprocess
16 import sys
17 17
18 # The Galaxy auto-install via tool_dependencies.xml will set this environment variable 18 # The Galaxy auto-install via tool_dependencies.xml will set this environment variable
19 effective_t3_dir = os.environ.get("EFFECTIVET3", "/opt/EffectiveT3/") 19 effective_t3_dir = os.environ.get("EFFECTIVET3", "/opt/EffectiveT3/")
20 effective_t3_jar = os.path.join(effective_t3_dir, "TTSS_GUI-1.0.1.jar") 20 effective_t3_jar = os.path.join(effective_t3_dir, "TTSS_GUI-1.0.1.jar")
21 21
30 model, threshold, fasta_file, tabular_file = sys.argv[1:] 30 model, threshold, fasta_file, tabular_file = sys.argv[1:]
31 31
32 if not os.path.isfile(fasta_file): 32 if not os.path.isfile(fasta_file):
33 sys.exit("Input FASTA file not found: %s" % fasta_file) 33 sys.exit("Input FASTA file not found: %s" % fasta_file)
34 34
35 if threshold not in ["selective", "sensitive"] \ 35 if threshold not in ["selective", "sensitive"] and not threshold.startswith("cutoff="):
36 and not threshold.startswith("cutoff="):
37 sys.exit("Threshold should be selective, sensitive, or cutoff=..., not %r" % threshold) 36 sys.exit("Threshold should be selective, sensitive, or cutoff=..., not %r" % threshold)
38 37
39 38
40 def clean_tabular(raw_handle, out_handle): 39 def clean_tabular(raw_handle, out_handle):
41 """Clean up Effective T3 output to make it tabular.""" 40 """Clean up Effective T3 output to make it tabular."""
42 count = 0 41 count = 0
43 positive = 0 42 positive = 0
44 errors = 0 43 errors = 0
45 for line in raw_handle: 44 for line in raw_handle:
46 if not line or line.startswith("#") \ 45 if not line or line.startswith("#") or line.startswith("Id; Description; Score;"):
47 or line.startswith("Id; Description; Score;"):
48 continue 46 continue
49 assert line.count(";") >= 3, repr(line) 47 assert line.count(";") >= 3, repr(line)
50 # Normally there will just be three semi-colons, however the 48 # Normally there will just be three semi-colons, however the
51 # original FASTA file's ID or description might have had 49 # original FASTA file's ID or description might have had
52 # semi-colons in it as well, hence the following hackery: 50 # semi-colons in it as well, hence the following hackery:
69 positive += 1 67 positive += 1
70 return count, positive, errors 68 return count, positive, errors
71 69
72 70
73 def run(cmd): 71 def run(cmd):
72 """Run the command line string via subprocess."""
74 # Avoid using shell=True when we call subprocess to ensure if the Python 73 # Avoid using shell=True when we call subprocess to ensure if the Python
75 # script is killed, so too is the child process. 74 # script is killed, so too is the child process.
76 try: 75 try:
77 child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 76 child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
78 except Exception, err: 77 except Exception, err: