initialize() {
// Use tree-sequence recording to speed up burn-in
initializeTreeSeq();
defineConstant('pop_size',100);
//defineConstant('T_N',10*pop_size);
defineConstant('ge_length',70000);
defineConstant('sweep_site',integerDiv((ge_length+1),2));
defineConstant('low_site',sweep_site-1);
defineConstant('high_site',1+sweep_site);
defineConstant('recombination_rate',0.00025);
defineConstant('mut_rate',0.00025);
//defineConstant('T_mu', 10/mut_rate); //round it
defineConstant('nucleotide_diversity', (4*pop_size*mut_rate)/(1+(2*4*pop_size*mut_rate)));
initializeRecombinationRate(recombination_rate);
initializeMutationRate(mut_rate);
// m1 is a neutral mutation
initializeMutationType('m0', 0.5, 'f', 0.0);
m0.mutationStackPolicy = "l";
initializeGenomicElementType('g1', m0, 1.0 );
initializeGenomicElement(g1, 0, low_site);
initializeGenomicElement(g1, sweep_site, sweep_site);
initializeGenomicElement(g1, high_site, ge_length);}
1 early(){
sim.addSubpop("p0", pop_size);
}
1:1000 late(){
div = calcHeterozygosity(p0.genomes);
catn(sim.cycle +","+ div);
}
//conditional termination of somulation based on val of nucleotide diversity
500:39999 late() {
div = calcHeterozygosity(p0.genomes);
if(div >= nucleotide_diversity*1.1){ // if(div >= nucleotide_diversity){
sim.simulationFinished();
catn('number of generations taken ' + sim.cycle);
sim.treeSeqOutput("burnin_no.1_early_10.trees");
}
}
// Run burn-in for ~10/mu generations
40000 late() {
// Output recorded tree-sequence
sim.treeSeqOutput("burnin_no.1._10_.trees");
}
heterozygosity = 2 * sum(p * (1 - p)) / length;
Consider the case with a single site at which there are n mutations, each at frequency 1/n. Each contributes 2 * 1/n * (1-1/n) to the sum, resulting in a heterozygosity of 2*(1-1/n). I started to file a bug report for this, before reading in the documentation
> The implementation of calcHeterozygosity(), viewable with functionSource(), treats every mutation as independent in the heterozygosity calculations. One could regard this choice as embodying an infinite-sites interpretation of the segregating mutations.
So, in fact, this is correct as defined, although in an extremely weird way. Effectively, it is computing the mean number of mutations that differ between a randomly chosen pair of sequences, divided by the length of the genome; since with "last" mutation stacking, any two sequences of length L can *each* have L different mutations, they will at maximum differ at 2*L mutations, thus saturating at a heterozygosity of 2.
--
SLiM forward genetic simulation: http://messerlab.org/slim/
---
You received this message because you are subscribed to the Google Groups "slim-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to slim-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/slim-discuss/11dcb3fd-52c0-4f5b-ac0e-0082a867be08n%40googlegroups.com.
> functionSource("calcHeterozygosity")
(float$)calcHeterozygosity(object<Genome> genomes, [No<Mutation> muts = NULL], [Ni$ start = NULL], [Ni$ end = NULL]) <SLiM>
{
if (genomes.length() == 0)
stop("ERROR (calcHeterozygosity()): genomes must be non-empty.");
if (community.allSpecies.length() > 1)
{
species = unique(genomes.individual.subpopulation.species, preserveOrder=F);
if (species.length() != 1)
stop("ERROR (calcHeterozygosity()): genomes must all belong to the same species.");
if (!isNULL(muts))
if (!all(muts.mutationType.species == species))
stop("ERROR (calcHeterozygosity()): muts must all belong to the same species as genomes.");
}
else
{
species = community.allSpecies;
}
length = species.chromosome.lastPosition + 1;
// handle windowing
if (!isNULL(start) & !isNULL(end))
{
if (start > end)
stop("ERROR (calcHeterozygosity()): start must be less than or equal to end.");
if (isNULL(muts))
muts = species.mutations;
mpos = muts.position;
muts = muts[(mpos >= start) & (mpos <= end)];
length = end - start + 1;
}
else if (!isNULL(start) | !isNULL(end))
{
stop("ERROR (calcHeterozygosity()): start and end must both be NULL or both be non-NULL.");
}
// do the calculation
p = genomes.mutationFrequenciesInGenomes(muts);
heterozygosity = 2 * sum(p * (1 - p)) / length;
return heterozygosity;
}
To view this discussion on the web visit https://groups.google.com/d/msgid/slim-discuss/2bf6e071-3aef-4477-8fb7-1e7cb53c6dc6n%40googlegroups.com.