예제 #1
0
 def test_genotype_matrix_ranges(self):
     dm = fwdpy11.data_matrix_from_tables(
         self.pop.tables, [i for i in range(2 * self.pop.N)], False, True)
     spos = np.array(dm.selected.positions)
     for i in np.arange(0, self.pop.tables.genome_length, 0.1):
         dmi = fwdpy11.data_matrix_from_tables(
             self.pop.tables, [i for i in range(2 * self.pop.N)],
             record_neutral=False,
             record_selected=True,
             begin=i,
             end=i + 0.1)
         w = np.where((spos >= i) & (spos < i + 0.1))[0]
         self.assertTrue(
             np.array_equal(spos[w], np.array(dmi.selected.positions)))
예제 #2
0
 def test_genotype_matrix(self):
     """
     Make data matrix objects from the tree sequences
     and compare their contents to those of tskit
     as well as to an explicit calculation of mutation counts.
     """
     dm = fwdpy11.data_matrix_from_tables(
         self.pop.tables, [i for i in range(2 * self.pop.N)], False, True,
         True)
     sa = np.array(dm.selected)
     cs = np.sum(sa, axis=1)
     dumped_ts = self.pop.dump_tables_to_tskit()
     mm = dumped_ts.genotype_matrix()
     mc = np.sum(mm, axis=1)
     ec = np.zeros(len(self.pop.mutations), dtype=np.uint32)
     for d in self.pop.diploids:
         for m in self.pop.haploid_genomes[d.first].smutations:
             ec[m] += 1
         for m in self.pop.haploid_genomes[d.second].smutations:
             ec[m] += 1
     for i, j, k in zip(self.pop.tables.mutations, cs, mc):
         self.assertEqual(self.pop.mcounts[i.key], ec[i.key])
         self.assertEqual(ec[i.key], j)
         self.assertEqual(ec[i.key], k)
     self.assertTrue(np.array_equal(ec, np.array(self.pop.mcounts)))
     self.assertEqual(ec.sum(), cs.sum())
     self.assertEqual(ec.sum(), mc.sum())
     self.assertTrue(np.array_equal(sa, mm))
     self.assertTrue(np.array_equal(cs, mc))
예제 #3
0
    def setUpClass(self):
        # TODO add neutral variants
        self.N = 1000
        self.demography = np.array([self.N] * self.N, dtype=np.uint32)
        self.rho = 1.
        self.theta = 100.
        self.nreps = 500
        self.mu = self.theta / (4 * self.N)
        self.r = self.rho / (4 * self.N)

        self.GSS = fwdpy11.GSS(VS=1, opt=0)
        a = fwdpy11.Additive(2.0, self.GSS)
        self.p = {
            'nregions': [],
            'sregions': [fwdpy11.GaussianS(0, 1, 1, 0.25)],
            'recregions': [fwdpy11.Region(0, 1, 1)],
            'rates': (0.0, 0.025, self.r),
            'gvalue': a,
            'prune_selected': False,
            'demography': self.demography
        }
        self.params = fwdpy11.ModelParams(**self.p)
        self.rng = fwdpy11.GSLrng(101 * 45 * 110 * 210)
        self.pop = fwdpy11.DiploidPopulation(self.N, 1.0)
        self.all_samples = [i for i in range(2 * self.N)]
        fwdpy11.evolvets(self.rng, self.pop, self.params, 100)
        self.dm = fwdpy11.data_matrix_from_tables(self.pop.tables,
                                                  self.all_samples, True, True)
        self.neutral = np.array(self.dm.neutral)
        self.npos = np.array(self.dm.neutral.positions)
        self.selected = np.array(self.dm.selected)
        self.spos = np.array(self.dm.selected.positions)
예제 #4
0
 def test_genotype_matrix(self):
     dm = fwdpy11.data_matrix_from_tables(
         self.pop.tables, [i for i in range(2 * self.pop.N)], False, True,
         True)
     rc = np.sum(dm.selected, axis=1)
     index = [i for i in range(len(self.pop.mcounts))]
     index = sorted(index, key=lambda x: self.pop.mutations[x].pos)
     mc = [self.pop.mcounts[i] for i in index if self.pop.mcounts[i] > 0]
     self.assertTrue(np.array_equal(rc, np.array(mc)))
예제 #5
0
 def test_VariantIteratorFromPopulation(self):
     dm = fwdpy11.data_matrix_from_tables(
         self.pop.tables, [i for i in range(2 * self.pop.N)], False, True,
         True)
     sa = np.array(dm.selected)
     cs = np.sum(sa, axis=1)
     i = 0
     vi = fwdpy11.VariantIterator(self.pop)
     for v in vi:
         c = self.pop.mcounts[self.pop.tables.mutations[i].key]
         self.assertEqual(c, cs[i])
         self.assertEqual(c, v.genotypes.sum())
         i += 1
     mc = np.array(self.pop.mcounts)
     self.assertEqual(i, len(np.where(mc > 0)[0]))
     self.assertEqual(i, len(self.pop.tables.mutations))
예제 #6
0
 def test_VariantIterator(self):
     """
     Test VariantIterator by asserting
     that sum of genotypes equal values in
     the corresponding DataMatrix and
     those in pop.mcounts
     """
     dm = fwdpy11.data_matrix_from_tables(
         self.pop.tables, [i for i in range(2 * self.pop.N)], False, True,
         True)
     sa = np.array(dm.selected)
     cs = np.sum(sa, axis=1)
     i = 0
     vi = fwdpy11.VariantIterator(self.pop.tables,
                                  [i for i in range(2 * self.pop.N)])
     for v in vi:
         c = self.pop.mcounts[self.pop.tables.mutations[i].key]
         self.assertEqual(c, cs[i])
         self.assertEqual(c, v.genotypes.sum())
         i += 1
     mc = np.array(self.pop.mcounts)
     self.assertEqual(i, len(np.where(mc > 0)[0]))
     self.assertEqual(i, len(self.pop.tables.mutations))