当前位置: 首页>>代码示例>>Python>>正文


Python Messages.calculate_at_codon_usage方法代码示例

本文整理汇总了Python中messages.Messages.calculate_at_codon_usage方法的典型用法代码示例。如果您正苦于以下问题:Python Messages.calculate_at_codon_usage方法的具体用法?Python Messages.calculate_at_codon_usage怎么用?Python Messages.calculate_at_codon_usage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在messages.Messages的用法示例。


在下文中一共展示了Messages.calculate_at_codon_usage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _code_fitness

# 需要导入模块: from messages import Messages [as 别名]
# 或者: from messages.Messages import calculate_at_codon_usage [as 别名]
    def _code_fitness(self, code, codon_usage = None):
        """ Gets the overall fitness of a code at the given codon usage,
            if no codon usage is given the codon usage of the 
            currently fixed code at equilibrium is used. """
        
        fitness_contributions = None

        if codon_usage is None:
            if self._last_messages is None:
                if code == self._current_code:
                    msgs = Messages(self._current_code.effective_code_matrix,
                                    self._fitness_matrix,
                                    self._message_mutation_matrix)
                    msgs.calculate_at_equilibrium()
                    self._last_messages = msgs
                    fitness_contributions = msgs.fitness_contributions
                else:
                    self._code_fitness(self._current_code)

        if fitness_contributions is None:
            msgs = Messages(code.effective_code_matrix,
                            self._fitness_matrix,
                            self._message_mutation_matrix)
            msgs.calculate_at_codon_usage(self._last_messages.codon_usage)
            fitness_contributions = msgs.fitness_contributions

        overall_fitness = self._overall_fitness(fitness_contributions)

        if codon_usage is None and code == self._current_code:
            self._current_code_fitness = overall_fitness

        return overall_fitness
开发者ID:kkauffman,项目名称:tRNAModel,代码行数:34,代码来源:evolver.py

示例2: Messages_Test

# 需要导入模块: from messages import Messages [as 别名]
# 或者: from messages.Messages import calculate_at_codon_usage [as 别名]
class Messages_Test(unittest.TestCase):
    def setUp(self):
        self.mutation_matrix = np.array([[ 0.96,  0.02,  0.  ,  0.  ,  0.  ,  0.  ,  0.  ,  0.02],
                                         [ 0.02,  0.96,  0.02,  0.  ,  0.  ,  0.  ,  0.  ,  0.  ],
                                         [ 0.  ,  0.02,  0.96,  0.02,  0.  ,  0.  ,  0.  ,  0.  ],
                                         [ 0.  ,  0.  ,  0.02,  0.96,  0.02,  0.  ,  0.  ,  0.  ],
                                         [ 0.  ,  0.  ,  0.  ,  0.02,  0.96,  0.02,  0.  ,  0.  ],
                                         [ 0.  ,  0.  ,  0.  ,  0.  ,  0.02,  0.96,  0.02,  0.  ],
                                         [ 0.  ,  0.  ,  0.  ,  0.  ,  0.  ,  0.02,  0.96,  0.02],
                                         [ 0.02,  0.  ,  0.  ,  0.  ,  0.  ,  0.  ,  0.02,  0.96]])

        pchem_vals = [0.05,0.15,0.24,0.41,0.44,0.51,0.54,0.79,0.83,0.92]
        site_ids = range(10)
        aa_ids = range(10)
        self.site_types = Ring_Site_Types(.25, zip(aa_ids, pchem_vals), zip(site_ids, pchem_vals), [1] * 10)
        
        self.code_matrix = np.ones((8,10)) / 10

        self.fitness_contributions = None
        self.message = Messages(self.code_matrix, self.site_types.fitness_matrix, self.mutation_matrix)

    def test_mutation_selection_matrix(self):
        mutation_selection_matrices = [self.message._mutation_selection_matrix(i) for i in xrange(10)]

        for i in xrange(10):
            self.assertTrue(np.allclose(mutation_selection_matrices[i],
                                        correct_mutation_selection_matrices[i]),
                            msg="Mutation Selection matrix did not match for site index {}.".format(i))
    
    def test_equilibrium_codon_usage(self):
        self.assertTrue(np.allclose(self.message.codon_usage, # Should default to calculating codon usage
                                    correct_equilibrium_codon_usage)) # at equilibrium

    def test_equilibrium_fitness_contributions(self):
        self.assertTrue(np.allclose(self.message.fitness_contributions, # Should also default to at equilibrium 
                                    correct_equilibrium_fitness_contributions))

    def test_nonequilibrium_fitness_contributions(self):
        self.message.calculate_at_codon_usage(nonequilibrium_codon_usage)
        fitness_contributions = self.message.fitness_contributions

        self.assertAlmostEqual(correct_nonequilibrium_fitness, np.prod(fitness_contributions))
开发者ID:kkauffman,项目名称:tRNAModel,代码行数:44,代码来源:messages_test.py


注:本文中的messages.Messages.calculate_at_codon_usage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。