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


Python Profile._score_profile方法代码示例

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


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

示例1: ProfileTests

# 需要导入模块: from cogent.core.profile import Profile [as 别名]
# 或者: from cogent.core.profile.Profile import _score_profile [as 别名]

#.........这里部分代码省略.........
                    [0.7, 0.1, 0.1, 0.1],
                    [0.6, 0.15, 0.05, 0.2],
                ]
            ),
            Alphabet="ACTG",
        )
        p_exp = Profile(
            array(
                [
                    [-1.322, 0.263, 1.0, -1.322],
                    [0.0, 0.0, 0.0, 0.0],
                    [-2.322, 1.678, -2.322, -1.322],
                    [1.485, -1.322, -1.322, -1.322],
                    [1.263, -0.737, -2.322, -0.322],
                ]
            ),
            Alphabet="ACTG",
        )
        self.assertFloatEqual(p.toLogOddsMatrix().Data, p_exp.Data, eps=1e-3)
        # works on empty matrix
        self.assertEqual(self.empty.toLogOddsMatrix().Data.tolist(), [[]])

    def test__score_indices(self):
        """_score_indices: should work on valid input"""
        self.assertEqual(self.score1._score_indices(array([0, 1, 1, 3, 0, 3]), offset=0), [6, 2, -3, 0])
        self.assertFloatEqual(
            self.score2._score_indices(array([3, 1, 2, 0, 2, 2, 3]), offset=0), [0.3, 1.4, 0.8, 1.4, 1.7]
        )
        self.assertFloatEqual(self.score2._score_indices(array([3, 1, 2, 0, 2, 2, 3]), offset=3), [1.4, 1.7])
        # Errors will be raised on invalid input. Errors are not handled
        # in this method. Validation of the input is done elsewhere
        self.assertRaises(IndexError, self.score2._score_indices, array([3, 1, 63, 0, 4, 2, 3]), offset=3)

    def test__score_profile(self):
        """_score_profile: should work on valid input"""
        p1 = Profile(
            array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0.5, 0.5], [0, 0, 0, 1], [0.25, 0.25, 0.25, 0.25]]), "TCAG"
        )
        p2 = Profile(
            array(
                [[0, 1, 0, 0], [0.2, 0, 0.8, 0], [0, 0, 0.5, 0.5], [1 / 3, 1 / 3, 0, 1 / 3], [0.25, 0.25, 0.25, 0.25]]
            ),
            "TCAG",
        )

        self.assertFloatEqual(self.score2._score_profile(p1, offset=0), [0.55, 1.25, 0.45])
        self.assertFloatEqual(self.score2._score_profile(p1, offset=2), [0.45])
        self.assertFloatEqual(self.score2._score_profile(p2, offset=0), [1.49, 1.043, 0.483], 1e-3)

        # Errors will be raised on invalid input. Errors are not handled
        # in this method. Validation of the input is done elsewhere
        # In this case you don't get an error, but for sure an unexpected
        # result
        self.assertFloatEqual(self.score2._score_profile(p1, offset=3).tolist(), [])

    def test_score_sequence(self):
        """score: should work correctly for Sequence as input
        """
        # works on normal valid data
        s1 = self.score1.score("ATTCAC", offset=0)
        self.assertEqual(s1, [6, 2, -3, 0])
        self.assertFloatEqual(self.score2.score("TCAAGT", offset=0), [0.5, 1.6, 1.7, 0.5])
        # works with different offset
        self.assertFloatEqual(self.score2.score("TCAAGT", offset=2), [1.7, 0.5])
        self.assertFloatEqual(self.score2.score("TCAAGT", offset=3), [0.5])
        # raises error on invalid offset
开发者ID:blankenberg,项目名称:pycogent,代码行数:70,代码来源:test_profile.py


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