-
Notifications
You must be signed in to change notification settings - Fork 1
/
20080317b.py
66 lines (60 loc) · 2.32 KB
/
20080317b.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""Analyze a nt mutation distribution and an aa stationary distribution.
Analyze a nucleotide mutation distribution
and an amino acid stationary distribution.
Calculate two output vectors from these input distributions.
The first output vector is the stationary nucleotide distribution.
The second output vector is the centered amino acid energy vector.
"""
from StringIO import StringIO
import math
from SnippetUtil import HandlingError
import SnippetUtil
import Codon
import DirectProtein
import Form
import FormOut
from Codon import g_sorted_nt_letters as nt_letters
from Codon import g_sorted_aa_letters as aa_letters
from Codon import g_sorted_non_stop_codons as codons
def get_form():
"""
@return: the body of a form
"""
# define some default strings
default_nt_string = '\n'.join(nt + ' : 1' for nt in nt_letters)
default_aa_string = '\n'.join(aa + ' : 1' for aa in aa_letters)
# define the form objects
form_objects = [
Form.MultiLine('nucleotides', 'nucleotide mutation distribution',
default_nt_string),
Form.MultiLine('aminoacids', 'amino acid stationary distribution',
default_aa_string)]
return form_objects
def get_form_out():
return FormOut.Report()
def get_response_content(fs):
# get the nucleotide distribution
nt_to_weight = SnippetUtil.get_distribution(fs.nucleotides,
'nucleotide', nt_letters)
# get the amino acid distribution
aa_to_weight = SnippetUtil.get_distribution(fs.aminoacids,
'amino acid', aa_letters)
# get results
mutation_distribution = [nt_to_weight[nt] for nt in nt_letters]
aa_distribution = [aa_to_weight[aa] for aa in aa_letters]
pair = DirectProtein.get_nt_distribution_and_aa_energies(
mutation_distribution, aa_distribution)
nt_distribution, aa_energies = pair
# write something
out = StringIO()
# write the stationary nucleotide distribution
print >> out, 'nucleotide stationary distribution:'
for nt, value in zip(nt_letters, nt_distribution):
print >> out, '%s : %s' % (nt, value)
print >> out, ''
# write the amino acid energies
print >> out, 'amino acid energies:'
for aa, value in zip(aa_letters, aa_energies):
print >> out, '%s : %s' % (aa, value)
# return the response
return out.getvalue()