annotate TakeABreak_wrapper.py @ 1:3ec608585f02 default tip

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