示例#1
0
    def _test_profile_split(self, sequences, length):
        counts = utils.counts(sequences, length)
        profile = klib.Profile(utils.as_array(counts, length))
        left, right = profile.split()

        assert len(left) == len(right)
        assert sum(left) + sum(right) == sum(counts.values()) * 2

        indices_left = {}
        indices_right = {}
        indices_palindrome = {}

        for s, c in counts.items():
            r = utils.reverse_complement(s)
            if s < r:
                indices_left[utils.count_index(s)] = c * 2
            elif s > r:
                indices_right[utils.count_index(r)] = counts[s] * 2
            else:
                indices_palindrome[utils.count_index(s)] = c

        assert ([c for c in left if c > 0] == [
            c for i, c in sorted(
                list(indices_left.items()) + list(indices_palindrome.items()))
        ])
        assert ([c for c in right if c > 0] == [
            c for i, c in sorted(
                list(indices_right.items()) + list(indices_palindrome.items()))
        ])
示例#2
0
文件: test_klib.py 项目: LUMC/kPAL
    def _test_profile_split(self, sequences, length):
        counts = utils.counts(sequences, length)
        profile = klib.Profile(utils.as_array(counts, length))
        left, right = profile.split()

        assert len(left) == len(right)
        assert sum(left) + sum(right) == sum(counts.values()) * 2

        indices_left = {}
        indices_right = {}
        indices_palindrome = {}

        for s, c in counts.items():
            r = utils.reverse_complement(s)
            if s < r:
                indices_left[utils.count_index(s)] = c * 2
            elif s > r:
                indices_right[utils.count_index(r)] = counts[s] * 2
            else:
                indices_palindrome[utils.count_index(s)] = c

        assert ([c for c in left if c > 0] ==
                [c for i, c in sorted(list(indices_left.items()) +
                                      list(indices_palindrome.items()))])
        assert ([c for c in right if c > 0] ==
                [c for i, c in sorted(list(indices_right.items()) +
                                      list(indices_palindrome.items()))])
示例#3
0
文件: test_klib.py 项目: LUMC/kPAL
    def test_profile_freq_diff_matrix(self):
        counts = utils.counts(utils.SEQUENCES, 4)
        profile = klib.Profile(utils.as_array(counts, 4))
        freq_diffs = profile._freq_diff_matrix()

        total = sum(counts.values())

        for left in itertools.product('ACGT', repeat=4):
            for right in itertools.product('ACGT', repeat=4):
                left = ''.join(left)
                right = ''.join(right)
                freq_diff = freq_diffs[utils.count_index(left)][utils.count_index(right)]
                if counts[right] > 0:
                    assert freq_diff == abs(counts[left] - counts[right]) / total
                else:
                    assert freq_diff == 0
示例#4
0
文件: test_klib.py 项目: LUMC/kPAL
    def test_profile_ratios_matrix(self):
        counts = utils.counts(utils.SEQUENCES, 4)
        profile = klib.Profile(utils.as_array(counts, 4))

        ratios = profile._ratios_matrix()
        total = sum(counts.values())

        for left in itertools.product('ACGT', repeat=4):
            for right in itertools.product('ACGT', repeat=4):
                left = ''.join(left)
                right = ''.join(right)
                ratio = ratios[utils.count_index(left)][utils.count_index(right)]
                try:
                    assert ratio == counts[left] / counts[right] / total
                except ZeroDivisionError:
                    assert ratio == -1.0
示例#5
0
    def test_profile_ratios_matrix(self):
        counts = utils.counts(utils.SEQUENCES, 4)
        profile = klib.Profile(utils.as_array(counts, 4))

        ratios = profile._ratios_matrix()
        total = sum(counts.values())

        for left in itertools.product('ACGT', repeat=4):
            for right in itertools.product('ACGT', repeat=4):
                left = ''.join(left)
                right = ''.join(right)
                ratio = ratios[utils.count_index(left)][utils.count_index(
                    right)]
                try:
                    assert ratio == counts[left] / counts[right] / total
                except ZeroDivisionError:
                    assert ratio == -1.0
示例#6
0
    def test_profile_freq_diff_matrix(self):
        counts = utils.counts(utils.SEQUENCES, 4)
        profile = klib.Profile(utils.as_array(counts, 4))
        freq_diffs = profile._freq_diff_matrix()

        total = sum(counts.values())

        for left in itertools.product('ACGT', repeat=4):
            for right in itertools.product('ACGT', repeat=4):
                left = ''.join(left)
                right = ''.join(right)
                freq_diff = freq_diffs[utils.count_index(left)][
                    utils.count_index(right)]
                if counts[right] > 0:
                    assert freq_diff == abs(counts[left] -
                                            counts[right]) / total
                else:
                    assert freq_diff == 0