コード例 #1
0
 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]]:
         with pytest.raises(ValueError):
             _ = stdpopsim.DFE(
                 id="abc",
                 description="test test",
                 long_description="test test test test",
                 proportions=bad_props,
                 mutation_types=[m1, m2],
             )
     for bad_mut_types in ["abc", {}, [1.0, 2.0], [m1], m1, ["a", "b"]]:
         with pytest.raises(ValueError):
             _ = stdpopsim.DFE(
                 id="abc",
                 description="test test",
                 long_description="test test test test",
                 proportions=[0.6, 0.4],
                 mutation_types=bad_mut_types,
             )
     for bad_sums in [[-0.4, 0.5], [0.6, 0.8], [139487135987, 0.0],
                      [0.2, 0.3]]:
         print(bad_sums)
         with pytest.raises(ValueError):
             _ = stdpopsim.DFE(
                 id="abc",
                 description="test test",
                 long_description="test test test test",
                 proportions=bad_sums,
                 mutation_types=[m1, m2],
             )
コード例 #2
0
ファイル: dfes.py プロジェクト: noscode/stdpopsim
def _KimDFE():
    id = "Gamma_K17"
    description = "Deleterious Gamma DFE"
    long_description = """
    Return neutral and negative MutationType()s representing a human DFE.
    Kim et al. (2017), https://doi.org/10.1534/genetics.116.197145
    """
    citations = [
        stdpopsim.Citation(
            author="Kim et al.",
            year=2017,
            doi="https://doi.org/10.1534/genetics.116.197145",
            reasons={stdpopsim.CiteReason.DFE},  # include the dfe_model reason
        )
    ]
    neutral = stdpopsim.MutationType()
    gamma_shape = 0.186  # shape
    gamma_mean = -0.01314833  # expected value
    h = 0.5  # dominance coefficient
    negative = stdpopsim.MutationType(
        dominance_coeff=h,
        distribution_type="g",  # gamma distribution
        distribution_args=[gamma_mean, gamma_shape],
    )

    return stdpopsim.DFE(
        id=id,
        description=description,
        long_description=long_description,
        mutation_types=[neutral, negative],
        proportions=[0.3, 0.7],
        citations=citations,
    )
コード例 #3
0
 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()
             props = [0.3, 0.7]
             if neutral:
                 s = 0
             else:
                 s = 0.1
             mt = [
                 stdpopsim.MutationType(distribution_type=dist,
                                        distribution_args=[s])
                 for _ in props
             ]
             dfes = [
                 stdpopsim.DFE(
                     id=str(j),
                     description="test",
                     long_description="test test",
                     proportions=props,
                     mutation_types=mt,
                 ) for j in range(2)
             ]
             contig.add_dfe(
                 intervals=np.array([[10, 30], [50, 100]]),
                 DFE=dfes[0],
             )
             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")
コード例 #4
0
 def test_no_msprime_dfe(self):
     # test we cannot simulate a non-neutral DFE with msprime
     m1 = stdpopsim.MutationType(
         dominance_coeff=0.2,
         distribution_type="e",
         distribution_args=[0.1],
     )
     desc = "test test"
     long_desc = "test test 🐢"
     dfe = stdpopsim.DFE(
         id="abc",
         description=desc,
         long_description=long_desc,
         mutation_types=[m1],
     )
     contig = stdpopsim.Contig.basic_contig(
         length=10000,
         mutation_rate=1e-6,
     )
     contig.add_dfe(
         intervals=np.array([[0, contig.length / 2]], dtype="int"),
         DFE=dfe,
     )
     model = stdpopsim.PiecewiseConstantSize(1000)
     samples = model.get_samples(2)
     engine = stdpopsim.get_engine("msprime")
     with pytest.raises(ValueError):
         _ = engine.simulate(
             model,
             contig,
             samples,
         )
コード例 #5
0
ファイル: dfes.py プロジェクト: noscode/stdpopsim
def _HuberDFE():
    id = "Gamma_H17"
    description = "Deleterious Gamma DFE"
    long_description = """
    Return neutral and negative MutationType()s representing a H**o sapiens DFE.
    Huber et al. (2017), https://doi.org/10.1073/pnas.1619508114.
    DFE parameters are based on the Full Model described in Table S2, in which
    All Data (none of the listed filters) were used.
    """  # [this was a different filtering scheme than the Huber et al DroMel DFE ]
    citations = [
        stdpopsim.Citation(
            author="Huber et al.",
            year=2017,
            doi="https://doi.org/10.1073/pnas.1619508114",
            reasons="to be defined",  # include the dfe_model reason
        )
    ]
    neutral = stdpopsim.MutationType()
    gamma_shape = 0.19  # shape
    gamma_mean = -0.014  # expected value
    h = 0.5  # dominance coefficient
    negative = stdpopsim.MutationType(
        dominance_coeff=h,
        distribution_type="g",  # gamma distribution
        distribution_args=[gamma_mean, gamma_shape],
    )

    return stdpopsim.DFE(
        id=id,
        description=description,
        long_description=long_description,
        mutation_types=[neutral, negative],
        proportions=[
            0.3,
            0.7,
        ],  # [0.3 and 0.7 were used in Xin's analysis,
        #  but I couldn't find these values in the Huber paper]
        citations=citations,
    )
コード例 #6
0
 def test_dfe_defaults(self):
     m1 = stdpopsim.MutationType()
     desc = "test test"
     long_desc = "test test 🐢"
     dfe = stdpopsim.DFE(
         id="abc",
         description=desc,
         long_description=long_desc,
         mutation_types=[m1],
         proportions=[],
     )
     assert isinstance(dfe.proportions, list)
     assert len(dfe.proportions) == 1
     assert dfe.proportions[0] == 1
コード例 #7
0
 def test_printing_dfe(self, capsys):
     m1 = stdpopsim.MutationType()
     desc = "test test"
     long_desc = "test test 🐢"
     dfe = stdpopsim.DFE(
         id="abc",
         description=desc,
         long_description=long_desc,
         mutation_types=[m1],
     )
     print(dfe)
     captured = capsys.readouterr()
     assert "DFE:\n" in captured.out
     assert "║" in captured.out
     assert "║  id               = abc\n" in captured.out
コード例 #8
0
def _HuberDFE():
    id = "Gamma_H17"
    description = "Deleterious Gamma DFE"
    long_description = """
    Return neutral and negative MutationType()s representing a drosophila DFE.
    Huber et al. (2017), https://doi.org/10.1073/pnas.1619508114.
    DFE parameters are based on the Full model described in Table S2, in which
    singletons are excluded and a recent mutation rate estimate is used
    (mu=3x10e-9, Keightley 2014).
    """
    citations = [
        stdpopsim.Citation(
            author="Huber et al.",
            year=2017,
            doi="https://doi.org/10.1073/pnas.1619508114",
            reasons={stdpopsim.CiteReason.DFE},  # include the dfe_model reason
        )
    ]
    neutral = stdpopsim.MutationType()
    gamma_shape = 0.33  # shape
    gamma_mean = -3.96e-04  # expected value
    h = 0.5  # dominance coefficient
    negative = stdpopsim.MutationType(
        dominance_coeff=h,
        distribution_type="g",  # gamma distribution
        distribution_args=[gamma_mean, gamma_shape],
    )

    return stdpopsim.DFE(
        id=id,
        description=description,
        long_description=long_description,
        mutation_types=[neutral, negative],
        proportions=[0.26, 0.74],  # LNS = 2.85 x LS
        citations=citations,
    )
コード例 #9
0
 def test_bad_mutation_types(self):
     bad_mut_params = {
         "f": ([0.1, 0.2], [], [np.inf]),
         "g": ([], [0.1, 0], [0.1, -0.1], [0.1, 0.4, 0.5], [0.1, np.inf]),
         "e": ([], [0, 1], [0.1, 0.4, 0.5], [np.inf]),
         "n": ([], [0.1, -1], [0.1, 0.4, 0.5], [0.1], [0.1,
                                                       0.0], [0.3, np.inf]),
         "w": ([], [-0.1, 1], [0.1, -1], [0.1, 0.4,
                                          0.5], [0.1], [np.inf, 2.3]),
         "l": ([], [0.1, -1], [0.1, 0.4, 0.5], [0.1], [0.1, np.inf]),
     }
     for t in bad_mut_params:
         for p in bad_mut_params[t]:
             print(t, p)
             with pytest.raises(ValueError):
                 stdpopsim.MutationType(distribution_type=t,
                                        distribution_args=p)
コード例 #10
0
 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]):
         mt = [stdpopsim.MutationType() for _ in props]
         dfe = stdpopsim.DFE(
             id="abc",
             description=desc,
             long_description=long_desc,
             proportions=props,
             mutation_types=mt,
         )
         assert dfe.id == "abc"
         assert dfe.description == desc
         assert dfe.long_description == long_desc
         for a, b in zip(props, dfe.proportions):
             assert a == b
         for a, b in zip(mt, dfe.mutation_types):
             assert a == b
コード例 #11
0
 def test_add_dfe(self):
     for clear in (True, False):
         contig = stdpopsim.Contig.basic_contig(length=100)
         if clear:
             contig.clear_dfes()
         props = [0.3, 0.7]
         mt = [stdpopsim.MutationType() for _ in props]
         dfes = [
             stdpopsim.DFE(
                 id=str(j),
                 description="test",
                 long_description="test test",
                 proportions=props,
                 mutation_types=mt,
             ) for j in range(3)
         ]
         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])
         assert len(contig.dfe_list) == 4 - clear
         assert len(contig.mutation_types()) == 7 - clear
         if clear:
             dfe_ids = []
             true_ints = []
         else:
             true_ints = [np.array([[0, 10]])]
             dfe_ids = ["neutral"]
         dfe_ids += [dfe.id for dfe in dfes]
         true_ints += [
             np.array([[10, 20], [60, 100]]),
             np.empty((0, 2)),
             np.array([[20, 60]]),
         ]
         for d, i in zip(contig.dfe_list, dfe_ids):
             assert d.id == i
         for a1, a2 in zip(contig.interval_list, true_ints):
             assert np.all(a1.shape == a2.shape)
             assert np.all(a1 == a2)
         self.verify_dfe_breakpoints(contig)
コード例 #12
0
 def test_dfe_breakpoints(self):
     contig = stdpopsim.Contig.basic_contig(length=100)
     contig.clear_dfes()
     mt = stdpopsim.MutationType()
     for j in range(3):
         dfe = stdpopsim.DFE(
             id=str(j),
             description="test",
             long_description="test test",
             mutation_types=[mt],
         )
         contig.add_dfe(
             np.array(
                 [[(j + 1) * 5,
                   (j + 1) * 10], [(j + 1) * 20, (j + 1) * 20 + 1]],
                 dtype="int",
             ),
             dfe,
         )
     self.verify_dfe_breakpoints(contig)
コード例 #13
0
 def test_mutation_types(self):
     mut_params = {
         "f": ([-0.1], [0], [0.1], [50]),
         "g": ([-0.1, 0.1], [0.1, 0.1], [50, 50]),
         "e": ([0.1], [10], [5000], [0]),
         "n": ([-0.1, 0.2], [0.1, 0.1], [50, 50]),
         "w": ([0.1, 0.2], [0.1, 0.1], [50, 50]),
         "l": ([-0.1, 0.2], [0.1, 0.1], [50, 50]),
     }
     for t in mut_params:
         for p in mut_params[t]:
             mt = stdpopsim.MutationType(distribution_type=t,
                                         distribution_args=p)
             if t == "l":
                 assert mt.distribution_type == "s"
             else:
                 assert mt.distribution_type == t
                 assert len(mt.distribution_args) == len(p)
                 for a, b in zip(mt.distribution_args, p):
                     assert a == b
コード例 #14
0
 def test_dfe_is_neutral(self):
     for neutral in (True, False):
         for dist in ("f", "e"):
             props = [0.3, 0.7]
             if neutral:
                 svals = [0.0, 0.0]
             else:
                 svals = [0.0, 0.1]
             mt = [
                 stdpopsim.MutationType(distribution_type=dist,
                                        distribution_args=[s])
                 for s in svals
             ]
             dfe = stdpopsim.DFE(
                 id=0,
                 description="test",
                 long_description="test test",
                 proportions=props,
                 mutation_types=mt,
             )
             assert dfe.is_neutral is (neutral and dist == "f")
コード例 #15
0
 def test_dominance_coeff(self):
     mt = stdpopsim.MutationType()
     assert mt.dominance_coeff == 0.5
     for dominance_coeff in (-10, 0, 0.5, 1, 50):
         mt = stdpopsim.MutationType(dominance_coeff=dominance_coeff)
         assert mt.dominance_coeff == dominance_coeff
コード例 #16
0
def adaptive_introgression(seed):
    """
    Adaptive introgression in HomSap/PapuansOutOfAfrica_10J19.

    A neutral mutation is drawn in Denisovans, transmitted to Papuans via a
    migration pulse, and is then positively selected in the Papuan population.
    The time of mutation introduction, the time of selection onset, and the
    selection coefficient, are each random variables.
    """
    species = stdpopsim.get_species("HomSap")
    model = species.get_demographic_model("PapuansOutOfAfrica_10J19")
    contig = species.get_contig("chr1", length_multiplier=0.001)
    samples = model.get_samples(
        100, 0, 0, 100, 2, 2  # YRI, CEU, CHB, Papuan, DenA, NeaA
    )

    # One mutation type, which we'll use for the positively selected mutation.
    # Neutral mutations will be added by the SLiM engine as usual, after the
    # SLiM phase of the simulation has completed.
    positive = stdpopsim.MutationType(convert_to_substitution=False)
    mutation_types = [positive]
    mut_id = len(mutation_types) - 1

    # We need some demographic model parameters to set bounds on the timing
    # of random variables and extended_events (below).
    # These values were copied from the PapuansOutOfAfrica_10J19 model
    # implementation, but can also be found in the catalog documentation.
    T_Den_Nea_split = 15090
    T_DenA_Den1_split = 9750
    T_Den1_Papuan_mig = 29.8e3 / model.generation_time
    # The drawn mutation is transmitted via Den1.
    T_Den_split = T_DenA_Den1_split
    T_mig = T_Den1_Papuan_mig

    # Draw random variables.
    rng = random.Random(seed)
    t_delta = 1000 / model.generation_time
    # Time of mutation introduction. As a lower bound, we use the split time of
    # the Denisovan lineages, plus a small offset (t_delta). The offset avoids
    # an edge case, where T_mut could be rounded to T_Den_split (see note below
    # about avoiding start_time < end_time).
    T_mut = rng.uniform(T_Den_split + t_delta, T_Den_Nea_split)
    # Time of selection onset. We use a non-zero lower bound, so that
    # weaker selection has time to act.
    T_sel = rng.uniform(t_delta, T_mig)
    # Selection coefficient.
    s = rng.uniform(0.001, 0.1)
    logger.info(f"Parameters: T_mut={T_mut:.3f}, T_sel={T_sel:.3f}, s={s:.3g}")

    # Place the drawn mutation in the middle of the contig.
    coordinate = round(contig.recombination_map.sequence_length / 2)

    pop = {p.name: i for i, p in enumerate(model.populations)}

    # Thinking forwards in time, we define a number of extended events that
    # correspond to drawing the mutation, conditioning on the new allele not
    # being lost, and its selection. The extended events will be time-sorted
    # by the SLiM engine, so the ordering here is only to aid clarity.
    # Like msprime.DemographicEvents, all the times used here have units of
    # generations before present.
    extended_events = [
        # Draw mutation in DenA.
        stdpopsim.ext.DrawMutation(
            time=T_mut,
            mutation_type_id=mut_id,
            population_id=pop["DenA"],
            coordinate=coordinate,
            # Save state before the mutation is introduced.
            save=True,
        ),
        # Because the drawn mutation is neutral at the time of introduction,
        # it's likely to be lost due to drift. To avoid this, we condition on
        # the mutation having AF > 0 in DenA. If this condition is false at any
        # time between start_time and end_time, the simulation will be
        # restored to the most recent save point.
        # Conditioning should start one generation after T_mut (not at T_mut!),
        # to avoid checking for the mutation before SLiM can introduce it.
        stdpopsim.ext.ConditionOnAlleleFrequency(
            # Note: if T_mut ~= T_Den_split, then we end up with:
            #       GenerationAfter(T_mut) < T_Den_split,
            #       which will give an error due to "start_time < end_time".
            start_time=stdpopsim.ext.GenerationAfter(T_mut),
            end_time=T_Den_split,
            mutation_type_id=mut_id,
            population_id=pop["DenA"],
            op=">",
            allele_frequency=0,
        ),
        # Denisovans split into DenA and Den1 at time T_Den_split,
        # so now we condition on having AF > 0 in Den1.
        stdpopsim.ext.ConditionOnAlleleFrequency(
            start_time=stdpopsim.ext.GenerationAfter(T_Den_split),
            end_time=T_mig,
            mutation_type_id=mut_id,
            population_id=pop["Den1"],
            op=">",
            allele_frequency=0,
            # Update save point at start_time (if the condition is met).
            save=True,
        ),
        # The Den1 lineage has migrants entering the Papaun lineage at T_mig,
        # so condition on AF > 0 in Papuans.
        stdpopsim.ext.ConditionOnAlleleFrequency(
            start_time=stdpopsim.ext.GenerationAfter(T_mig),
            end_time=0,
            mutation_type_id=mut_id,
            population_id=pop["Papuan"],
            op=">",
            allele_frequency=0,
            # Update save point at start_time (if the condition is met).
            # If the Den1 migrants didn't carry the mutation, we will
            # instead restore to the previous save point.
            save=True,
        ),
        # The mutation is positively selected in Papuans at T_sel.
        # Note that this will have no effect, unless/until a mutation with the
        # specified mutation_type_id is found in the population.
        stdpopsim.ext.ChangeMutationFitness(
            start_time=T_sel,
            end_time=0,
            mutation_type_id=mut_id,
            population_id=pop["Papuan"],
            selection_coeff=s,
            dominance_coeff=0.5,
        ),
        # Condition on AF > 0.05 in Papuans at the end of the simulation.
        stdpopsim.ext.ConditionOnAlleleFrequency(
            start_time=0,
            end_time=0,
            mutation_type_id=mut_id,
            population_id=pop["Papuan"],
            op=">",
            allele_frequency=0.05,
        ),
    ]

    # Simulate.
    engine = stdpopsim.get_engine("slim")
    ts = engine.simulate(
        model,
        contig,
        samples,
        seed=rng.randrange(1, 2 ** 32),
        extended_events=extended_events,
        slim_scaling_factor=10,
        slim_burn_in=0.1,
        # Set slim_script=True to print the script instead of running it.
        # slim_script=True,
    )

    return ts, T_mut, T_sel, s
コード例 #17
0
class TestContig(object):

    example_dfe = stdpopsim.DFE(
        id="abc",
        description="example DFE",
        long_description="test test beep boop beep",
        proportions=[0.3, 0.7],
        mutation_types=[stdpopsim.MutationType() for _ in range(2)],
    )

    def verify_dfe_breakpoints(self, contig):
        breaks, dfe_labels = contig.dfe_breakpoints()
        for j, intervals in enumerate(contig.interval_list):
            for left, right in intervals:
                assert left in breaks
                assert right in breaks
                k = np.searchsorted(breaks, left)
                assert dfe_labels[k] == j

    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):
        contig = stdpopsim.Contig.basic_contig(length=100)
        # bad intervals
        with pytest.raises(ValueError):
            contig.add_dfe(np.array([10, 20]), self.example_dfe)
        with pytest.raises(ValueError):
            contig.add_dfe("abc", self.example_dfe)

    def test_dfe_breakpoints(self):
        contig = stdpopsim.Contig.basic_contig(length=100)
        contig.clear_dfes()
        mt = stdpopsim.MutationType()
        for j in range(3):
            dfe = stdpopsim.DFE(
                id=str(j),
                description="test",
                long_description="test test",
                mutation_types=[mt],
            )
            contig.add_dfe(
                np.array(
                    [[(j + 1) * 5,
                      (j + 1) * 10], [(j + 1) * 20, (j + 1) * 20 + 1]],
                    dtype="int",
                ),
                dfe,
            )
        self.verify_dfe_breakpoints(contig)

    def test_add_dfe(self):
        for clear in (True, False):
            contig = stdpopsim.Contig.basic_contig(length=100)
            if clear:
                contig.clear_dfes()
            props = [0.3, 0.7]
            mt = [stdpopsim.MutationType() for _ in props]
            dfes = [
                stdpopsim.DFE(
                    id=str(j),
                    description="test",
                    long_description="test test",
                    proportions=props,
                    mutation_types=mt,
                ) for j in range(3)
            ]
            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])
            assert len(contig.dfe_list) == 4 - clear
            assert len(contig.mutation_types()) == 7 - clear
            if clear:
                dfe_ids = []
                true_ints = []
            else:
                true_ints = [np.array([[0, 10]])]
                dfe_ids = ["neutral"]
            dfe_ids += [dfe.id for dfe in dfes]
            true_ints += [
                np.array([[10, 20], [60, 100]]),
                np.empty((0, 2)),
                np.array([[20, 60]]),
            ]
            for d, i in zip(contig.dfe_list, dfe_ids):
                assert d.id == i
            for a1, a2 in zip(contig.interval_list, true_ints):
                assert np.all(a1.shape == a2.shape)
                assert np.all(a1 == a2)
            self.verify_dfe_breakpoints(contig)

    @pytest.mark.skip(reason="TODO allow more flexible inputs")
    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)
            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()
                props = [0.3, 0.7]
                if neutral:
                    s = 0
                else:
                    s = 0.1
                mt = [
                    stdpopsim.MutationType(distribution_type=dist,
                                           distribution_args=[s])
                    for _ in props
                ]
                dfes = [
                    stdpopsim.DFE(
                        id=str(j),
                        description="test",
                        long_description="test test",
                        proportions=props,
                        mutation_types=mt,
                    ) for j in range(2)
                ]
                contig.add_dfe(
                    intervals=np.array([[10, 30], [50, 100]]),
                    DFE=dfes[0],
                )
                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")
コード例 #18
0
 def test_netural_mutation_type(self):
     mt = stdpopsim.MutationType()
     assert mt.is_neutral
コード例 #19
0
 def test_not_neutral_mutation_type(self):
     mt = stdpopsim.MutationType(
         distribution_type="f",
         distribution_args=[1],
     )
     assert not mt.is_neutral
コード例 #20
0
 def test_bad_distribution_type(self):
     for distribution_type in (1, {}, None, "~", "!", "F"):
         with pytest.raises(ValueError):
             stdpopsim.MutationType(distribution_type=distribution_type)
コード例 #21
0
 def test_bad_dominance_coeff(self):
     for dominance_coeff in (np.inf, np.nan):
         with pytest.raises(ValueError):
             stdpopsim.MutationType(dominance_coeff=dominance_coeff)
コード例 #22
0
 def test_convert_to_substitution(self):
     mt = stdpopsim.MutationType()
     assert mt.convert_to_substitution is True
     for c in (True, False):
         mt = stdpopsim.MutationType(convert_to_substitution=c)
         assert mt.convert_to_substitution == c