def run(options): panel = mykrobe.Panel(options.panel_dir) species = panel.metadata['species'] if panel.metadata['is_built_in']: custom_probe_and_json = None panel_name = panel.metadata['name'] else: custom_probe_and_json = (panel.probes_fasta, panel.var_to_res_json) panel_name = None # This is for when we run the test in nextflow_mykrobe_predict_test.py. # Depending on sample, we want it to be resistant, susceptible, # or the run to fail if options.testing and options.sample_name.endswith('1_2'): sys.exit(1) mykrobe.run_predict( options.reads_files, options.output_dir, options.sample_name, species, panel=panel_name, custom_probe_and_json=custom_probe_and_json, unittest=options.testing, )
def test_run_predict_and_check_susceptibility(self): '''test run_predict and susceptibility_dict_from_json_file''' reads_file = os.path.join(data_dir, 'run_predict.reads.fq.gz') tmp_out = 'tmp.mykrobe_run_predict' mykrobe.run_predict([reads_file], tmp_out, 'sample_name', 'tb') json_file = os.path.join(tmp_out, 'out.json') suscept_data = mykrobe.susceptibility_dict_from_json_file(json_file) for drug in suscept_data: if drug == 'Isoniazid': self.assertEqual('R', suscept_data[drug]['predict']) else: self.assertEqual('S', suscept_data[drug]['predict']) shutil.rmtree(tmp_out)
def test_run_predict_and_check_susceptibility_fake_run_susceptible(self): '''test run_predict and susceptibility_dict_from_json_file in unittest mode with no resistant calls''' reads_file = os.path.join(data_dir, 'run_predict.reads.fq.gz') tmp_out = 'tmp.mykrobe_run_predict' mykrobe.run_predict([reads_file], tmp_out, 'sample_name', 'tb', unittest=True, unittest_resistant=False) json_file = os.path.join(tmp_out, 'out.json') suscept_data = mykrobe.susceptibility_dict_from_json_file(json_file) for drug in suscept_data: self.assertEqual('S', suscept_data[drug]['predict']) shutil.rmtree(tmp_out)
def test_run_predict_and_check_susceptibility_custom_panel(self): '''test run_predict and susceptibility_dict_from_json_file with custom panel''' # rerun the prvious test, but with custom probe and js on file. These just have the # embB_D328Y muatation. Should be susceptible reads_file = os.path.join(data_dir, 'run_predict.reads.fq.gz') tmp_out = 'tmp.mykrobe_run_predict' custom_probe = os.path.join(data_dir, 'run_predict.probes.fa') custom_json = os.path.join(data_dir, 'run_predict.json') mykrobe.run_predict([reads_file, reads_file], tmp_out, 'sample_name', 'tb', custom_probe_and_json=(custom_probe, custom_json)) json_file = os.path.join(tmp_out, 'out.json') suscept_data = mykrobe.susceptibility_dict_from_json_file(json_file) for drug in suscept_data: if drug == 'Ethambutol': self.assertEqual('S', suscept_data[drug]['predict']) else: self.assertEqual('N', suscept_data[drug]['predict']) shutil.rmtree(tmp_out)