def get_response_content(fs): # deserialize the xml data to create a DirectProteinMixture try: mixture_model = DirectProtein.deserialize_mixture_model(fs.model) except ValueError as e: raise HandlingError(e) expected_rate = mixture_model.get_expected_rate() codon_distribution = mixture_model.get_codon_stationary_distribution() aa_distribution = mixture_model.get_aa_stationary_distribution() nt_distribution = mixture_model.get_nt_stationary_distribution() ordered_codons = list(sorted(Codon.g_non_stop_codons)) # show the summary out = StringIO() print >> out, 'expected codon 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) print >> out, '' print >> out, 'amino acid distribution:' for aa, proportion in zip(Codon.g_aa_letters, aa_distribution): print >> out, '%s : %s' % (aa, proportion) print >> out, '' print >> out, 'codon distribution:' for codon, proportion in zip(ordered_codons, codon_distribution): print >> out, '%s : %s' % (codon, proportion) return out.getvalue()
def get_response_content(fs): # get the newick string try: tree = Newick.parse(fs.tree, Newick.NewickTree) tree.assert_valid() except Newick.NewickSyntaxError as e: raise HandlingError(e) # get the normalized Direct RNA mixture model mixture_model = DirectProtein.deserialize_mixture_model(fs.model) mixture_model.normalize() # simulate the alignment try: alignment = PhyLikelihood.simulate_alignment(tree, mixture_model, fs.ncols) except PhyLikelihood.SimulationError as e: raise HandlingError(e) # get the alignment arr = [] for node in tree.gen_tips(): arr.append(alignment.get_fasta_sequence(node.name)) # return the alignment string return '\n'.join(arr) + '\n'
def get_response_content(fs): # deserialize the xml data to create a DirectProteinMixture try: mixture_model = DirectProtein.deserialize_mixture_model(fs.model) except ValueError as e: raise HandlingError(e) # Normalize the mixture model to have an expected rate of one # substitution per unit of branch length. mixture_model.normalize() # begin writing the html file out = StringIO() # write the html header print >> out, '<html>' print >> out, '<head>' print >> out, '<style type="text/css">td{font-size:x-small;}</style>' print >> out, '</head>' print >> out, '<body>' # write the symmetric components of the rate matrices for category_i, matrix_object in enumerate(mixture_model.rate_matrices): codon_v = matrix_object.get_stationary_distribution() matrix = matrix_object.dictionary_rate_matrix symmetric_matrix = {} for ca, pa in zip(codons, codon_v): for cb, pb in zip(codons, codon_v): value = matrix[(ca, cb)] / (math.sqrt(pb) / math.sqrt(pa)) symmetric_matrix[(ca, cb)] = value print >> out, 'the symmetric component of the rate matrix' print >> out, 'for category %d:' % (category_i + 1) print >> out, '<table>' print >> out, RateMatrix.codon_rate_matrix_to_html_string( symmetric_matrix) print >> out, '</table>' print >> out, '<br/><br/>' # write the html footer print >> out, '</body>' print >> out, '</html>' # return the response return out.getvalue()