forked from tatumdmortimer/popgen-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dadi_neutral.py
executable file
·54 lines (42 loc) · 1.49 KB
/
dadi_neutral.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
#!/usr/bin/env python
import sys
import argparse
import numpy
from numpy import array
import dadi
from datetime import datetime
def get_args():
# parse command line arguments
parser = argparse.ArgumentParser(description='Run dadi analysis')
parser.add_argument("sfs", help="SFS in dadi format",
type=argparse.FileType('r'))
parser.add_argument("-f", "--fold", help="Fold the SFS before analysis",
action="store_true")
return parser.parse_args()
args = get_args()
startTime = datetime.now()
data = dadi.Spectrum.from_file(args.sfs)
ns = data.sample_sizes
if args.fold:
data = data.fold()
# Neutral model
pts_l = [110,120,130] # grid point settings
neutral_func = dadi.Demographics1D.snm
neutral_params = array([])
neutral_upper_bound = []
neutral_func_ex = dadi.Numerics.make_extrap_log_func(neutral_func)
neutral_model = neutral_func_ex(neutral_params, ns, pts_l)
neutral_ll = dadi.Inference.ll_multinom(neutral_model, data)
print "Neutral model log-likelihood: %f" % neutral_ll
# Output SFS for data
data_sfs_file = open("observedSFS.txt", "w")
for i in range(1,len(data)-1):
data_sfs_file.write(str(data[i]) + '\n')
data_sfs_file.close()
# Output SFS for neutral model
neutral_sfs = dadi.Inference.optimally_scaled_sfs(neutral_model, data)
neutral_sfs_file = open("neutralModelSFS.txt", 'w')
for i in range(1,len(neutral_sfs)-1):
neutral_sfs_file.write(str(neutral_sfs[i]) + '\n')
neutral_sfs_file.close()
print datetime.now() - startTime