annotate glimmer3_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 --> glimmer3
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 shutil
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
9 import subprocess
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
10 import sys
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
11
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
12 def __main__():
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
13 # load arguments
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
14 print 'Parsing input options...'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
15 parser = optparse.OptionParser()
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
16 parser.add_option('--glSequence', dest='sequence', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
17 parser.add_option('--glIcm', dest='icm', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
18 #parser.add_option('--glPrefix', dest='prefix', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
19 parser.add_option('--glStartCodons', dest='start_codons', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
20 parser.add_option('--glRbsPwm', dest='rbs_pwm', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
21 parser.add_option('--glGcPercent', dest='gc_percent', type='float', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
22 parser.add_option('--glEntropy', dest='entropy', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
23 parser.add_option('--glFirstCodon', action='store_true', dest='first_codon', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
24 parser.add_option('--glGeneLen', dest='gene_len', type='int', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
25 parser.add_option('--glIgnore', dest='ignore', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
26 parser.add_option('--glLinear', action='store_true', dest='linear', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
27 parser.add_option('--glOrfCoords', dest='orf_coords', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
28 parser.add_option('--glSeparateGenes', action='store_true', dest='separate_genes', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
29 parser.add_option('--glMaxOverlap', dest='max_olap', type='int', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
30 parser.add_option('--glStartProbs', dest='start_probs', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
31 parser.add_option('--glIgnoreScoreLen', dest='ignore_score_len', type='int', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
32 parser.add_option('--glNoIndep', action='store_true', dest='no_indep', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
33 parser.add_option('--glThreshold', dest='threshold', type='int', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
34 parser.add_option('--glExtend', action='store_true', dest='extend', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
35 parser.add_option('--glTransTable', dest='trans_table', type='int', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
36 parser.add_option('--glStopCodons', dest='stop_codons', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
37 parser.add_option('--glDetail', dest='detail', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
38 parser.add_option('--glPredict', dest='predict', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
39 parser.add_option('--logfile', dest='logfile', help='')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
40 (options, args) = parser.parse_args()
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
41 if len(args) > 0:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
42 parser.error('Wrong number of arguments')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
43
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
44 # build Glimmer3 command to be executed
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
45 # sequence file
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
46 sequence = options.sequence
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
47 # icm file
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
48 icm = options.icm
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
49 # prefix (not needed)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
50 prefix = 'prefix'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
51 # start codons
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
52 if options.start_codons:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
53 start_codons = '--start_codons %s' % (options.start_codons)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
54 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
55 start_codons = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
56 # rbs_pwm
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
57 if options.rbs_pwm:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
58 rbs_pwm = '--rbs_pwm %s' % (options.rbs_pwm)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
59 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
60 rbs_pwm = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
61 # gc percentage
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
62 if options.gc_percent is not None:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
63 gc_percent = '--gc_percent %s' % (options.gc_percent)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
64 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
65 gc_percent = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
66 # entropy
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
67 if options.entropy:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
68 entropy = "--entropy '%s'" % (options.entropy)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
69 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
70 entropy = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
71 # first_codon
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
72 if options.first_codon:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
73 first_codon = '--first_codon'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
74 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
75 first_codon = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
76 # gene length
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
77 if options.gene_len is not None:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
78 gene_len = '--gene_len %d' % (options.gene_len)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
79 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
80 gene_len = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
81 # ignore
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
82 if options.ignore:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
83 ignore = '--ignore %s' % (options.ignore)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
84 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
85 ignore = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
86 # linear
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
87 if options.linear:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
88 linear = '--linear'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
89 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
90 linear = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
91 # orf_coords
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
92 if options.orf_coords:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
93 orf_coords = '--orf_coords %s' % (options.orf_coords)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
94 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
95 orf_coords = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
96 # separate genes
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
97 if options.separate_genes:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
98 separate_genes = '--separate_genes'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
99 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
100 separate_genes = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
101 # max overlap
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
102 if options.max_olap is not None:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
103 max_olap = '--max_olap %d' % (options.max_olap)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
104 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
105 max_olap = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
106 # start probs
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
107 if options.start_probs:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
108 start_probs = '--start_probs %s' % (options.start_probs)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
109 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
110 start_probs = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
111 # ignore score length
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
112 if options.ignore_score_len is not None:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
113 ignore_score_len = '--ignore_score_len %d' % (options.ignore_score_len)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
114 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
115 ignore_score_len = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
116 # no indep
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
117 if options.no_indep:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
118 no_indep = '--no_indep'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
119 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
120 no_indep = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
121 # threshold
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
122 if options.threshold is not None:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
123 threshold = '--threshold %d' % (options.threshold)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
124 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
125 threshold = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
126 # extend
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
127 if options.extend:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
128 extend = '--extend'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
129 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
130 extend = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
131 # trans table
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
132 if options.trans_table is not None:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
133 trans_table = '--trans_table %d' % (options.trans_table)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
134 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
135 trans_table = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
136 # stop codons
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
137 if options.stop_codons:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
138 stop_codons = '--stop_codons %s' % (options.stop_codons)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
139 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
140 stop_codons = ''
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
141 logfile = options.logfile
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
142
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
143 # Build Glimmer3 command
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
144 cmd = 'glimmer3 %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s' % (start_codons, rbs_pwm, gc_percent, entropy, first_codon, gene_len, ignore, linear, orf_coords, separate_genes, max_olap, start_probs, ignore_score_len, no_indep, threshold, extend, trans_table, stop_codons, sequence, icm, prefix)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
145 print '\nGlimmer3 command to be executed: \n %s' % (cmd)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
146
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
147 print 'Executing Glimmer3...'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
148 if logfile:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
149 log = open(logfile, 'w')
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
150 else:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
151 log = sys.stdout
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
152 try:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
153 subprocess.check_call(cmd, stdout=log, stderr=subprocess.STDOUT, shell=True)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
154 finally:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
155 if log != sys.stdout:
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
156 log.close()
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
157 print 'Glimmer3 executed!'
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
158
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
159 shutil.move(prefix + ".detail", options.detail)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
160 shutil.move(prefix + ".predict", options.predict)
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
161
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
162
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
163 if __name__ == "__main__":
9c8ffce71f7c Uploaded
crs4
parents:
diff changeset
164 __main__()