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


Python Profile.prettyPrint方法代碼示例

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


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

示例1: ProfileTests

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

#.........這裏部分代碼省略.........
        self.assertRaises(ProfileError, p.normalizePositions)
        p = Profile(array([[0.0, 0.0]]), "AB")
        self.assertRaises(ProfileError, p.normalizePositions)

        # negative numbers!!!!!!
        p1 = Profile(array([[3, -2], [4, -3]]), "AB")
        p1.normalizePositions()
        self.assertEqual(p1.Data, array([[3, -2], [4, -3]]))
        p2 = Profile(array([[3, -3], [4, -3]]), "AB")
        self.assertRaises(ProfileError, p2.normalizePositions)

    def test_normalizeSequences(self):
        """normalizeSequences: should normalize or raise appropriate error
        """
        p = self.full.copy()
        p.normalizeSequences()
        self.assertEqual(p.Data, array([[2 / 9, 4 / 17], [3 / 9, 5 / 17], [4 / 9, 8 / 17]]))
        self.assertEqual(sum(p.Data, axis=0), [1, 1])
        p = self.empty_row.copy()
        p.normalizeSequences()
        self.assertEqual(p.Data, array([[1, 1], [0, 0]]))
        p = self.empty_col.copy()
        self.assertRaises(ProfileError, p.normalizeSequences)
        p = Profile(array([[0.0], [0.0]]), "AB")
        self.assertRaises(ProfileError, p.normalizeSequences)

        # negative numbers!!!!!!
        p1 = Profile(array([[3, 4], [-2, -3]]), "AB")
        p1.normalizeSequences()
        self.assertEqual(p1.Data, array([[3, 4], [-2, -3]]))
        p2 = Profile(array([[3, 4], [-3, -3]]), "AB")
        self.assertRaises(ProfileError, p2.normalizeSequences)

    def test_prettyPrint_without_parameters(self):
        """prettyPrint: should work without parameters passed in"""
        p = self.full
        self.assertEqual(p.prettyPrint(), "2\t4\n3\t5\n4\t8")
        self.assertEqual(p.prettyPrint(include_header=True), "A\tB\n2\t4\n3\t5\n4\t8")
        self.assertEqual(p.prettyPrint(transpose_data=True), "2\t3\t4\n4\t5\t8")
        self.assertEqual(p.prettyPrint(include_header=True, transpose_data=True), "A\t2\t3\t4\nB\t4\t5\t8")
        # empty
        self.assertEqual(self.empty.prettyPrint(), "")
        self.assertEqual(self.empty.prettyPrint(transpose_data=True), "")

        # it will still print with invalid data (e.g if len(CharOrder)
        # doesn't match the data
        p = self.full.copy()
        p.CharOrder = "ABC"

        self.assertEqual(p.prettyPrint(include_header=True), "A\tB\tC\n2\t4\t \n3\t5\t \n4\t8\t ")
        # it will truncate the CharOrder if data is transposed
        # and CharOrder is longer then the number of rows in the
        # transposed data
        self.assertEqual(p.prettyPrint(include_header=True, transpose_data=True), "A\t2\t3\t4\nB\t4\t5\t8")

    def test_prettyPrint_four_cases(self):
        """prettyPrint: with/without header/transpose/limit"""
        p = self.full
        p = self.pp
        self.assertEqual(p.prettyPrint(), "1\t 2\t 3\t 4\n5\t 6\t 7\t 8\n9\t10\t11\t12")
        self.assertEqual(p.prettyPrint(column_limit=3), "1\t 2\t 3\n5\t 6\t 7\n9\t10\t11")
        self.assertEqual(
            p.prettyPrint(column_limit=3, include_header=True), "A\t B\t C\n1\t 2\t 3\n5\t 6\t 7\n9\t10\t11"
        )
        self.assertEqual(
            p.prettyPrint(column_limit=3, include_header=False, transpose_data=True),
開發者ID:blankenberg,項目名稱:pycogent,代碼行數:70,代碼來源:test_profile.py

示例2: LoadSeqs

# 需要導入模塊: from cogent.core.profile import Profile [as 別名]
# 或者: from cogent.core.profile.Profile import prettyPrint [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.prettyPrint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。