def setUpClass(cls): """For setup, ensure db does not exist.""" cls.config = CompleteTestConfig() cls.dbfile = cls.config.db remove_db(cls.dbfile) pipeline = Phenoscoring(cls.config) pipeline.build()
class RemoveModelsTests(unittest.TestCase): """Test cases for updating a non-empty phenoscoring db with more models""" def setUp(self): """For setup, ensure db does not exist, then build a new one""" config = CompleteTestConfig() self.dbfile = config.db remove_db(self.dbfile) self.pipeline = Phenoscoring(config) self.pipeline.build() impc = Phenoscoring(IMPCTestConfig()) impc.update() # handles for models self.desctab = ModelDescriptionTable(self.dbfile) self.phenstab = ModelPhenotypeTable(self.dbfile) self.scoretab = ModelScoreTable(self.dbfile) def tearDown(self): """At end, ensure test db is deleted.""" remove_db(self.dbfile) def test_clear_models(self): """can remove all models at once.""" # ensure that db is non empty self.assertGreater(self.desctab.count_rows(), 0) self.assertGreater(self.phenstab.count_rows(), 0) self.assertGreater(self.scoretab.count_rows(), 0) # attempt to clear everything impc = Phenoscoring(IMPCTestConfig()) impc.clearmodels() self.assertEqual(self.desctab.count_rows(), 0) self.assertEqual(self.phenstab.count_rows(), 0) self.assertEqual(self.scoretab.count_rows(), 0) def test_remove_models(self): """can remove a partial set of data""" # get an initial set of database row counts num_desc = self.desctab.count_rows() num_phens = self.phenstab.count_rows() num_score = self.scoretab.count_rows() # run a model removal using a small descriptions file config = IMPCTestConfig() config.model_descriptions = "prep-IMPC-descriptions-update.tsv" config.model_phenotypes = None impc = Phenoscoring(config) impc.remove() # the number of rows in tables should decrease self.assertLess(self.desctab.count_rows(), num_desc, "number of models should decrease") self.assertLess(self.phenstab.count_rows(), num_phens, "number of phenotypes should decrease") self.assertLess(self.scoretab.count_rows(), num_score, "number of score entries should decrease")
def test_update_phenotypes(self): """update of phenotypes adds new phenotypes.""" # rerun the update, should give twice the number of phenotypes impc2 = Phenoscoring(IMPCTestConfig()) impc2.update() phentab = ModelPhenotypeTable(self.dbfile) self.assertEqual(phentab.count_rows(), 28, "phenotypes added twice")
def setUpClass(self): """For setup, ensure db does not exist, then build a new one""" config = CompleteTestConfig() self.dbfile = config.db remove_db(self.dbfile) self.pipeline = Phenoscoring(config) self.pipeline.build()
def setUpClass(cls): """For setup, ensure db does not exist.""" cls.config = CompleteTestConfig() cls.dbfile = cls.config.db cls.k = cls.config.reference_neighbors_k remove_db(cls.dbfile) pipeline = Phenoscoring(cls.config) pipeline.build() cls.neighbors = get_reference_neighbors(cls.dbfile, cls.k)
def test_build_mgi(self): """can build a phenoscoring database using only MGI data""" mgi = Phenoscoring(MGITestConfig()) mgi.update() # in contrast to complete config, this db should have fewer rows desctab = ModelDescriptionTable(self.dbfile) self.assertEqual(desctab.count_rows(), 6) modeltab = ModelPhenotypeTable(self.dbfile) self.assertEqual(modeltab.count_rows(), 9)
def setUp(self): """For setup, ensure db does not exist.""" self.config = CompleteTestConfig() self.dbfile = self.config.db remove_db(self.dbfile) pipeline = Phenoscoring(CompleteTestConfig()) pipeline.build() # add something into the db self.desctab = ModelDescriptionTable(self.dbfile) self.desctab.add(id="a", category="test") self.desctab.save()
def test_build_impc(self): """can build a phenoscoring database using only IMPC data""" impc = Phenoscoring(IMPCTestConfig()) impc.update() # in contrast to complete build, this db should have IMPC-only rows desctab = ModelDescriptionTable(self.dbfile) self.assertEqual(desctab.count_rows(), 8) modeltab = ModelPhenotypeTable(self.dbfile) self.assertEqual(modeltab.count_rows(), 14)
def test_update_phenotypes_badids(self): """update of phenotypes aborts when file contains incorrect ids.""" phentab = ModelPhenotypeTable(self.dbfile) self.assertEqual(phentab.count_rows(), 14, "initial phenotypes") config = IMPCTestConfig() config.model_descriptions = None config.model_phenotypes = "prep-IMPC-phenotypes-badids.tsv" impc2 = Phenoscoring(config) impc2.update() self.assertEqual(phentab.count_rows(), 14, "phenotypes unchanged")
def test_reset_build(self): """stops processing if build() called a second time.""" # make sure to start the db has something self.assertGreater(self.desctab.count_rows(), 0) # rebuild config = CompleteTestConfig() config.reset = True pipeline = Phenoscoring(config) pipeline.build() # the tables should now be cleared in the build self.assertEqual(self.desctab.count_rows(), 0)
def test_can_avoid_rebuild(self): """stops processing if build() called a second time.""" # make sure to start the db has something self.assertGreater(self.desctab.count_rows(), 0) # attempt rebuild config = CompleteTestConfig() config.reset = False pipeline = Phenoscoring(config) pipeline.build() # the tables should still be non-empty self.assertGreater(self.desctab.count_rows(), 0)
def test_clear_models(self): """can remove all models at once.""" # ensure that db is non empty self.assertGreater(self.desctab.count_rows(), 0) self.assertGreater(self.phenstab.count_rows(), 0) self.assertGreater(self.scoretab.count_rows(), 0) # attempt to clear everything impc = Phenoscoring(IMPCTestConfig()) impc.clearmodels() self.assertEqual(self.desctab.count_rows(), 0) self.assertEqual(self.phenstab.count_rows(), 0) self.assertEqual(self.scoretab.count_rows(), 0)
def test_export(self): """export a table with reference priors""" config = MGITestConfig() config.table = "reference_priors" # export the table out = StringIO() pipeline = Phenoscoring(config) pipeline.export(out) # check some basic properties outvalue = out.getvalue().strip().split("\n") self.assertGreater(len(outvalue), 4) self.assertEqual(outvalue[0], "id\tvalue")
def setUpClass(cls): """For setup, ensure db does not exist.""" config = CompleteTestConfig() config.null_prior = 0.2 cls.dbfile = config.db cls.pipeline = Phenoscoring(config) cls.pipeline.build() obopath = check_file(config.obo, config.db, "obo") cls.obo = MinimalObo(obopath, True) # a dummy set of default values cls.obodefaults = dict.fromkeys(cls.obo.ids(), 0.2) cls.obozeros = dict.fromkeys(cls.obo.ids(), 0) cls.ref_priors = get_ref_priors(config.db) cls.rs, cls.rs2 = get_refsets(config.db, ref_priors=cls.ref_priors) cls.rs.learn_obo(cls.obo) cls.rs2.learn_obo(cls.obo) # for testing individual configurations cls.y3model = Representation(name="Y3").set("Y:003", 0.8) cls.refA = Representation(name="refA").set("Y:002", 1) cls.refA.defaults(cls.obozeros) cls.refB = Representation(name="refB").set("Y:002", 1) cls.refB.defaults(cls.obozeros)
def setUpClass(cls): """For setup, ensure db does not exist""" cls.config = config = MGITestConfig() cls.dbfile = config.db remove_db(cls.dbfile) cls.pipeline = Phenoscoring(cls.config) cls.pipeline.build() cls.pipeline.update()
def test_update_descriptions(self): """run update multiple times to change content of model descriptions.""" desctab = ModelDescriptionTable(self.dbfile) self.assertEqual(desctab.count_rows(), 8, "initial set of model descriptions") self.assertFalse(self.descriptions_contain("description", "UPDATED")) # run an update operation with only model descriptions config = IMPCTestConfig() config.model_descriptions = "prep-IMPC-descriptions-update.tsv" config.model_phenotypes = None impc2 = Phenoscoring(config) impc2.update() self.assertEqual(desctab.count_rows(), 8, "number of models should be unchanged") self.assertTrue(self.descriptions_contain("description", "UPDATED"), "descriptions in updated file contain string UPDATED")
def test_update_skip_compute(self): """run update but skip score calculation""" # extract current number of models and scores desctab = ModelDescriptionTable(self.dbfile) scorestab = ModelScoreTable(self.dbfile) num_models = desctab.count_rows() num_scores = scorestab.count_rows() # run an update, but without computing scores config = MGITestConfig() config.skip_compute = True mgi = Phenoscoring(config) mgi.update() self.assertGreater(desctab.count_rows(), num_models, "number of models should increase") self.assertEqual(scorestab.count_rows(), num_scores, "number of scores should remain")
def test_remove_models(self): """can remove a partial set of data""" # get an initial set of database row counts num_desc = self.desctab.count_rows() num_phens = self.phenstab.count_rows() num_score = self.scoretab.count_rows() # run a model removal using a small descriptions file config = IMPCTestConfig() config.model_descriptions = "prep-IMPC-descriptions-update.tsv" config.model_phenotypes = None impc = Phenoscoring(config) impc.remove() # the number of rows in tables should decrease self.assertLess(self.desctab.count_rows(), num_desc, "number of models should decrease") self.assertLess(self.phenstab.count_rows(), num_phens, "number of phenotypes should decrease") self.assertLess(self.scoretab.count_rows(), num_score, "number of score entries should decrease")
def setUpClass(cls): """create a new db with some model and references definitions.""" config = MGITestConfig() config.action = "build" cls.dbfile = config.db config.obo = check_file(config.obo, config.db) # build a new database cls.pipeline = Phenoscoring(config) cls.pipeline.build() # add model and definitions (don't compute scores) desc_file = check_file(config.model_descriptions, config.db) phen_file = check_file(config.model_phenotypes, config.db) cls.pipeline._update(desc_file, phen_file)
def setUpClass(cls): """create a new db with model definitions""" cls.config = config = IMPCTestConfig() cls.dbfile = dbfile = cls.config.db remove_db(cls.dbfile) config.scale_oo_scores = False config.obo = check_file(config.obo, dbfile) cls.desc_file = check_file(config.model_descriptions, dbfile) cls.phen_file = check_file(config.model_phenotypes, dbfile) # build a db cls.pipeline = Phenoscoring(config) cls.pipeline.build() # add some model definitions (don't compute) cls.pipeline.update()
def test_update_nowork(self): """can run build repeatedly without over-inserting""" # run update again, but without setting phenotypes impc = Phenoscoring(IMPCTestConfig()) impc.model_phenotypes = None impc.update() desctab = ModelDescriptionTable(self.dbfile) self.assertEqual(desctab.count_rows(), 8, "number of descriptions should be unchanged") # run again without setting anything impc.model_descriptions = None impc.update() self.assertEqual(desctab.count_rows(), 8, "number of descriptions should be unchanged")
def test_build_both(self): """can update database sequentially with MGI and IMPC""" mgi = Phenoscoring(MGITestConfig()) mgi.update() impc = Phenoscoring(IMPCTestConfig()) impc.update() desctab = ModelDescriptionTable(self.dbfile) self.assertEqual(desctab.count_rows(), 14, "8 IMPC, 6 MGI") modeltab = ModelPhenotypeTable(self.dbfile) self.assertEqual(modeltab.count_rows(), 23, "9 MGI, 14 IMPC") scoretab = ModelScoreTable(self.dbfile) self.assertGreater(scoretab.count_rows(), 0, "score table is non-empty")
def setUpClass(cls): """For setup, ensure db does not exist.""" config = MGITestConfig() config.scale_oo_scores = False cls.dbfile = config.db config.obo = check_file(config.obo, config.db) cls.pipeline = Phenoscoring(config) cls.pipeline.build() # first add some rows to the db by hand model = ModelScoreTable(config.db) model.add("model:1", "DISEASE:1", "stamp", 0.95, 0.98) model.add("model:2", "DISEASE:1", "stamp", 0.94, 0.96) model.add("model:3", "DISEASE:1", "stamp", 0.24, 0.96) model.add("model:4", "DISEASE:2", "stamp", 0.92, 0.95) model.add("model:5", "DISEASE:2", "stamp", 0.86, 0.85) model.add("model:6", "DISEASE:3", "stamp", 0.96, 0.95) model.save()
def setUp(self): """For setup, ensure db does not exist, then build a new one""" config = CompleteTestConfig() self.dbfile = config.db remove_db(self.dbfile) self.pipeline = Phenoscoring(config) self.pipeline.build() impc = Phenoscoring(IMPCTestConfig()) impc.update() # handles for models self.desctab = ModelDescriptionTable(self.dbfile) self.phenstab = ModelPhenotypeTable(self.dbfile) self.scoretab = ModelScoreTable(self.dbfile)
class AddModelsTests(unittest.TestCase): """Test cases for adding models to an empty phenoscoring db""" @classmethod def setUpClass(self): """For setup, ensure db does not exist, then build a new one""" config = CompleteTestConfig() self.dbfile = config.db remove_db(self.dbfile) self.pipeline = Phenoscoring(config) self.pipeline.build() @classmethod def tearDownClass(self): """At end, ensure test db is deleted.""" remove_db(self.dbfile) def setUp(self): """At beginning of each test, make sure there are no models.""" self.pipeline.clearmodels() def test_build_impc(self): """can build a phenoscoring database using only IMPC data""" impc = Phenoscoring(IMPCTestConfig()) impc.update() # in contrast to complete build, this db should have IMPC-only rows desctab = ModelDescriptionTable(self.dbfile) self.assertEqual(desctab.count_rows(), 8) modeltab = ModelPhenotypeTable(self.dbfile) self.assertEqual(modeltab.count_rows(), 14) def test_build_mgi(self): """can build a phenoscoring database using only MGI data""" mgi = Phenoscoring(MGITestConfig()) mgi.update() # in contrast to complete config, this db should have fewer rows desctab = ModelDescriptionTable(self.dbfile) self.assertEqual(desctab.count_rows(), 6) modeltab = ModelPhenotypeTable(self.dbfile) self.assertEqual(modeltab.count_rows(), 9) def test_build_both(self): """can update database sequentially with MGI and IMPC""" mgi = Phenoscoring(MGITestConfig()) mgi.update() impc = Phenoscoring(IMPCTestConfig()) impc.update() desctab = ModelDescriptionTable(self.dbfile) self.assertEqual(desctab.count_rows(), 14, "8 IMPC, 6 MGI") modeltab = ModelPhenotypeTable(self.dbfile) self.assertEqual(modeltab.count_rows(), 23, "9 MGI, 14 IMPC") scoretab = ModelScoreTable(self.dbfile) self.assertGreater(scoretab.count_rows(), 0, "score table is non-empty")
help="model for detailed calculation log") parser.add_argument("--reference", action="store", help="reference for detailed calculation log") # inputs for exporting tables parser.add_argument("--table", action="store", help="name of table to export") # ################################################################## # Execute the program if module is used as an executable if __name__ == "__main__": config = parser.parse_args() pipeline = Phenoscoring(config) if config.action == "build": # create a new sqlite database with references pipeline.build() if config.action == "clearmodels": # remove all models and model scores from the database pipeline.clearmodels() if config.action == "update": # add new or update existing model defintions/phenotypes pipeline.update() if config.action == "remove": # remove a subset of models from the database pipeline.remove()
def setUp(self): """At beginning of each test, make sure IMPC models are loaded.""" self.pipeline.clearmodels() impc = Phenoscoring(IMPCTestConfig()) impc.update()