0
|
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 parser = optparse.OptionParser()
|
|
17 parser.add_option('-r', dest='reference', help='reference FASTA file')
|
|
18 parser.add_option('-c', dest='contigs', help='contigs FASTA file')
|
|
19 parser.add_option('-p', dest='prefix', default='prefix', help='prefix ')
|
|
20 parser.add_option('-l', dest='logfile', help='logfile')
|
|
21 parser.add_option('--ml', dest='mugsylog', help='mugsylog file')
|
|
22 parser.add_option('--maf', dest='maf', help='ouput MAF alignment file ')
|
|
23 (options, args) = parser.parse_args()
|
|
24 if len(args) > 0:
|
|
25 parser.error('Wrong number of arguments')
|
2
|
26
|
0
|
27 logfile = options.logfile
|
|
28 wd = tempfile.mkdtemp()
|
|
29 try:
|
|
30 command = "mugsy --directory %s --prefix %s --log %s %s %s" % (wd, options.prefix, options.mugsylog, options.reference, options.contigs)
|
|
31 print 'Mugsy command to be executed:\n ' + command
|
2
|
32
|
0
|
33 log = open(logfile, 'w') if logfile else sys.stdout
|
|
34 try:
|
|
35 subprocess.check_call(command, stderr=log, shell=True) # need to redirect stderr because mugsy writes its logging info there
|
|
36 finally:
|
|
37 if log != sys.stdout:
|
|
38 log.close()
|
|
39 print 'Mugsy executed!'
|
2
|
40
|
0
|
41 shutil.move(os.path.join(wd, options.prefix + '.maf'), options.maf)
|
|
42 finally:
|
|
43 shutil.rmtree(wd)
|
|
44
|
|
45
|
|
46 if __name__ == "__main__":
|
|
47 __main__()
|