comparison mugsy.py @ 2:13f806b78483 draft default tip

Add Boost requirement.
author crs4
date Fri, 25 Oct 2013 06:39:33 -0400
parents 1e8862eb2eba
children
comparison
equal deleted inserted replaced
1:2dcf5873f1b1 2:13f806b78483
11 import subprocess 11 import subprocess
12 import sys 12 import sys
13 import tempfile 13 import tempfile
14 14
15 def __main__(): 15 def __main__():
16 """ main function """
17 parser = optparse.OptionParser() 16 parser = optparse.OptionParser()
18 parser.add_option('-r', dest='reference', help='reference FASTA file') 17 parser.add_option('-r', dest='reference', help='reference FASTA file')
19 parser.add_option('-c', dest='contigs', help='contigs FASTA file') 18 parser.add_option('-c', dest='contigs', help='contigs FASTA file')
20 parser.add_option('-p', dest='prefix', default='prefix', help='prefix ') 19 parser.add_option('-p', dest='prefix', default='prefix', help='prefix ')
21 parser.add_option('-l', dest='logfile', help='logfile') 20 parser.add_option('-l', dest='logfile', help='logfile')
22 parser.add_option('--ml', dest='mugsylog', help='mugsylog file') 21 parser.add_option('--ml', dest='mugsylog', help='mugsylog file')
23 parser.add_option('--maf', dest='maf', help='ouput MAF alignment file ') 22 parser.add_option('--maf', dest='maf', help='ouput MAF alignment file ')
24 (options, args) = parser.parse_args() 23 (options, args) = parser.parse_args()
25 if len(args) > 0: 24 if len(args) > 0:
26 parser.error('Wrong number of arguments') 25 parser.error('Wrong number of arguments')
27 26
28 logfile = options.logfile 27 logfile = options.logfile
29 wd = tempfile.mkdtemp() 28 wd = tempfile.mkdtemp()
30 try: 29 try:
31 command = "mugsy --directory %s --prefix %s --log %s %s %s" % (wd, options.prefix, options.mugsylog, options.reference, options.contigs) 30 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 31 print 'Mugsy command to be executed:\n ' + command
33 32
34 log = open(logfile, 'w') if logfile else sys.stdout 33 log = open(logfile, 'w') if logfile else sys.stdout
35 try: 34 try:
36 subprocess.check_call(command, stderr=log, shell=True) # need to redirect stderr because mugsy writes its logging info there 35 subprocess.check_call(command, stderr=log, shell=True) # need to redirect stderr because mugsy writes its logging info there
37 finally: 36 finally:
38 if log != sys.stdout: 37 if log != sys.stdout:
39 log.close() 38 log.close()
40 print 'Mugsy executed!' 39 print 'Mugsy executed!'
41 40
42 shutil.move(os.path.join(wd, options.prefix + '.maf'), options.maf) 41 shutil.move(os.path.join(wd, options.prefix + '.maf'), options.maf)
43 finally: 42 finally:
44 shutil.rmtree(wd) 43 shutil.rmtree(wd)
45 44
46 45