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


Python profile.Profile类代码示例

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


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

示例1: test_toLogOddsMatrix

 def test_toLogOddsMatrix(self):
     """toLogOddsMatrix: should work as expected"""
     # This test can be short, because it mainly depends on toOddsMatrix
     # for which everything has been tested
     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(
             [
                 [-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(), [[]])
开发者ID:blankenberg,项目名称:pycogent,代码行数:31,代码来源:test_profile.py

示例2: test_randomIndices

    def test_randomIndices(self):
        """randomIndices: 99% of new frequencies should be within 3*SD
        """
        r_num, c_num = 100, 20
        num_elements = r_num * c_num
        r = random([r_num, c_num])
        p = Profile(r, "A" * c_num)
        p.normalizePositions()
        d = p.Data
        n = 1000

        # Test only works on normalized profile, b/c of 1-d below
        means = n * d
        three_stds = sqrt(d * (1 - d) * n) * 3
        result = [p.randomIndices() for x in range(n)]
        a = Alignment(transpose(result))

        def absoluteProfile(alignment, char_order):
            f = a.columnFreqs()
            res = zeros([len(f), len(char_order)])
            for row, freq in enumerate(f):
                for i in freq:
                    res[row, ord(i)] = freq[i]
            return res

        ap = absoluteProfile(a, p.CharOrder)
        failure = abs(ap - means) > three_stds
        assert sum(sum(failure)) / num_elements <= 0.01
开发者ID:blankenberg,项目名称:pycogent,代码行数:28,代码来源:test_profile.py

示例3: test_randomSequence

    def test_randomSequence(self):
        """randomSequence: 99% of new frequencies should be within 3*SD"""
        r_num, c_num = 100, 20
        num_elements = r_num * c_num
        alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        r = random([r_num, c_num])
        p = Profile(r, alpha[:c_num])
        p.normalizePositions()
        d = p.Data
        n = 1000

        # Test only works on normalized profile, b/c of 1-d below
        means = n * d
        three_stds = sqrt(d * (1 - d) * n) * 3

        a = Alignment([p.randomSequence() for x in range(n)])

        def absoluteProfile(alignment, char_order):
            f = a.columnFreqs()
            res = zeros([len(f), len(char_order)])
            for row, freq in enumerate(f):
                for i in freq:
                    col = char_order.index(i)
                    res[row, col] = freq[i]
            return res

        ap = absoluteProfile(a, p.CharOrder)
        failure = abs(ap - means) > three_stds
        assert sum(sum(failure)) / num_elements <= 0.01
开发者ID:blankenberg,项目名称:pycogent,代码行数:29,代码来源:test_profile.py

示例4: test_toOddsMatrix

    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,代码行数:35,代码来源:test_profile.py

示例5: test_dataAt

 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")
开发者ID:blankenberg,项目名称:pycogent,代码行数:8,代码来源:test_profile.py

示例6: test_score_no_trans_table

 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,代码行数:9,代码来源:test_profile.py

示例7: test_dataAt

 def test_dataAt(self):
     """dataAt: should work on valid position and character"""
     p = Profile(array([[.2,.4,.4,0],[.1,0,.9,0],[.1,.2,.3,.4]]),\
         Alphabet="TCAG")
     self.assertEqual(p.dataAt(0,'C'),.4)
     self.assertEqual(p.dataAt(1,'T'),.1)
     self.assertRaises(ProfileError, p.dataAt, 1, 'U')
     self.assertRaises(ProfileError, p.dataAt, -2, 'T')
     self.assertRaises(ProfileError, p.dataAt, 5, 'T')
开发者ID:miklou,项目名称:pycogent,代码行数:9,代码来源:test_profile.py

示例8: test_columnUncertainty

 def test_columnUncertainty(self):
     """columnUncertainty: should handle full and empty profiles
     """
     p = Profile(array([[0.25, 0.5], [0.25, 0.5], [0.25, 0], [0.25, 0]]), "AB")
     self.assertEqual(p.columnUncertainty(), [2, 1])
     # for empty cols nothing is returned as the uncertainty
     self.assertEqual(self.empty.columnUncertainty().tolist(), [])
     p = Profile(array([[], [], []]), "")
     self.assertEqual(p.columnUncertainty().tolist(), [])
     # doesn't work on 1D array
     self.assertRaises(ProfileError, self.oned.columnUncertainty)
开发者ID:blankenberg,项目名称:pycogent,代码行数:11,代码来源:test_profile.py

示例9: mVOR

def mVOR(alignment,n=1000,order=DNA_ORDER):
    """Returns sequence weights according to the modified Voronoi method.
    
    alignment: Alignment object
    n: sample size (=number of random profiles to be generated)
    order: specifies the order of the characters found in the alignment,
        used to build the sequence and random profiles.
    
    mVOR is a modification of the VOR method. Instead of generating discrete
    random sequences, it generates random profiles, to sample more equally from
    the sequence space and to prevent random sequences to be equidistant to 
    multiple sequences in the alignment. 

    See the Implementation notes to see how the random profiles are generated
    and compared to the 'sequence profiles' from the alignment.

    Random generalized sequences (or a profile filled with random numbers):
    Sequences that are equidistant to multiple sequences in the alignment
    can form a problem in small datasets. For longer sequences the likelihood
    of this event is negligable. Generating 'random generalized sequences' is 
    a solution, because we're then sampling from continuous sequence space. 
    Each column of a random profile is generated by normalizing a set of 
    independent, exponentially distributed random numbers. In other words, a 
    random profile is a two-dimensional array (rows are chars in the alphabet, 
    columns are positions in the alignment) filled with a random numbers, 
    sampled from the standard exponential distribution (lambda=1, and thus 
    the mean=1), where each column is normalized to one. These random profiles 
    are compared to the special profiles of just one sequence (ones for the 
    single character observed at that position). The distance between the 
    two profiles is simply the Euclidean distance.

    """
    
    weights = zeros(len(alignment.Names),Float64)

    #get seq profiles
    seq_profiles = {}
    for k,v in list(alignment.items()):
        #seq_profiles[k] = ProfileFromSeq(v,order=order)
        seq_profiles[k] = SeqToProfile(v,alphabet=order)

    for count in range(n):
        #generate a random profile
        exp = exponential(1,[alignment.SeqLen,len(order)])
        r = Profile(Data=exp,Alphabet=order)
        r.normalizePositions()
        #append the distance between the random profile and the sequence
        #profile to temp
        temp = [seq_profiles[key].distance(r) for key in alignment.Names]
        votes = row_to_vote(array(temp))
        weights += votes
    weight_dict = Weights(dict(list(zip(alignment.Names,weights))))
    weight_dict.normalize()
    return weight_dict
开发者ID:cxhernandez,项目名称:pycogent,代码行数:54,代码来源:methods.py

示例10: test__div_

    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]]))
开发者ID:blankenberg,项目名称:pycogent,代码行数:12,代码来源:test_profile.py

示例11: test_rowUncertainty

    def test_rowUncertainty(self):
        """rowUncertainty: should handle full and empty profiles
        """
        p = Profile(array([[0.25, 0.25, 0.25, 0.25], [0.5, 0.5, 0, 0]]), "ABCD")
        self.assertEqual(p.rowUncertainty(), [2, 1])

        # for empty rows 0 is returned as the uncertainty
        self.assertEqual(self.empty.rowUncertainty().tolist(), [])
        p = Profile(array([[], [], []]), "")
        self.assertEqual(p.rowUncertainty().tolist(), [])
        # doesn't work on 1D array
        self.assertRaises(ProfileError, self.oned.rowUncertainty)
开发者ID:blankenberg,项目名称:pycogent,代码行数:12,代码来源:test_profile.py

示例12: test_toConsensus_include_all

 def test_toConsensus_include_all(self):
     """toConsensus: Should include all possibilities when include_all=True
     """
     p1 = Profile(array([[.2,0,.8,0],[0,.1,.2,.7],[0,0,0,1],\
         [.2,.3,.4,.1],[.5,.5,0,0]]),\
         Alphabet=DNA, CharOrder="TCAG")
     self.assertEqual(p1.toConsensus(cutoff=0.4, include_all=True),\
         "AGGAY")
     p2 = Profile(array([[.25,0.25,.25,0.25],[0.1,.1,.1,0],\
         [.4,0,.4,0],[0,.2,0.2,0.3]]),\
         Alphabet=DNA, CharOrder="TCAG")
     self.assertEqual(p2.toConsensus(cutoff=0.4,\
         include_all=True), "NHWV")
开发者ID:miklou,项目名称:pycogent,代码行数:13,代码来源:test_profile.py

示例13: test_reduce_operators

    def test_reduce_operators(self):
        """reduce: should work fine with different operators
        """
        # different operators, normalize input, don't normalize output
        p1 = Profile(array([[1, 0, 0], [0, 1, 0]]), Alphabet="ABC")
        p2 = Profile(array([[1, 0, 0], [0, 0, 1]]), Alphabet="ABC")

        self.assertEqual(p1.reduce(p2).Data, array([[1, 0, 0], [0, 0.5, 0.5]]))
        self.assertEqual(
            p1.reduce(p2, add, normalize_input=True, normalize_output=False).Data, array([[2, 0, 0], [0, 1, 1]])
        )
        self.assertEqual(
            p1.reduce(p2, subtract, normalize_input=True, normalize_output=False).Data, array([[0, 0, 0], [0, 1, -1]])
        )
        self.assertEqual(
            p1.reduce(p2, multiply, normalize_input=True, normalize_output=False).Data, array([[1, 0, 0], [0, 0, 0]])
        )

        self.assertRaises(ProfileError, p1.reduce, p2, divide, normalize_input=True, normalize_output=False)

        # don't normalize and normalize only input
        p3 = Profile(array([[1, 2], [3, 4]]), Alphabet="AB")
        p4 = Profile(array([[4, 3], [2, 1]]), Alphabet="AB")

        self.assertEqual(
            p3.reduce(p4, add, normalize_input=False, normalize_output=False).Data, array([[5, 5], [5, 5]])
        )
        self.assertFloatEqual(
            p3.reduce(p4, add, normalize_input=True, normalize_output=False).Data,
            array([[19 / 21, 23 / 21], [23 / 21, 19 / 21]]),
        )

        # normalize input and output
        p5 = Profile(array([[1, 1, 0, 0], [1, 1, 1, 1]]), Alphabet="ABCD")
        p6 = Profile(array([[1, 0, 0, 0], [1, 0, 0, 1]]), Alphabet="ABCD")

        self.assertEqual(
            p5.reduce(p6, add, normalize_input=True, normalize_output=True).Data,
            array([[0.75, 0.25, 0, 0], [0.375, 0.125, 0.125, 0.375]]),
        )

        # it can collapse empty profiles when normalizing is turned off
        self.assertEqual(
            self.empty.reduce(self.empty, normalize_input=False, normalize_output=False).Data.tolist(), [[]]
        )
开发者ID:blankenberg,项目名称:pycogent,代码行数:45,代码来源:test_profile.py

示例14: test_normalizeSequences

    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)
开发者ID:blankenberg,项目名称:pycogent,代码行数:21,代码来源:test_profile.py

示例15: test_normalizePositions

    def test_normalizePositions(self):
        """normalizePositions: should normalize or raise appropriate error
        """
        p = self.full.copy()
        p.normalizePositions()
        self.assertEqual(p.Data, array([[2 / 6, 4 / 6], [3 / 8, 5 / 8], [4 / 12, 8 / 12]]))
        self.assertEqual(sum(p.Data, 1), [1, 1, 1])
        p = self.empty_col.copy()
        p.normalizePositions()
        self.assertEqual(p.Data, array([[0, 1], [0, 1]]))
        p = self.empty_row.copy()
        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)
开发者ID:blankenberg,项目名称:pycogent,代码行数:21,代码来源:test_profile.py


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