-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrey_zone.py
80 lines (68 loc) · 2.45 KB
/
grey_zone.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
#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 existence and duration 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, with m = 1/10000 and Nm = 10 and N = 100000#
#############################################################################
import simuPOP as sim
import numpy as np
import os
import time
from simuPOP.sampling import drawRandomSample
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
pop = sim.Population([100000]*2, 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.0001],
[0.0001,0]
],
mode=sim.BY_PROPORTION),
matingScheme=sim.RandomMating(ops=sim.Recombinator(rates=0.01)),
postOps=[
sim.PyOperator(func=calcFst, step=50)
],
gen = 5000
)