Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/ancestry.md
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,7 @@ In this example, we use the {class}`SMC(k) <.SmcKApproxCoalescent>` model to run
simulations:
```{code-cell}
ts = msprime.sim_ancestry(4, population_size=10,
model=msprime.SmcKApproxCoalescent(hull_offset=1),
model=msprime.SmcKApproxCoalescent(1),
random_seed=1)
SVG(ts.draw_svg(y_axis=True, time_scale="log_time"))
```
Expand Down
3 changes: 1 addition & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ for discussion and examples of individual features.
sim_ancestry
SampleSet
StandardCoalescent
SmcApproxCoalescent
SmcPrimeApproxCoalescent
SmcKApproxCoalescent
DiscreteTimeWrightFisher
FixedPedigree
BetaCoalescent
Expand Down
19 changes: 10 additions & 9 deletions msprime/ancestry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ class SmcApproxCoalescent(AncestryModel):
This model is implemented using a naive rejection sampling approach
and so it may not be any more efficient to simulate than the
standard Hudson model.
We recommend using the ``SmcKApproxCoalescent(hull_offset=0)`` instead
We recommend using the ``SmcKApproxCoalescent(0)`` instead

The string ``"smc"`` can be used to refer to this model.
"""
Expand All @@ -1822,7 +1822,8 @@ class SmcPrimeApproxCoalescent(AncestryModel):
This model is implemented using a naive rejection sampling approach
and so it may not be any more efficient to simulate than the
standard Hudson model. We recommend using the
``SmcKApproxCoalescent(hull_offset=1)`` instead.
``SmcKApproxCoalescent(1)`` for discrete genomes instead, or
``SmcKApproxCoalescent(1e-14)`` for continous genomes.

The string ``"smc_prime"`` can be used to refer to this model.
"""
Expand All @@ -1845,23 +1846,23 @@ class SmcKApproxCoalescent(ParametricAncestryModel):

Specifically, if the hull_offset is set to 0, then only overlapping genomic
tracts can be joined by a common ancestor event (this is equivalent to the
SMC model). If the hull_offset is set to 1, then overlapping or adjacent
genomic tracts can be joined by a common ancestor (this is equivalent to the
SMC' model). If the hull_offset is set to full the sequence length, then any
segments can share a common ancestor, which is equivalent to the standard Hudson
coalescent.
SMC model). If the hull_offset is set to 1 (for discrete genomes), then
overlapping or adjacent genomic tracts can be joined by a common ancestor
(this is equivalent to the SMC' model). If the hull_offset is set to full
the sequence length, then any segments can share a common ancestor, which
is equivalent to the standard Hudson coalescent.

:param float hull_offset: Determines the maximum distance between genomic tracts
of ancestral material that can be joined by a common ancestor event.
Defaults to 0 (equivalent to the SMC model).

"""

name = "smc_k"

hull_offset: float

# We have to define an __init__ to enforce keyword-only behaviour
def __init__(self, *, duration=None, hull_offset=0.0):
def __init__(self, hull_offset, *, duration=None):
self.duration = duration
self.hull_offset = hull_offset

Expand Down
16 changes: 8 additions & 8 deletions tests/test_ancestry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3052,7 +3052,7 @@ class TestSMCK:
def test_discrete(self, seed):
tss = msprime.sim_ancestry(
samples=10,
model=msprime.SmcKApproxCoalescent(),
model=msprime.SmcKApproxCoalescent(1),
recombination_rate=0.005,
sequence_length=1000,
random_seed=seed,
Expand All @@ -3064,7 +3064,7 @@ def test_discrete(self, seed):
def test_continuous(self):
tss = msprime.sim_ancestry(
samples=10,
model=msprime.SmcKApproxCoalescent(),
model=msprime.SmcKApproxCoalescent(1),
recombination_rate=0.005,
sequence_length=1000,
num_replicates=10,
Expand All @@ -3086,7 +3086,7 @@ def test_ancient_samples(self):
ts = msprime.sim_ancestry(
initial_state=tables,
population_size=10_000,
model=msprime.SmcKApproxCoalescent(),
model=msprime.SmcKApproxCoalescent(1),
recombination_rate=1e-6,
)
for tree in ts.trees():
Expand All @@ -3098,7 +3098,7 @@ def test_model_switch(self):
population_size=10_000,
model=[
msprime.StandardCoalescent(duration=10),
msprime.SmcKApproxCoalescent(duration=10),
msprime.SmcKApproxCoalescent(1, duration=10),
msprime.StandardCoalescent(),
],
random_seed=10,
Expand All @@ -3114,7 +3114,7 @@ def test_model_switch_high_rec(self):
population_size=10_000,
model=[
msprime.StandardCoalescent(duration=100),
msprime.SmcKApproxCoalescent(),
msprime.SmcKApproxCoalescent(1),
],
random_seed=10,
recombination_rate=1e-4,
Expand All @@ -3129,7 +3129,7 @@ def test_smc_k_plus(self, hull_offset, discrete_genome):
tss = msprime.sim_ancestry(
samples=10,
population_size=10_000,
model=msprime.SmcKApproxCoalescent(hull_offset=hull_offset),
model=msprime.SmcKApproxCoalescent(hull_offset),
random_seed=10,
recombination_rate=1e-5,
sequence_length=100,
Expand All @@ -3149,7 +3149,7 @@ def test_two_pops(self):
ts = msprime.sim_ancestry(
samples={0: 2, 1: 2},
demography=demography,
model=msprime.SmcKApproxCoalescent(),
model=msprime.SmcKApproxCoalescent(1),
random_seed=74024,
recombination_rate=1e-5,
sequence_length=100,
Expand All @@ -3166,7 +3166,7 @@ def test_gc(self):
):
msprime.sim_ancestry(
samples=10,
model=msprime.SmcKApproxCoalescent(),
model=msprime.SmcKApproxCoalescent(1),
sequence_length=100,
gene_conversion_rate=1.0,
gene_conversion_tract_length=5,
Expand Down
8 changes: 6 additions & 2 deletions tests/test_demography.py
Original file line number Diff line number Diff line change
Expand Up @@ -2521,7 +2521,7 @@ class TestMigrationRecordsSmcPrime(MigrationRecordsMixin):


class TestMigrationRecordsSmcK(MigrationRecordsMixin):
model = msprime.SmcKApproxCoalescent()
model = msprime.SmcKApproxCoalescent(1)


class TestMigrationRecordsDtwf(MigrationRecordsMixin):
Expand Down Expand Up @@ -2576,7 +2576,11 @@ def test_full_arg_migration(self):
self.verify_two_pops_full_arg(ts)

def test_full_arg_migration_smc(self):
for model in ["smc", "smc_prime", msprime.SmcKApproxCoalescent()]:
for model in [
msprime.SmcApproxCoalescent(),
msprime.SmcPrimeApproxCoalescent(),
msprime.SmcKApproxCoalescent(1),
]:
population_configurations = [
msprime.PopulationConfiguration(10),
msprime.PopulationConfiguration(10),
Expand Down
14 changes: 7 additions & 7 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_smc_models(self):
assert repr(model) == repr_s
assert str(model) == repr_s

model = msprime.SmcKApproxCoalescent()
model = msprime.SmcKApproxCoalescent(0.0)
repr_s = "SmcKApproxCoalescent(duration=None, hull_offset=0.0)"
assert repr(model) == repr_s
assert str(model) == repr_s
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_model_instances(self):
msprime.StandardCoalescent(),
msprime.SmcApproxCoalescent(),
msprime.SmcPrimeApproxCoalescent(),
msprime.SmcKApproxCoalescent(),
msprime.SmcKApproxCoalescent(1),
msprime.DiscreteTimeWrightFisher(),
msprime.FixedPedigree(),
msprime.SweepGenicSelection(
Expand Down Expand Up @@ -332,11 +332,11 @@ def test_sweep_genic_selection(self):
msprime.SweepGenicSelection(1)

def test_smck_coalescent(self):
model = msprime.SmcKApproxCoalescent()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should resinstate this test to check that it raises a TypeError (or whatever it is)

# mandatory positional argument
with pytest.raises(TypeError):
        msprime.SmcKApproxCoalescent()

assert model.duration is None
assert model.hull_offset == 0.0

model = msprime.SmcKApproxCoalescent(hull_offset=1.1)
with pytest.raises(TypeError, match="hull_offset"):
model = msprime.SmcKApproxCoalescent()

model = msprime.SmcKApproxCoalescent(1.1)
assert model.duration is None
assert model.hull_offset == 1.1

Expand Down Expand Up @@ -471,7 +471,7 @@ def test_dirac_coalescent_parameters(self):

def test_smck_coalescent_parameters(self):
for hull_offset in [0.01, 10.0, 0.99]:
model = msprime.SmcKApproxCoalescent(hull_offset=hull_offset)
model = msprime.SmcKApproxCoalescent(hull_offset)
assert model.hull_offset == hull_offset
d = model._as_lowlevel()
assert d == {"name": "smc_k", "hull_offset": hull_offset, "duration": None}
Expand Down
12 changes: 6 additions & 6 deletions verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -4535,7 +4535,7 @@ class SmckvsSmcKApproxCoalescent(Test):
"""

models = {
"SmcKApprox": msprime.SmcKApproxCoalescent(),
"SmcKApprox": msprime.SmcKApproxCoalescent(hull_offset=0.0),
"smc": msprime.SmcApproxCoalescent(),
}

Expand Down Expand Up @@ -4955,9 +4955,9 @@ def test_gc_tract_length_smc(self):
Runs the check for the mean length of gene conversion tracts.
"""
models = {
"Hudson": msprime.SmcApproxCoalescent(),
"SMC": msprime.SmcKApproxCoalescent(),
"SMCK": msprime.StandardCoalescent(),
"SMC": msprime.SmcApproxCoalescent(),
"SMCK": msprime.SmcKApproxCoalescent(hull_offset=0.0),
"Hudson": msprime.StandardCoalescent(),
}
num_replicates = 10
n = 10
Expand Down Expand Up @@ -5053,7 +5053,7 @@ def test_smc_k_num_trees_gc(self):

models_to_run = [
(msprime.SmcApproxCoalescent(), "msprime (hudson)"),
(msprime.SmcKApproxCoalescent(), "smc"),
(msprime.SmcApproxCoalescent(), "smc"),
(msprime.SmcPrimeApproxCoalescent(), "smc_prime"),
(msprime.SmcKApproxCoalescent(hull_offset=0.0), "smc_k(0)"),
(msprime.SmcKApproxCoalescent(hull_offset=1.0), "smc_k(1)"),
Expand Down Expand Up @@ -5618,7 +5618,7 @@ def test_above_root_smck(self):
samples=10,
sequence_length=100,
recombination_rate=0.1,
model=msprime.SmcKApproxCoalescent(),
model=msprime.SmcKApproxCoalescent(hull_offset=0.0),
num_replicates=300,
)

Expand Down