-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbottleneck.py
102 lines (88 loc) · 3.03 KB
/
bottleneck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#This is a exemple of the scripts used in the article "Large‐scale genetic
##panmixia in the blue shark (Prionace glauca): A single worldwide population,
##or a genetic lag‐time effect of the “grey zone” of differentiation?" to
##determine the possible consequences of bottlenecks on the detection
##of the grey zone.
#written by Diane Bailleul, with the help of Bo Peng and Solenn Stoeckel.
#email: [email protected]
#Please, do not use (with or witout modifications) without citing
##SimuPop and the original article.
#########################################################################################
#Fst computation with migration, 3 populations and bottleneck at generation 500, N/10000#
#########################################################################################
import simuPOP as sim
from simuPOP.sampling import drawRandomSample
from simuPOP.demography import *
import math
import numpy as np
import os
import time
global NOM
NOM = time.strftime('%Y-%m-%d-%Hh %Mmin',time.localtime())
print NOM
global CHEMIN
CHEMIN = os.getcwd()
print CHEMIN
def reccord (chaine,nfic):
cheminfst = os.path.join(CHEMIN, (NOM + nfic + '.txt'))
resultsfst=open(cheminfst,'a')
resultsfst.write(chaine)
resultsfst.close
return cheminfst
def calcFst(pop):
sortie = ''
sim.stat(pop, structure=range(10), vars=['F_st'])
Fstpop = pop.dvars().F_st
for a in range(100):
sample = drawRandomSample(pop, sizes=[50]*2)
sim.stat(sample, structure=range(10), vars=['F_st'])
Fstsample = sample.dvars().F_st
sample.addInfoFields('order')
order = list(range(100))
fstsim = ''
for rep in range(1000):
merged=sample
merged.mergeSubPops()
np.random.shuffle(order)
merged.setIndInfo(order, field = 'order')
merged.sortIndividuals('order')
merged.splitSubPop(0, [50]*2)
sim.stat(merged, structure=range(10), vars=['F_st'])
fstsim += '%s\t' % merged.dvars().F_st
sortie += '%3d\t%.6f\t%3d\t%.6f\t%s\n' % (pop.dvars().gen, Fstpop, a, Fstsample, fstsim)
reccord (sortie, "dataout")
return True
model = EventBasedModel(
... N0=([1000000]*3),
... events=[
... ResizeEvent(at=500, sizes=1000),
... ]
... )
pop = sim.Population(size=model.init_size, loci=[10]*10,
... infoFields='migrate_to')
pop.evolve(
initOps=[
sim.InitSex(),
sim.InitGenotype(freq=[0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1])
],
preOps=[
sim.Migrator(rate=[
[0,0.000005,0.000005],
[0.000005,0,0.000005],
[0.000005,0.000005,0],
],mode=sim.BY_PROPORTION, end=499),
sim.Migrator(rate=[
[0,0.005,0.005],
[0.005,0,0.005],
[0.005,0.005,0],
],mode=sim.BY_PROPORTION, begin=500)
],
matingScheme=sim.RandomMating(subPopSize=model,ops=sim.Recombinator(rates=0.01)),
postOps=[
sim.PyOperator(func=calcFst, step=100)
],
gen = 1000
)
for idx, name in enumerate(pop.subPopNames()):
... print('%s (%d): %.4f' % (name, pop.subPopSize(name),
... pop.dvars(idx).alleleFreq[0][0]))