Repository: popsim-consortium/stdpopsim (language: python)

Issue:
make capitalization of DFE/dfe consistent in methods
There's a mix of capitalization of DFE right now (e.g. `species.get_dfe` or `contig.add_DFE`). I vote to make them all lower-case except for the class name.


Discussion / hints:
works for me

Fix patch:
diff --git a/docs/tutorial.rst b/docs/tutorial.rst
index 7f7c386bd..16a1144c7 100644
--- a/docs/tutorial.rst
+++ b/docs/tutorial.rst
@@ -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.
 
@@ -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
@@ -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(
@@ -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
 
@@ -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(
@@ -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,
     )
diff --git a/stdpopsim/dfe.py b/stdpopsim/dfe.py
index e1fea6cd6..8f1ef4aa0 100644
--- a/stdpopsim/dfe.py
+++ b/stdpopsim/dfe.py
@@ -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
@@ -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"
diff --git a/stdpopsim/genomes.py b/stdpopsim/genomes.py
index b821d0925..1611fee5d 100644
--- a/stdpopsim/genomes.py
+++ b/stdpopsim/genomes.py
@@ -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
@@ -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
@@ -349,7 +349,7 @@ 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).
@@ -357,22 +357,22 @@ def clear_DFEs(self):
         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.


Test patch:
diff --git a/tests/test_engines.py b/tests/test_engines.py
index b798a3e1d..4b2ac9d69 100644
--- a/tests/test_engines.py
+++ b/tests/test_engines.py
@@ -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 = [
@@ -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 = [
@@ -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)
diff --git a/tests/test_genomes.py b/tests/test_genomes.py
index 20fde87a3..4b128cc66 100644
--- a/tests/test_genomes.py
+++ b/tests/test_genomes.py
@@ -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(
@@ -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",
@@ -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 = [
@@ -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:
@@ -109,7 +109,7 @@ 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]],
@@ -117,14 +117,14 @@ def test_add_DFE_interval_formats(self):
             ([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
@@ -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")
 
@@ -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.
     """
@@ -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]):
@@ -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 🐢"
@@ -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 🐢"
@@ -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]]:
@@ -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,
@@ -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,
         )
@@ -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,
         )
diff --git a/tests/test_slim_engine.py b/tests/test_slim_engine.py
index ae35711c5..7c69f4efb 100644
--- a/tests/test_slim_engine.py
+++ b/tests/test_slim_engine.py
@@ -186,7 +186,7 @@ def test_recap_and_rescale(self):
         for proportion, seed in zip((0, 1), (1234, 2345)):
             contig = species.get_contig("chr22", length_multiplier=0.001)
             # need selected mutations so that SLiM produces some
-            contig.add_DFE(
+            contig.add_dfe(
                 intervals=np.array([[0, contig.length / 2]], dtype="int"),
                 DFE=stdpopsim.DFE(
                     id="test",
@@ -714,7 +714,7 @@ class TestGenomicElementTypes(PiecewiseConstantSizeMixin):
     def get_example_dfes(self):
         # this is in a function because scoping is weird
         example_dfes = [
-            stdpopsim.dfe.neutral_DFE(),
+            stdpopsim.dfe.neutral_dfe(),
             stdpopsim.DFE(
                 id="simple",
                 description="just one mut type",
@@ -760,7 +760,7 @@ def test_slim_simulates_dfes(self):
         breaks = np.linspace(0, contig.length, n + 1)
         for j, dfe in enumerate(dfes):
             interval = [breaks[j], breaks[j + 1]]
-            contig.add_DFE(intervals=np.array([interval], dtype="int"), DFE=dfe)
+            contig.add_dfe(intervals=np.array([interval], dtype="int"), DFE=dfe)
         engine = stdpopsim.get_engine("slim")
         ts = engine.simulate(
             demographic_model=self.model,
@@ -870,7 +870,7 @@ def verify_genomic_elements(self, contig, ts):
     @pytest.mark.filterwarnings("ignore::msprime.IncompletePopulationMetadataWarning")
     def test_no_dfe(self):
         contig = get_test_contig()
-        contig.clear_DFEs()
+        contig.clear_dfes()
         assert len(contig.dfe_list) == 0
         engine = stdpopsim.get_engine("slim")
         with pytest.raises(ValueError):
@@ -902,7 +902,7 @@ def test_multiple_dfes(self):
         L = contig.length
         example_dfes = self.get_example_dfes()
         for j, dfe in enumerate(example_dfes):
-            contig.add_DFE(
+            contig.add_dfe(
                 np.array([[10 * (j + 1), 100 * (10 - j)], [L / 2, L]], dtype="int"), dfe
             )
         assert len(contig.dfe_list) == 1 + len(example_dfes)
@@ -922,8 +922,8 @@ def test_unused_dfe(self):
         # test that even if a DFE ends up being unused then it'll still be there
         contig = get_test_contig()
         example_dfes = self.get_example_dfes()
-        contig.add_DFE(np.array([[0, contig.length]], dtype="int"), example_dfes[0])
-        contig.add_DFE(np.array([[0, contig.length]], dtype="int"), example_dfes[3])
+        contig.add_dfe(np.array([[0, contig.length]], dtype="int"), example_dfes[0])
+        contig.add_dfe(np.array([[0, contig.length]], dtype="int"), example_dfes[3])
         assert len(contig.dfe_list) == 3
         engine = stdpopsim.get_engine("slim")
         ts = engine.simulate(
@@ -956,10 +956,10 @@ def test_same_dfes(self):
             proportions=[0.2, 0.8],
             mutation_types=self.example_mut_types[7:9],
         )
-        contig.add_DFE(np.array([[0, 0.5 * L]], dtype="int"), dfe0)
-        contig.add_DFE(np.array([[0.2 * L, 0.4 * L]], dtype="int"), dfe0)
-        contig.add_DFE(np.array([[0.45 * L, L]], dtype="int"), dfe1)
-        contig.add_DFE(np.array([[0.7 * L, 0.9 * L]], dtype="int"), dfe0)
+        contig.add_dfe(np.array([[0, 0.5 * L]], dtype="int"), dfe0)
+        contig.add_dfe(np.array([[0.2 * L, 0.4 * L]], dtype="int"), dfe0)
+        contig.add_dfe(np.array([[0.45 * L, L]], dtype="int"), dfe1)
+        contig.add_dfe(np.array([[0.7 * L, 0.9 * L]], dtype="int"), dfe0)
         assert len(contig.dfe_list) == 5
         engine = stdpopsim.get_engine("slim")
         ts = engine.simulate(
@@ -987,7 +987,7 @@ def test_slim_produces_mutations(self):
             ],
             proportions=[0.5, 0.5],
         )
-        contig.add_DFE(np.array([[0, contig.length]], dtype="int"), dfe)
+        contig.add_dfe(np.array([[0, contig.length]], dtype="int"), dfe)
         ts = slim_simulate_no_recap(
             demographic_model=self.model,
             contig=contig,