예제 #1
0
def app_combivep_reference_updater():
    #update LJB reference database
    ljb_controller = LjbController()
    ljb_controller.update()
    #update UCSC reference database
    ucsc_controller = UcscController()
    ucsc_controller.update()
class TestUcscController(SafeRefDBTester):


    def __init__(self, test_name):
        SafeRefDBTester.__init__(self, test_name)

    def setUp(self):
        self.test_class = 'ucsc_controller'

    def init_ucsc_controller_instance(self):
        self.__ucsc_controller = UcscController()

#    def test_clean_raw_database(self):
#        #initialize variables
##        self.individual_debug = True
#        self.init_test('test_clean_raw_database')
#        self.init_ucsc_controller_instance()
#        test_file = os.path.join(self.data_dir, 'test_clean_raw_database.txt')
#        working_file = os.path.join(self.working_dir, 'test_clean_raw_database.txt')
#        out_file  = os.path.join(self.working_dir, 'clean_database.txt')
#        expected_out_file = os.path.join(self.data_dir, 'expected_clean_database.txt')
#        self.copy_file(test_file, working_file)
#
#        self.__ucsc_controller.clean_raw_database(working_file, out_file)
#        self.assertTrue(filecmp.cmp(out_file, expected_out_file), "Raw UCSC database haven't been clean properly");
#
    def test_tabix_database(self):
        #init
        self.init_test('test_tabix_database')
        self.init_ucsc_controller_instance()
        test_file         = os.path.join(self.data_dir, 'test_tabix_database.txt')
        working_file      = os.path.join(self.working_dir, 'test_tabix_database.txt')
        expected_out_file = os.path.join(self.working_dir, 'test_tabix_database.txt.gz')
        self.copy_file(test_file, working_file)

        #test if the 'tabix' files are produced
        out_file = self.__ucsc_controller.tabix_database(working_file)
        self.assertEqual(expected_out_file, out_file, "Tabix doesn't work correctly")
        self.assertTrue(os.path.exists(out_file), "Tabix doesn't work correctly")
        self.assertTrue(os.path.exists(out_file+'.tbi'), "Tabix doesn't work correctly")

        #test if it is readable
        ucsc_reader = UcscReader()
        ucsc_reader.read(out_file)
        readable = False
        for rec in ucsc_reader.fetch_array_snps('chr3', 108572604, 108572605):
            readable = True
            self.assertEqual(rec[combivep_settings.UCSC_0_INDEX_START_POS], '108572604', "Database tabixing doesn't work correctly")
            break
        self.assertTrue(readable, "Tabixed ucsc database is not readable")

    @unittest.skip("temporary disable due to high bandwidth usage")
    def test_not_update(self):
        #init
        self.init_test('test_not_update')
        self.init_ucsc_controller_instance()
        self.__ucsc_controller.config_file = os.path.join(self.data_dir, 'test_not_update_config_file.txt')
        #run test
        self.assertFalse(self.__ucsc_controller.update(), "UCSC controller cannot identify correct update status")

    def tearDown(self):
        self.remove_working_dir()