Пример #1
0
 def test_model_collection_result_repr(self):
     """constructed result can do the different repr"""
     result = model_collection_result(None)
     coll = model_collection_result(None)
     coll.update(self._model_results)
     got = result.__repr__()
     self.assertIsInstance(got, str)
     got = result._repr_html_()
     self.assertIsInstance(got, str)
Пример #2
0
 def test_get_best_model(self):
     """should correctly identify the best model"""
     coll = model_collection_result(None)
     coll.update(self._model_results)
     got = coll.get_best_model()
     # we ensure a model_result instance is returned from the possible set
     self.assertIn(got, self._model_results.values())
Пример #3
0
 def test_to_hypothesis(self):
     """creates a hypothesis_result from two model results"""
     mr = model_collection_result(source="blah")
     mr.update(self._model_results)
     hyp = mr.get_hypothesis_result("F81", "HKY85")
     self.assertIsInstance(hyp, hypothesis_result)
     self.assertEqual(hyp.null.name, "F81")
Пример #4
0
 def test_select_model(self):
     """correctly select models"""
     # we ensure a series of model_result instances is returned
     coll = model_collection_result(None)
     coll.update(self._model_results)
     got = coll.select_models()
     self.assertTrue(len(got) > 0)
     possible = list(self._model_results.values())
     for m in got:
         self.assertIn(m, possible)
Пример #5
0
 def test_json_roundtrip(self):
     """roundtrip from json correct"""
     coll = model_collection_result(name="blah", source="blah2")
     coll.update(self._model_results)
     self.assertEqual(coll.name, "blah")
     self.assertEqual(coll.source, "blah2")
     orig = coll.__repr__()
     got = deserialise_object(coll.to_json())
     self.assertEqual(got.__repr__(), orig)
     self.assertIsInstance(got, model_collection_result)
     self.assertEqual(got.name, coll.name)
     self.assertEqual(got.source, coll.source)
     # select_models() should not fail
     got = deserialise_object(coll.to_json())
     m = got.select_models()
     self.assertIsInstance(m[0], model_result)
Пример #6
0
    def test_model_collection_result(self):
        """round trip of model collection works"""
        from cogent3.app import evo as evo_app
        from cogent3.evolve.parameter_controller import (
            AlignmentLikelihoodFunction,
        )

        _data = {
            "Human": "ATGCGGCTCGCGGAGGCCGCGCTCGCGGAG",
            "Mouse": "ATGCCCGGCGCCAAGGCAGCGCTGGCGGAG",
            "Opossum": "ATGCCAGTGAAAGTGGCGGCGGTGGCTGAG",
        }
        aln = make_aligned_seqs(data=_data, moltype="dna")
        opt_args = dict(max_evaluations=10, limit_action="ignore")
        m1 = evo_app.model("F81", split_codons=True, opt_args=opt_args)
        m2 = evo_app.model("GTR", split_codons=True, opt_args=opt_args)
        models = (m1, m2)
        mc_result = model_collection_result(name="collection", source="blah")
        for model in models:
            mc_result[model.name] = model(aln)

        for model in models:
            for i in range(1, 4):
                self.assertIsInstance(
                    mc_result[model.name][i], AlignmentLikelihoodFunction
                )

        data = mc_result.to_json()
        got_obj = deserialise_object(data)
        for model in models:
            for i in range(1, 4):
                self.assertIsInstance(got_obj[model.name][i], dict)

        # but after invoking deserialised_values
        got_obj.deserialised_values()
        for model in models:
            for i in range(1, 4):
                self.assertIsInstance(
                    got_obj[model.name][i], AlignmentLikelihoodFunction
                )
Пример #7
0
 def test_model_collection_result_invalid_setitem(self):
     """model_collection_result raise TypeError if trying to set incorrect item type"""
     mcr = model_collection_result()
     with self.assertRaises(TypeError):
         mcr["null"] = 23
Пример #8
0
 def test_repr_str(self):
     """it works even when no values"""
     mr = model_collection_result(source="blah")
     self.assertIsInstance(repr(mr), str)