def test_selectBestData_many_options(self): self.maxDiff = None correct_data_dict = openJson('Unit Tests/selectData_many_organisms' '_correct.json') data = openJson('Unit Tests/selectData_many_organisms.json') data_test_forward = SelectBestData.toEnzymeStructure_f(data) data_test_backward = SelectBestData.toEnzymeStructure_b(data) selectBestData(data_test_forward, DataType.turnover) selectBestData(data_test_backward, DataType.turnover) data_test_forward_dict = {} data_test_backward_dict = {} for enzyme in data_test_forward: enzyme_dict = data_test_forward[ enzyme].getSimpleDict() if enzyme_dict != {}: data_test_forward_dict[enzyme] = enzyme_dict for enzyme in data_test_backward: enzyme_dict = data_test_backward[ enzyme].getSimpleDict() if enzyme_dict != {}: data_test_backward_dict[enzyme] = enzyme_dict with open('Unit Tests/test_data_selection_output.json', 'w') \ as outfile: json.dump(data_test_forward_dict, outfile, indent=4) with open('Unit Tests/test_data_selection_output_2.json', 'w')\ as outfile: json.dump(data_test_backward_dict, outfile, indent=4) self.assertDictEqual(correct_data_dict, data_test_forward_dict) self.assertDictEqual(correct_data_dict, data_test_backward_dict)
def test_getData(self): '''Ensure getData can extract and return correct data as a list of dict ''' sample_reaction = openJson('Unit Tests/sample_brenda_reaction.json') expected_return = openJson('Unit Tests/expected_getData_return.json') returned_data = getData(sample_reaction, 'thioredoxin', DataType.turnover) for index, entry in enumerate(returned_data): self.assertDictEqual(returned_data[index], expected_return[index])
def test_get_molecular_weight_data_from_mixed(self): '''Ensure getData can extract specific activities data as a list of dict''' sample_reaction = openJson( 'Unit Tests/sample_mixed_brenda_reaction.json') returned_data = getData(sample_reaction, 'thioredoxin', DataType.molecular_weight) for index, entry in enumerate(returned_data): self.assertDictEqual( returned_data[index], CopyData.expected_molecular_weight_return[index])
def test_get_turnover_data_from_mixed(self): '''Ensure getData can extract and return correct data as a list of dict when the data_types are mixed.''' sample_reaction = openJson( 'Unit Tests/sample_mixed_brenda_reaction.json') returned_data = getData(sample_reaction, 'thioredoxin', DataType.turnover) for index, entry in enumerate(returned_data): self.assertDictEqual(returned_data[index], CopyData.expected_turnover_return[index])
pool.close() pool.join() local_model.update(lm_1.get()) local_model.update(lm_2.get()) local_model.update(lm_3.get()) local_model.update(lm_4.get()) if sys.argv[1] == 'model': write('JSONs/iCHOv1_keggs.json', local_model) elif sys.argv[1] == 'k1-model': write('JSONs/iCHOv1_K1_keggs.json', local_model) else: write('Unit Tests/iCHOv1_keggs_test.json', local_model) elif sys.argv[1] == 'brenda-keggs' or sys.argv[1] == 'brenda-test': print('Opening brenda output...') if sys.argv[1] == 'brenda-keggs': treated_brenda_output = openJson( 'JSONs/treated_BRENDA_output.json') elif sys.argv[1] == 'brenda-test': treated_brenda_output = openJson( 'Unit Tests/sample_brenda_output.json') brenda_keggs = {} reactions1 = {} reactions2 = {} reactions3 = {} reactions4 = {} counter = 0 for reaction in treated_brenda_output: if counter % 4 == 0: reactions1[reaction] = treated_brenda_output[reaction] if counter % 4 == 1: reactions2[reaction] = treated_brenda_output[reaction] if counter % 4 == 2:
loop = 'csm' if loop == 'csm': searching = False finally: return mol_weights if __name__ == '__main__': sub_dict_1 = {} sub_dict_2 = {} sub_dict_3 = {} sub_dict_4 = {} mol_weights = {} if len(sys.argv) == 1: brenda_parameters = openJson('JSONs/brenda_parameters.json') else: brenda_parameters = openJson(sys.argv[1]) simplified_brenda = {} for bigg_id in brenda_parameters: simplified_brenda[bigg_id] = brenda_parameters[bigg_id][0] optimized_bigg = {} for k, v in simplified_brenda.items(): optimized_bigg[v] = optimized_bigg.get(v, []) optimized_bigg[v].append(k) counter = 0 for ec_number in optimized_bigg: if counter % 4 == 0: sub_dict_1[ec_number] = optimized_bigg[ec_number] if counter % 4 == 1: sub_dict_2[ec_number] = optimized_bigg[ec_number]
class MatchById(unittest.TestCase): '''Contains functions to test Match By Id Note: openJson already checked in TestFileIO.py ''' def loadMadeUpModel(path): '''Load a cobra model using a structure based on Enzymes and Metabolite Candidates Args: path: filepath to made up mode. Note: This function, based on DataTreatment.storeBiGGRepresentation is for testing purposes, and allows to load a made up model. ''' made_up_model = cobra.io.load_json_model(path) local_repr = {} for reaction in made_up_model.reactions: if reaction.id == 'CSND' or reaction.id == 'DHPM1': local_repr[reaction.id] = Enzyme(reaction.id) for reactant in reaction.reactants: local_repr[reaction.id].forward[reactant.name] = \ Metabolite(reactant.name, bigg=reactant.id) for product in reaction.products: local_repr[reaction.id].backward[product.name] = \ Metabolite(product.name, bigg=product.id) return local_repr brenda_keggs = openJson('Unit Tests/sample_brenda_keggs.json') treated_brenda_output = openJson( 'Unit Tests/sample_simple_brenda_output.json') data_type = DataType.turnover potential_updates_dict = openJson( 'Unit Tests/correct_potential_updates.json') simple_test_model = loadMadeUpModel('Unit Tests/simple_test_model.json') simple_test_model['CSND'].with_kegg['C00380'] = 'cyt' simple_test_model['CSND'].with_kegg['D00323'] = '5-fluorocyt' simple_test_model['DHPM1'].with_kegg['C00148'] = 'DL-p' correct_potential_updates = {} for reaction in potential_updates_dict: correct_potential_updates.update({reaction: Enzyme(reaction)}) if reaction in brenda_keggs: for kegg in brenda_keggs[reaction]: brenda_name = brenda_keggs[reaction][kegg] if kegg in simple_test_model[reaction].with_kegg: if simple_test_model[reaction].with_kegg[kegg] in\ simple_test_model[reaction].forward: if treated_brenda_output[reaction][ brenda_keggs[reaction][kegg]] != []: name = simple_test_model[reaction].with_kegg[kegg] correct_potential_updates[reaction].forward[ name] = [] for entry in treated_brenda_output[reaction][ brenda_name]: data = { 'organism': entry['organism'], 'wild-type': entry['wild-type'], 'turnover': entry['turnoverNumber'] } correct_potential_updates[reaction].forward[ name].append(MetaboliteCandidate( brenda_name, data)) elif simple_test_model[reaction].with_kegg[kegg] in\ simple_test_model[reaction].backward: name = simple_test_model[reaction].with_kegg[kegg] correct_potential_updates[reaction].backward[name] = [] for entry in treated_brenda_output[reaction][brenda_name]: data = { 'organism': entry['organism'], 'wild-type': entry['wild-type'], 'turnover': entry['turnoverNumber'] } correct_potential_updates[reaction].backward[ name].append(MetaboliteCandidate( brenda_name, data)) correct_unmatched = openJson('Unit Tests/correct_unmatched.json') def test_matchById_potential_updates(self): '''matchByName should match BiGG metabolites with BRENDA metabolites given a file containing their respective KEGG Ids. ''' potential_updates = {} matchById(potential_updates, MatchById.brenda_keggs, MatchById.treated_brenda_output, MatchById.data_type, MatchById.simple_test_model) writeEnzymes('Unit Tests/return_matchById_potential_updates.json', potential_updates) potential_updates_as_dict = {} correct_potential_updates_as_dict = {} for enzyme in potential_updates: potential_updates_as_dict[enzyme] = \ potential_updates[enzyme].getDict() for enzyme in MatchById.correct_potential_updates: correct_potential_updates_as_dict[enzyme] = \ MatchById.correct_potential_updates[enzyme].getDict() self.assertDictEqual(potential_updates_as_dict, correct_potential_updates_as_dict, msg='Potential updates incorrect.')