def pop_arg(pop): ev = [] for kk in range(100): rec_events = 0 gclones = pop.get_genotypes() nclones = pop.get_clone_sizes() pop0 = h.haploid_highd(L) pop0.track_locus_genealogy(range(L)) pop0.set_genotypes(gclones, nclones) pop0.set_fitness_additive(ff) for pair in epi_values: pop0.add_fitness_coefficient(epi_values[pair], [pair[0], pair[1]]) pop0.recombination_model = h.CROSSOVERS pop0.mutation_rate = 0 # mutation rate per site per generation pop0.outcrossing_rate = 1 # probability of sexual reproduction per gen pop0.crossover_rate = rec # probability of crossover per site per gen pop0.evolve(0) pop0.evolve(1) for i in range(L - 1): j = i + 1 tree0 = pop0.genealogy.get_tree(i).print_newick() tree1 = pop0.genealogy.get_tree(j).print_newick() rec_events += int(tree0 != tree1) for kkk in range(1): ev.append(rec_events) return ev
def init_pop(add_sel, epi_values): pop = h.haploid_highd(L) pop.carrying_capacity = N pop.recombination_model = h.CROSSOVERS pop.mutation_rate = mu # mutation rate per site per generation pop.outcrossing_rate = 1 # probability of sexual reproduction per gen pop.crossover_rate = rec # probability of crossover per site per gen pop.set_fitness_additive(add_sel) for pair in epi_values: pop.add_fitness_coefficient(epi_values[pair], [pair[0], pair[1]]) #g = np.random.choice([False,True],L,[0.5,0.5]) pop.set_wildtype(N) pop.evolve(0) # it's crucial don't know why return pop
#asexual: N=10000 s=0.01 r=0.0 U=0.1 #sexual: N=1000 s=0.01 r=1.0 U=0.1 L = 1000 #number of segregating sites s = -1e-6 #single site effect N = 200 #population size U = 0.1 #genome wide mutation rate r = 0.0 #outcrossing rate sample_size = 30 #number of individuals whose genealogy is looked at nsamples = 3 #number of trees burnin = 2000 #either ~5*N or 5/s, depending on whether coalescence is dominated by drift or draft dt = 1000 #time between samples #set up population, switch to all_polymorphic mode pop = h.haploid_highd(L) #set the per-site mutation rate pop.mutation_rate = U / pop.L #set the population size via the carrying capacity pop.carrying_capacity = N #set the crossover rate, outcrossing_rate and recombination model pop.outcrossing_rate = r pop.recombination_model = h.CROSSOVERS pop.crossover_rate = 1.0 / pop.L #set the effect sizes of the mutations that are injected (the same at each site in this case) pop.set_fitness_additive(np.ones(L) * s)
i = epis1[kkk] j = epis2[kkk] if j < i: [i, j] = [j, i] #for i in epis: #for j in epis: if i in L_dif and j in L_dif and j > i and True: #np.random.random(1)[0] < ppp: #i in L_dif: #value = np.sqrt(Vi/float(L1))/float(L1-1)*float(N) #value = np.random.gamma(np.sqrt(Vi/float(L1))/float(L1-1)*N,1.0,1)[0] #value = np.random.normal(0,np.sqrt(Vi/float(L1))/float(L1-1),1)[0] value = np.random.normal( 0, np.sqrt(Vi / float(L1)) * ppp, 1)[0] #value = np.sqrt(Vi/float(L1))/float(L1-1) #value = value / float(N) epi_values[(i, j)] = value pop1 = h.haploid_highd(L) pop1.carrying_capacity = N pop1.set_wildtype(N) pop1.recombination_model = h.CROSSOVERS pop1.mutation_rate = mu # mutation rate per site per generation pop1.outcrossing_rate = 1 # probability of sexual reproduction per gen pop1.crossover_rate = rec # probability of crossover per site per gen pop1.set_fitness_additive(ff) for pair in epi_values: i = pair[0] j = pair[1] pop1.add_fitness_coefficient(epi_values[(i, j)], [i, j]) pop2 = h.haploid_highd(L) pop2.carrying_capacity = N pop2.set_wildtype(N)
# installed in the PYTHONPATH) import sys sys.path.insert(0, '../pkg/python') import numpy as np import matplotlib.pyplot as plt import FFPopSim as h # specify parameters N = 500 # population size L = 1000 # number of loci mu = 0.1 / N # mutation rate r = 10.0 / L / N # crossover rate # set up population pop = h.haploid_highd(L) # produce an instance of haploid_lowd with L loci pop.carrying_capacity = N # set the steady-state population size pop.outcrossing_rate = 1 # obligate sexual pop.crossover_rate = r # crossover rate per locus pop.mutation_rate = mu # mutation rate per locus # initialize the population with # - N/2 individuals with genotypes 00000000...0000 # - N/2 with the opposite genotype 11111111...1111 pop.set_genotypes([np.zeros(L), np.ones(L)], [N / 2, N / 2]) # locus pairs for which LD is to be tracked ld_points = np.arange(5, L - 1, 100) locus_pairs = [[L / 2, l1] for l1 in ld_points] print "Evolve for >> N generations and measure correlations between loci, aka LD."
#neutral asexual: N=100 s=0.00001 r=0.0 #selected asexual: N=10000 s=0.01 r=0.0 #selected sexual: N=1000 s=0.01 r=1.0 L = 1000 #number of segregating sites s = 1e-2 #single site effect N = 10000 #population size r = 0.0 #outcrossing rate sample_size=30 #number of individuals whose genealogy is looked at nsamples = 3 #number of trees burnin = 2000 #either ~5*N or 5/s, depending on whether coalescence is dominated by drift or draft dt = 1000 #time between samples #set up population, switch on infinite sites mode pop=h.haploid_highd(L, all_polymorphic=True) #set the population size via the carrying capacity pop.carrying_capacity= N #set the crossover rate, outcrossing_rate and recombination model pop.outcrossing_rate = r pop.recombination_model = h.CROSSOVERS pop.crossover_rate = 1.0/pop.L #set the effect sizes of the mutations that are injected (the same at each site in this case) pop.set_fitness_additive(np.ones(L)*s) #track the genealogy at a central locus L/2 (which one doesn't matter in the asexual case) pop.track_locus_genealogy([L/2])
# Import module import sys sys.path.insert(0, '../pkg/python') import numpy as np import matplotlib.pyplot as plt import FFPopSim as h from Bio import Phylo # Globals L = 1000 # number of loci N = 300 # population size # Construct class pop = h.haploid_highd(L, all_polymorphic=False) # Set a growth rate explicitely pop.growth_rate = 2.5 # Start tracking genealogy of two loci pop.track_locus_genealogy([3, 60]) # Test fitness landscapes rep = np.zeros(L) rep[np.random.random(L) > 0.5] = -0.1 pop.set_trait_additive(rep) # Show the additive part of the fitness landscape print pop.get_trait_additive()
# parse the command line arguments import argparse parser = argparse.ArgumentParser(description="Simulate a population on a mixed additive/epistatic fitness function") parser.add_argument('--pop', default=10000, type=float, help='Population size (N)') parser.add_argument('--rec', default=0,type=float, help='out-crossing rate (r)') parser.add_argument('--sigma', default=0.05,type=float, help='Sigma') parser.add_argument('--hsq', default=0,type=float, help='heritability') parser.add_argument('--Ttraj', default=200,type=int, help='Length of trajectory in generations') parser.add_argument('--dt', default=1,type =int, help='time increments of trajectory') params=parser.parse_args() # set up the population L = 1000 # number of loci pop = ffpop.haploid_highd(L) # create an instance of the class pop.outcrossing_rate = params.rec # outcrossing rate pop.recombination_model = ffpop.CROSSOVERS # recombination model # set random epistatic fitness lanscape pop.set_random_epistasis(params.sigma * np.sqrt(1 - params.hsq)) # set heritability if (params.hsq > 0): pop.set_trait_additive(np.ones(L) * params.sigma * sqrt(params.hsp / L)) # initialize population in linkage equilibrium with all # allele frequencies at 0.5 pop.set_allele_frequencies(np.ones(L) * 0.5, params.pop)
import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm import FFPopSim as h # specify parameters N = 1000 # Population size L = 100 # number of loci mu = 0.000001 # no new mutations r = 0.01 # crossover rate outc = 0.01 # outcrossing rate ### set up pop = h.haploid_highd(L) # produce an instance of haploid_lowd with L loci pop.carrying_capacity = N # set the steady-state population size pop.outcrossing_rate = outc # set the outcrossing rate pop.crossover_rate = r # assign the recombination rate pop.mutation_rate = mu # assign the mutation rate # initialize the population with # - N/2 individuals with genotype 0, that is ---- # - N/2 with the opposite genotype, that is ++++ pop.set_wildtype(N) # Fitness pop.set_trait_additive(0.001 * np.ones(L), 0) pop.add_trait_coefficient(0.13, [0,2], 0) # evolve for some time
import sys sys.path.insert(0, '../pkg/python') import numpy as np import matplotlib.pyplot as plt import FFPopSim as h # specify parameters N = 10000 # population size L = 100 # number of loci mu = 0.0 # no new mutations r = 0.1/L # crossover rate # set up population pop = h.haploid_highd(L) # produce an instance of haploid_highd pop.carrying_capacity = N # set the steady-state population size pop.recombination_model = h.CROSSOVERS # specify crossover recombination pop.outcrossing_rate = 1 # obligate sexual pop.crossover_rate = r # assign the crossover rate per locus pop.mutation_rate = mu # assign the mutation rate per locus # initialize the population with # - N/2 individuals with genotype 00..00 or --..-- # - N/2 with the opposite genotype 11..11 or ++..++ pop.set_genotypes([np.zeros(L,dtype='int'), np.ones(L,dtype='int')], [N/2, N/2]) # locus pairs for which LD is to be tracked locus_pairs = [[0,10],
csize,cmut = get_mut_count_subtree(C) sub_tree_size += csize tmp_mut_count.extend(cmut) tmp_mut_count.append([csize,C.branch_length]) return sub_tree_size, tmp_mut_count def get_SFS(T): sample_size,SFS = get_mut_count_subtree(T.root) SFS = np.asarray(SFS) SFS[:,0]/=sample_size return sample_size,SFS L=100 pop=h.haploid_highd(L) pop.outcrossing_rate=1.0 pop.crossover_rate=1.0/pop.L pop.mutation_rate=0.0/pop.L pop.carrying_capacity=100 #track the loci 10, 50 and 90 pop.track_locus_genealogy([10,50,90]) #initialize the populations pop.set_wildtype(pop.carrying_capacity) pop.status() #evolve population for several coalescent times pop.evolve(4*pop.N)
help='out-crossing rate (r)') parser.add_argument('--sigma', default=0.05, type=float, help='Sigma') parser.add_argument('--hsq', default=0, type=float, help='heritability') parser.add_argument('--Ttraj', default=200, type=int, help='Length of trajectory in generations') parser.add_argument('--dt', default=1, type=int, help='time increments of trajectory') params = parser.parse_args() # set up the population L = 1000 # number of loci pop = ffpop.haploid_highd(L) # create an instance of the class pop.outcrossing_rate = params.rec # outcrossing rate pop.recombination_model = ffpop.CROSSOVERS # recombination model # set random epistatic fitness lanscape pop.set_random_epistasis(params.sigma * np.sqrt(1 - params.hsq)) # set heritability if (params.hsq > 0): pop.set_trait_additive(np.ones(L) * params.sigma * sqrt(params.hsp / L)) # initialize population in linkage equilibrium with all # allele frequencies at 0.5 pop.set_allele_frequencies(np.ones(L) * 0.5, params.pop) # evolve and store statistics along the way
''' # Import module import sys sys.path.insert(0, '../pkg/python') import numpy as np import matplotlib.pyplot as plt import FFPopSim as h from Bio import Phylo # Globals L = 1000 # number of loci N = 300 # population size # Construct class pop = h.haploid_highd(L, all_polymorphic=False) # Set a growth rate explicitely pop.growth_rate = 2.5 # Start tracking genealogy of two loci pop.track_locus_genealogy([3, 60]) # Test fitness landscapes rep = np.zeros(L) rep[np.random.random(L) > 0.5] = -0.1 pop.set_trait_additive(rep) # Show the additive part of the fitness landscape print pop.get_trait_additive()
F_matrix = np.zeros((L, L)) k = 0 for i in range(0, L): for j in range(0, L): if i != j: F_matrix[i][j] = Fij[k] k += 1 return [mu_true, sigma_true, F_matrix] [mu_tr, sigma_tr, F] = RFM(0.0, sigma, L) params = [L, N, n_savings, sv_int, mu, r, rho, sigma, mu_tr, sigma_tr] # to pass as argument to functions !AVOID MODIFY! # [0 1 2 3 4 5 6 7 8 9 ] hpop = pop.haploid_highd(L) def declare_initial(params): """ Print of initial parameters of the system. """ print('*--*--*--*--*--*--*--*--*') print('|') print('* L = %d' % params[0]) print('| N = %d' % params[1]) print('* T = %d' % (params[2] * params[3])) print('| mu = %.5f' % params[4]) print('* r = %.5f' % params[5]) print('| rho = %.5f' % params[6]) print('* sigma = %.5f' % params[7])