Пример #1
0
    def test_one_event(self):
        expected_event = msprime.AncestryModelChange(
            time=1.33, model=msprime.StandardCoalescent())
        model, events = ancestry._parse_model_arg(["dtwf", (1.33, "hudson")])
        assert model == msprime.DiscreteTimeWrightFisher()
        assert events == [expected_event]

        model, events = ancestry._parse_model_arg(["dtwf", (1.33, None)])
        assert model == msprime.DiscreteTimeWrightFisher()
        assert events == [expected_event]

        model, events = ancestry._parse_model_arg(
            ["dtwf", (1.33, msprime.StandardCoalescent())])
        assert model == msprime.DiscreteTimeWrightFisher()
        assert events == [expected_event]

        model, events = ancestry._parse_model_arg(["dtwf", expected_event])
        assert model == msprime.DiscreteTimeWrightFisher()
        assert events == [expected_event]
        # We should take a copy of the event.
        assert events[0] is not expected_event

        model, events = ancestry._parse_model_arg(["dtwf", (None, None)])
        assert model == msprime.DiscreteTimeWrightFisher()
        assert events == [
            msprime.AncestryModelChange(time=None,
                                        model=msprime.StandardCoalescent())
        ]
Пример #2
0
    def test_two_events(self):
        expected_events = [
            msprime.AncestryModelChange(time=1,
                                        model=msprime.StandardCoalescent()),
            msprime.AncestryModelChange(time=2,
                                        model=msprime.SmcApproxCoalescent()),
        ]
        model, events = ancestry._parse_model_arg(
            ["dtwf", (1, "hudson"), (2, "smc")])
        assert model == msprime.DiscreteTimeWrightFisher()
        assert events == expected_events

        model, events = ancestry._parse_model_arg(
            ["dtwf", (1, None), (2, msprime.SmcApproxCoalescent())])
        assert model == msprime.DiscreteTimeWrightFisher()
        assert events == expected_events

        model, events = ancestry._parse_model_arg(
            ["dtwf", expected_events[0], (2, msprime.SmcApproxCoalescent())])
        assert model == msprime.DiscreteTimeWrightFisher()
        assert events == expected_events

        model, events = ancestry._parse_model_arg(
            ["dtwf", expected_events[0], (2, msprime.SmcApproxCoalescent())])
        assert model == msprime.DiscreteTimeWrightFisher()
        assert events == expected_events
        assert events[0] is not expected_events[0]

        model, events = ancestry._parse_model_arg(["dtwf"] + expected_events)
        assert model == msprime.DiscreteTimeWrightFisher()
        assert events == expected_events
        assert events[0] is not expected_events[0]
        assert events[1] is not expected_events[1]
Пример #3
0
    def test_one_event(self):
        expected_event = msprime.SimulationModelChange(
            time=1.33, model=msprime.StandardCoalescent())
        model, events = ancestry._parse_model_arg(["dtwf", (1.33, "hudson")])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, [expected_event])

        model, events = ancestry._parse_model_arg(["dtwf", (1.33, None)])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, [expected_event])

        model, events = ancestry._parse_model_arg(
            ["dtwf", (1.33, msprime.StandardCoalescent())])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, [expected_event])

        model, events = ancestry._parse_model_arg(["dtwf", expected_event])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, [expected_event])
        # We should take a copy of the event.
        self.assertIsNot(events[0], expected_event)

        model, events = ancestry._parse_model_arg(["dtwf", (None, None)])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(
            events,
            [
                msprime.SimulationModelChange(
                    time=None, model=msprime.StandardCoalescent())
            ],
        )
Пример #4
0
    def test_two_events(self):
        expected_events = [
            msprime.SimulationModelChange(time=1,
                                          model=msprime.StandardCoalescent()),
            msprime.SimulationModelChange(time=2,
                                          model=msprime.SmcApproxCoalescent()),
        ]
        model, events = ancestry._parse_model_arg(
            ["dtwf", (1, "hudson"), (2, "smc")])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, expected_events)

        model, events = ancestry._parse_model_arg(
            ["dtwf", (1, None), (2, msprime.SmcApproxCoalescent())])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, expected_events)

        model, events = ancestry._parse_model_arg(
            ["dtwf", expected_events[0], (2, msprime.SmcApproxCoalescent())])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, expected_events)

        model, events = ancestry._parse_model_arg(
            ["dtwf", expected_events[0], (2, msprime.SmcApproxCoalescent())])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, expected_events)
        self.assertIsNot(events[0], expected_events[0])

        model, events = ancestry._parse_model_arg(["dtwf"] + expected_events)
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, expected_events)
        self.assertIsNot(events[0], expected_events[0])
        self.assertIsNot(events[1], expected_events[1])
Пример #5
0
    def test_single_model(self):
        models = ancestry._parse_model_arg("hudson")
        assert models == [msprime.StandardCoalescent()]

        models = ancestry._parse_model_arg(msprime.StandardCoalescent())
        assert models == [msprime.StandardCoalescent()]

        models = ancestry._parse_model_arg("dtwf")
        assert models == [msprime.DiscreteTimeWrightFisher()]

        models = ancestry._parse_model_arg(msprime.DiscreteTimeWrightFisher())
        assert models == [msprime.DiscreteTimeWrightFisher()]
Пример #6
0
    def test_one_change(self):
        models = ancestry._parse_model_arg(
            [msprime.DiscreteTimeWrightFisher(duration=1.33), "hudson"])
        assert models == [
            msprime.DiscreteTimeWrightFisher(duration=1.33),
            msprime.StandardCoalescent(),
        ]

        models = ancestry._parse_model_arg(
            [msprime.DiscreteTimeWrightFisher(duration=1.33), None])
        assert models == [
            msprime.DiscreteTimeWrightFisher(duration=1.33),
            msprime.StandardCoalescent(),
        ]
Пример #7
0
    def test_single_model(self):
        model, events = ancestry._parse_model_arg("hudson")
        self.assertEqual(model, msprime.StandardCoalescent())
        self.assertEqual(events, [])

        model, events = ancestry._parse_model_arg(msprime.StandardCoalescent())
        self.assertEqual(model, msprime.StandardCoalescent())
        self.assertEqual(events, [])

        model, events = ancestry._parse_model_arg("dtwf")
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, [])

        model, events = ancestry._parse_model_arg(
            msprime.DiscreteTimeWrightFisher())
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, [])
Пример #8
0
 def test_two_changes(self):
     models = ancestry._parse_model_arg([
         msprime.DiscreteTimeWrightFisher(duration=1),
         msprime.StandardCoalescent(duration=2),
         msprime.SmcApproxCoalescent(duration=3),
     ])
     assert models == [
         msprime.DiscreteTimeWrightFisher(duration=1),
         msprime.StandardCoalescent(duration=2),
         msprime.SmcApproxCoalescent(duration=3),
     ]
Пример #9
0
    def test_single_model_list(self):
        model, events = ancestry._parse_model_arg([None])
        assert model == msprime.StandardCoalescent()
        assert events == []

        # Tuples are also accepted as input.
        model, events = ancestry._parse_model_arg((None, ))
        assert model == msprime.StandardCoalescent()
        assert events == []

        model, events = ancestry._parse_model_arg(["hudson"])
        assert model == msprime.StandardCoalescent()
        assert events == []

        model, events = ancestry._parse_model_arg(
            [msprime.StandardCoalescent()])
        assert model == msprime.StandardCoalescent()
        assert events == []

        model, events = ancestry._parse_model_arg(["dtwf"])
        assert model == msprime.DiscreteTimeWrightFisher()
        assert events == []

        model, events = ancestry._parse_model_arg(
            [msprime.DiscreteTimeWrightFisher()])
        assert model == msprime.DiscreteTimeWrightFisher()
        assert events == []
Пример #10
0
    def test_single_model_list(self):
        model, events = ancestry._parse_model_arg([None])
        self.assertEqual(model, msprime.StandardCoalescent())
        self.assertEqual(events, [])

        # Tuples are also accepted as input.
        model, events = ancestry._parse_model_arg((None, ))
        self.assertEqual(model, msprime.StandardCoalescent())
        self.assertEqual(events, [])

        model, events = ancestry._parse_model_arg(["hudson"])
        self.assertEqual(model, msprime.StandardCoalescent())
        self.assertEqual(events, [])

        model, events = ancestry._parse_model_arg(
            [msprime.StandardCoalescent()])
        self.assertEqual(model, msprime.StandardCoalescent())
        self.assertEqual(events, [])

        model, events = ancestry._parse_model_arg(["dtwf"])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, [])

        model, events = ancestry._parse_model_arg(
            [msprime.DiscreteTimeWrightFisher()])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, [])
Пример #11
0
    def test_errors(self):
        with pytest.raises(ValueError, match="at least one AncestryModel"):
            ancestry._parse_model_arg([])
        for bad_model in ["X", ["X"]]:
            with pytest.raises(ValueError, match="Model 'X' unknown"):
                ancestry._parse_model_arg(bad_model)

        # Anything that's not a list or tuple is interpreted as a model
        with pytest.raises(TypeError,
                           match="Ancestry model must be a string or"):
            ancestry._parse_model_arg({})
Пример #12
0
    def test_errors(self):
        with pytest.raises(ValueError):
            ancestry._parse_model_arg([])
        with pytest.raises(ValueError):
            ancestry._parse_model_arg("X")
        # Anything that's not a list or tuple is interpreted as a model
        with pytest.raises(TypeError):
            ancestry._parse_model_arg({})

        for bad_model_change_type in [None, "str", {}]:
            with pytest.raises(TypeError):
                ancestry._parse_model_arg([None, bad_model_change_type])

        for bad_model_change_tuple in [[], [1, None, None]]:
            with pytest.raises(ValueError):
                ancestry._parse_model_arg(["hudson", bad_model_change_tuple])

        for bad_time in ["sdf", [], {}]:
            with pytest.raises(ValueError):
                ancestry._parse_model_arg(["hudson", (bad_time, "hudson")])

        for bad_model_type in [[], {}]:
            with pytest.raises(TypeError):
                ancestry._parse_model_arg(["hudson", (1, bad_model_type)])
Пример #13
0
 def test_none(self):
     model, events = ancestry._parse_model_arg(None)
     assert model == msprime.StandardCoalescent()
     assert events == []
Пример #14
0
 def test_none(self):
     model, events = ancestry._parse_model_arg(None)
     self.assertEqual(model, msprime.StandardCoalescent())
     self.assertEqual(events, [])