Created
April 29, 2013 21:31
-
-
Save jonchang/5484957 to your computer and use it in GitHub Desktop.
Runs RAxML in parallel on a bunch of sequences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import os.path | |
import os | |
import errno | |
import multiprocessing | |
import functools | |
import subprocess | |
import pdb | |
import dendropy | |
def mkdir_p(path): | |
"""Makes a directory if it doesn't exist, and does nothing if it does.""" | |
try: | |
os.makedirs(path) | |
except OSError as exc: | |
if exc.errno == errno.EEXIST and os.path.isdir(path): | |
pass | |
else: raise | |
def get_args(): | |
parser = argparse.ArgumentParser(description="run raxml") | |
parser.add_argument("align", nargs="+", help="alignments in phylip format") | |
parser.add_argument("--prefix", help="directory prefix for output") | |
return parser.parse_args() | |
def run(filename, outdir): | |
cmd = "raxmlHPC-PTHREADS-SSE3 -m GTRCAT -n best -s {0} -N 10 -w {1}".format(filename, outdir) | |
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
stdout, stderr = process.communicate() | |
def main(): | |
args = get_args() | |
if args.prefix: | |
mkdir_p(args.prefix) | |
pool = multiprocessing.Pool() | |
pool.map(run, args.align) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment