当前位置: 首页>>代码示例>>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;未经允许,请勿转载。