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

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