def __init__(self, config): self.callback_url = config['SDK_CALLBACK_URL'] self.token = config['KB_AUTH_TOKEN'] self.dfu = DataFileUtil(self.callback_url) self.fba = fba_tools(self.callback_url) self.SBMLTools = SBMLTools(self.callback_url) self.uploader_utils = UploaderUtil(config)
def setUpClass(cls): cls.token = environ.get('KB_AUTH_TOKEN', None) config_file = environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('kb_uploadmethods'): cls.cfg[nameval[0]] = nameval[1] authServiceUrl = cls.cfg.get( 'auth-service-url', "https://kbase.us/services/authorization/Sessions/Login") auth_client = _KBaseAuth(authServiceUrl) cls.user_id = auth_client.get_user(cls.token) # WARNING: don't call any logging methods on the context object, # it'll result in a NoneType error cls.ctx = MethodContext(None) cls.ctx.update({ 'token': cls.token, 'user_id': cls.user_id, 'provenance': [{ 'service': 'kb_uploadmethods', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL, token=cls.token) cls.serviceImpl = kb_uploadmethods(cls.cfg) cls.dfu = DataFileUtil(os.environ['SDK_CALLBACK_URL'], token=cls.token) cls.gfu = GenomeFileUtil(os.environ['SDK_CALLBACK_URL'], token=cls.token) cls.fba_tools = fba_tools(os.environ['SDK_CALLBACK_URL'], token=cls.token) cls.scratch = cls.cfg['scratch'] cls.shockURL = cls.cfg['shock-url'] suffix = int(time.time() * 1000) cls.wsName = "test_kb_uploadmethods_phenotype_set" + str(suffix) cls.wsClient.create_workspace({'workspace': cls.wsName}) cls.prepare_data()
def run_ThermoStoichWizard(self, ctx, params): """ This example function accepts any number of parameters and returns results in a KBaseReport :param params: instance of mapping from String to unspecified object :returns: instance of type "ReportResults" -> structure: parameter "report_name" of String, parameter "report_ref" of String """ # ctx is the context object # return variables are: output #BEGIN run_ThermoStoichWizard uuid_string = str(uuid.uuid4()) objects_created = [] output_files = [] n_lambda_bins = int(params['n_lambda_bins']) lambda_cutoff = float(params['lambda_cutoff']) ####################################################################### # check out the input table ####################################################################### print("Input parameter", params['input_tbl']) dfu = DataFileUtil(self.callback_url) input_tbl = dfu.get_objects({'object_refs': [params['input_tbl']]})['data'][0] # # investigate input_tbl # for peak in input_tbl['data']['instances']: # print(peak, input_tbl['data']['instances'][peak]) # break # print(input_tbl['info']) tbl_cols = [ info['attribute'] for info in input_tbl['data']['attributes'] ] tbl_df = pd.DataFrame.from_dict(input_tbl['data']['instances'], orient='index', columns=tbl_cols) ####################################################################### # compute thermo stoichiometry ####################################################################### fticr = FTICRResult(tbl_df) fticr.to_csv(os.path.join(self.shared_folder, "input_compounds.csv")) fticr.run() output_folder = os.path.join(self.shared_folder, 'csv') os.mkdir(output_folder) fticr.save_result_files(output_folder) # output_filenames = ["stoichD","stoichA","stoichCat","stoichAn_O2","stoichAn_HCO3","stoichMet_O2","stoichMet_HCO3","thermodynamic_props"] output_filenames = ["stoichMet_O2", "thermodynamic_props"] output_files = [{ 'path': output_folder + '/{}.csv'.format(n), 'name': '{}.csv'.format(n), 'label': n, 'description': n } for n in output_filenames] # filter out the unassigned peaks num_peaks = fticr.num_peaks num_cpds = fticr.num_cpds print('num_peaks:{}, num_cpds:{}'.format(num_peaks, num_cpds)) ####################################################################### # average compositions by lambda bins ####################################################################### if params['bin_method'] == "cumulative": new_comp = fticr.average_by_lambda_bins(n_bins=n_lambda_bins, cutoff=lambda_cutoff) elif params['bin_method'] == "uniform": new_comp = fticr.average_by_lambda_bins_uniform( n_bins=n_lambda_bins, cutoff=lambda_cutoff) else: raise ("bin_method was wrong:", params['bin_method']) average_comp_path = os.path.join(output_folder, "avg_comp_from_lambda_bins.csv") new_comp.to_csv(average_comp_path) output_files.append({ 'path': average_comp_path, 'name': 'avg_comp_from_lambda_bins.csv', 'label': 'average compositions for each lambda bin', 'description': 'average compositions for each lambda bin' }) # compute the reactions for bin averaged compositions new_fticr = FTICRResult(new_comp, dtype=np.float) new_fticr.run() selected_folder = os.path.join(self.shared_folder, 'bin_avg') os.mkdir(selected_folder) new_fticr.save_result_files(selected_folder) output_filenames = ["stoichMet_O2"] output_files += [{ 'path': selected_folder + '/{}.csv'.format(n), 'name': '{}_from_lambda_bins.csv'.format(n), 'label': '{}_from_lambda_bins'.format(n), 'description': '{}_from_lambda_bins'.format(n), } for n in output_filenames] ####################################################################### # create the tsv files for fba ####################################################################### fticr.create_fba_model_files(self.shared_folder) new_fticr.create_fba_model_files(self.shared_folder, prefix='bin_avg') ####################################################################### # generate fbamodel ####################################################################### fbaobj = fba_tools(self.callback_url) def generate_fbamodel(fbaobj, model_prefix, workspace_name, compounds_file, reactions_file): fba_param = { # 'model_name':'model' + params['output_surfix'], 'file_type': 'tsv', 'compounds_file': { 'path': compounds_file }, 'model_file': { 'path': reactions_file }, 'biomass': ['xrxn1_c0'], # TODO: how to define a biomass reaction 'model_name': "{}_{}".format(model_prefix, params['output_surfix']), 'workspace_name': workspace_name # } fba_model_wref = fbaobj.tsv_file_to_model(p=fba_param) print('fba_model:', fba_model_wref) return fba_model_wref # stoichiometries = ["stoichD","stoichA","stoichCat","stoichAn_O2","stoichAn_HCO3","stoichMet_O2","stoichMet_HCO3"] stoichiometries = ["stoichMet_O2"] for stoich in stoichiometries: fba_model_wref = generate_fbamodel( fbaobj, model_prefix=stoich, workspace_name=params['workspace_name'], compounds_file=os.path.join(self.shared_folder, "temp_comps.tsv"), reactions_file=os.path.join(self.shared_folder, "temp_{}.tsv".format(stoich))) objects_created.append({ 'ref': fba_model_wref['ref'], 'description': "FBA model for {}".format(stoich) }) fba_model_wref = generate_fbamodel( fbaobj, model_prefix="Bin_Averaged_" + stoich, workspace_name=params['workspace_name'], compounds_file=os.path.join(self.shared_folder, "bin_avg_comps.tsv"), reactions_file=os.path.join(self.shared_folder, "bin_avg_{}.tsv".format(stoich))) objects_created.append({ 'ref': fba_model_wref['ref'], 'description': "FBA model for {}".format(stoich) }) ####################################################################### # create the tsv files for media ####################################################################### # media_tsv_file = os.path.join(self.shared_folder, "temp_media.tsv") # fticr.create_media_file(media_tsv_file) ####################################################################### # generate media ####################################################################### # media_param = { # 'file_type':'tsv', # 'media_file':{'path': media_tsv_file}, # 'media_name': "ThermoStoic_media_{}".format(params['output_surfix']), # 'workspace_name': params['workspace_name'] # } # media_wref = fbaobj.tsv_file_to_media(p=media_param) # print('media:', media_wref) # objects_created.append({'ref': media_wref['ref'], # 'description': "Media object contains the initial condition."}) ####################################################################### # html report ####################################################################### html_folder = os.path.join(self.shared_folder, 'html') os.mkdir(html_folder) ####################################################################### # figures ####################################################################### van_krevelen_path = os.path.join(html_folder, "van_krevelen.png") # fticr.plot_van_krevelen(fout=van_krevelen_path) # fig, ax = plt.subplots(1,2,figsize=(12,6),sharex=True,sharey=True) plt.figure(figsize=(7, 5)) df = fticr._assigned_tbl.copy() df["H:C"] = df.H / df.C df["O:C"] = df.O / df.C g1 = sns.scatterplot("O:C", "H:C", hue="Class", alpha=1, s=15, data=df) g1.set_xlabel("O:C", fontsize=15) g1.set_ylabel("H:C", fontsize=15) plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left", fontsize=10) plt.tight_layout() plt.savefig(van_krevelen_path) van_krevelen_lambda_bins_path = os.path.join( html_folder, "van_krevelen_by_lambda_bins.png") plt.figure(figsize=(7, 5)) new_comp["H:C"] = new_comp.H / new_comp.C new_comp["O:C"] = new_comp.O / new_comp.C g = sns.scatterplot("O:C", "H:C", hue="Class", s=100, data=new_comp) g.set_xlabel("O:C", fontsize=15) g.set_ylabel("H:C", fontsize=15) g.set_xlim(g1.get_xlim()) g.set_ylim(g1.get_ylim()) plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left", fontsize=12) plt.tight_layout() # plt.savefig(van_krevelen_path) plt.savefig(van_krevelen_lambda_bins_path) lambda_dist_path = os.path.join(html_folder, "lambda_dist.png") fticr.plot_lambda_dist(fout=lambda_dist_path) # delGcat0_dist_path = os.path.join(html_folder, "delGcat0_dist.png") # fticr.plot_delta_gibb_dist('delGcat0', r'$\Delta G_{Cox}^0$', delGcat0_dist_path) # delGcat_dist_path = os.path.join(html_folder, "delGcat_dist.png") # fticr.plot_delta_gibb_dist('delGcat', r'$\Delta G_{Cox}$', delGcat_dist_path) delGcox0_dist_path = os.path.join(html_folder, "delGcox0_dist.png") fticr.plot_delta_gibb_dist('delGcox0PerC', r'$\Delta G_{Cox}^0$', delGcox0_dist_path) # delGcox_dist_path = os.path.join(html_folder, "delGcox_dist.png") # fticr.plot_delta_gibb_dist('delGcox', r'$\Delta G_{Cox}$', delGcox_dist_path) output_files.append({ 'path': van_krevelen_path, 'name': 'van_krevelen.png', 'label': 'van Krevelen diagram for compounds', 'description': 'van Krevelen diagram for compounds' }) output_files.append({ 'path': van_krevelen_lambda_bins_path, 'name': 'van_krevelen_by_lambda_bins.png', 'label': 'van Krevelen diagram for each lambda bin', 'description': 'van Krevelen diagram for each lambda bin' }) output_files.append({ 'path': lambda_dist_path, 'name': 'lambda_dist.png', 'label': 'lambda distribution', 'description': 'lambda distribution' }) # output_files.append({'path': delGcat0_dist_path, 'name': 'delGcat0_dist.png', # 'label': 'delGcat0 distribution', # 'description': 'Gibbs free energy change for an electron donor half reaction'}) # output_files.append({'path': delGcat_dist_path, 'name': 'delGcat_dist.png', # 'label': 'delGcat distribution', 'description': 'Gibbs free energy change for catabolic reaction'}) output_files.append({ 'path': delGcox0_dist_path, 'name': 'delGcox0_dist.png', 'label': 'delGcox0 distribution', 'description': 'Gibbs energies for the oxidation half reactions' }) # output_files.append({'path': delGcox_dist_path, 'name': 'delGcox_dist.png', # 'label': 'delGcox distribution', # 'description': 'Gibbs energies for the oxidation half reactions'}) summary_str = '<ul class="list-group list-group-flush">' summary_str += '<li class="list-group-item">Average: {:.3f}</li>' summary_str += '<li class="list-group-item">Standard deviation: {:.3f}</li>' summary_str += '<li class="list-group-item">Median: {:.3f}</li>' summary_str += '</ul>' html_str = '<div class="col-md-6">' html_str += '<div class="card mb-6 box-shadow">' html_str += '<img class="card-img-top" alt="lambda_dist" src="lambda_dist.png" style="width: 100%; display: block;">' html_str += '<div class="card-body">' html_str += '<p class="card-text">Energy coupling thermodynamic parameter</p>' html_str += '</div>' html_str += summary_str.format(*fticr.get_summary('lambda_O2')) html_str += '</div>' html_str += '</div>' html_str += '<div class="col-md-6">' html_str += '<div class="card mb-6 box-shadow">' html_str += '<img class="card-img-top" alt="delGcox0_dist" src="delGcox0_dist.png" style="width: 100%; display: block;">' html_str += '<div class="card-body">' html_str += '<p class="card-text">Gibbs free energy change for catabolic reaction</p>' html_str += '</div>' html_str += summary_str.format(*fticr.get_summary('delGcox0PerC')) html_str += '</div>' html_str += '</div>' # html_str += '<div class="col-md-4">' # html_str += '<div class="card mb-4 box-shadow">' # html_str += '<img class="card-img-top" alt="delGcat_dist" src="delGcat_dist.png" style="width: 100%; display: block;">' # html_str += '<div class="card-body">' # html_str += '<p class="card-text">Gibbs free energy change for an electron donor half reaction</p>' # html_str += '</div>' # html_str += summary_str.format(*fticr.get_summary('delGcat')) # html_str += '</div>' # html_str += '</div>' html_str += '<div class="col-md-6">' html_str += '<div class="card mb-6 box-shadow">' html_str += '<img class="card-img-top" alt="van_krevelen" src="van_krevelen.png" style="width: 100%; display: block;">' html_str += '<div class="card-body">' html_str += '<p class="card-text">Van Krevelen diagram for all compositions</p>' html_str += '</div>' html_str += '</div>' html_str += '</div>' html_str += '<div class="col-md-6">' html_str += '<div class="card mb-6 box-shadow">' html_str += '<img class="card-img-top" alt="van_krevelen_by_lambda_bins" src="van_krevelen_by_lambda_bins.png" style="width: 100%; display: block;">' html_str += '<div class="card-body">' html_str += '<p class="card-text">Van Krevelen Diagram for average compositions of lambda bins</p>' html_str += '</div>' html_str += '</div>' html_str += '</div>' with open( os.path.join(os.path.dirname(__file__), 'templates', 'template.html'), 'r') as template_file: report_html = template_file.read() report_html = report_html.replace( 'Number of peaks:', 'Number of peaks: {}'.format(num_peaks)) report_html = report_html.replace( 'Number of compounds:', 'Number of compounds: {}'.format(num_cpds)) report_html = report_html.replace('<!--[Results]-->', html_str) with open(os.path.join(html_folder, "index.html"), 'w') as index_file: index_file.write(report_html) report = KBaseReport(self.callback_url) html_dir = { 'path': html_folder, 'name': 'index.html', # MUST match the filename of your main html page 'description': 'Thermo Stoich Wizard Report' } report_info = report.create_extended_report({ 'objects_created': objects_created, 'file_links': output_files, 'html_links': [html_dir], 'direct_html_link_index': 0, 'report_object_name': 'thermo_stoich_wizard_report_' + params['output_surfix'], 'workspace_name': params['workspace_name'] }) output = { 'report_name': report_info['name'], 'report_ref': report_info['ref'], } #END run_ThermoStoichWizard # At some point might do deeper type checking... if not isinstance(output, dict): raise ValueError('Method run_ThermoStoichWizard return value ' + 'output is not type dict as required.') # return the results return [output]
def run_omreegalozpathway_completeness(self, ctx, params): """ This example function accepts any number of parameters and returns results in a KBaseReport :param params: instance of mapping from String to unspecified object :returns: instance of type "ReportResults" -> structure: parameter "report_name" of String, parameter "report_ref" of String """ # ctx is the context object # return variables are: output #BEGIN run_omreegalozpathway_completeness #Preparing report client report_client = KBaseReport(self.callback_url) #Original report info report_info = report_client.create({ 'report': { 'objects_created': [], 'text_message': params['main_input_ref'] }, 'workspace_name': params['workspace_name'] }) token = os.environ.get('KB_AUTH_TOKEN', None) #Checking the input params if "main_input_ref" in params: main_input_ref = params['main_input_ref'] else: logging.info( 'the reference number is not in the params, program must end.') raise Exception("main_input_ref not in params") #Creating the workspace client object ws = Workspace(self.ws_url, token=token) #Getting information about the main input ref obj_info = ws.get_object_info3({'objects': [{'ref': main_input_ref}]}) #Catching errors: if "infos" in obj_info: #Getting information from object reference number object_name = obj_info["infos"][0][1] object_type = obj_info["infos"][0][2] ws_name = obj_info["infos"][0][7] #Logging: logging.debug("Object Type: " + object_type) logging.debug("Object Name: " + object_name) logging.debug("Workspace Name: " + ws_name) else: logging.info( "The function ws.get_object_info3 failed to download the right information. The program must abort." ) raise Exception("Could not find infos in obj_info") #We create the output file name and add information to it later. output_file_name = 'pathways_measurements' #This part is a hack, need to check type of data more accurately. if object_type[:17] == 'KBaseFBA.FBAModel': logging.info("Succesfully recognized type as FBA Model") #Preparing the output file name which we return to the user output_file_name += '_fba_model' #Creating an fba tools object fba_t = fba_tools(self.callback_url) # Getting the TSV file from the object X = fba_t.export_model_as_tsv_file({"input_ref": main_input_ref}) # Logging logging.info( "the object output from fba tools export model as tsv file:") logging.info(X) #Locating where the reactions tsv was placed (Not well done- replace this with a robust form) reactions_file_path = os.path.join( self.shared_folder, object_name + '/' + object_name + '-reactions.tsv') #Preparing an output path for a future function output_path = os.path.join(self.shared_folder, output_file_name + '.tsv') #This function performs the percentage calculation work for FBAModel Object Types. html_path = reactions_file_to_pathway_reactions_and_percentages( reactions_file_path, output_path, object_name) # Using KBase Gene Families- Domain Annotation elif object_type[:34] == "KBaseGeneFamilies.DomainAnnotation": logging.info("Succesfully recognized type as Domain Annotation") output_file_name += '_domain_annotation' #We get the object using workspace's get_objects2 function obj = ws.get_objects2({'objects': [{'ref': main_input_ref}]}) #Within the way the object dictionary is given, what we are looking for is in the location as follows: Y = obj['data'][0]['data']['data'] #Preparing our own output_file_path with Domain Annotation instead of FBAModel (why?) output_file_path = os.path.join(self.shared_folder, output_file_name + '.tsv') #This function (written for the module) finds percentages of pathway completeness. html_path = TIGRFAM_file_to_pathway_reactions_and_percentages( Y, output_file_path, object_name) else: logging.info("Object type unknown") raise Exception( "Could not recognize ref to object- Check if object is FBA Model or Domain Annotation type. If so, the error is in the program, not the input - contact [email protected]." ) html_dict = [{"path": html_path, "name": 'Completeness_Table'}] #Preparing final report: report = report_client.create_extended_report({ 'direct_html_link_index': 0, 'message': 'Here are the pathway completeness results', 'workspace_name': ws_name, 'html_links': html_dict }) output = { 'report_name': report['name'], 'report_ref': report['ref'], } #END run_omreegalozpathway_completeness # At some point might do deeper type checking... if not isinstance(output, dict): raise ValueError( 'Method run_omreegalozpathway_completeness return value ' + 'output is not type dict as required.') # return the results return [output]
def run_omreegalozMediaPermutations(self, ctx, params): """ This example function accepts any number of parameters and returns results in a KBaseReport :param params: instance of mapping from String to unspecified object :returns: instance of type "ReportResults" -> structure: parameter "report_name" of String, parameter "report_ref" of String """ # ctx is the context object # return variables are: output #BEGIN run_omreegalozMediaPermutations report = KBaseReport(self.callback_url) create_ext_report_params = dict() create_ext_report_params["workspace_name"] = params['workspace_name'] token = os.environ.get('KB_AUTH_TOKEN', None) ws = Workspace(self.ws_url, token=token) fba_t = fba_tools(self.callback_url) #Check parameters here: Input should be a genome object instead of metabolic model metabolic_model_ref, base_media_ref, variable_media_ref, run_type, output_name = check_params( params) logging.debug("RUN TYPE: " + run_type) #Downloading and naming variable media: # DOWNLOAD TSV FILE OF MEDIA AND SAVE IT TO TEMP WORK DIR variable_media_obj = fba_t.export_media_as_tsv_file( {'input_ref': variable_media_ref}) var_med_info = ws.get_object_info3( {'objects': [{ 'ref': variable_media_ref }]}) if "infos" in var_med_info: #The way the variable media file is stored is in this location in the scratch directory: var_med_filename = os.path.join( var_med_info['infos'][0][1], var_med_info['infos'][0][1] + '.tsv') var_media_tsv_file_location = os.path.join(self.shared_folder, var_med_filename) #Main workspace is defined by location of the variable media item. ws_main = var_med_info["infos"][0][7] logging.debug(var_med_filename) logging.debug(variable_media_obj) else: raise Exception( "The variable media object info was not retrieved correctly- try a different Media Object." ) # Getting information about other objects in use: metabolic_model_info = ws.get_object_info3( {'objects': [{ 'ref': metabolic_model_ref }]}) base_med_obj_info = ws.get_object_info3( {'objects': [{ 'ref': base_media_ref }]}) #Making output information: output_dir_name = 'Multiple_FBA_Analysis' output_dir_path = os.path.join(self.shared_folder, output_dir_name) os.mkdir(output_dir_path) if "infos" in metabolic_model_info: metabolic_model_object_name = metabolic_model_info["infos"][0][1] metabolic_model_object_type = metabolic_model_info["infos"][0][2] metabolic_model_ws = metabolic_model_info["infos"][0][7] else: logging.critical( "For the metabolic model, the workspace function get_object_info3 did not work as expected." ) raise Exception( "Get Object Info failed - problem with workspace or token?") if "infos" in base_med_obj_info: base_med_object_name = base_med_obj_info["infos"][0][1] base_med_object_type = base_med_obj_info["infos"][0][2] base_media_ws = base_med_obj_info["infos"][0][7] else: logging.critical( "For the media, the workspace function get_object_info_3 did not work as expected." ) raise Exception( "Get Object Info failed - problem with workspace or token?") #CHECK IF FBA MODEL OBJECT: if metabolic_model_object_type[:17] == "KBaseFBA.FBAModel": logging.info('Succesfully recognized type as FBA Model') run_dict = dict() run_dict["fbamodel_id"] = metabolic_model_object_name run_dict["fbamodel_workspace"] = ws_main run_dict["workspace"] = ws_main run_dict["fba_output_id"] = "FBA_Output_Test" #This is where FBA is called: RESULTS = run_multiple_media_fba(fba_t, run_dict, var_media_tsv_file_location, base_med_object_name, run_type, base_media_ref) results_refs_and_names = RESULTS[0] media_to_compounds_str = RESULTS[1] fba_refs_list = [] #Make a directory to store the reactions tsv files all_rxn_tsvs_dir = os.path.join(self.shared_folder, "FBA_TSVs") os.mkdir(all_rxn_tsvs_dir) for fba_result in results_refs_and_names: ref_num = fba_result[0] fba_refs_list.append(ref_num) #We download the model as a tsv list- it is downloaded into a folder of its name fba_t.export_model_as_tsv_file({"input_ref": ref_num}) fba_tsv_name = fba_result[1] + "-reactions.tsv" reactions_tsv_file = os.path.join( self.shared_folder, os.path.join(fba_result[1], fba_tsv_name)) # We move the downloaded file to our directory called FBA_TSVs shutil.move(reactions_tsv_file, os.path.join(all_rxn_tsvs_dir, fba_tsv_name)) #Analyze the reactions tsvs: run_analysis_on_dir(all_rxn_tsvs_dir, self.shared_folder) comparisons_folder = os.path.join(self.shared_folder, "Comparisons") #Here, given the fba ids, we download the TSVs #The fba models will be downloaded into their names: #new_obj = ws.get_objects2({'objects':[{'ref': ref_num}]}) #result_filename = fba_name + '.txt' #f = open(os.path.join(output_dir_path, result_filename),"w") #f.write(str(new_obj)) #f.close() #HERE WE RUN COMPARE FBA: """ comp_fba_params = {"fba_id_list": fba_ids_list, "fbacomparison_output_id": output_name} comp_fba_params['workspace'] = ws_main comp_fba_ref_dict = fba_t.compare_fba_solutions(comp_fba_params) logging.info("COMPARE FBA RESULTS:") logging.info(comp_fba_ref_dict) new_comp_fba_ref = comp_fba_ref_dict['new_fbacomparison_ref'] #new_obj = ws.get_objects2({'objects':[{'ref': new_comp_fba_ref}]}) #result_filename = 'Compared_FBA_Results.txt' #f = open(os.path.join(self.shared_folder, result_filename),"w") #f.write(str(new_obj)) #f.close() create_ext_report_params['objects_created'] = [{'ref': new_comp_fba_ref, 'description': "The fba comparison output"}] """ #Did not recognize type as FBA Model: else: logging.critical("Wrong object type!") raise Exception("Could not recognize type of object!") create_ext_report_params['message'] = media_to_compounds_str file_links_list = [] for f in os.listdir(comparisons_folder): file_links_list.append({ "path": os.path.join(comparisons_folder, f), "name": f, "label": f }) create_ext_report_params['file_links'] = file_links_list report_info = report.create_extended_report(create_ext_report_params) logging.debug(report_info) output = { 'report_name': report_info['name'], 'report_ref': report_info['ref'], } #END run_omreegalozMediaPermutations # At some point might do deeper type checking... if not isinstance(output, dict): raise ValueError( 'Method run_omreegalozMediaPermutations return value ' + 'output is not type dict as required.') # return the results return [output]