| 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 | 
|  | 15 or with the galaxy_mapsembler2 package in the GenOuest toolshed | 
|  | 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") | 
|  | 26         parser.add_option("-t", dest="output_extension") | 
|  | 27         parser.add_option("-k", dest="kmer") | 
|  | 28         parser.add_option("-c", dest="coverage") | 
|  | 29         parser.add_option("-d", dest="substitutions") | 
|  | 30         parser.add_option("-g", dest="genome_size") | 
|  | 31         parser.add_option("-f", dest="process_search") | 
|  | 32         parser.add_option("-x", dest="max_length") | 
|  | 33         parser.add_option("-y", dest="max_depth") | 
|  | 34         parser.add_option("--output") | 
|  | 35         parser.add_option("-i", dest="index_files") | 
|  | 36 | 
|  | 37         (options, args) = parser.parse_args() | 
|  | 38 | 
|  | 39 	# import tools | 
|  | 40 	os.symlink(os.environ['TOOLS'], os.getcwd()+'/tools') | 
|  | 41 | 
|  | 42 	# execute mapsembler | 
|  | 43 	cmd_line=[] | 
|  | 44 	cmd_line.append("run_mapsembler2_pipeline.sh") | 
|  | 45 | 
|  | 46 	# change starter extension | 
|  | 47 	cmd_line.extend(["-s", options.input_starters]) | 
|  | 48 | 
|  | 49 	#inputs | 
|  | 50 	cmd_line.append("-r") | 
|  | 51 | 
|  | 52 	#cmd_line.append(inputs) | 
|  | 53 	cmd_line.append(' '.join(options.input_files.split(","))) | 
|  | 54 | 
|  | 55 	# add parameters into the command line | 
|  | 56 	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]) | 
|  | 57 | 
|  | 58 	# open the output log file | 
|  | 59         log = open(options.output, "w") | 
|  | 60 	log.write("[COMMAND LINE] "+' '.join(cmd_line)) | 
|  | 61 | 
|  | 62 	process=subprocess.Popen(cmd_line, | 
|  | 63                    stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 
|  | 64 | 
|  | 65         stdoutput, stderror = process.communicate() | 
|  | 66 | 
|  | 67 	# results recuperation | 
|  | 68 	log.write(stdoutput) | 
|  | 69 	log.write(stderror) | 
|  | 70 | 
|  | 71 	# close log file | 
|  | 72 	log.close() | 
|  | 73 | 
|  | 74 	# move results files inside the job_outputs dir | 
|  | 75 	os.mkdir("job_outputs") | 
|  | 76 	result_files = glob.glob("res_*") | 
|  | 77 	for file in result_files: | 
|  | 78 		shutil.move(file, "job_outputs/") | 
|  | 79 | 
|  | 80 | 
|  | 81 	# move index files | 
|  | 82 	if options.index_files == "true": | 
|  | 83 	        index_files = glob.glob("index_*") | 
|  | 84 		for index in index_files: | 
|  | 85 			shutil.move(index, "job_outputs/") | 
|  | 86 | 
|  | 87 	# move json result into gjson | 
|  | 88         json_files = glob.glob("job_outputs/*.json") | 
|  | 89         for json in json_files: | 
|  | 90 		shutil.move(json, json.replace(".json", ".gjson")) | 
|  | 91 | 
|  | 92 | 
|  | 93 if __name__ == "__main__": __main__() | 
|  | 94 |