annotate anomaly_wrapper.py @ 0:9c8ffce71f7c draft default tip

Uploaded
author crs4
date Mon, 09 Sep 2013 12:16:17 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
1 # -*- coding: utf-8 -*-
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
2 """
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
3 Glimmer --> anomaly
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
4 version 0.2 (andrea.pinna@crs4.it)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
5 """
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
6
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
7 import optparse
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
8 import subprocess
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
9 import sys
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
10
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
11 def __main__():
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
12 # load arguments
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
13 print 'Parsing Anomaly input options...'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
14 parser = optparse.OptionParser()
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
15 parser.add_option('--anSequence', dest='sequence', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
16 parser.add_option('--anCoords', dest='coords', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
17 parser.add_option('--anCheckFirstCodon', action='store_true', dest='check_first_codon', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
18 parser.add_option('--anCheckStopCodon', action='store_true', dest='check_stop_codon', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
19 parser.add_option('--anStartCodons', dest='start_codons', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
20 parser.add_option('--anStopCodons', dest='stop_codons', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
21 parser.add_option('--anOutput', dest='output', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
22 parser.add_option('--logfile', dest='logfile', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
23 (options, args) = parser.parse_args()
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
24 if len(args) > 0:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
25 parser.error('Wrong number of arguments')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
26
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
27 # build Anomaly command to be executed
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
28 # sequence file
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
29 sequence = options.sequence
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
30 coords = options.coords
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
31 if options.start_codons:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
32 start_codons = '-A %s' % (options.start_codons)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
33 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
34 start_codons = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
35 if options.stop_codons:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
36 stop_codons = '-Z %s' % (options.stop_codons)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
37 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
38 stop_codons = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
39 if options.check_first_codon:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
40 check_first_codon = '-s'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
41 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
42 check_first_codon = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
43 if options.check_stop_codon:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
44 check_stop_codon = '-t'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
45 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
46 check_stop_codon = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
47 output = options.output
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
48 logfile = options.logfile
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
49
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
50 # Build Anomaly command
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
51 cmd = 'anomaly %s %s %s %s %s %s > %s' % (start_codons, check_first_codon, check_stop_codon, stop_codons, sequence, coords, output)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
52 print '\nAnomaly command to be executed: \n %s' % (cmd)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
53
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
54 print 'Executing Anomaly...'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
55 if logfile:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
56 log = open(logfile, 'w')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
57 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
58 log = sys.stdout
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
59 try:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
60 subprocess.check_call(cmd, stdout=log, stderr=subprocess.STDOUT, shell=True)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
61 finally:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
62 if log != sys.stdout:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
63 log.close()
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
64 print 'Anomaly executed!'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
65
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
66
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
67 if __name__ == "__main__":
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
68 __main__()