Mercurial > repos > iuc > raxml
comparison raxml.py @ 1:b0d6eb76ad87 draft
planemo upload for repository https://github.com/stamatak/standard-RAxML commit 80c5ab90ac30fe083328ef7ad507d2e578daea90
| author | iuc |
|---|---|
| date | Sat, 25 Jun 2016 19:34:35 -0400 |
| parents | 934206441123 |
| children | 6f7ff8a3bd79 |
comparison
equal
deleted
inserted
replaced
| 0:934206441123 | 1:b0d6eb76ad87 |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 """ | 2 """ |
| 3 Runs RAxML on a sequence file. | 3 Runs RAxML on a sequence file. |
| 4 For use with RAxML version 8.2.4 | 4 For use with RAxML version 8.2.4 |
| 5 """ | 5 """ |
| 6 import os, shutil, subprocess, sys, optparse, fnmatch, glob | 6 import fnmatch |
| 7 import glob | |
| 8 import optparse | |
| 9 import os | |
| 10 import subprocess | |
| 11 import sys | |
| 12 | |
| 7 | 13 |
| 8 def stop_err(msg): | 14 def stop_err(msg): |
| 9 sys.stderr.write("%s\n" % msg) | 15 sys.stderr.write("%s\n" % msg) |
| 10 sys.exit() | 16 sys.exit() |
| 17 | |
| 11 | 18 |
| 12 def getint(name): | 19 def getint(name): |
| 13 basename = name.partition('RUN.') | 20 basename = name.partition('RUN.') |
| 14 if basename[2] != '': | 21 if basename[2] != '': |
| 15 num = basename[2] | 22 num = basename[2] |
| 16 return int(num) | 23 return int(num) |
| 17 | 24 |
| 25 | |
| 18 def __main__(): | 26 def __main__(): |
| 19 usage = "usage: %prog -T <threads> -s <input> -n <output> -m <model> [optional arguments]" | 27 usage = "usage: %prog -T <threads> -s <input> -n <output> -m <model> [optional arguments]" |
| 20 | 28 |
| 21 # Parse the primary wrapper's command line options | 29 # Parse the primary wrapper's command line options |
| 22 parser = optparse.OptionParser(usage = usage) | 30 parser = optparse.OptionParser(usage=usage) |
| 23 # raxml binary name, hardcoded in the xml file | 31 # raxml binary name, hardcoded in the xml file |
| 24 parser.add_option("--binary", action="store", type="string", dest="binary", help="Command to run") | 32 parser.add_option("--binary", action="store", type="string", dest="binary", help="Command to run") |
| 25 # (-a) | 33 # (-a) |
| 26 parser.add_option("--weightfile", action="store", type="string", dest="weightfile", help="Column weight file") | 34 parser.add_option("--weightfile", action="store", type="string", dest="weightfile", help="Column weight file") |
| 27 # (-A) | 35 # (-A) |
| 116 threads = "-T %d" % options.threads | 124 threads = "-T %d" % options.threads |
| 117 cmd.append(threads) | 125 cmd.append(threads) |
| 118 # Source | 126 # Source |
| 119 source = "-s %s" % options.source | 127 source = "-s %s" % options.source |
| 120 cmd.append(source) | 128 cmd.append(source) |
| 121 #Hardcode to "galaxy" first to simplify the output part of the wrapper | 129 # Hardcode to "galaxy" first to simplify the output part of the wrapper |
| 122 #name = "-n %s" % options.name | 130 # name = "-n %s" % options.name |
| 123 name = "-n galaxy" | 131 name = "-n galaxy" |
| 124 cmd.append(name) | 132 cmd.append(name) |
| 125 ## Model | 133 # Model |
| 126 model_type = options.model_type | 134 model_type = options.model_type |
| 127 base_model = options.base_model | 135 base_model = options.base_model |
| 128 aa_search_matrix = options.aa_search_matrix | 136 aa_search_matrix = options.aa_search_matrix |
| 129 aa_empirical_freq = options.aa_empirical_freq | 137 aa_empirical_freq = options.aa_empirical_freq |
| 130 if model_type == 'aminoacid': | 138 if model_type == 'aminoacid': |
| 158 if options.weightfile: | 166 if options.weightfile: |
| 159 weightfile = "-a %s" % options.weightfile | 167 weightfile = "-a %s" % options.weightfile |
| 160 cmd.append(weightfile) | 168 cmd.append(weightfile) |
| 161 # (-A) | 169 # (-A) |
| 162 if options.secondary_structure_model: | 170 if options.secondary_structure_model: |
| 163 secondary_structure_model = "-A %s" % options.secondary_structure_model | 171 secondary_structure_model = "-A %s" % options.secondary_structure_model |
| 164 cmd.append(secondary_structure_model ) | 172 cmd.append(secondary_structure_model ) |
| 165 # (-b) | 173 # (-b) |
| 166 if options.bootseed: | 174 if options.bootseed: |
| 167 bootseed = "-b %d" % options.bootseed | 175 bootseed = "-b %d" % options.bootseed |
| 168 cmd.append(bootseed) | 176 cmd.append(bootseed) |
| 189 cmd.append(groupingfile) | 197 cmd.append(groupingfile) |
| 190 if options.enable_evol_heuristics: | 198 if options.enable_evol_heuristics: |
| 191 enable_evol_heuristics = "-G %f" % options.enable_evol_heuristics | 199 enable_evol_heuristics = "-G %f" % options.enable_evol_heuristics |
| 192 cmd.append(enable_evol_heuristics ) | 200 cmd.append(enable_evol_heuristics ) |
| 193 if options.initial_rearrangement_setting: | 201 if options.initial_rearrangement_setting: |
| 194 initial_rearrangement_setting = "-i %s" % options.initial_rearrangement_setting | 202 initial_rearrangement_setting = "-i %s" % options.initial_rearrangement_setting |
| 195 cmd.append(initial_rearrangement_setting) | 203 cmd.append(initial_rearrangement_setting) |
| 196 if options.posterior_bootstopping_analysis: | 204 if options.posterior_bootstopping_analysis: |
| 197 posterior_bootstopping_analysis = "-I %s" % options.posterior_bootstopping_analysis | 205 posterior_bootstopping_analysis = "-I %s" % options.posterior_bootstopping_analysis |
| 198 cmd.append(posterior_bootstopping_analysis) | 206 cmd.append(posterior_bootstopping_analysis) |
| 199 if options.majority_rule_consensus: | 207 if options.majority_rule_consensus: |
| 223 cmd.append(constraint_file) | 231 cmd.append(constraint_file) |
| 224 if options.bin_model_parameter_file: | 232 if options.bin_model_parameter_file: |
| 225 bin_model_parameter_file_name = "RAxML_binaryModelParameters.galaxy" | 233 bin_model_parameter_file_name = "RAxML_binaryModelParameters.galaxy" |
| 226 os.symlink(options.bin_model_parameter_file, bin_model_parameter_file_name ) | 234 os.symlink(options.bin_model_parameter_file, bin_model_parameter_file_name ) |
| 227 bin_model_parameter_file = "-R %s" % options.bin_model_parameter_file | 235 bin_model_parameter_file = "-R %s" % options.bin_model_parameter_file |
| 228 #Needs testing. Is the hardcoded name or the real path needed? | 236 # Needs testing. Is the hardcoded name or the real path needed? |
| 229 cmd.append(bin_model_parameter_file) | 237 cmd.append(bin_model_parameter_file) |
| 230 if options.secondary_structure_file: | 238 if options.secondary_structure_file: |
| 231 secondary_structure_file = "-S %s" % options.secondary_structure_file | 239 secondary_structure_file = "-S %s" % options.secondary_structure_file |
| 232 cmd.append(secondary_structure_file) | 240 cmd.append(secondary_structure_file) |
| 233 if options.starting_tree: | 241 if options.starting_tree: |
| 258 full_cmd = " ".join(cmd) | 266 full_cmd = " ".join(cmd) |
| 259 print "Command string: %s" % full_cmd | 267 print "Command string: %s" % full_cmd |
| 260 | 268 |
| 261 try: | 269 try: |
| 262 proc = subprocess.Popen(args=full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 270 proc = subprocess.Popen(args=full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 263 except Exception, err: | 271 except Exception as err: |
| 264 sys.stderr.write("Error invoking command: \n%s\n\n%s\n" % (cmd, err)) | 272 sys.stderr.write("Error invoking command: \n%s\n\n%s\n" % (cmd, err)) |
| 265 sys.exit(1) | 273 sys.exit(1) |
| 266 stdout, stderr = proc.communicate() | 274 stdout, stderr = proc.communicate() |
| 267 return_code = proc.returncode | 275 return_code = proc.returncode |
| 268 if return_code: | 276 if return_code: |
| 272 sys.stderr.write("%s\n" % cmd) | 280 sys.stderr.write("%s\n" % cmd) |
| 273 else: | 281 else: |
| 274 sys.stdout.write(stdout) | 282 sys.stdout.write(stdout) |
| 275 sys.stdout.write(stderr) | 283 sys.stdout.write(stderr) |
| 276 | 284 |
| 277 #Multiple runs - concatenate | 285 # Multiple runs - concatenate |
| 278 if number_of_runs_opt > 0: | 286 if number_of_runs_opt > 0: |
| 279 if (bootseed == 0) and (rapid_bootstrap_random_seed == 0 ): | 287 if (bootseed == 0) and (rapid_bootstrap_random_seed == 0 ): |
| 280 runfiles = glob.glob('RAxML*RUN*') | 288 runfiles = glob.glob('RAxML*RUN*') |
| 281 runfiles.sort(key=getint) | 289 runfiles.sort(key=getint) |
| 282 # Logs | 290 # Logs |
| 283 outfile = open('RAxML_log.galaxy','w') | 291 outfile = open('RAxML_log.galaxy', 'w') |
| 284 for filename in runfiles: | 292 for filename in runfiles: |
| 285 if fnmatch.fnmatch(filename, 'RAxML_log.galaxy.RUN.*'): | 293 if fnmatch.fnmatch(filename, 'RAxML_log.galaxy.RUN.*'): |
| 286 infile = open(filename, 'r') | 294 infile = open(filename, 'r') |
| 287 filename_line = "%s\n" % filename | 295 filename_line = "%s\n" % filename |
| 288 outfile.write(filename_line) | 296 outfile.write(filename_line) |
| 289 for line in infile: | 297 for line in infile: |
| 290 outfile.write(line) | 298 outfile.write(line) |
| 291 infile.close() | 299 infile.close() |
| 292 outfile.close() | 300 outfile.close() |
| 293 # Parsimony Trees | 301 # Parsimony Trees |
| 294 outfile = open('RAxML_parsimonyTree.galaxy','w') | 302 outfile = open('RAxML_parsimonyTree.galaxy', 'w') |
| 295 for filename in runfiles: | 303 for filename in runfiles: |
| 296 if fnmatch.fnmatch(filename, 'RAxML_parsimonyTree.galaxy.RUN.*'): | 304 if fnmatch.fnmatch(filename, 'RAxML_parsimonyTree.galaxy.RUN.*'): |
| 297 infile = open(filename, 'r') | 305 infile = open(filename, 'r') |
| 298 filename_line = "%s\n" % filename | 306 filename_line = "%s\n" % filename |
| 299 outfile.write(filename_line) | 307 outfile.write(filename_line) |
| 300 for line in infile: | 308 for line in infile: |
| 301 outfile.write(line) | 309 outfile.write(line) |
| 302 infile.close() | 310 infile.close() |
| 303 outfile.close() | 311 outfile.close() |
| 304 # Results | 312 # Results |
| 305 outfile = open('RAxML_result.galaxy','w') | 313 outfile = open('RAxML_result.galaxy', 'w') |
| 306 for filename in runfiles: | 314 for filename in runfiles: |
| 307 if fnmatch.fnmatch(filename, 'RAxML_result.galaxy.RUN.*'): | 315 if fnmatch.fnmatch(filename, 'RAxML_result.galaxy.RUN.*'): |
| 308 infile = open(filename, 'r') | 316 infile = open(filename, 'r') |
| 309 filename_line = "%s\n" % filename | 317 filename_line = "%s\n" % filename |
| 310 outfile.write(filename_line) | 318 outfile.write(filename_line) |
| 315 # Multiple Model Partition Files | 323 # Multiple Model Partition Files |
| 316 if multiple_model: | 324 if multiple_model: |
| 317 files = glob.glob('RAxML_bestTree.galaxy.PARTITION.*') | 325 files = glob.glob('RAxML_bestTree.galaxy.PARTITION.*') |
| 318 if len(files) > 0: | 326 if len(files) > 0: |
| 319 files.sort(key=getint) | 327 files.sort(key=getint) |
| 320 outfile = open('RAxML_bestTreePartitions.galaxy','w') | 328 outfile = open('RAxML_bestTreePartitions.galaxy', 'w') |
| 321 # Best Tree Partitions | 329 # Best Tree Partitions |
| 322 for filename in files: | 330 for filename in files: |
| 323 if fnmatch.fnmatch(filename, 'RAxML_bestTree.galaxy.PARTITION.*'): | 331 if fnmatch.fnmatch(filename, 'RAxML_bestTree.galaxy.PARTITION.*'): |
| 324 infile = open(filename, 'r') | 332 infile = open(filename, 'r') |
| 325 filename_line = "%s\n" % filename | 333 filename_line = "%s\n" % filename |
| 327 for line in infile: | 335 for line in infile: |
| 328 outfile.write(line) | 336 outfile.write(line) |
| 329 infile.close() | 337 infile.close() |
| 330 outfile.close() | 338 outfile.close() |
| 331 else: | 339 else: |
| 332 outfile = open('RAxML_bestTreePartitions.galaxy','w') | 340 outfile = open('RAxML_bestTreePartitions.galaxy', 'w') |
| 333 outfile.write("No partition files were produced.\n") | 341 outfile.write("No partition files were produced.\n") |
| 334 outfile.close() | 342 outfile.close() |
| 335 | 343 |
| 336 # Result Partitions | 344 # Result Partitions |
| 337 files = glob.glob('RAxML_result.galaxy.PARTITION.*') | 345 files = glob.glob('RAxML_result.galaxy.PARTITION.*') |
| 338 if len(files) > 0: | 346 if len(files) > 0: |
| 339 files.sort(key=getint) | 347 files.sort(key=getint) |
| 340 outfile = open('RAxML_resultPartitions.galaxy','w') | 348 outfile = open('RAxML_resultPartitions.galaxy', 'w') |
| 341 for filename in files: | 349 for filename in files: |
| 342 if fnmatch.fnmatch(filename, 'RAxML_result.galaxy.PARTITION.*'): | 350 if fnmatch.fnmatch(filename, 'RAxML_result.galaxy.PARTITION.*'): |
| 343 infile = open(filename, 'r') | 351 infile = open(filename, 'r') |
| 344 filename_line = "%s\n" % filename | 352 filename_line = "%s\n" % filename |
| 345 outfile.write(filename_line) | 353 outfile.write(filename_line) |
| 346 for line in infile: | 354 for line in infile: |
| 347 outfile.write(line) | 355 outfile.write(line) |
| 348 infile.close() | 356 infile.close() |
| 349 outfile.close() | 357 outfile.close() |
| 350 else: | 358 else: |
| 351 outfile = open('RAxML_resultPartitions.galaxy','w') | 359 outfile = open('RAxML_resultPartitions.galaxy', 'w') |
| 352 outfile.write("No partition files were produced.\n") | 360 outfile.write("No partition files were produced.\n") |
| 353 outfile.close() | 361 outfile.close() |
| 354 | 362 |
| 355 # DEBUG options | 363 # DEBUG options |
| 356 infof = open('RAxML_info.galaxy','a') | 364 infof = open('RAxML_info.galaxy', 'a') |
| 357 infof.write('\nOM: CLI options DEBUG START:\n') | 365 infof.write('\nOM: CLI options DEBUG START:\n') |
| 358 infof.write(options.__repr__()) | 366 infof.write(options.__repr__()) |
| 359 infof.write('\nOM: CLI options DEBUG END\n') | 367 infof.write('\nOM: CLI options DEBUG END\n') |
| 360 | 368 |
| 361 if __name__=="__main__": __main__() | 369 if __name__ == "__main__": |
| 370 __main__() |
