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


Python Profile.score方法代码示例

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


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

示例1: test_score_no_trans_table

# 需要导入模块: from cogent.core.profile import Profile [as 别名]
# 或者: from cogent.core.profile.Profile import score [as 别名]
 def test_score_no_trans_table(self):
     """score: should work when no translation table is present
     """
     p = Profile(Data=array([[-1, 0, 1, 2], [-2, 2, 0, 0], [-3, 5, 1, 0]]), Alphabet=DNA, CharOrder="ATGC")
     # remove translation table
     del p.__dict__["_translation_table"]
     # then score the profile
     s1 = p.score(DNA.Sequence("ATTCAC"), offset=0)
     self.assertEqual(s1, [6, 2, -3, 0])
开发者ID:blankenberg,项目名称:pycogent,代码行数:11,代码来源:test_profile.py

示例2: ProfileTests

# 需要导入模块: from cogent.core.profile import Profile [as 别名]
# 或者: from cogent.core.profile.Profile import score [as 别名]
class ProfileTests(TestCase):
    """Tests for Profile object"""

    def setUp(self):
        """setUp method for all Profile tests"""
        self.full = Profile(array([[2, 4], [3, 5], [4, 8]]), "AB")
        self.empty = Profile(array([[]]), "AB")
        self.empty_row = Profile(array([[1, 1], [0, 0]]), "AB")
        self.empty_col = Profile(array([[0, 1], [0, 1]]), "AB")
        self.consensus = Profile(
            array([[0.2, 0, 0.8, 0], [0, 0.1, 0.2, 0.7], [0, 0, 0, 1], [0.2, 0.3, 0.4, 0.1], [0.5, 0.5, 0, 0]]),
            Alphabet=DNA,
            CharOrder="TCAG",
        )
        self.not_same_value = Profile(
            array([[0.3, 0.5, 0.1, 0.1], [0.4, 0.6, 0, 0.7], [0.3, 0.2, 0, 0], [0, 0, 4, 0]]),
            Alphabet=DNA,
            CharOrder="TCAG",
        )
        self.zero_entry = Profile(array([[0.3, 0.2, 0, 0.5], [0, 0, 0.8, 0.2]]), Alphabet="UCAG")
        self.score1 = Profile(Data=array([[-1, 0, 1, 2], [-2, 2, 0, 0], [-3, 5, 1, 0]]), Alphabet=DNA, CharOrder="ATGC")
        self.score2 = Profile(array([[0.2, 0.4, 0.4, 0], [0.1, 0, 0.9, 0], [0.1, 0.2, 0.3, 0.4]]), Alphabet="TCAG")
        self.oned = Profile(array([0.25, 0.25, 0.25, 0.25]), "ABCD")
        self.pp = Profile(array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]), "ABCD")

    def test_init(self):
        """__init__: should set all attributed correctly"""
        self.assertRaises(TypeError, Profile)
        self.assertRaises(TypeError, Profile, array([[2, 3]]))
        # only alphabet
        p = Profile(array([[0.2, 0.8], [0.7, 0.3]]), "AB")
        self.assertEqual(p.Data, [[0.2, 0.8], [0.7, 0.3]])
        self.assertEqual(p.Alphabet, "AB")
        self.assertEqual(p.CharOrder, list("AB"))
        self.assertEqual(translate("ABBA", p._translation_table), "\x00\x01\x01\x00")
        # alphabet and char order
        p = Profile(array([[0.1, 0.2], [0.4, 0.3]]), Alphabet=DNA, CharOrder="AG")
        self.assertEqual(p.CharOrder, "AG")
        assert p.Alphabet is DNA
        # non-character alphabet
        p = Profile(array([[0.1, 0.2], [0.4, 0.3]]), Alphabet=[7, 3], CharOrder=[3, 7])
        self.assertEqual(p.CharOrder, [3, 7])
        self.assertEqual(p.Alphabet, [7, 3])
        self.assertEqual(p.Data, [[0.1, 0.2], [0.4, 0.3]])

    def test_str(self):
        """__str__: should return string representation of data in profile
        """
        self.assertEqual(str(self.empty_row), str(array([[1, 1], [0, 0]])))

    def test_make_translation_table(self):
        """_make_translation_table: should return correct table from char order
        """
        p = Profile(array([[0.2, 0.8], [0.7, 0.3]]), "ABCDE", "AB")
        self.assertEqual(translate("ABBA", p._translation_table), "\x00\x01\x01\x00")

    def test_hasValidData(self):
        """hasValidData: should work on full and empty profiles"""
        full = self.full.copy()
        full.normalizePositions()
        self.assertEqual(full.hasValidData(), True)
        self.assertEqual(self.empty_row.hasValidData(), False)
        self.assertEqual(self.empty.hasValidData(), False)

    def test_hasValidAttributes(self):
        """hasValidAttributes: should work for different alphabets/char orders
        """
        p = Profile(array([[1, 2], [3, 4]]), Alphabet="ABCD", CharOrder="BAC")
        # self.Data doesn't match len(CharOrder)
        self.assertEqual(p.hasValidAttributes(), False)
        p = Profile(array([[1, 2], [3, 4]]), Alphabet="ABCD", CharOrder="AX")
        # not all chars in CharOrder in Alphabet
        self.assertEqual(p.hasValidAttributes(), False)
        p = Profile(array([[1, 2], [3, 4]]), Alphabet="ABCD", CharOrder="CB")
        # should be fine
        self.assertEqual(p.hasValidAttributes(), True)

    def test_isValid(self):
        """isValid: should work as expected"""
        # everything valid
        p1 = Profile(array([[0.3, 0.7], [0.8, 0.2]]), Alphabet="AB", CharOrder="AB")
        # invalid data, valid attributes
        p2 = Profile(array([[1, 2], [3, 4]]), Alphabet="ABCD", CharOrder="BA")
        # invalid attributes, valid data
        p3 = Profile(array([[0.3, 0.7], [0.8, 0.2]]), Alphabet="ABCD", CharOrder="AF")

        self.assertEqual(p1.isValid(), True)
        self.assertEqual(p2.isValid(), False)
        self.assertEqual(p3.isValid(), False)

    def test_dataAt(self):
        """dataAt: should work on valid position and character"""
        p = Profile(array([[0.2, 0.4, 0.4, 0], [0.1, 0, 0.9, 0], [0.1, 0.2, 0.3, 0.4]]), Alphabet="TCAG")
        self.assertEqual(p.dataAt(0, "C"), 0.4)
        self.assertEqual(p.dataAt(1, "T"), 0.1)
        self.assertRaises(ProfileError, p.dataAt, 1, "U")
        self.assertRaises(ProfileError, p.dataAt, -2, "T")
        self.assertRaises(ProfileError, p.dataAt, 5, "T")

    def test_copy(self):
#.........这里部分代码省略.........
开发者ID:blankenberg,项目名称:pycogent,代码行数:103,代码来源:test_profile.py

示例3: LoadSeqs

# 需要导入模块: from cogent.core.profile import Profile [as 别名]
# 或者: from cogent.core.profile.Profile import score [as 别名]
#!/usr/bin/env python
# taken from http://pycogent.sourceforge.net/
from cogent.core.profile import Profile
from cogent import LoadSeqs, RNA
aln = LoadSeqs("data/trna_profile.fasta", moltype=RNA)
print len(aln.Seqs)
print len(aln)
pf = aln.getPosFreqs()
print pf.prettyPrint(include_header=True, column_limit=6, col_sep='   ')
pf.normalizePositions()
print pf.prettyPrint(include_header=True, column_limit=6, col_sep='   ')
print pf.isValid()
print '\n'.join(['%s: %.3f'%(c,f) for (c,f) in zip(pf.CharOrder, pf.dataAt(4)) if f!=0])
print pf.toConsensus(fully_degenerate=False)
pf.Alphabet=RNA
print "to consensus"
print pf.toConsensus(fully_degenerate=True)
print pf.toConsensus(cutoff=0.8)
print pf.toConsensus(cutoff=0.6)
loop_profile = Profile(pf.Data[54:60,:], Alphabet=RNA, CharOrder=pf.CharOrder)
print loop_profile.prettyPrint(include_header=True, column_limit=6, col_sep='   ')
yeast = RNA.Sequence('GCGGAUUUAGCUCAGUU-GGGAGAGCGCCAGACUGAAGAUCUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCACCA')
scores = loop_profile.score(yeast)
print scores
print max(scores)
print scores.argmax()
开发者ID:kmiddleton,项目名称:eebprogramming,代码行数:28,代码来源:5profiles.py


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