當前位置: 首頁>>代碼示例>>Python>>正文


Python Profile.toOddsMatrix方法代碼示例

本文整理匯總了Python中cogent.core.profile.Profile.toOddsMatrix方法的典型用法代碼示例。如果您正苦於以下問題:Python Profile.toOddsMatrix方法的具體用法?Python Profile.toOddsMatrix怎麽用?Python Profile.toOddsMatrix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cogent.core.profile.Profile的用法示例。


在下文中一共展示了Profile.toOddsMatrix方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_toOddsMatrix

# 需要導入模塊: from cogent.core.profile import Profile [as 別名]
# 或者: from cogent.core.profile.Profile import toOddsMatrix [as 別名]
    def test_toOddsMatrix(self):
        """toOddsMatrix: should work on valid data or raise an error
        """
        p = Profile(
            array(
                [
                    [0.1, 0.3, 0.5, 0.1],
                    [0.25, 0.25, 0.25, 0.25],
                    [0.05, 0.8, 0.05, 0.1],
                    [0.7, 0.1, 0.1, 0.1],
                    [0.6, 0.15, 0.05, 0.2],
                ]
            ),
            Alphabet="ACTG",
        )
        p_exp = Profile(
            array([[0.4, 1.2, 2, 0.4], [1, 1, 1, 1], [0.2, 3.2, 0.2, 0.4], [2.8, 0.4, 0.4, 0.4], [2.4, 0.6, 0.2, 0.8]]),
            Alphabet="ACTG",
        )
        self.assertEqual(p.toOddsMatrix().Data, p_exp.Data)
        assert p.Alphabet is p.toOddsMatrix().Alphabet
        self.assertEqual(p.toOddsMatrix([0.25, 0.25, 0.25, 0.25]).Data, p_exp.Data)

        # fails if symbol_freqs has wrong size
        self.assertRaises(ProfileError, p.toOddsMatrix, [0.25, 0.25, 0.25, 0.25, 0.25, 0.25])
        self.assertRaises(ProfileError, self.zero_entry.toOddsMatrix, [0.1, 0.2, 0.3])
        # works on empty profile
        self.assertEqual(self.empty.toOddsMatrix().Data.tolist(), [[]])
        # works with different input
        self.assertEqual(self.zero_entry.toOddsMatrix().Data, array([[1.2, 0.8, 0, 2], [0, 0, 3.2, 0.8]]))
        self.assertFloatEqual(
            self.zero_entry.toOddsMatrix([0.1, 0.2, 0.3, 0.4]).Data, array([[3, 1, 0, 1.25], [0, 0, 2.667, 0.5]]), 1e-3
        )
        # fails when one of the background frequencies is 0
        self.assertRaises(ProfileError, self.zero_entry.toOddsMatrix, [0.1, 0.2, 0.3, 0])
開發者ID:blankenberg,項目名稱:pycogent,代碼行數:37,代碼來源:test_profile.py

示例2: ProfileTests

# 需要導入模塊: from cogent.core.profile import Profile [as 別名]
# 或者: from cogent.core.profile.Profile import toOddsMatrix [as 別名]

#.........這裏部分代碼省略.........

    def test__div_(self):
        """__div__ and __truediv__: always true division b/c __future__.division
        """
        p1 = Profile(array([[2, 3], [4, 5]]), "AB")
        p2 = Profile(array([[1, 0], [4, 5]]), "AB")  # Int 0
        p3 = Profile(array([[1, 0.0], [4, 5]]), "AB")  # Float 0.0
        p4 = Profile(array([[1, 2], [8.0, 5]]), "AB")  # Float 0.0

        self.assertRaises(ProfileError, p1.__truediv__, p2)
        # infinity in result data
        self.assertRaises(ProfileError, p1.__div__, p3)
        self.assertFloatEqual((p1.__div__(p4)).Data, array([[2, 1.5], [0.5, 1]]))

    def test_distance(self):
        """distance: should return correct distance between the profiles
        """
        p1 = Profile(array([[2, 4], [3, 1]]), "AB")
        p2 = Profile(array([[4, 6], [5, 3]]), "AB")
        p3 = Profile(array([[4, 6], [5, 3], [1, 1]]), "AB")
        p4 = Profile(array([2, 2]), "AB")
        p5 = Profile(array([2, 2, 2]), "AB")
        p6 = Profile(array([[]]), "AB")

        self.assertEqual(p1.distance(p2), 4)
        self.assertEqual(p2.distance(p1), 4)
        self.assertEqual(p1.distance(p4), sqrt(6))
        self.assertEqual(p6.distance(p6), 0)

        # Raises error when frames are not aligned
        self.assertRaises(ProfileError, p1.distance, p3)
        self.assertRaises(ProfileError, p1.distance, p5)

    def test_toOddsMatrix(self):
        """toOddsMatrix: should work on valid data or raise an error
        """
        p = Profile(
            array(
                [
                    [0.1, 0.3, 0.5, 0.1],
                    [0.25, 0.25, 0.25, 0.25],
                    [0.05, 0.8, 0.05, 0.1],
                    [0.7, 0.1, 0.1, 0.1],
                    [0.6, 0.15, 0.05, 0.2],
                ]
            ),
            Alphabet="ACTG",
        )
        p_exp = Profile(
            array([[0.4, 1.2, 2, 0.4], [1, 1, 1, 1], [0.2, 3.2, 0.2, 0.4], [2.8, 0.4, 0.4, 0.4], [2.4, 0.6, 0.2, 0.8]]),
            Alphabet="ACTG",
        )
        self.assertEqual(p.toOddsMatrix().Data, p_exp.Data)
        assert p.Alphabet is p.toOddsMatrix().Alphabet
        self.assertEqual(p.toOddsMatrix([0.25, 0.25, 0.25, 0.25]).Data, p_exp.Data)

        # fails if symbol_freqs has wrong size
        self.assertRaises(ProfileError, p.toOddsMatrix, [0.25, 0.25, 0.25, 0.25, 0.25, 0.25])
        self.assertRaises(ProfileError, self.zero_entry.toOddsMatrix, [0.1, 0.2, 0.3])
        # works on empty profile
        self.assertEqual(self.empty.toOddsMatrix().Data.tolist(), [[]])
        # works with different input
        self.assertEqual(self.zero_entry.toOddsMatrix().Data, array([[1.2, 0.8, 0, 2], [0, 0, 3.2, 0.8]]))
        self.assertFloatEqual(
            self.zero_entry.toOddsMatrix([0.1, 0.2, 0.3, 0.4]).Data, array([[3, 1, 0, 1.25], [0, 0, 2.667, 0.5]]), 1e-3
        )
開發者ID:blankenberg,項目名稱:pycogent,代碼行數:70,代碼來源:test_profile.py


注:本文中的cogent.core.profile.Profile.toOddsMatrix方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。