0
|
1 #!/usr/bin/env python
|
|
2 import sys, subprocess, glob
|
|
3 import os, re, shutil, optparse
|
|
4 from os.path import basename
|
|
5
|
|
6 """
|
|
7 WARNING :
|
|
8
|
|
9 Mapsembler2.py needs mapsembler2_exe binaries in your $PATH
|
|
10
|
|
11 Mapsember2 is available after compiling sources :
|
|
12
|
|
13 http://www.irisa.fr/symbiose/people/ppeterlongo/mapsembler2_2.2.3.zip
|
|
14
|
2
|
15 or with the package_mapsembler2_2_2_3 package in the GUGGO toolshed and main toolshed
|
0
|
16
|
|
17
|
|
18 """
|
|
19
|
|
20 def __main__():
|
|
21
|
|
22 # arguments recuperation
|
|
23 parser = optparse.OptionParser()
|
|
24 parser.add_option("-s", dest="input_starters")
|
|
25 parser.add_option("-r", dest="input_files")
|
3
|
26 parser.add_option("-e", dest="extension_format")
|
0
|
27 parser.add_option("-t", dest="output_extension")
|
|
28 parser.add_option("-k", dest="kmer")
|
|
29 parser.add_option("-c", dest="coverage")
|
|
30 parser.add_option("-d", dest="substitutions")
|
|
31 parser.add_option("-g", dest="genome_size")
|
|
32 parser.add_option("-f", dest="process_search")
|
|
33 parser.add_option("-x", dest="max_length")
|
|
34 parser.add_option("-y", dest="max_depth")
|
|
35 parser.add_option("--output")
|
|
36 parser.add_option("-i", dest="index_files")
|
|
37
|
|
38 (options, args) = parser.parse_args()
|
|
39
|
|
40 # import tools
|
|
41 os.symlink(os.environ['TOOLS'], os.getcwd()+'/tools')
|
|
42
|
|
43 # execute mapsembler
|
|
44 cmd_line=[]
|
|
45 cmd_line.append("run_mapsembler2_pipeline.sh")
|
|
46
|
|
47 # change starter extension
|
|
48 cmd_line.extend(["-s", options.input_starters])
|
|
49
|
|
50 #inputs
|
|
51 cmd_line.append("-r")
|
|
52
|
2
|
53 inputs_tab = []
|
|
54
|
|
55 for input in options.input_files.split(","):
|
|
56 os.symlink(input, os.path.basename(input)+'.'+options.extension_format)
|
|
57 inputs_tab.append(os.path.basename(input)+'.'+options.extension_format)
|
|
58
|
|
59 cmd_line.append(' '.join(inputs_tab))
|
0
|
60
|
|
61 # add parameters into the command line
|
|
62 cmd_line.extend(["-t", options.output_extension, "-k", options.kmer, "-c", options.coverage, "-d", options.substitutions, "-g", options.genome_size, "-f", options.process_search, "-x", options.max_length, "-y", options.max_depth])
|
|
63
|
|
64 # open the output log file
|
|
65 log = open(options.output, "w")
|
|
66 log.write("[COMMAND LINE] "+' '.join(cmd_line))
|
|
67
|
2
|
68 process=subprocess.call(cmd_line)
|
0
|
69
|
|
70 # close log file
|
|
71 log.close()
|
|
72
|
|
73 # move results files inside the job_outputs dir
|
|
74 os.mkdir("job_outputs")
|
|
75 result_files = glob.glob("res_*")
|
|
76 for file in result_files:
|
|
77 shutil.move(file, "job_outputs/")
|
|
78
|
|
79
|
|
80 # move index files
|
|
81 if options.index_files == "true":
|
|
82 index_files = glob.glob("index_*")
|
|
83 for index in index_files:
|
|
84 shutil.move(index, "job_outputs/")
|
|
85
|
|
86 # move json result into gjson
|
|
87 json_files = glob.glob("job_outputs/*.json")
|
|
88 for json in json_files:
|
|
89 shutil.move(json, json.replace(".json", ".gjson"))
|
|
90
|
|
91
|
|
92 if __name__ == "__main__": __main__()
|
|
93
|