Skip to content

Commit 902179d

Browse files
committed
first pass
update documentation and float k values hull offset a required positional arg remove string remapping fix verifications added lost test not remove named argument and add a test fix test fix doc
1 parent 1526582 commit 902179d

File tree

7 files changed

+39
-35
lines changed

7 files changed

+39
-35
lines changed

docs/ancestry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,7 @@ In this example, we use the {class}`SMC(k) <.SmcKApproxCoalescent>` model to run
22592259
simulations:
22602260
```{code-cell}
22612261
ts = msprime.sim_ancestry(4, population_size=10,
2262-
model=msprime.SmcKApproxCoalescent(hull_offset=1),
2262+
model=msprime.SmcKApproxCoalescent(1),
22632263
random_seed=1)
22642264
SVG(ts.draw_svg(y_axis=True, time_scale="log_time"))
22652265
```

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: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ class SmcApproxCoalescent(AncestryModel):
17981798
This model is implemented using a naive rejection sampling approach
17991799
and so it may not be any more efficient to simulate than the
18001800
standard Hudson model.
1801-
We recommend using the ``SmcKApproxCoalescent(hull_offset=0)`` instead
1801+
We recommend using the ``SmcKApproxCoalescent(0)`` instead
18021802
18031803
The string ``"smc"`` can be used to refer to this model.
18041804
"""
@@ -1822,7 +1822,8 @@ class SmcPrimeApproxCoalescent(AncestryModel):
18221822
This model is implemented using a naive rejection sampling approach
18231823
and so it may not be any more efficient to simulate than the
18241824
standard Hudson model. We recommend using the
1825-
``SmcKApproxCoalescent(hull_offset=1)`` instead.
1825+
``SmcKApproxCoalescent(1)`` for discrete genomes instead, or
1826+
``SmcKApproxCoalescent(1e-14)`` for continous genomes.
18261827
18271828
The string ``"smc_prime"`` can be used to refer to this model.
18281829
"""
@@ -1845,23 +1846,23 @@ class SmcKApproxCoalescent(ParametricAncestryModel):
18451846
18461847
Specifically, if the hull_offset is set to 0, then only overlapping genomic
18471848
tracts can be joined by a common ancestor event (this is equivalent to the
1848-
SMC model). If the hull_offset is set to 1, then overlapping or adjacent
1849-
genomic tracts can be joined by a common ancestor (this is equivalent to the
1850-
SMC' model). If the hull_offset is set to full the sequence length, then any
1851-
segments can share a common ancestor, which is equivalent to the standard Hudson
1852-
coalescent.
1849+
SMC model). If the hull_offset is set to 1 (for discrete genomes), then
1850+
overlapping or adjacent genomic tracts can be joined by a common ancestor
1851+
(this is equivalent to the SMC' model). If the hull_offset is set to full
1852+
the sequence length, then any segments can share a common ancestor, which
1853+
is equivalent to the standard Hudson coalescent.
18531854
18541855
:param float hull_offset: Determines the maximum distance between genomic tracts
18551856
of ancestral material that can be joined by a common ancestor event.
1856-
Defaults to 0 (equivalent to the SMC model).
1857+
18571858
"""
18581859

18591860
name = "smc_k"
18601861

18611862
hull_offset: float
18621863

18631864
# We have to define an __init__ to enforce keyword-only behaviour
1864-
def __init__(self, *, duration=None, hull_offset=0.0):
1865+
def __init__(self, hull_offset, *, duration=None):
18651866
self.duration = duration
18661867
self.hull_offset = hull_offset
18671868

tests/test_ancestry.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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(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(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(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(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(1),
31183118
],
31193119
random_seed=10,
31203120
recombination_rate=1e-4,
@@ -3129,7 +3129,7 @@ def test_smc_k_plus(self, hull_offset, discrete_genome):
31293129
tss = msprime.sim_ancestry(
31303130
samples=10,
31313131
population_size=10_000,
3132-
model=msprime.SmcKApproxCoalescent(hull_offset=hull_offset),
3132+
model=msprime.SmcKApproxCoalescent(hull_offset),
31333133
random_seed=10,
31343134
recombination_rate=1e-5,
31353135
sequence_length=100,
@@ -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(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(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(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(1),
2583+
]:
25802584
population_configurations = [
25812585
msprime.PopulationConfiguration(10),
25822586
msprime.PopulationConfiguration(10),

tests/test_models.py

Lines changed: 7 additions & 7 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(0.0)
6464
repr_s = "SmcKApproxCoalescent(duration=None, hull_offset=0.0)"
6565
assert repr(model) == repr_s
6666
assert str(model) == repr_s
@@ -144,7 +144,7 @@ def test_model_instances(self):
144144
msprime.StandardCoalescent(),
145145
msprime.SmcApproxCoalescent(),
146146
msprime.SmcPrimeApproxCoalescent(),
147-
msprime.SmcKApproxCoalescent(),
147+
msprime.SmcKApproxCoalescent(1),
148148
msprime.DiscreteTimeWrightFisher(),
149149
msprime.FixedPedigree(),
150150
msprime.SweepGenicSelection(
@@ -332,11 +332,11 @@ def test_sweep_genic_selection(self):
332332
msprime.SweepGenicSelection(1)
333333

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

339-
model = msprime.SmcKApproxCoalescent(hull_offset=1.1)
336+
with pytest.raises(TypeError, match="hull_offset"):
337+
model = msprime.SmcKApproxCoalescent()
338+
339+
model = msprime.SmcKApproxCoalescent(1.1)
340340
assert model.duration is None
341341
assert model.hull_offset == 1.1
342342

@@ -471,7 +471,7 @@ def test_dirac_coalescent_parameters(self):
471471

472472
def test_smck_coalescent_parameters(self):
473473
for hull_offset in [0.01, 10.0, 0.99]:
474-
model = msprime.SmcKApproxCoalescent(hull_offset=hull_offset)
474+
model = msprime.SmcKApproxCoalescent(hull_offset)
475475
assert model.hull_offset == hull_offset
476476
d = model._as_lowlevel()
477477
assert d == {"name": "smc_k", "hull_offset": hull_offset, "duration": None}

verification.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4535,7 +4535,7 @@ class SmckvsSmcKApproxCoalescent(Test):
45354535
"""
45364536

45374537
models = {
4538-
"SmcKApprox": msprime.SmcKApproxCoalescent(),
4538+
"SmcKApprox": msprime.SmcKApproxCoalescent(hull_offset=0.0),
45394539
"smc": msprime.SmcApproxCoalescent(),
45404540
}
45414541

@@ -4955,9 +4955,9 @@ def test_gc_tract_length_smc(self):
49554955
Runs the check for the mean length of gene conversion tracts.
49564956
"""
49574957
models = {
4958-
"Hudson": msprime.SmcApproxCoalescent(),
4959-
"SMC": msprime.SmcKApproxCoalescent(),
4960-
"SMCK": msprime.StandardCoalescent(),
4958+
"SMC": msprime.SmcApproxCoalescent(),
4959+
"SMCK": msprime.SmcKApproxCoalescent(hull_offset=0.0),
4960+
"Hudson": msprime.StandardCoalescent(),
49614961
}
49624962
num_replicates = 10
49634963
n = 10
@@ -5053,7 +5053,7 @@ def test_smc_k_num_trees_gc(self):
50535053

50545054
models_to_run = [
50555055
(msprime.SmcApproxCoalescent(), "msprime (hudson)"),
5056-
(msprime.SmcKApproxCoalescent(), "smc"),
5056+
(msprime.SmcApproxCoalescent(), "smc"),
50575057
(msprime.SmcPrimeApproxCoalescent(), "smc_prime"),
50585058
(msprime.SmcKApproxCoalescent(hull_offset=0.0), "smc_k(0)"),
50595059
(msprime.SmcKApproxCoalescent(hull_offset=1.0), "smc_k(1)"),
@@ -5618,7 +5618,7 @@ def test_above_root_smck(self):
56185618
samples=10,
56195619
sequence_length=100,
56205620
recombination_rate=0.1,
5621-
model=msprime.SmcKApproxCoalescent(),
5621+
model=msprime.SmcKApproxCoalescent(hull_offset=0.0),
56225622
num_replicates=300,
56235623
)
56245624

0 commit comments

Comments
 (0)