def _run_continuous(self, version): """ Changed one session file: - 012.txt resp & stdev changed from 0.0 to 0.1. Confirmed that this session file causes the BMDS GUI to crash as well. """ output_folder = version.replace(".", "") + "_outputs" input_path = os.path.join(BMDS_TEST_PATH, 'continuous', 'inputs') output_path = os.path.join(BMDS_TEST_PATH, 'continuous', output_folder) if os.path.exists(output_path): shutil.rmtree(output_path) os.makedirs(output_path) wb, ws = self._create_xls_wb() row = 0 # begin model runs bmds = BMDS.versions[version]() files = sorted(os.listdir(input_path)) for f in files: fn = os.path.join(input_path, f) dataset = self._load_continuous(fn) endpoint_d = self._get_continuous_endpoint_d(dataset) for setting in self.default_c_models: # get default bmds settings run_instance = bmds.models['C'][setting['model_name']]() runnable = endpoint_d['numDG'] >= run_instance.minimum_DG if runnable: row += 1 logging.debug('Running {0}:{1}'.format( f, setting['model_name'])) # change the poly degree for the multistage model if setting['model_name'] == 'Polynomial': setting['override'][ 'degree_poly'] = endpoint_d['numDG'] - 1 if endpoint_d['dataset_increasing']: setting['override']['restrict_polynomial'] = 1 else: setting['override']['restrict_polynomial'] = -1 d_file = run_instance.dfile_print(endpoint_d) model = BMD_model_run(model_name=run_instance.model_name) results = model.execute_bmds(bmds, run_instance, d_file, create_image=False) file_identifier = f[:(len(f) - 4)] model_name = setting['model_name'] self._print_individual_run(ws, results, file_identifier, model_name, row, output_path, d_file) # save excel file wb.save(os.path.join(output_path, 'outputs.xls'))
def _run_continuous(self, version): """ Changed one session file: - 012.txt resp & stdev changed from 0.0 to 0.1. Confirmed that this session file causes the BMDS GUI to crash as well. """ output_folder = version.replace(".", "") + "_outputs" input_path = os.path.join(BMDS_TEST_PATH, 'continuous', 'inputs') output_path = os.path.join(BMDS_TEST_PATH, 'continuous', output_folder) if os.path.exists(output_path): shutil.rmtree(output_path) os.makedirs(output_path) wb, ws = self._create_xls_wb() row = 0 # begin model runs bmds = BMDS.versions[version]() files = sorted(os.listdir(input_path)) for f in files: fn = os.path.join(input_path, f) dataset = self._load_continuous(fn) endpoint_d = self._get_continuous_endpoint_d(dataset) for setting in self.default_c_models: # get default bmds settings run_instance = bmds.models['C'][setting['model_name']]() runnable = endpoint_d['numDG'] >= run_instance.minimum_DG if runnable: row += 1 logging.debug('Running {0}:{1}'.format(f, setting['model_name'])) # change the poly degree for the multistage model if setting['model_name'] == 'Polynomial': setting['override']['degree_poly'] = endpoint_d['numDG'] - 1 if endpoint_d['dataset_increasing']: setting['override']['restrict_polynomial'] = 1 else: setting['override']['restrict_polynomial'] = -1 d_file = run_instance.dfile_print(endpoint_d) model = BMD_model_run(model_name=run_instance.model_name) results = model.execute_bmds(bmds, run_instance, d_file, create_image=False) file_identifier = f[:(len(f)-4)] model_name = setting['model_name'] self._print_individual_run(ws, results, file_identifier, model_name, row, output_path, d_file) # save excel file wb.save(os.path.join(output_path, 'outputs.xls'))
def _run_dichotomous(self, version): """ One change made to input files: 038.dat, dropped highest dose. Confirmed that this causes the standard BMDS models to hard-hang and therefore, removed the high dose from this case which fixed modeling issue. """ output_folder = version.replace(".", "") + "_outputs" input_path = os.path.join(BMDS_TEST_PATH, 'dichotomous', 'inputs') output_path = os.path.join(BMDS_TEST_PATH, 'dichotomous', output_folder) if os.path.exists(output_path): shutil.rmtree(output_path) os.makedirs(output_path) wb, ws = self._create_xls_wb() row = 0 # begin model runs bmds = BMDS.versions[version]() files = sorted(os.listdir(input_path)) for f in files: fn = os.path.join(input_path, f) dataset = self._load_dichotomous(fn) endpoint_d = self._get_dichotomous_endpoint_d(dataset) for setting in self.default_d_models: row += 1 # change the poly degree for the multistage model if setting['model_name'] == 'Multistage': setting['override']['degree_poly'] = len(dataset) - 1 # get default bmds settings logging.debug('Running {0}:{1}'.format(f, setting['model_name'])) run_instance = bmds.models['D'][setting['model_name']]() d_file = run_instance.dfile_print(endpoint_d) model = BMD_model_run(model_name=run_instance.model_name) results = model.execute_bmds(bmds, run_instance, d_file, create_image=False) file_identifier = f[:(len(f) - 4)] model_name = run_instance.model_name self._print_individual_run(ws, results, file_identifier, model_name, row, output_path, d_file) # save excel file wb.save(os.path.join(output_path, 'outputs.xls'))
def _run_dichotomous(self, version): """ One change made to input files: 038.dat, dropped highest dose. Confirmed that this causes the standard BMDS models to hard-hang and therefore, removed the high dose from this case which fixed modeling issue. """ output_folder = version.replace(".", "") + "_outputs" input_path = os.path.join(BMDS_TEST_PATH, 'dichotomous', 'inputs') output_path = os.path.join(BMDS_TEST_PATH, 'dichotomous', output_folder) if os.path.exists(output_path): shutil.rmtree(output_path) os.makedirs(output_path) wb, ws = self._create_xls_wb() row = 0 # begin model runs bmds = BMDS.versions[version]() files = sorted(os.listdir(input_path)) for f in files: fn = os.path.join(input_path, f) dataset = self._load_dichotomous(fn) endpoint_d = self._get_dichotomous_endpoint_d(dataset) for setting in self.default_d_models: row += 1 # change the poly degree for the multistage model if setting['model_name'] == 'Multistage': setting['override']['degree_poly'] = len(dataset)-1 # get default bmds settings logging.debug('Running {0}:{1}'.format(f, setting['model_name'])) run_instance = bmds.models['D'][setting['model_name']]() d_file = run_instance.dfile_print(endpoint_d) model = BMD_model_run(model_name=run_instance.model_name) results = model.execute_bmds(bmds, run_instance, d_file, create_image=False) file_identifier = f[:(len(f)-4)] model_name = run_instance.model_name self._print_individual_run( ws, results, file_identifier, model_name, row, output_path, d_file) # save excel file wb.save(os.path.join(output_path, 'outputs.xls'))
def test_run_Continuous_231(self): """ Test suite for standard Continuous 2.3.1. models. This test contains basic models, with very minimal modifications. It also assumes the standard 1 SD BMR. Note that in the polynomial case, the degree_poly value is overridden from the default. """ session = BMD_session(BMDS_version='2.31', bmrs=self.bmr_c) run_suite = ( { 'type': 'Linear', 'fn': '2-continuous-tc-LinearCV-1SD.out' }, { 'type': 'Polynomial', 'fn': '2-continuous-tc-Poly4CV-1SD.out', 'override': { 'degree_poly': 4, 'restrict_polynomial': 1 }, 'override_text': ['Degree of Polynomial = 4'] }, { 'type': 'Power', 'fn': '2-continuous-tc-PowerCV-1SD.out' }, { 'type': 'Hill', 'fn': '2-continuous-tc-HillCV-1SD.out' }, { 'type': 'Exponential-M2', 'fn': '2-continuous-tc-M2M2ExpCV-1SD.out' }, { 'type': 'Exponential-M3', 'fn': '2-continuous-tc-M3M3ExpCV-1SD.out' }, { 'type': 'Exponential-M4', 'fn': '2-continuous-tc-M4M4ExpCV-1SD.out' }, { 'type': 'Exponential-M5', 'fn': '2-continuous-tc-M5M5ExpCV-1SD.out' }, ) for run in run_suite: logging.debug('Testing ' + run['fn']) m_run = self.v.models['C'][run['type']]() if 'override' in run: m_run.update_model(run['override'], run['override_text'], self.bmr_c) m = BMD_model_run(model_name=run['type'], BMD_session=session, option_override={}, option_override_text=[""]) m.run_model(self.v, m_run, self.dataset_continuous) output_text = m.output_text.splitlines()[10:] fn = os.path.join(BMDS_TEST_PATH, run['fn']) gold_standard = self.import_bmds_output_file(fn) # with open(os.path.join(BMDS_TEST_PATH, 'test_output.txt'), 'w') as f: # f.write('\n'.join(output_text)) # with open(os.path.join(BMDS_TEST_PATH, 'gold_standard.txt'), 'w') as f: # f.write('\n'.join(gold_standard)) self.assertTrue(output_text == gold_standard)
def test_run_Dichotomous_231(self): """ Test suite for standard Dichotomous 2.3.1. models. This test contains basic models, with very minimal modifications. It also assumes the standard 10% BMR check. Note that in a few multistage cases, the degree_poly value is overridden from the default. """ session = BMD_session(BMDS_version='2.31', bmrs=self.bmr_d) run_suite = ( { 'type': 'Logistic', 'fn': '1-dichotomous-tc-Logistic-10%.out' }, { 'type': 'LogLogistic', 'fn': '1-dichotomous-tc-LogLogistic-10%.out' }, { 'type': 'Weibull', 'fn': '1-dichotomous-tc-Weibull-10%.out' }, { 'type': 'Probit', 'fn': '1-dichotomous-tc-Probit-10%.out' }, { 'type': 'LogProbit', 'fn': '1-dichotomous-tc-LogProbit-10%.out' }, { 'type': 'Gamma', 'fn': '1-dichotomous-tc-Gamma-10%.out' }, { 'type': 'Multistage', 'fn': '1-dichotomous-tc-Multi1-10%.out', 'override': { 'degree_poly': 1 }, 'override_text': ['Degree of Polynomial = 1'] }, { 'type': 'Multistage', 'fn': '1-dichotomous-tc-Multi2-10%.out', 'override': { 'degree_poly': 2 }, # todo: these lines shouldn't be required, think parent class needs to update child class 'override_text': ['Degree of Polynomial = 2'] }, { 'type': 'Multistage', 'fn': '1-dichotomous-tc-Multi3-10%.out', 'override': { 'degree_poly': 3 }, 'override_text': ['Degree of Polynomial = 3'] }, ) for run in run_suite: logging.debug('Testing ' + run['fn']) m_run = self.v.models['D'][run['type']]() if 'override' in run: m_run.update_model(run['override'], run['override_text'], self.bmr_d) m = BMD_model_run(model_name=run['type'], BMD_session=session, option_override={}, option_override_text=[""]) m.run_model(self.v, m_run, self.dataset_dichotomous) output_text = m.output_text.splitlines()[10:] fn = os.path.join(BMDS_TEST_PATH, run['fn']) gold_standard = self.import_bmds_output_file(fn) # f = file(os.path.join(BMDS_TEST_PATH, 'test_output.txt'), 'w') # f.write('\n'.join(output_text)) # f.close() # f = file(os.path.join(BMDS_TEST_PATH, 'gold_standard.txt'), 'w') # f.write('\n'.join(gold_standard)) # f.close() self.assertTrue(output_text == gold_standard)
def test_run_Continuous_231(self): """ Test suite for standard Continuous 2.3.1. models. This test contains basic models, with very minimal modifications. It also assumes the standard 1 SD BMR. Note that in the polynomial case, the degree_poly value is overridden from the default. """ session = BMD_session(BMDS_version='2.31', bmrs=self.bmr_c) run_suite = ( { 'type': 'Linear', 'fn': '2-continuous-tc-LinearCV-1SD.out' }, { 'type': 'Polynomial', 'fn': '2-continuous-tc-Poly4CV-1SD.out', 'override': { 'degree_poly': 4, 'restrict_polynomial': 1 }, 'override_text': ['Degree of Polynomial = 4'] }, { 'type': 'Power', 'fn': '2-continuous-tc-PowerCV-1SD.out' }, { 'type': 'Hill', 'fn': '2-continuous-tc-HillCV-1SD.out' }, { 'type': 'Exponential-M2', 'fn': '2-continuous-tc-M2M2ExpCV-1SD.out' }, { 'type': 'Exponential-M3', 'fn': '2-continuous-tc-M3M3ExpCV-1SD.out' }, { 'type': 'Exponential-M4', 'fn': '2-continuous-tc-M4M4ExpCV-1SD.out' }, { 'type': 'Exponential-M5', 'fn': '2-continuous-tc-M5M5ExpCV-1SD.out' }, ) for run in run_suite: logging.debug('Testing ' + run['fn']) m_run = self.v.models['C'][run['type']]() if 'override' in run: m_run.update_model(run['override'], run['override_text'], self.bmr_c) m = BMD_model_run( model_name=run['type'], BMD_session=session, option_override={}, option_override_text=[""]) m.run_model(self.v, m_run, self.dataset_continuous) output_text = m.output_text.splitlines()[10:] fn = os.path.join(BMDS_TEST_PATH, run['fn']) gold_standard = self.import_bmds_output_file(fn) # with open(os.path.join(BMDS_TEST_PATH, 'test_output.txt'), 'w') as f: # f.write('\n'.join(output_text)) # with open(os.path.join(BMDS_TEST_PATH, 'gold_standard.txt'), 'w') as f: # f.write('\n'.join(gold_standard)) self.assertTrue(output_text == gold_standard)
def test_run_Dichotomous_231(self): """ Test suite for standard Dichotomous 2.3.1. models. This test contains basic models, with very minimal modifications. It also assumes the standard 10% BMR check. Note that in a few multistage cases, the degree_poly value is overridden from the default. """ session = BMD_session(BMDS_version='2.31', bmrs=self.bmr_d) run_suite = ( { 'type': 'Logistic', 'fn': '1-dichotomous-tc-Logistic-10%.out' }, { 'type': 'LogLogistic', 'fn': '1-dichotomous-tc-LogLogistic-10%.out' }, { 'type': 'Weibull', 'fn': '1-dichotomous-tc-Weibull-10%.out' }, { 'type': 'Probit', 'fn': '1-dichotomous-tc-Probit-10%.out' }, { 'type': 'LogProbit', 'fn': '1-dichotomous-tc-LogProbit-10%.out' }, { 'type': 'Gamma', 'fn': '1-dichotomous-tc-Gamma-10%.out' }, { 'type': 'Multistage', 'fn': '1-dichotomous-tc-Multi1-10%.out', 'override': {'degree_poly': 1}, 'override_text': ['Degree of Polynomial = 1'] }, { 'type': 'Multistage', 'fn': '1-dichotomous-tc-Multi2-10%.out', 'override': {'degree_poly': 2}, # todo: these lines shouldn't be required, think parent class needs to update child class 'override_text': ['Degree of Polynomial = 2'] }, { 'type': 'Multistage', 'fn': '1-dichotomous-tc-Multi3-10%.out', 'override': {'degree_poly': 3}, 'override_text': ['Degree of Polynomial = 3'] }, ) for run in run_suite: logging.debug('Testing ' + run['fn']) m_run = self.v.models['D'][run['type']]() if 'override' in run: m_run.update_model(run['override'], run['override_text'], self.bmr_d) m = BMD_model_run( model_name=run['type'], BMD_session=session, option_override={}, option_override_text=[""]) m.run_model(self.v, m_run, self.dataset_dichotomous) output_text = m.output_text.splitlines()[10:] fn = os.path.join(BMDS_TEST_PATH, run['fn']) gold_standard = self.import_bmds_output_file(fn) # f = file(os.path.join(BMDS_TEST_PATH, 'test_output.txt'), 'w') # f.write('\n'.join(output_text)) # f.close() # f = file(os.path.join(BMDS_TEST_PATH, 'gold_standard.txt'), 'w') # f.write('\n'.join(gold_standard)) # f.close() self.assertTrue(output_text == gold_standard)