Skip to content

Commit ef2cd8c

Browse files
committed
updates for simulating and plotting sawtooth. useful for benchmarking.
1 parent 7592fa8 commit ef2cd8c

File tree

4 files changed

+46
-14
lines changed

4 files changed

+46
-14
lines changed

smcpp/commands/plot.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,24 @@ def main(self, args):
7474
if len(args.offsets) != len(args.model):
7575
raise RuntimeError("Please specify one offset per model")
7676
for fn, off in zip_longest(args.model, args.offsets, fillvalue=None):
77-
if not os.path.exists(fn):
78-
sys.exit("File not found: %s" % fn)
79-
res = json.load(open(fn, "rt"))
80-
if args.step_function:
81-
mod = res["model"]
82-
klass = getattr(model, mod["class"])
83-
m = klass.from_dict(mod)
84-
a = m.stepwise_values().astype("float")
85-
s = m.s
86-
d = {"a": m.stepwise_values(), "s": m.s, "N0": mod["N0"]}
77+
if fn in ["human", "sawtooth"]:
78+
label = None
79+
p = getattr(util, fn)
80+
d = {k: p[k] for k in "abs"}
81+
d['N0'] = p['N0']
8782
else:
88-
d = res
83+
if not os.path.exists(fn):
84+
sys.exit("File not found: %s" % fn)
85+
res = json.load(open(fn, "rt"))
86+
if args.step_function:
87+
mod = res["model"]
88+
klass = getattr(model, mod["class"])
89+
m = klass.from_dict(mod)
90+
a = m.stepwise_values().astype("float")
91+
s = m.s
92+
d = {"a": m.stepwise_values(), "s": m.s, "N0": mod["N0"]}
93+
else:
94+
d = res
8995
d["g"] = args.g
9096
psfs.append((d, off or 0))
9197
fig, series = plotting.plot_psfs(

smcpp/plotting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def g(x, y, label, data=data, **kwargs):
7070
y = np.concatenate([y, [a[-1], a[-1]]])
7171
# if not logy:
7272
# y *= 1e-3
73-
series.append((fn, x, y, my_axplot, off, N0, g))
73+
series.append((None, x, y, my_axplot, off, N0, g))
7474
elif "model" in d:
7575
cls = getattr(model, d["model"]["class"])
7676
mb = cls.from_dict(d["model"])

util/make_datasets.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
sys.path.append("util/")
88
import multiprocessing
99
import argparse
10-
import cPickle as pickle
10+
import pickle
1111
import os.path
1212
import vcf
13-
import cStringIO
1413
from collections import Counter
1514

1615
import scrm, smcpp.util

util/sim_sawtooth.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
3+
import msprime as msp
4+
from smcpp.util import sawtooth
5+
import sys
6+
7+
if __name__ == "__main__":
8+
sawtooth_events = [
9+
(.000582262, 1318.18),
10+
(.00232905, -329.546),
11+
(.00931919, 82.3865),
12+
(.0372648, -20.5966),
13+
(.149059, 5.14916),
14+
(0.596236, 0.),
15+
]
16+
N0 = 14312
17+
de = (
18+
[msp.PopulationParametersChange(time=0, initial_size=5 * N0)] +
19+
[
20+
msp.PopulationParametersChange(
21+
time=4 * t * N0,
22+
growth_rate=g / (4 * N0))
23+
for t, g in sawtooth_events
24+
])
25+
msp.DemographyDebugger(demographic_events=de).print_history()
26+
msp.simulate(int(sys.argv[1]), length=1e8, mutation_rate=1.25e-8, recombination_rate=1e-9,
27+
demographic_events=de).write_vcf(open(sys.argv[2], "wt"), ploidy=2)

0 commit comments

Comments
 (0)