def test_send_notification(self): """Send an email notification""" rm = RunMonitor(self.config) exception = None try: rm.send_notification({'name': "test run"},"dummy value") except Exception, e: exception = e
def test_parse_description(self): """Parse a description""" org_description = \ """- extra comment - project:J.Doe_11_02,J.Doe_12_01,J.Doe_13_01 - setup:2x101bp""".strip() rm = RunMonitor(self.config) org_metadata = rm.parse_description(org_description) exp_description = rm.create_description(org_metadata) exp_metadata = rm.parse_description(exp_description) self.assertEqual(org_description, exp_description, "The recreated card description does not match the original") self.assertDictEqual(org_metadata, exp_metadata, "The recreated card metadata does not match the original")
def test_list_runs(self): """List run folders""" run_folders = ["120106_SN12345_0144_AABC123CXX", "120521_M00123_0001_AFCGHY76-KTY500", "130423_D00134_0011_AD1Y4UACXX"] invalid_run_folders = ["ABC_SN123_0123_BASDC34CXX", "120106_SN12345_0144_CABC123CXX", "120521_K00123_0001_AFCGHY76-KTY500"] for d in run_folders + invalid_run_folders: os.mkdir(os.path.join(self.dump_folder,d)) rm = RunMonitor(self.config) rm.get_run_info = mock.Mock(return_value={}) rm.get_run_parameters = mock.Mock(return_value={}) runs = rm.list_runs() self.assertListEqual(sorted(run_folders), sorted([r['name'] for r in runs]), "Did not return expected list of runs") for d in run_folders + invalid_run_folders: shutil.rmtree(os.path.join(self.dump_folder,d))
def test_get_status_list(self): """Get the status list to write card to""" run_folder = "120106_SN12345_0144_AABC123CXX" run_path = os.path.join(self.dump_folder,run_folder) os.mkdir(run_path) flags = ['initial_processing_started.txt', 'initial_processing_completed.txt', 'first_read_processing_started.txt'] for f in flags: with open(os.path.join(run_path,f),"w") as fh: fh.write("{}Z".format(str(datetime.datetime.utcfromtimestamp(time.time() - 9*60*60)))) run = {'name': run_folder, 'path': run_path} rm = RunMonitor(self.config) rm.get_run_info = mock.Mock(return_value={'Reads': [{},{'IsIndexedRead': 'Y'},{'IsIndexedRead': 'Y'},{}]}) self.assertEqual(rm.get_status_list(run), "Check status", "Expected status list 'Check status'") os.unlink(os.path.join(run_path,flags[-1])) self.assertEqual(rm.get_status_list(run), "First read", "Expected status list 'First read'") open(os.path.join(run_path,'Basecalling_Netcopy_complete_Read1.txt'),'w').close() self.assertEqual(rm.get_status_list(run), "Index read", "Expected status list 'Index read'") open(os.path.join(run_path,'Basecalling_Netcopy_complete_Read2.txt'),'w').close() self.assertEqual(rm.get_status_list(run), "Index read", "Expected status list 'Index read'") open(os.path.join(run_path,'Basecalling_Netcopy_complete_Read3.txt'),'w').close() self.assertEqual(rm.get_status_list(run), "Second read", "Expected status list 'Second read'") open(os.path.join(run_path,'Basecalling_Netcopy_complete_Read4.txt'),'w').close() self.assertEqual(rm.get_status_list(run), "Processing", "Expected status list 'Processing'") shutil.rmtree(run_path)
def test_update_trello_board(self): """Update Trello list with runs""" run_folders = ["120106_SN12345_0144_AABC123CXX", "120521_M00123_0001_AFCGHY76-KTY500"] for d in run_folders: os.mkdir(os.path.join(self.dump_folder,d)) rm = RunMonitor(self.config) rm.get_run_projects = mock.Mock(return_value=['J.Doe_11_01','J.Moe_12_02']) rm.get_status_list = mock.Mock(return_value='First read') rm.get_run_info = mock.Mock(return_value={'Reads': [{'NumCycles': 50},{'IsIndexedRead': 'Y'},{'NumCycles': 50}]}) rm.get_run_parameters = mock.Mock(return_value={}) rm.update_trello_board() lst = rm.trello.get_list(rm.trello_board,'First read') for run in run_folders: card = rm.trello.get_card(lst,run) self.assertIsNotNone(card, "Could not locate created card for run") self.assertEqual(run, card.name, "Created card name and run name are not equal") shutil.rmtree(os.path.join(self.dump_folder,run)) # Move a card to another list run = {'name': run_folders[0]} rm.list_runs = mock.Mock(return_value=[run]) rm.get_status_list.return_value = 'Index read' rm.update_trello_board() lst = rm.trello.get_list(rm.trello_board,'Index read') card = rm.trello.get_card(lst,run['name']) self.assertIsNotNone(card, "Could not locate created card for run") self.assertEqual(run['name'], card.name, "Created card name and run name are not equal")
def update_run_status(self): """Update the status of runs on the run tracking board""" # Create a RunMonitor object to update the run tracking board from hugin.run_monitor import RunMonitor rm = RunMonitor(self.config) rm.run_folders = self.archive_folders rm.samplesheet_folders = [] # Loop over the runs and check whether all samples and projects have been transferred to the # analysis folder for run in rm.list_runs(): print("Checking run {}".format(run['name'])) if self.get_run_status(run): rm.set_run_completed(run) # Loop over the projects in the run and move them to the bcbb list # Note that this can cause the card to be moved back to sequencing by the run_monitor in case # the project is sequenced on multiple flowcells. Has no good solution at this moment. for project in run.get('projects',[]): self.add_project_card(project,BCBB_ANALYSIS_IN_PROGRESS)
def monitor(config,check_descrip,check_finish): rm = RunMonitor(config) if check_descrip: rm.check_missing_description() elif check_finish: rm.check_finish_status() else: rm.update_trello_board() rm.update_trello_project_board() rm.archive_cards()
def monitor(config): rm = RunMonitor(config) rm.update_trello_board() rm.update_trello_project_board() rm.archive_cards()