def setUpClass(cls): # Clean up before running each test, in case quited test before tearDown() was run, eg when debugging cls.__cleanup() # Use test YAML configuration file Configuration(cls.__test_configuration_file) # Delete test database if it exists if os.path.exists(Configuration().database_location): os.remove(Configuration().database_location) # Create the database create_database_controller.run() # Populate the database download_cancer_genomics_controller.run() # Pre-prepare the downloaded data by converting it into a form that can be used for machine learning prepare_machine_learning_data_controller.run()
def test_tables_have_been_created(self): # Create the database create_database_controller.run() # Connect to the database, and get all of the table names into a list db = sqlite3.connect(Configuration().database_location) cursor = db.cursor() results = cursor.execute( "SELECT name FROM sqlite_master WHERE type='table';").fetchall() # At least 5 tables should have been created (more detailed tests are in a separate test class) self.assertGreaterEqual(len(results), 5)
def run(): logger = Configuration().get_logger(__name__) try: logger.info("Starting predicting_cancer_variants") create_database_controller.run() download_cancer_genomics_controller.run() prepare_machine_learning_data_controller.run() logger.info("predicting_cancer_variants complete") except Exception as e: message = "predicting_cancer_variants has failed" logger.exception(message, exc_info=e) raise SystemExit(message)
def run(): logger = Configuration().get_logger(__name__) try: logger.info("Preparing machine learning data") StagingTable().prepare() PatientTable().prepare() NetDataTable().prepare() logger.info("Preparation of machine learning data complete") except Exception as e: message = "Failed to prepare machine learning data" logger.exception(message, exc_info=e) raise SystemExit(message)
def test_error_is_raised_if_config_file_does_not_exist(self): non_existent_configuration_file = r"c:\this\file\does\not-exist.yaml" c = Configuration(non_existent_configuration_file) try: # this should raise an error because the config file does not exist c._Configuration__get_configuration_filename() # should not reach here self.fail("An exception was not raised") except FileNotFoundError as e: # expected to reach here self.assertEqual( str(e), "This configuration file does not exist: '{}'".format( non_existent_configuration_file)) pass except: self.fail("The wrong exception was raised")
def run(): logger = Configuration().get_logger(__name__) try: logger.info("Creating tables") StudiesTable().create() CancerTable().create() MolecularTable().create() MutationTable().create() GeneTable().create() logger.info("Table creation complete") except Exception as e: message = "Failed to create tables" logger.exception(message, exc_info=e) raise SystemExit(message)
def run(): logger = Configuration().get_logger(__name__) try: logger.info( "Downloading and storing data from large-scale online Cancer Genomics database cBioPortal.org" ) StudiesDownloader().download_and_save_all_data() GeneDownloader().download_and_save_all_data() CancerDownloader().download_and_save_all_data() MolecularDownloader().download_and_save_data_every_large_study() MutationDownloader().download_and_save_data_every_large_study() logger.info("Downloads complete") except Exception as e: message = "Failed to download and store data" logger.exception(message, exc_info=e) raise SystemExit(message)
def __init__(self, cancer_ids=[], manually_test_model=False, show_confusion=True, cross_validate=True, compare_with_dummy=True, precision_and_recall_verbosity=True, show_precision_and_recall=True): self._configuration = Configuration() self.__logger = self._configuration.get_logger(__name__) self.__retriever = DataRetriever() self.df = self.__retriever.fetch() self.cancer_ids = cancer_ids self.show_confusion = show_confusion self.cross_validate = cross_validate self.manually_test_model = manually_test_model self.compare_with_dummy = compare_with_dummy self.verbose_level_precision_and_recall = precision_and_recall_verbosity self.show_precision_and_recall_graph = show_precision_and_recall
def __init__(self): self._configuration = Configuration() self.__logger = self._configuration.get_logger(__name__)
def test_can_fetch_study_url(self): c = Configuration() self.assertIn("www.cbioportal.org", c.study_url)
def test_can_fetch_cancer_table(self): c = Configuration( r"Test Configuration Files\test_configuration_file_absolute_path.yaml" ) self.assertEqual("test_cancer_study", c.database_table_study)
def test_can_fetch_database_location_with_absolute_path(self): c = Configuration( r"Test Configuration Files\test_configuration_file_absolute_path.yaml" ) self.assertEqual(r"c:\a-test\location\file.yaml", c.database_location)
def test_default_config_file_is_correct(self): c = Configuration() self.assertIn(r'Configuration Files\predicting_cancer_variants.yaml', c._Configuration__get_default_configuration_filename())
def test_application_root_is_ok(self): c = Configuration() self.assertIn('predicting_cancer_variants', c.application_root)
def test_database_file_exists(self): # Database should now exist self.assertTrue(os.path.exists(Configuration().database_location))
def test_error_is_not_raised_if_config_file_does_exist(self): c = Configuration( r"Test Configuration Files\test_configuration_file_absolute_path.yaml" ) self.assertIn(r'test_configuration_file_absolute_path.yaml', c._Configuration__get_configuration_filename())
def __init__(self): self.__database_helper = DatabaseHelper() self.__configuration = Configuration() self.__logger = self.__configuration.get_logger(__name__)