Beispiel #1
0
 def test_masked_windowed_divergence(self):
     h = HaplotypeArray([[0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 1],
                         [0, 1, 1, 1], [1, 1, 1, 1], [0, 0, 1, 2],
                         [0, 1, 1, 2], [0, 1, -1, -1], [-1, -1, -1, -1]])
     h1 = h.take([0, 1], axis=1)
     h2 = h.take([2, 3], axis=1)
     ac1 = h1.count_alleles()
     ac2 = h2.count_alleles()
     pos = SortedIndex([2, 4, 7, 14, 15, 18, 19, 25, 27])
     mask = np.tile(np.repeat(np.array([True, False]), 5), 3)
     expect, _, _, _ = allel.windowed_divergence(pos,
                                                 ac1,
                                                 ac2,
                                                 size=5,
                                                 start=1,
                                                 stop=31)
     expect = expect[::2]
     actual, _, _, _ = allel.windowed_divergence(pos,
                                                 ac1,
                                                 ac2,
                                                 size=10,
                                                 start=1,
                                                 stop=31,
                                                 is_accessible=mask)
     assert_array_almost_equal(expect, actual)
Beispiel #2
0
    def test_mean_pairwise_divergence(self):

        # simplest case, two haplotypes in each population
        h = HaplotypeArray([[0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 1],
                            [0, 1, 1, 1], [1, 1, 1, 1], [0, 0, 1, 2],
                            [0, 1, 1, 2], [0, 1, -1, -1], [-1, -1, -1, -1]])
        h1 = h.take([0, 1], axis=1)
        h2 = h.take([2, 3], axis=1)
        ac1 = h1.count_alleles()
        ac2 = h2.count_alleles()

        expect = [0 / 4, 2 / 4, 4 / 4, 2 / 4, 0 / 4, 4 / 4, 3 / 4, -1, -1]
        actual = allel.mean_pairwise_difference_between(ac1, ac2, fill=-1)
        aeq(expect, actual)
Beispiel #3
0
    def test_windowed_divergence(self):

        # simplest case, two haplotypes in each population
        h = HaplotypeArray([[0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 1],
                            [0, 1, 1, 1], [1, 1, 1, 1], [0, 0, 1, 2],
                            [0, 1, 1, 2], [0, 1, -1, -1], [-1, -1, -1, -1]])
        h1 = h.take([0, 1], axis=1)
        h2 = h.take([2, 3], axis=1)
        ac1 = h1.count_alleles()
        ac2 = h2.count_alleles()
        # mean pairwise divergence
        # expect = [0/4, 2/4, 4/4, 2/4, 0/4, 4/4, 3/4, -1, -1]
        pos = SortedIndex([2, 4, 7, 14, 15, 18, 19, 25, 27])
        expect = [(6 / 4) / 10, (9 / 4) / 10, 0 / 11]
        actual, _, _, _ = allel.windowed_divergence(pos,
                                                    ac1,
                                                    ac2,
                                                    size=10,
                                                    start=1,
                                                    stop=31)
        assert_array_almost_equal(expect, actual)