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