Mercurial > repos > crs4 > mugsy
diff mugsy.py @ 0:1e8862eb2eba draft
Uploaded
author | crs4 |
---|---|
date | Fri, 06 Sep 2013 05:58:59 -0400 |
parents | |
children | 13f806b78483 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mugsy.py Fri Sep 06 05:58:59 2013 -0400 @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +""" +Mugsy wrapper + +For draft genomes a single multi-FASTA file containig all contigs should be provided. +""" + +import optparse +import os +import shutil +import subprocess +import sys +import tempfile + +def __main__(): + """ main function """ + parser = optparse.OptionParser() + parser.add_option('-r', dest='reference', help='reference FASTA file') + parser.add_option('-c', dest='contigs', help='contigs FASTA file') + parser.add_option('-p', dest='prefix', default='prefix', help='prefix ') + parser.add_option('-l', dest='logfile', help='logfile') + parser.add_option('--ml', dest='mugsylog', help='mugsylog file') + parser.add_option('--maf', dest='maf', help='ouput MAF alignment file ') + (options, args) = parser.parse_args() + if len(args) > 0: + parser.error('Wrong number of arguments') + + logfile = options.logfile + wd = tempfile.mkdtemp() + try: + command = "mugsy --directory %s --prefix %s --log %s %s %s" % (wd, options.prefix, options.mugsylog, options.reference, options.contigs) + print 'Mugsy command to be executed:\n ' + command + + log = open(logfile, 'w') if logfile else sys.stdout + try: + subprocess.check_call(command, stderr=log, shell=True) # need to redirect stderr because mugsy writes its logging info there + finally: + if log != sys.stdout: + log.close() + print 'Mugsy executed!' + + shutil.move(os.path.join(wd, options.prefix + '.maf'), options.maf) + finally: + shutil.rmtree(wd) + + +if __name__ == "__main__": + __main__()