-
Notifications
You must be signed in to change notification settings - Fork 1
/
20080201b.py
51 lines (45 loc) · 1.64 KB
/
20080201b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Create a GY94 codon rate matrix from codon weights and two other parameters.
The rows and columns in the output will be ordered
alphabetically by codon regardless of the input order.
Kappa controls the transition / transversion rate.
Omega controls the non-synonymous / synonymous rate.
"""
from StringIO import StringIO
from SnippetUtil import HandlingError
import SnippetUtil
import CodonFrequency
import Codon
import RateMatrix
import Form
import FormOut
def get_form():
"""
@return: the body of a form
"""
# define the default codon weight lines
default_weight_lines = []
cf = CodonFrequency.codon_frequency_b
for codon in Codon.g_sorted_non_stop_codons:
weight = cf.codon_to_non_stop_proportion(codon)
line = codon + ' : ' + str(weight)
default_weight_lines.append(line)
# define the form objects
form_objects = [
Form.MultiLine('weights', 'codon weights',
'\n'.join(default_weight_lines)),
Form.Float('kappa', 'kappa', 2),
Form.Float('omega', 'omega', .01)]
return form_objects
def get_form_out():
return FormOut.CodonRateMatrix()
def get_response_content(fs):
# get the codon distribution
codons = Codon.g_sorted_non_stop_codons
distribution = SnippetUtil.get_distribution(fs.weights, 'codon', codons)
# get the rate matrix defined by the weights and kappa and omega
r = RateMatrix.get_gy94_rate_matrix(distribution, fs.kappa, fs.omega)
# show the rate matrix in convenient text form
out = StringIO()
for ca in codons:
print >> out, '\t'.join(str(r[(ca, cb)]) for cb in codons)
return out.getvalue()