def choose_chrom(pool, chrmap): # Since Alleles is a subclass of ndarray, numpy has been # treating pool as a multidimensional array. We'll generate # the indices ourself and get them that way. Eventually # I'll come back and fix the isinstancing of Alleles. qi, qw = np.random.randint(0, len(pool), 2) q, w = pool[qi], pool[qw] r = recombine(q, w, chrmap) return r
def test_recombine(): a = Alleles(np.zeros(10)) b = Alleles(np.ones(10)) m = np.arange(1, 100, 10) n = recombine(a, b, m) assert len(n) == len(m) assert type(n) == type(a) == type(b) assert_raises(ValueError, recombine, None, None, None)
def gamete(self): """ Provides a set of half-genotypes to use with method fertilize """ if not self.genotypes: self.get_genotypes() g = [recombine(chrom[0], chrom[1], self.chromosomes[i].genetic_map) for i, chrom in enumerate(self.genotypes)] return g
def choose_chrom(pool, chrmap): """ Get two random chromosomes, recombine them, return the result """ # Since Alleles is a subclass of ndarray, numpy has been # treating pool as a multidimensional array. We'll generate # the indices ourself and get them that way. Eventually # I'll come back and fix the isinstancing of Alleles. qi, qw = np.random.randint(0, len(pool), 2) q, w = pool[qi], pool[qw] r = recombine(q, w, chrmap) return r
def gamete(self): """ Provides a set of half-genotypes to use with method fertilize :returns: a collection of AlleleContainers :rtype: list """ if not self.genotypes: self.get_genotypes() g = [ recombine(chrom[0], chrom[1], self.chromosomes[i].genetic_map) for i, chrom in enumerate(self.genotypes) ] return g
def gamete(self): """ Provides a set of half-genotypes to use with method fertilize :returns: a collection of AlleleContainers :rtype: list """ if not self.genotypes: self.get_genotypes() g = [recombine(chrom[0], chrom[1], self.chromosomes[i].genetic_map) for i, chrom in enumerate(self.genotypes)] return g
import numpy as np from pydigree import ChromosomeTemplate from pydigree.recombination import recombine from pydigree.rand import choice as randchoice from pydigree.rand import sample_with_replacement nmark = 5000 poolsize = 10000 ngen = 25 c = ChromosomeTemplate() for x in range(nmark): c.add_genotype(np.random.random(), .1) mapp = [.1]*nmark print("Initializing pool") pool = [c.linkageequilibrium_chromosome(sparse=True) for x in range(poolsize)] for x in range(ngen): print("Iteration {}".format(x)) recombs = [recombine(randchoice(pool), randchoice(pool), mapp) for x in range(poolsize)] pool = sample_with_replacement(recombs+pool, poolsize)