comparison TakeABreak_wrapper.py @ 0:dbd6e370c891

Imported from capsule None
author cmonjeau
date Fri, 05 Jun 2015 11:40:02 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:dbd6e370c891
1 import sys, tempfile, subprocess, glob
2 import os, re, shutil
3 import optparse
4 from os.path import basename
5
6 """
7
8 Created by Cyril Monjeaud
9 Cyril.Monjeaud@irisa.fr
10
11 WARNING :
12
13 TakeABreak_wrapper.py needs:
14
15 - dbgh5 & TakeABreak binaries in your $PATH
16
17 All these files are available after compiling the sources of TakeABreak :
18
19 http://colibread.inria.fr/files/2014/01/TakeABreak-1.1.0-Source.tar_.gz
20
21 or with the package_takeabreak dependency in the toolshed
22
23 """
24
25 def __main__():
26
27 # create a special dir inside job working dir
28 tmp_dir = tempfile.mkdtemp()
29 os.chdir(tmp_dir)
30
31 # retrieve arguments
32 parser = optparse.OptionParser()
33 parser.add_option("-i", dest="reads_files")
34 parser.add_option("-k", dest="kmer")
35 parser.add_option("-S", dest="kmersolid")
36
37 parser.add_option("-g", dest="graph_file")
38 parser.add_option("-c", dest="complexity")
39 parser.add_option("-m", dest="maxsimprct")
40 parser.add_option("-r", dest="optimization")
41
42 parser.add_option("--output_graph")
43 parser.add_option("--output_fasta")
44 parser.add_option("--output_log")
45
46 (options, args) = parser.parse_args()
47
48 cmd_line=[]
49 if options.reads_files:
50 # start the command line
51 cmd_line.append("TakeABreak")
52 cmd_line.extend(["-in",options.reads_files,"-kmer-size",options.kmer,"-abundance",options.kmersolid])
53 else:
54 # start the command line
55 os.symlink(options.graph_file, "graph.h5")
56 cmd_line.append("TakeABreak")
57 cmd_line.extend(["-graph", "graph.h5"])
58
59 cmd_line.extend(["-out","galaxy","-lct",options.complexity,"-max-sim",options.maxsimprct,"-repeat",options.optimization])
60
61 # execute command line
62 p=subprocess.Popen(cmd_line,
63 stdout=subprocess.PIPE,stderr=subprocess.PIPE)
64
65 stdoutput, stderror = p.communicate()
66
67 # log file
68 logfile=open(options.output_log, "w")
69 logfile.write("[COMMAND LINE]"+' '.join(cmd_line)+"\n\n")
70 logfile.write(stdoutput)
71 logfile.write(stderror)
72 logfile.close()
73
74 if options.reads_files:
75
76 # create output h5
77 shutil.copy("galaxy.h5", options.output_graph)
78
79 # create output fasta
80 shutil.copy("galaxy.fasta", options.output_fasta)
81
82 if __name__ == "__main__": __main__()
83