comparison mugsy.py @ 0:1e8862eb2eba draft

Uploaded
author crs4
date Fri, 06 Sep 2013 05:58:59 -0400
parents
children 13f806b78483
comparison
equal deleted inserted replaced
-1:000000000000 0:1e8862eb2eba
1 # -*- coding: utf-8 -*-
2 """
3 Mugsy wrapper
4
5 For draft genomes a single multi-FASTA file containig all contigs should be provided.
6 """
7
8 import optparse
9 import os
10 import shutil
11 import subprocess
12 import sys
13 import tempfile
14
15 def __main__():
16 """ main function """
17 parser = optparse.OptionParser()
18 parser.add_option('-r', dest='reference', help='reference FASTA file')
19 parser.add_option('-c', dest='contigs', help='contigs FASTA file')
20 parser.add_option('-p', dest='prefix', default='prefix', help='prefix ')
21 parser.add_option('-l', dest='logfile', help='logfile')
22 parser.add_option('--ml', dest='mugsylog', help='mugsylog file')
23 parser.add_option('--maf', dest='maf', help='ouput MAF alignment file ')
24 (options, args) = parser.parse_args()
25 if len(args) > 0:
26 parser.error('Wrong number of arguments')
27
28 logfile = options.logfile
29 wd = tempfile.mkdtemp()
30 try:
31 command = "mugsy --directory %s --prefix %s --log %s %s %s" % (wd, options.prefix, options.mugsylog, options.reference, options.contigs)
32 print 'Mugsy command to be executed:\n ' + command
33
34 log = open(logfile, 'w') if logfile else sys.stdout
35 try:
36 subprocess.check_call(command, stderr=log, shell=True) # need to redirect stderr because mugsy writes its logging info there
37 finally:
38 if log != sys.stdout:
39 log.close()
40 print 'Mugsy executed!'
41
42 shutil.move(os.path.join(wd, options.prefix + '.maf'), options.maf)
43 finally:
44 shutil.rmtree(wd)
45
46
47 if __name__ == "__main__":
48 __main__()