Exemple #1
0
    def test_two_events(self):
        expected_events = [
            msprime.SimulationModelChange(time=1,
                                          model=msprime.StandardCoalescent()),
            msprime.SimulationModelChange(time=2,
                                          model=msprime.SmcApproxCoalescent()),
        ]
        model, events = msprime.parse_model_arg(
            ["dtwf", (1, "hudson"), (2, "smc")])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, expected_events)

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

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

        model, events = msprime.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 = msprime.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])
Exemple #2
0
    def test_one_event(self):
        expected_event = msprime.SimulationModelChange(
            time=1.33, model=msprime.StandardCoalescent())
        model, events = msprime.parse_model_arg(["dtwf", (1.33, "hudson")])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, [expected_event])

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

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

        model, events = msprime.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 = msprime.parse_model_arg(["dtwf", (None, None)])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(
            events,
            [
                msprime.SimulationModelChange(
                    time=None, model=msprime.StandardCoalescent())
            ],
        )
Exemple #3
0
    def test_single_model(self):
        model, events = msprime.parse_model_arg("hudson")
        self.assertEqual(model, msprime.StandardCoalescent())
        self.assertEqual(events, [])

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

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

        model, events = msprime.parse_model_arg(
            msprime.DiscreteTimeWrightFisher())
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, [])
Exemple #4
0
    def test_single_model_list(self):
        model, events = msprime.parse_model_arg([None])
        self.assertEqual(model, msprime.StandardCoalescent())
        self.assertEqual(events, [])

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

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

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

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

        model, events = msprime.parse_model_arg(
            [msprime.DiscreteTimeWrightFisher()])
        self.assertEqual(model, msprime.DiscreteTimeWrightFisher())
        self.assertEqual(events, [])
Exemple #5
0
    def test_errors(self):
        with self.assertRaises(ValueError):
            msprime.parse_model_arg([])
        with self.assertRaises(ValueError):
            msprime.parse_model_arg("X")
        # Anything that's not a list or tuple is interpreted as a model
        with self.assertRaises(TypeError):
            msprime.parse_model_arg({})

        for bad_model_change_type in [None, "str", {}]:
            with self.assertRaises(TypeError):
                msprime.parse_model_arg([None, bad_model_change_type])

        for bad_model_change_tuple in [[], [1, None, None]]:
            with self.assertRaises(ValueError):
                msprime.parse_model_arg(["hudson", bad_model_change_tuple])

        for bad_time in ["sdf", [], {}]:
            with self.assertRaises(ValueError):
                msprime.parse_model_arg(["hudson", (bad_time, "hudson")])

        for bad_model_type in [[], {}]:
            with self.assertRaises(TypeError):
                msprime.parse_model_arg(["hudson", (1, bad_model_type)])
Exemple #6
0
 def test_none(self):
     model, events = msprime.parse_model_arg(None)
     self.assertEqual(model, msprime.StandardCoalescent())
     self.assertEqual(events, [])