コード例 #1
0
ファイル: test_build.py プロジェクト: tkonopka/phenoscoring
 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()
コード例 #2
0
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")
コード例 #3
0
ファイル: test_build.py プロジェクト: tkonopka/phenoscoring
 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)
コード例 #4
0
ファイル: test_build.py プロジェクト: tkonopka/phenoscoring
 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()        
コード例 #5
0
ファイル: test_build.py プロジェクト: tkonopka/phenoscoring
 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)
コード例 #6
0
ファイル: test_build.py プロジェクト: tkonopka/phenoscoring
 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)
コード例 #7
0
ファイル: test_update.py プロジェクト: tkonopka/phenoscoring
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")
コード例 #8
0
ファイル: phenoscoring.py プロジェクト: tkonopka/phenoscoring
                    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()

    if config.action == "recompute":
        # remove all scores and re-generate them from scratch