-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path20080310b.py
44 lines (38 loc) · 1.3 KB
/
20080310b.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
"""Summarize the properties of a Direct RNA mixture model.
See "Population Genetics Without Intraspecific Data" by Thorne et al.
for more information about the Direct RNA model.
"""
from StringIO import StringIO
from SnippetUtil import HandlingError
import Codon
import DirectRna
import Form
import FormOut
def get_form():
"""
@return: the body of a form
"""
# define the default xml string
default_xml_string = DirectRna.get_sample_xml_string()
# define the form objects
return [Form.MultiLine('model', 'mixture model', default_xml_string)]
def get_form_out():
return FormOut.Report()
def get_response_content(fs):
# deserialize the xml data to create a DirectRnaMixture
try:
mixture_model = DirectRna.deserialize_mixture_model(fs.model)
except ValueError as e:
raise HandlingError(e)
expected_rate = mixture_model.get_expected_rate()
nt_distribution = mixture_model.get_nt_stationary_distribution()
# write the summary
out = StringIO()
print >> out, 'expected substitution rate:'
print >> out, expected_rate
print >> out, ''
print >> out, 'nucleotide distribution:'
for nt, proportion in zip(Codon.g_nt_letters, nt_distribution):
print >> out, '%s : %s' % (nt, proportion)
# return the summary
return out.getvalue()