Skip to content

Commit 85155aa

Browse files
committed
first pass
update documentation and float k values
1 parent 1526582 commit 85155aa

File tree

5 files changed

+37
-27
lines changed

5 files changed

+37
-27
lines changed

docs/api.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ for discussion and examples of individual features.
2121
sim_ancestry
2222
SampleSet
2323
StandardCoalescent
24-
SmcApproxCoalescent
25-
SmcPrimeApproxCoalescent
24+
SmcKApproxCoalescent
2625
DiscreteTimeWrightFisher
2726
FixedPedigree
2827
BetaCoalescent

msprime/ancestry.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def _model_factory(model: None | str | AncestryModel) -> AncestryModel:
6767
"""
6868
model_map = {
6969
"hudson": StandardCoalescent(),
70-
"smc": SmcApproxCoalescent(),
71-
"smc_prime": SmcPrimeApproxCoalescent(),
70+
"smc": SmcKApproxCoalescent(hull_offset=0.0),
71+
"smc_prime": SmcKApproxCoalescent(hull_offset=1.0),
7272
"dtwf": DiscreteTimeWrightFisher(),
7373
"fixed_pedigree": FixedPedigree(),
7474
}
@@ -1799,8 +1799,6 @@ class SmcApproxCoalescent(AncestryModel):
17991799
and so it may not be any more efficient to simulate than the
18001800
standard Hudson model.
18011801
We recommend using the ``SmcKApproxCoalescent(hull_offset=0)`` instead
1802-
1803-
The string ``"smc"`` can be used to refer to this model.
18041802
"""
18051803

18061804
name = "smc"
@@ -1824,7 +1822,6 @@ class SmcPrimeApproxCoalescent(AncestryModel):
18241822
standard Hudson model. We recommend using the
18251823
``SmcKApproxCoalescent(hull_offset=1)`` instead.
18261824
1827-
The string ``"smc_prime"`` can be used to refer to this model.
18281825
"""
18291826

18301827
name = "smc_prime"
@@ -1851,17 +1848,22 @@ class SmcKApproxCoalescent(ParametricAncestryModel):
18511848
segments can share a common ancestor, which is equivalent to the standard Hudson
18521849
coalescent.
18531850
1851+
The string ``"smc"`` can be used to refer to this model with a `` hull_offset=0``.
1852+
1853+
The string ``"smc_prime"`` can be used to refer to this model with a
1854+
`` hull_offset=1``.
1855+
18541856
:param float hull_offset: Determines the maximum distance between genomic tracts
18551857
of ancestral material that can be joined by a common ancestor event.
1856-
Defaults to 0 (equivalent to the SMC model).
1858+
18571859
"""
18581860

18591861
name = "smc_k"
18601862

18611863
hull_offset: float
18621864

18631865
# We have to define an __init__ to enforce keyword-only behaviour
1864-
def __init__(self, *, duration=None, hull_offset=0.0):
1866+
def __init__(self, *, hull_offset, duration=None):
18651867
self.duration = duration
18661868
self.hull_offset = hull_offset
18671869

tests/test_ancestry.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ def test_model(self):
14531453
# Extensive testing of the model parsing is done elsewhere.
14541454
sim = ancestry._parse_sim_ancestry(10, model="smc")
14551455
assert len(sim.models) == 1
1456-
assert isinstance(sim.models[0], msprime.SmcApproxCoalescent)
1456+
assert isinstance(sim.models[0], msprime.SmcKApproxCoalescent)
14571457
assert sim.models[0].duration is None
14581458

14591459
sim = ancestry._parse_sim_ancestry(
@@ -3052,7 +3052,7 @@ class TestSMCK:
30523052
def test_discrete(self, seed):
30533053
tss = msprime.sim_ancestry(
30543054
samples=10,
3055-
model=msprime.SmcKApproxCoalescent(),
3055+
model=msprime.SmcKApproxCoalescent(hull_offset=1),
30563056
recombination_rate=0.005,
30573057
sequence_length=1000,
30583058
random_seed=seed,
@@ -3064,7 +3064,7 @@ def test_discrete(self, seed):
30643064
def test_continuous(self):
30653065
tss = msprime.sim_ancestry(
30663066
samples=10,
3067-
model=msprime.SmcKApproxCoalescent(),
3067+
model=msprime.SmcKApproxCoalescent(hull_offset=1),
30683068
recombination_rate=0.005,
30693069
sequence_length=1000,
30703070
num_replicates=10,
@@ -3086,7 +3086,7 @@ def test_ancient_samples(self):
30863086
ts = msprime.sim_ancestry(
30873087
initial_state=tables,
30883088
population_size=10_000,
3089-
model=msprime.SmcKApproxCoalescent(),
3089+
model=msprime.SmcKApproxCoalescent(hull_offset=1),
30903090
recombination_rate=1e-6,
30913091
)
30923092
for tree in ts.trees():
@@ -3098,7 +3098,7 @@ def test_model_switch(self):
30983098
population_size=10_000,
30993099
model=[
31003100
msprime.StandardCoalescent(duration=10),
3101-
msprime.SmcKApproxCoalescent(duration=10),
3101+
msprime.SmcKApproxCoalescent(hull_offset=1, duration=10),
31023102
msprime.StandardCoalescent(),
31033103
],
31043104
random_seed=10,
@@ -3114,7 +3114,7 @@ def test_model_switch_high_rec(self):
31143114
population_size=10_000,
31153115
model=[
31163116
msprime.StandardCoalescent(duration=100),
3117-
msprime.SmcKApproxCoalescent(),
3117+
msprime.SmcKApproxCoalescent(hull_offset=1),
31183118
],
31193119
random_seed=10,
31203120
recombination_rate=1e-4,
@@ -3149,7 +3149,7 @@ def test_two_pops(self):
31493149
ts = msprime.sim_ancestry(
31503150
samples={0: 2, 1: 2},
31513151
demography=demography,
3152-
model=msprime.SmcKApproxCoalescent(),
3152+
model=msprime.SmcKApproxCoalescent(hull_offset=1),
31533153
random_seed=74024,
31543154
recombination_rate=1e-5,
31553155
sequence_length=100,
@@ -3166,7 +3166,7 @@ def test_gc(self):
31663166
):
31673167
msprime.sim_ancestry(
31683168
samples=10,
3169-
model=msprime.SmcKApproxCoalescent(),
3169+
model=msprime.SmcKApproxCoalescent(hull_offset=1),
31703170
sequence_length=100,
31713171
gene_conversion_rate=1.0,
31723172
gene_conversion_tract_length=5,

tests/test_demography.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,7 +2521,7 @@ class TestMigrationRecordsSmcPrime(MigrationRecordsMixin):
25212521

25222522

25232523
class TestMigrationRecordsSmcK(MigrationRecordsMixin):
2524-
model = msprime.SmcKApproxCoalescent()
2524+
model = msprime.SmcKApproxCoalescent(hull_offset=1)
25252525

25262526

25272527
class TestMigrationRecordsDtwf(MigrationRecordsMixin):
@@ -2576,7 +2576,11 @@ def test_full_arg_migration(self):
25762576
self.verify_two_pops_full_arg(ts)
25772577

25782578
def test_full_arg_migration_smc(self):
2579-
for model in ["smc", "smc_prime", msprime.SmcKApproxCoalescent()]:
2579+
for model in [
2580+
msprime.SmcApproxCoalescent(),
2581+
msprime.SmcPrimeApproxCoalescent(),
2582+
msprime.SmcKApproxCoalescent(hull_offset=1),
2583+
]:
25802584
population_configurations = [
25812585
msprime.PopulationConfiguration(10),
25822586
msprime.PopulationConfiguration(10),

tests/test_models.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_smc_models(self):
6060
assert repr(model) == repr_s
6161
assert str(model) == repr_s
6262

63-
model = msprime.SmcKApproxCoalescent()
63+
model = msprime.SmcKApproxCoalescent(hull_offset=0.0)
6464
repr_s = "SmcKApproxCoalescent(duration=None, hull_offset=0.0)"
6565
assert repr(model) == repr_s
6666
assert str(model) == repr_s
@@ -115,8 +115,8 @@ def test_bad_model_names(self):
115115
def test_named_model_variants(self):
116116
simulation_models = [
117117
("hudson", msprime.StandardCoalescent),
118-
("smc", msprime.SmcApproxCoalescent),
119-
("smc_prime", msprime.SmcPrimeApproxCoalescent),
118+
("smc", msprime.SmcKApproxCoalescent),
119+
("smc_prime", msprime.SmcKApproxCoalescent),
120120
("dtwf", msprime.DiscreteTimeWrightFisher),
121121
("fixed_pedigree", msprime.FixedPedigree),
122122
]
@@ -128,6 +128,11 @@ def test_named_model_variants(self):
128128
model = ancestry._model_factory(model=name)
129129
assert isinstance(model, model_class)
130130

131+
if name == "smc":
132+
assert model.hull_offset == 0.0
133+
elif name == "smc_prime":
134+
assert model.hull_offset == 1.0
135+
131136
def test_named_parametric_models_fail(self):
132137
parametric_models = ["beta", "dirac"]
133138
for name in parametric_models:
@@ -144,7 +149,7 @@ def test_model_instances(self):
144149
msprime.StandardCoalescent(),
145150
msprime.SmcApproxCoalescent(),
146151
msprime.SmcPrimeApproxCoalescent(),
147-
msprime.SmcKApproxCoalescent(),
152+
msprime.SmcKApproxCoalescent(hull_offset=1),
148153
msprime.DiscreteTimeWrightFisher(),
149154
msprime.FixedPedigree(),
150155
msprime.SweepGenicSelection(
@@ -332,9 +337,6 @@ def test_sweep_genic_selection(self):
332337
msprime.SweepGenicSelection(1)
333338

334339
def test_smck_coalescent(self):
335-
model = msprime.SmcKApproxCoalescent()
336-
assert model.duration is None
337-
assert model.hull_offset == 0.0
338340

339341
model = msprime.SmcKApproxCoalescent(hull_offset=1.1)
340342
assert model.duration is None
@@ -371,7 +373,10 @@ def test_hudson(self):
371373
assert sim2.num_rejected_common_ancestor_events == 0
372374

373375
def test_smc_variants(self):
374-
for model in ["smc", "smc_prime"]:
376+
for model in [
377+
msprime.SmcApproxCoalescent(),
378+
msprime.SmcPrimeApproxCoalescent(),
379+
]:
375380
threshold = 20
376381
sim = ancestry._parse_simulate(
377382
sample_size=10, recombination_rate=5, model=model, random_seed=432

0 commit comments

Comments
 (0)