annotate mugsy.py @ 1:2dcf5873f1b1 draft

Update Orione citation.
author crs4
date Mon, 09 Sep 2013 05:40:19 -0400
parents 1e8862eb2eba
children 13f806b78483
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 """ main function """
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
17 parser = optparse.OptionParser()
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
18 parser.add_option('-r', dest='reference', help='reference FASTA file')
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
19 parser.add_option('-c', dest='contigs', help='contigs FASTA file')
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
20 parser.add_option('-p', dest='prefix', default='prefix', help='prefix ')
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
21 parser.add_option('-l', dest='logfile', help='logfile')
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
22 parser.add_option('--ml', dest='mugsylog', help='mugsylog file')
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
23 parser.add_option('--maf', dest='maf', help='ouput MAF alignment file ')
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
24 (options, args) = parser.parse_args()
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
25 if len(args) > 0:
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
26 parser.error('Wrong number of arguments')
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
27
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
28 logfile = options.logfile
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
29 wd = tempfile.mkdtemp()
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
30 try:
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
31 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
32 print 'Mugsy command to be executed:\n ' + command
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
33
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
34 log = open(logfile, 'w') if logfile else sys.stdout
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
35 try:
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
36 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
37 finally:
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
38 if log != sys.stdout:
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
39 log.close()
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
40 print 'Mugsy executed!'
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
41
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
42 shutil.move(os.path.join(wd, options.prefix + '.maf'), options.maf)
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
43 finally:
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
44 shutil.rmtree(wd)
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
45
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
46
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
47 if __name__ == "__main__":
1e8862eb2eba Uploaded
crs4
parents:
diff changeset
48 __main__()