comparison build-icm_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 --> build-icm
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 Build-ICM input options...'
14 parser = optparse.OptionParser()
15 parser.add_option('--biSequence', dest='sequence', help='')
16 parser.add_option('--biDepth', dest='depth', type='int', help='')
17 parser.add_option('--biNoStops', action='store_true', dest='no_stops', help='')
18 parser.add_option('--biPeriod', dest='period', type='int', help='')
19 parser.add_option('--biReverse', action='store_true', dest='reverse', help='')
20 parser.add_option('--biWidth', dest='width', type='int', help='')
21 parser.add_option('--biTransTable', dest='trans_table', type='int', help='')
22 parser.add_option('--biStopCodons', dest='stop_codons', help='')
23 parser.add_option('--biIcm', dest='output', help='')
24 parser.add_option('--logfile', dest='logfile', help='')
25 (options, args) = parser.parse_args()
26 if len(args) > 0:
27 parser.error('Wrong number of arguments')
28
29 # build Build-ICM command to be executed
30 sequence = options.sequence
31 if options.depth is not None:
32 depth = '--depth %d' % (options.depth)
33 else:
34 depth = ''
35 if options.no_stops:
36 no_stops = '--no_stops'
37 else:
38 no_stops = ''
39 if options.period is not None:
40 period = '--period %d' % (options.period)
41 else:
42 period = ''
43 if options.reverse:
44 reverse = '--reverse'
45 else:
46 reverse = ''
47 if options.width is not None:
48 width = '--width %d' % (options.width)
49 else:
50 width = ''
51 if options.trans_table is not None:
52 trans_table = '--trans_table %d' % (options.trans_table)
53 else:
54 trans_table = ''
55 if options.stop_codons:
56 stop_codons = '--stop_codons %s' % (options.stop_codons)
57 else:
58 stop_codons = ''
59 output = options.output
60 logfile = options.logfile
61
62 # Build Build-ICM command
63 cmd = 'build-icm %s %s %s %s %s %s %s %s < %s ' % (depth, no_stops, period, reverse, width, trans_table, stop_codons, output, sequence)
64 print '\nBuild-ICM command to be executed: \n %s' % (cmd)
65
66 print 'Executing Build-ICM...'
67 if logfile:
68 log = open(logfile, 'w')
69 else:
70 log = sys.stdout
71 try:
72 subprocess.check_call(cmd, stdout=log, stderr=subprocess.STDOUT, shell=True)
73 finally:
74 if log != sys.stdout:
75 log.close()
76 print 'Build-ICM executed!'
77
78
79 if __name__ == "__main__":
80 __main__()