From 11e6e2c9c5b369396775a3c88b79a5a8883f832d Mon Sep 17 00:00:00 2001 From: Jonathan Karr Date: Wed, 1 Sep 2021 15:49:56 -0400 Subject: [PATCH] feat: updated to Biosimulators-utils 0.1.114: organized options, added option to control logging; added Python package to specs; added fonts to Docker image --- Dockerfile | 7 +++++- biosimulators.json | 14 +++++++++-- biosimulators_bionetgen/_version.py | 2 +- biosimulators_bionetgen/core.py | 39 +++++++++++------------------ biosimulators_bionetgen/utils.py | 10 +++++--- requirements.txt | 2 +- tests/test_core_main.py | 33 +++++++++++++----------- 7 files changed, 59 insertions(+), 48 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3fb7103..430263e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ FROM python:3.9-slim-buster -ARG VERSION="0.1.11" +ARG VERSION="0.1.12" ARG SIMULATOR_VERSION=2.6.0 # metadata @@ -70,6 +70,11 @@ RUN apt-get update -y \ && rm -rf /var/lib/apt/lists/* ENV PATH=${PATH}:/opt/BioNetGen-${SIMULATOR_VERSION}/ +# fonts for matplotlib +RUN apt-get update -y \ + && apt-get install -y --no-install-recommends libfreetype6 \ + && rm -rf /var/lib/apt/lists/* + # install BioSimulators-compliant command-line interface to BioNetGen COPY . /root/Biosimulators_BioNetGen RUN pip install /root/Biosimulators_BioNetGen \ diff --git a/biosimulators.json b/biosimulators.json index 75befd6..86e5bc5 100644 --- a/biosimulators.json +++ b/biosimulators.json @@ -17,6 +17,10 @@ }, "operatingSystemType": "Linux" }, + "pythonApi": { + "package": "biosimulators-bionetgen", + "module": "biosimulators_bionetgen" + }, "authors": [{ "firstName": "Ali", "middleName": "Sinan", @@ -91,7 +95,13 @@ } ], "references": { - "identifiers": [{ + "identifiers": [ + { + "namespace": "pypi", + "id": "bionetgen", + "url": "https://pypi.org/project/bionetgen/" + }, + { "namespace": "pypi", "id": "biosimulators-bionetgen", "url": "https://pypi.org/project/biosimulators-bionetgen/" @@ -434,7 +444,7 @@ "modelingFrameworks": [{ "namespace": "SBO", - "id": "SBO_0000295" + "id": "SBO_0000680" }], "modelFormats": [{ "namespace": "EDAM", diff --git a/biosimulators_bionetgen/_version.py b/biosimulators_bionetgen/_version.py index 13b7089..e6d0c4f 100644 --- a/biosimulators_bionetgen/_version.py +++ b/biosimulators_bionetgen/_version.py @@ -1 +1 @@ -__version__ = '0.1.11' +__version__ = '0.1.12' diff --git a/biosimulators_bionetgen/core.py b/biosimulators_bionetgen/core.py index 9bfd7ae..53fd0a9 100644 --- a/biosimulators_bionetgen/core.py +++ b/biosimulators_bionetgen/core.py @@ -12,7 +12,7 @@ get_variables_results_from_observable_results, add_variables_to_model) from .warnings import IgnoredBnglFileContentWarning from biosimulators_utils.combine.exec import exec_sedml_docs_in_archive -from biosimulators_utils.config import get_config +from biosimulators_utils.config import get_config, Config # noqa: F401 from biosimulators_utils.log.data_model import CombineArchiveLog, TaskLog # noqa: F401 from biosimulators_utils.viz.data_model import VizFormat # noqa: F401 from biosimulators_utils.report.data_model import ReportFormat, VariableResults, SedDocumentResults # noqa: F401 @@ -27,11 +27,7 @@ __all__ = ['exec_sedml_docs_in_combine_archive', 'exec_sed_task'] -def exec_sedml_docs_in_combine_archive(archive_filename, out_dir, - return_results=False, - report_formats=None, plot_formats=None, - bundle_outputs=None, keep_individual_outputs=None, - raise_exceptions=True): +def exec_sedml_docs_in_combine_archive(archive_filename, out_dir, config=None): """ Execute the SED tasks defined in a COMBINE/OMEX archive and save the outputs Args: @@ -43,12 +39,7 @@ def exec_sedml_docs_in_combine_archive(archive_filename, out_dir, * HDF5: directory in which to save a single HDF5 file (``{ out_dir }/reports.h5``), with reports at keys ``{ relative-path-to-SED-ML-file-within-archive }/{ report.id }`` within the HDF5 file - return_results (:obj:`bool`, optional): whether to return the result of each output of each SED-ML file - report_formats (:obj:`list` of :obj:`ReportFormat`, optional): report format (e.g., csv or h5) - plot_formats (:obj:`list` of :obj:`VizFormat`, optional): report format (e.g., pdf) - bundle_outputs (:obj:`bool`, optional): if :obj:`True`, bundle outputs into archives for reports and plots - keep_individual_outputs (:obj:`bool`, optional): if :obj:`True`, keep individual output files - raise_exceptions (:obj:`bool`, optional): whether to raise exceptions + config (:obj:`Config`, optional): BioSimulators common configuration Returns: :obj:`tuple`: @@ -59,21 +50,17 @@ def exec_sedml_docs_in_combine_archive(archive_filename, out_dir, sed_doc_executer = functools.partial(exec_sed_doc, exec_sed_task) return exec_sedml_docs_in_archive(sed_doc_executer, archive_filename, out_dir, apply_xml_model_changes=False, - return_results=return_results, - report_formats=report_formats, - plot_formats=plot_formats, - bundle_outputs=bundle_outputs, - keep_individual_outputs=keep_individual_outputs, - raise_exceptions=raise_exceptions) + config=config) -def exec_sed_task(sed_task, variables, log=None): +def exec_sed_task(sed_task, variables, log=None, config=None): """ Execute a task and save its results Args: sed_task (:obj:`Task`): task variables (:obj:`list` of :obj:`Variable`): variables that should be recorded log (:obj:`TaskLog`, optional): log for the task + config (:obj:`Config`, optional): BioSimulators common configuration Returns: :obj:`tuple`: @@ -104,8 +91,9 @@ def exec_sed_task(sed_task, variables, log=None): * BioNetGen * :obj:`get_variables_results_from_observable_results` """ - config = get_config() - log = log or TaskLog() + config = config or get_config() + if config.LOG and not log: + log = TaskLog() if config.VALIDATE_SEDML: raise_errors_warnings( @@ -157,10 +145,11 @@ def exec_sed_task(sed_task, variables, log=None): variable_results[key] = variable_results[key][-(sed_task.simulation.number_of_points + 1):] # log action - log.algorithm = alg_kisao_id - log.simulator_details = { - 'actions': bionetgen_task.actions, - } + if config.LOG: + log.algorithm = alg_kisao_id + log.simulator_details = { + 'actions': bionetgen_task.actions, + } # return the values of the variables and log return variable_results, log diff --git a/biosimulators_bionetgen/utils.py b/biosimulators_bionetgen/utils.py index 851f262..170a756 100644 --- a/biosimulators_bionetgen/utils.py +++ b/biosimulators_bionetgen/utils.py @@ -6,9 +6,10 @@ :License: MIT """ -from .config import Config +from .config import Config as SimulatorConfig from .data_model import Model, ModelBlock, Task, KISAO_SIMULATION_METHOD_ARGUMENTS_MAP # noqa: F401 from .io import write_task, read_simulation_results +from biosimulators_utils.config import Config # noqa: F401 from biosimulators_utils.report.data_model import VariableResults from biosimulators_utils.sedml.data_model import (ModelAttributeChange, Variable, # noqa: F401 Symbol, UniformTimeCourseSimulation) @@ -197,12 +198,13 @@ def add_variables_to_model(model, variables): raise NotImplementedError(msg) -def add_simulation_to_task(task, simulation): +def add_simulation_to_task(task, simulation, config=None): """ Add a SED simulation to a BioNetGen task Args: task (:obj:`Task`): BioNetGen task simulation (:obj:`UniformTimeCourseSimulation`): SED simulation + config (:obj:`Config`, optional): configuration Raises: :obj:`NotImplementedError`: if BioNetGen doesn't support the request algorithm or @@ -227,7 +229,7 @@ def add_simulation_to_task(task, simulation): simulate_args['n_steps'] = int(n_steps) - algorithm_substitution_policy = get_algorithm_substitution_policy() + algorithm_substitution_policy = get_algorithm_substitution_policy(config=config) exec_kisao_id = get_preferred_substitute_algorithm_by_ids( simulation.algorithm.kisao_id, KISAO_SIMULATION_METHOD_ARGUMENTS_MAP.keys(), substitution_policy=algorithm_substitution_policy) @@ -298,7 +300,7 @@ def exec_bionetgen_task(task): write_task(task, task_filename) # execute the task - bionetgen_path = Config().bionetgen_path + bionetgen_path = SimulatorConfig().bionetgen_path try: subprocess.check_call([bionetgen_path, task_filename, '--outdir', temp_dirname]) except Exception: diff --git a/requirements.txt b/requirements.txt index 6d0c164..774db38 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -biosimulators_utils[bngl,logging] >= 0.1.104 +biosimulators_utils[bngl,logging] >= 0.1.114 kisao pandas diff --git a/tests/test_core_main.py b/tests/test_core_main.py index d66c7ab..5a7488c 100644 --- a/tests/test_core_main.py +++ b/tests/test_core_main.py @@ -11,6 +11,7 @@ from biosimulators_bionetgen.core import exec_sed_task, exec_sedml_docs_in_combine_archive from biosimulators_utils.combine import data_model as combine_data_model from biosimulators_utils.combine.io import CombineArchiveWriter +from biosimulators_utils.config import get_config from biosimulators_utils.report import data_model as report_data_model from biosimulators_utils.report.io import ReportReader from biosimulators_utils.sedml import data_model as sedml_data_model @@ -72,13 +73,15 @@ def test_exec_sedml_docs_in_combine_archive(self): doc, archive_filename = self._build_combine_archive() out_dir = os.path.join(self.dirname, 'out') - exec_sedml_docs_in_combine_archive(archive_filename, out_dir, - report_formats=[ - report_data_model.ReportFormat.h5, - report_data_model.ReportFormat.csv, - ], - bundle_outputs=True, - keep_individual_outputs=True) + + config = get_config() + config.REPORT_FORMATS = [report_data_model.ReportFormat.h5, report_data_model.ReportFormat.csv,] + config.BUNDLE_OUTPUTS = True + config.KEEP_INDIVIDUAL_OUTPUTS = True + + _, log = exec_sedml_docs_in_combine_archive(archive_filename, out_dir, config=config) + if log.exception: + raise log.exception self._assert_combine_archive_outputs(doc, out_dir) @@ -87,13 +90,15 @@ def test_exec_sedml_docs_in_combine_archive_with_all_algorithms(self): doc, archive_filename = self._build_combine_archive(algorithm=alg) out_dir = os.path.join(self.dirname, alg.kisao_id) - exec_sedml_docs_in_combine_archive(archive_filename, out_dir, - report_formats=[ - report_data_model.ReportFormat.h5, - report_data_model.ReportFormat.csv, - ], - bundle_outputs=True, - keep_individual_outputs=True) + + config = get_config() + config.REPORT_FORMATS = [report_data_model.ReportFormat.h5, report_data_model.ReportFormat.csv,] + config.BUNDLE_OUTPUTS = True + config.KEEP_INDIVIDUAL_OUTPUTS = True + + _, log = exec_sedml_docs_in_combine_archive(archive_filename, out_dir, config=config) + if log.exception: + raise log.exception self._assert_combine_archive_outputs(doc, out_dir) def test_exec_with_cli(self):