Skip to content

Commit

Permalink
feat: updated to Biosimulators-utils 0.1.114: organized options, adde…
Browse files Browse the repository at this point in the history
…d option to control logging; added Python package to specs; added fonts to Docker image
  • Loading branch information
jonrkarr committed Sep 1, 2021
1 parent 8eca48d commit 11e6e2c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 48 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down
14 changes: 12 additions & 2 deletions biosimulators.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
},
"operatingSystemType": "Linux"
},
"pythonApi": {
"package": "biosimulators-bionetgen",
"module": "biosimulators_bionetgen"
},
"authors": [{
"firstName": "Ali",
"middleName": "Sinan",
Expand Down Expand Up @@ -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/"
Expand Down Expand Up @@ -434,7 +444,7 @@

"modelingFrameworks": [{
"namespace": "SBO",
"id": "SBO_0000295"
"id": "SBO_0000680"
}],
"modelFormats": [{
"namespace": "EDAM",
Expand Down
2 changes: 1 addition & 1 deletion biosimulators_bionetgen/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.11'
__version__ = '0.1.12'
39 changes: 14 additions & 25 deletions biosimulators_bionetgen/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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`:
Expand All @@ -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`:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
10 changes: 6 additions & 4 deletions biosimulators_bionetgen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
biosimulators_utils[bngl,logging] >= 0.1.104
biosimulators_utils[bngl,logging] >= 0.1.114
kisao
pandas
33 changes: 19 additions & 14 deletions tests/test_core_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand Down

0 comments on commit 11e6e2c

Please sign in to comment.