Mercurial > repos > da-intersect > testdavid
comparison mrf.py @ 2:0442b1c31ef2 draft default tip
Uploaded
author | da-intersect |
---|---|
date | Tue, 25 Jun 2013 20:45:01 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:1321822ee8bc | 2:0442b1c31ef2 |
---|---|
1 #!/usr/bin/env python2.6 | |
2 import subprocess | |
3 import sys | |
4 import re | |
5 import shutil | |
6 import os | |
7 from optparse import OptionParser | |
8 | |
9 toolname = "MRF" | |
10 | |
11 | |
12 def main(): | |
13 | |
14 tool_path = os.path.dirname(os.path.realpath(sys.argv[0])) + "/" + toolname | |
15 | |
16 usage = "usage: %prog [options] arg" | |
17 parser = OptionParser(usage) | |
18 parser.add_option("-f", "--file", | |
19 action="store", type="string", dest="configfile", | |
20 help="File containing the Values") | |
21 | |
22 parser.add_option("-o", "--output", | |
23 action="store", type="string", dest="outputfile", nargs=4, | |
24 help="Output file where to store the result") | |
25 | |
26 (options, args) = parser.parse_args() | |
27 | |
28 if options.configfile is None or options.outputfile is None: | |
29 print "Missing arguments" | |
30 parser.print_help() | |
31 exit (1) | |
32 | |
33 mrf(tool_path, options.configfile, options.outputfile) | |
34 | |
35 def mrf(tool_path, configfile, outputfile): | |
36 | |
37 | |
38 f = open(configfile, 'r+b') | |
39 | |
40 tool = subprocess.Popen([tool_path],stdin=f, stdout=subprocess.PIPE) | |
41 tool.wait() | |
42 f.close() | |
43 | |
44 if tool.returncode != 0: | |
45 sys.stderr.write("There was a problem when running the $toolname tool") | |
46 output = tool.stdout.read() | |
47 print output | |
48 exit (1) | |
49 | |
50 output = tool.stdout.read() | |
51 print output | |
52 | |
53 # Determining the Output file generated by MRF | |
54 m1 = re.search("(.*Cluster: )*(\/.*\.pos$)", output, re.MULTILINE ) | |
55 m1_1 = re.search("(\/.*\/dataset_[0-9]*.dat-dataset_[0-9]*\.dat-\w*)(\..*)", m1.group(2), re.MULTILINE) | |
56 prefix = m1_1.group(1) | |
57 | |
58 m2 = re.search("(.*Cluster: )*(\/.*\.pos$)", output, re.MULTILINE ) | |
59 file1 = m2.group(2) | |
60 | |
61 file2 = prefix + '.mrf.txt' | |
62 | |
63 m3 = re.search("(.*Morphology: )*(\/.*\.txt$)",output, re.MULTILINE ) | |
64 file3 = m3.group(2) | |
65 | |
66 file4 = prefix + '.wc_histogram.txt' | |
67 | |
68 #Move the generated files to the Galaxy outputs and remove the tmp file | |
69 | |
70 shutil.move(file1, outputfile[0]) | |
71 | |
72 lines = open(file2).readlines() | |
73 open(outputfile[1], 'w').writelines(lines[1:]) | |
74 os.remove(file2) | |
75 | |
76 shutil.move(file3, outputfile[2]) | |
77 shutil.move(file4, outputfile[3]) | |
78 | |
79 if __name__ == "__main__": | |
80 main() |