Skip to content

Commit

Permalink
swapping out function names
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkern authored and petrelharp committed Nov 5, 2021
1 parent 70e27bd commit fa0c76d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 57 deletions.
12 changes: 6 additions & 6 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ To do this, we need to
- choose a distribution of fitness effects (a :class:`.DFE`),
- choose which part(s) of the Contig to apply the DFE to
(e.g., by choosing an :class:`.Annotation`), and
- add these to the :meth:`Contig <.Contig.add_DFE>`,
- add these to the :meth:`Contig <.Contig.add_dfe>`,
with the Annotation saying which portions of the genome the DFE
applies to.

Expand Down Expand Up @@ -932,7 +932,7 @@ specifying which set of *intervals* it will apply to:

.. code-block:: python
contig.add_DFE(intervals=np.array([[0, int(contig.length)]]), DFE=dfe)
contig.add_dfe(intervals=np.array([[0, int(contig.length)]]), DFE=dfe)
model = species.get_demographic_model("OutOfAfrica_3G09")
samples = model.get_samples(100, 100, 100) # YRI, CEU, CHB
Expand Down Expand Up @@ -995,7 +995,7 @@ are removed from the intervals associated with previous DFEs.
samples = model.get_samples(100, 100, 100) # YRI, CEU, CHB
gene_interval = np.array([[10000, 20000]])
contig.add_DFE(intervals=gene_interval, DFE=dfe)
contig.add_dfe(intervals=gene_interval, DFE=dfe)
engine = stdpopsim.get_engine("slim")
ts = engine.simulate(
Expand Down Expand Up @@ -1067,7 +1067,7 @@ To simulate with the HomSap/Gamma_K17 DFE, now applied
to *all* exons on chromosome 21
(the remainder of the chromosome will have only neutral mutations),
we extract the intervals from the :class:`.Annotation` object
and use this in :meth:`.Contig.add_DFE`:
and use this in :meth:`.Contig.add_dfe`:

.. code-block:: python
Expand All @@ -1079,7 +1079,7 @@ and use this in :meth:`.Contig.add_DFE`:
exons = species.get_annotations("ensembl_havana_104_exons")
exon_intervals = exons.get_chromosome_annotations("chr20").astype("int")
contig.add_DFE(intervals=exon_intervals, DFE=dfe)
contig.add_dfe(intervals=exon_intervals, DFE=dfe)
engine = stdpopsim.get_engine("slim")
ts = engine.simulate(
Expand Down Expand Up @@ -1181,7 +1181,7 @@ the index of the new mutation type in the contig's list of mutation types.
description="added mutation",
long_description="mutation type to be added",
)
contig.add_DFE(
contig.add_dfe(
intervals=np.empty((0, 2), dtype="int"),
DFE=dfe,
)
Expand Down
4 changes: 2 additions & 2 deletions stdpopsim/dfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class DFE:
Class representing a "Distribution of Fitness Effects", i.e., a DFE.
The class records the different *mutation types*, and the *proportions*
with which they occur. The overall rate of mutations will be determined
by the Contig to which the DFE is applied (see :meth:`.Contig.add_DFE`).
by the Contig to which the DFE is applied (see :meth:`.Contig.add_dfe`).
Instances of this class are constructed by DFE implementors, following the
:ref:`developer documentation <sec_development_dfe_model>`. To instead
Expand Down Expand Up @@ -239,7 +239,7 @@ def __str__(self):
return s


def neutral_DFE(convert_to_substitution=True):
def neutral_dfe(convert_to_substitution=True):
id = "neutral"
description = "neutral DFE"
long_description = "strictly neutral mutations"
Expand Down
16 changes: 8 additions & 8 deletions stdpopsim/genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class Contig:
Information about targets of selection are contained in the ``dfe_list``
and ``interval_list``. These must be of the same length, and the k-th DFE
applies to the k-th interval; see :meth:`.add_DFE` for more information.
applies to the k-th interval; see :meth:`.add_dfe` for more information.
:ivar mutation_rate: The rate of mutation per base per generation.
:vartype mutation_rate: float
Expand Down Expand Up @@ -199,9 +199,9 @@ class Contig:
interval_list = attr.ib(factory=list)

def __attrs_post_init__(self):
self.add_DFE(
self.add_dfe(
np.array([[0, int(self.length)]]),
stdpopsim.dfe.neutral_DFE(),
stdpopsim.dfe.neutral_dfe(),
)

@staticmethod
Expand Down Expand Up @@ -349,30 +349,30 @@ def dfe_breakpoints(self):
dfe_labels[np.isin(breaks[:-1], intervals[:, 0], assume_unique=True)] = j
return breaks, dfe_labels

def clear_DFEs(self):
def clear_dfes(self):
"""
Removes all DFEs from the contig (as well as the corresponding list of
intervals).
"""
self.dfe_list = []
self.interval_list = []

def add_DFE(self, intervals, DFE):
def add_dfe(self, intervals, DFE):
"""
Adds the provided DFE to the contig, applying to the regions of the
contig specified in ``intervals``. These intervals are also *removed*
from the intervals of any previously-present DFEs - in other words,
more recently-added DFEs take precedence. Each DFE added in this way
carries its own MutationTypes: no mutation types are shared between
DFEs added by different calls to ``add_DFE( )``, even if the same DFE
DFEs added by different calls to ``add_dfe( )``, even if the same DFE
object is added more than once.
For instance, if we do
```
a1 = np.array([[0, 100]])
a2 = np.array([[50, 120]])
contig.add_DFE(a1, dfe1)
contig.add_DFE(a2, dfe2)
contig.add_dfe(a1, dfe1)
contig.add_dfe(a2, dfe2)
```
then ``dfe1`` applies to the region from 0 to 50 and ``dfe2`` applies to the
region from 50 to 120.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_non_neutral_contig(self):
model = species.get_demographic_model("AshkSub_7G19")
samples = model.get_samples(10)
contig = stdpopsim.Contig.basic_contig(length=100)
contig.clear_DFEs()
contig.clear_dfes()
props = [1]
mt = [stdpopsim.MutationType(distribution_type="f", distribution_args=[1])]
dfes = [
Expand All @@ -123,12 +123,12 @@ def test_non_neutral_contig(self):
mutation_types=mt,
)
]
contig.add_DFE(intervals=np.array([[0, 50]]), DFE=dfes[0])
contig.add_dfe(intervals=np.array([[0, 50]]), DFE=dfes[0])
engine = stdpopsim.get_engine("msprime")
with pytest.raises(ValueError):
engine.simulate(model, contig, samples, seed=1)
# okay now change selection coefficient to neutral
contig.clear_DFEs()
contig.clear_dfes()
props = [1]
mt = [stdpopsim.MutationType(distribution_type="f", distribution_args=[0])]
dfes = [
Expand All @@ -140,6 +140,6 @@ def test_non_neutral_contig(self):
mutation_types=mt,
)
]
contig.add_DFE(intervals=np.array([[0, 50]]), DFE=dfes[0])
contig.add_dfe(intervals=np.array([[0, 50]]), DFE=dfes[0])
engine = stdpopsim.get_engine("msprime")
engine.simulate(model, contig, samples, seed=1)
50 changes: 25 additions & 25 deletions tests/test_genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ def verify_dfe_breakpoints(self, contig):
k = np.searchsorted(breaks, left)
assert dfe_labels[k] == j

def test_default_DFE(self):
def test_default_dfe(self):
contig = stdpopsim.Contig.basic_contig(length=100)
assert len(contig.dfe_list) == 1
assert len(contig.interval_list) == 1
assert contig.dfe_list[0].id == "neutral"
assert np.all(contig.interval_list[0] == np.array([[0, contig.length]]))

def test_add_DFE_errors(self):
def test_add_dfe_errors(self):
contig = stdpopsim.Contig.basic_contig(length=100)
# bad intervals
with pytest.raises(ValueError):
contig.add_DFE(np.array([10, 20]), self.example_dfe)
contig.add_dfe(np.array([10, 20]), self.example_dfe)
with pytest.raises(ValueError):
contig.add_DFE("abc", self.example_dfe)
contig.add_dfe("abc", self.example_dfe)

def test_dfe_breakpoints(self):
contig = stdpopsim.Contig.basic_contig(length=100)
contig.clear_DFEs()
contig.clear_dfes()
mt = stdpopsim.MutationType()
for j in range(3):
dfe = stdpopsim.DFE(
Expand All @@ -55,7 +55,7 @@ def test_dfe_breakpoints(self):
long_description="test test",
mutation_types=[mt],
)
contig.add_DFE(
contig.add_dfe(
np.array(
[[(j + 1) * 5, (j + 1) * 10], [(j + 1) * 20, (j + 1) * 20 + 1]],
dtype="int",
Expand All @@ -64,11 +64,11 @@ def test_dfe_breakpoints(self):
)
self.verify_dfe_breakpoints(contig)

def test_add_DFE(self):
def test_add_dfe(self):
for clear in (True, False):
contig = stdpopsim.Contig.basic_contig(length=100)
if clear:
contig.clear_DFEs()
contig.clear_dfes()
props = [0.3, 0.7]
mt = [stdpopsim.MutationType() for _ in props]
dfes = [
Expand All @@ -81,12 +81,12 @@ def test_add_DFE(self):
)
for j in range(3)
]
contig.add_DFE(
contig.add_dfe(
intervals=np.array([[10, 30], [50, 100]]),
DFE=dfes[0],
)
contig.add_DFE(intervals=np.array([[30, 40]]), DFE=dfes[1])
contig.add_DFE(intervals=np.array([[20, 60]]), DFE=dfes[2])
contig.add_dfe(intervals=np.array([[30, 40]]), DFE=dfes[1])
contig.add_dfe(intervals=np.array([[20, 60]]), DFE=dfes[2])
assert len(contig.dfe_list) == 4 - clear
assert len(contig.mutation_types()) == 7 - clear
if clear:
Expand All @@ -109,22 +109,22 @@ def test_add_DFE(self):
self.verify_dfe_breakpoints(contig)

@pytest.mark.skip(reason="TODO allow more flexible inputs")
def test_add_DFE_interval_formats(self):
def test_add_dfe_interval_formats(self):
L = 50818
for intervals in (
[[0, L]],
[[0, int(0.2 * L)]],
([0, int(0.2 * L)], [int(0.6 * L), L]),
):
contig = stdpopsim.Contig.basic_contig(length=L)
contig.add_DFE(intervals=intervals, DFE=self.example_dfe)
contig.add_dfe(intervals=intervals, DFE=self.example_dfe)
np.testing.assert_array_equal(intervals, contig.interval_list[1])

def test_is_neutral(self):
for neutral in (True, False):
for dist in ("f", "e"):
contig = stdpopsim.Contig.basic_contig(length=100)
contig.clear_DFEs()
contig.clear_dfes()
props = [0.3, 0.7]
if neutral:
s = 0
Expand All @@ -146,11 +146,11 @@ def test_is_neutral(self):
)
for j in range(2)
]
contig.add_DFE(
contig.add_dfe(
intervals=np.array([[10, 30], [50, 100]]),
DFE=dfes[0],
)
contig.add_DFE(intervals=np.array([[30, 40]]), DFE=dfes[1])
contig.add_dfe(intervals=np.array([[30, 40]]), DFE=dfes[1])
# exponential with mean zero doesn't count as neutral!
assert contig.is_neutral is (neutral and dist == "f")

Expand Down Expand Up @@ -227,7 +227,7 @@ def test_not_neutral_mutation_type(self):
assert not mt.is_neutral


class TestAll_DFE_Models:
class TestAll_dfe_Models:
"""
Tests for registered simulation dfe models.
"""
Expand All @@ -244,7 +244,7 @@ def test_all_instances(self, DFE):


class TestDFE:
def test_basic_DFE(self):
def test_basic_dfe(self):
desc = "test test"
long_desc = "test test 🐢"
for props in ([0.4, 0.6], [1.0, 0.0], [1.0], [1 / 3, 1 / 3, 1 / 3]):
Expand All @@ -264,7 +264,7 @@ def test_basic_DFE(self):
for a, b in zip(mt, dfe.mutation_types):
assert a == b

def test_DFE_defaults(self):
def test_dfe_defaults(self):
m1 = stdpopsim.MutationType()
desc = "test test"
long_desc = "test test 🐢"
Expand All @@ -280,7 +280,7 @@ def test_DFE_defaults(self):
assert dfe.proportions[0] == 1

@pytest.mark.usefixtures("capsys")
def test_printing_DFE(self, capsys):
def test_printing_dfe(self, capsys):
m1 = stdpopsim.MutationType()
desc = "test test"
long_desc = "test test 🐢"
Expand All @@ -296,7 +296,7 @@ def test_printing_DFE(self, capsys):
assert "║" in captured.out
assert "║ id = abc\n" in captured.out

def test_DFE_errors(self):
def test_dfe_errors(self):
m1 = stdpopsim.MutationType()
m2 = stdpopsim.MutationType()
for bad_props in [["abc"], 1.0, [1.0], [0.2, 0.4, 0.4], [-0.1, -0.1]]:
Expand Down Expand Up @@ -329,7 +329,7 @@ def test_DFE_errors(self):
)

@pytest.mark.skipif(IS_WINDOWS, reason="SLiM not available on windows")
def test_no_msprime_DFE(self):
def test_no_msprime_dfe(self):
# test we cannot simulate a non-neutral DFE with msprime
m1 = stdpopsim.MutationType(
dominance_coeff=0.2,
Expand All @@ -348,7 +348,7 @@ def test_no_msprime_DFE(self):
length=10000,
mutation_rate=1e-6,
)
contig.add_DFE(
contig.add_dfe(
intervals=np.array([[0, contig.length / 2]], dtype="int"),
DFE=dfe,
)
Expand Down Expand Up @@ -380,8 +380,8 @@ def test_simulation_runs(self):
length=10000,
mutation_rate=1e-6, # Ne=1e3 and length=1e4 so theta=40
)
contig.clear_DFEs()
contig.add_DFE(
contig.clear_dfes()
contig.add_dfe(
intervals=np.array([[0, contig.length / 2]], dtype="int"),
DFE=self.dfe,
)
Expand Down

0 comments on commit fa0c76d

Please sign in to comment.