def test_snapshot_report_file(model, tmpdir): filename = str(tmpdir.join("index.html")) _, results = api.test_model(model, results=True, pytest_args=["--tb", "no"]) report = api.snapshot_report(results, html=True) assert report.startswith("<!doctype html>")
def snapshot(model, filename, pytest_args, exclusive, skip, solver, solver_timeout, experimental, custom_tests, custom_config): """ Take a snapshot of a model's state and generate a report. MODEL: Path to model file. Can also be supplied via the environment variable MEMOTE_MODEL or configured in 'setup.cfg' or 'memote.ini'. """ model_obj, sbml_ver, notifications = api.validate_model(model) if model_obj is None: LOGGER.critical( "The model could not be loaded due to the following SBML errors.") utils.stdout_notifications(notifications) api.validation_report(model, notifications, filename) sys.exit(1) if not any(a.startswith("--tb") for a in pytest_args): pytest_args = ["--tb", "no"] + pytest_args # Add further directories to search for tests. pytest_args.extend(custom_tests) config = ReportConfiguration.load() # Update the default test configuration with custom ones (if any). for custom in custom_config: config.merge(ReportConfiguration.load(custom)) model_obj.solver = solver _, results = api.test_model(model_obj, sbml_version=sbml_ver, results=True, pytest_args=pytest_args, skip=skip, exclusive=exclusive, experimental=experimental, solver_timeout=solver_timeout) with open(filename, "w", encoding="utf-8") as file_handle: LOGGER.info("Writing snapshot report to '%s'.", filename) file_handle.write(api.snapshot_report(results, config))
def snapshot(model, filename, pytest_args, solver, custom): """ Take a snapshot of a model's state and generate a report. MODEL: Path to model file. Can also be supplied via the environment variable MEMOTE_MODEL or configured in 'setup.cfg' or 'memote.ini'. """ if not any(a.startswith("--tb") for a in pytest_args): pytest_args = ["--tb", "short"] + pytest_args if not any(a.startswith("-v") for a in pytest_args): pytest_args.append("-vv") model.solver = solver _, results = api.test_model(model, results=True, pytest_args=pytest_args, custom=custom) api.snapshot_report(results, filename)
def snapshot(model, filename, pytest_args, solver, custom_tests, custom_config): """ Take a snapshot of a model's state and generate a report. MODEL: Path to model file. Can also be supplied via the environment variable MEMOTE_MODEL or configured in 'setup.cfg' or 'memote.ini'. """ if not any(a.startswith("--tb") for a in pytest_args): pytest_args = ["--tb", "no"] + pytest_args # Add further directories to search for tests. pytest_args.extend(custom_tests) config = ReportConfiguration.load() # Update the default test configuration with custom ones (if any). for custom in custom_config: config.merge(ReportConfiguration.load(custom)) model.solver = solver _, results = api.test_model(model, results=True, pytest_args=pytest_args) api.snapshot_report(results, config, filename)
def snapshot(model, filename, pytest_args, exclusive, skip, solver, experimental, custom_tests, custom_config): """ Take a snapshot of a model's state and generate a report. MODEL: Path to model file. Can also be supplied via the environment variable MEMOTE_MODEL or configured in 'setup.cfg' or 'memote.ini'. """ if not any(a.startswith("--tb") for a in pytest_args): pytest_args = ["--tb", "no"] + pytest_args # Add further directories to search for tests. pytest_args.extend(custom_tests) config = ReportConfiguration.load() # Update the default test configuration with custom ones (if any). for custom in custom_config: config.merge(ReportConfiguration.load(custom)) model.solver = solver _, results = api.test_model(model, results=True, pytest_args=pytest_args, skip=skip, exclusive=exclusive, experimental=experimental) with open(filename, "w", encoding="utf-8") as file_handle: LOGGER.info("Writing snapshot report to '%s'.", filename) file_handle.write(api.snapshot_report(results, config))
def run_memote(self, ctx, params): """ :param params: instance of type "RunMemoteParams" -> structure: parameter "workspace" of String, parameter "model_id" of String, parameter "media_id" of String, parameter "out_model_id" of String :returns: instance of type "RunMemoteResults" -> structure: parameter "model_ref" of String """ # ctx is the context object # return variables are: output #BEGIN run_memote print(params) kbase_api = cobrakbase.KBaseAPI(ctx['token'], config={'workspace-url': self.ws_url}) modelseed = cobrakbase.modelseed.from_local( '/kb/module/data/ModelSEEDDatabase') kmodel_data = kbase_api.get_object(params['model_id'], params['workspace']) fbamodel = KBaseFBAModel(kmodel_data) builder = KBaseFBAModelToCobraBuilder(fbamodel) if 'genome_ref' in kmodel_data: logging.info("Annotating model with genome information: %s", kmodel_data['genome_ref']) ref_data = kbase_api.get_object_info_from_ref( kmodel_data['genome_ref']) genome_data = kbase_api.get_object(ref_data.id, ref_data.workspace_id) builder.with_genome(KBaseGenome(genome_data)) media = None if 'media_id' in params and not params[ 'media_id'] == "" and not params['media_id'] == None: print("MEDIA ID", params['media_id']) media_data = kbase_api.get_object(params['media_id'], params['workspace']) media = KBaseBiochemMedia(media_data) if media == None: if 'gapfillings' in kmodel_data and len( kmodel_data['gapfillings']) > 0: print("Pulling media from gapfilling...", kmodel_data['gapfillings']) ref = kmodel_data['gapfillings'][0]['media_ref'] ref_data = kbase_api.get_object_info_from_ref(ref) media_data = kbase_api.get_object(ref_data.id, ref_data.workspace_id) media = KBaseBiochemMedia(media_data) if not media == None: builder.with_media(media) #converts to cobra model object with builder model = builder.build() cobrakbase.annotate_model_with_modelseed(model, modelseed) #modelseed = cobrakbase.modelseed.from_local('/kb/module/data/ModelSEEDDatabase-dev') #print(cobrakbase.annotate_model_with_modelseed(model, modelseed)) a, results = memote_api.test_model(model, results=True, skip=['test_thermodynamics']) config = ReportConfiguration.load() html = memote_api.snapshot_report(results, config) report_folder = self.shared_folder with open(report_folder + "/report.html", 'w') as f: f.write(html) cobra.io.write_sbml_model(model, report_folder + "/model.xml") report_client = KBaseReport(self.callback_url) report_params = { 'direct_html_link_index': 0, 'workspace_name': params['workspace'], 'report_object_name': 'run_memote_' + uuid.uuid4().hex, 'objects_created': [], 'html_links': [{ 'name': 'report', 'description': 'Memote HTML Report', 'path': report_folder + "/report.html" }], 'file_links': [{ 'name': params['model_id'] + ".xml", 'description': 'desc', 'path': report_folder + "/model.xml" }] } report_info = report_client.create_extended_report(report_params) output = { 'report_name': report_info['name'], 'report_ref': report_info['ref'] } #END run_memote # At some point might do deeper type checking... if not isinstance(output, dict): raise ValueError('Method run_memote return value ' + 'output is not type dict as required.') # return the results return [output]
def test_snapshot_report_file(model, tmpdir): filename = str(tmpdir.join("index.html")) _, results = api.test_model(model, results=True) api.snapshot_report(results, filename=filename) assert exists(filename)