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