Skip to content

Commit

Permalink
updating
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Dec 11, 2020
1 parent 5f1b558 commit ff1a9d1
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 88 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length = 150
exclude =
tests/*
docs/*
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
*.pyc
_pycache__/
# compiled Python files
*.egg-info/
__pycache__/
*.pyc
dist/
build/

# test results
tests/results/

# coverage files
htmlcov/
.coverage
coverage.xml

# compiled documentation
README.rst
docs/objects.inv
docs/.buildinfo
docs/.doctrees/
docs/_raw_sources/
docs/_sources/
32 changes: 28 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,39 @@ coverage html

## Documentation convention

BioSimulators-BioNetGen is documented using [reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html) and the [napoleon Sphinx plugin](https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html).
BioSimulators-BioNetGen is documented using [reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html) and the [napoleon Sphinx plugin](https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html). The documentation can be compiled by running the following commands:

```
python -m pip install -r docs-src/requirements.txt
sphinx-apidoc . setup.py --output-dir docs-src/source --force --module-first --no-toc
sphinx-build docs-src docs
```

## Submitting changes

Please use GitHub pull requests to submit changes. Each request should include a brief description of the new and/or modified features.

## Releasing and deploying new versions

Contact the [BioSimulators Team](mailto:info@biosimulators.org) to request release and deployment of new changes.
## Releasing new versions

To release changes, contact the [lead developers](mailto:info@biosimulators.org) to request their release.

Below are instructions for releasing a new version:

1. Make the required changes to the repository.
* To update the version of the underyling simulator, update its version numbers in the following files:
* `requirements.txt`
* `Dockerfile`
* `biosimulators.json`
2. Commit the changes to this repository.
3. Increment the `__version__` variable in `biosimulators_bionetgen/_version.py`.
4. Commit this change to `biosimulators_bionetgen/_version.py`.
5. Add a tag for the new version by running `git tag { version }`. `version` should be equal to the value of the
`__version__` variable in `biosimulators_bionetgen/_version.py`.
6. Push these commits and the new tag to GitHub by running `git push && git push --tags`.
7. This push will trigger a GitHub action which will execute the following tasks:
* Create a GitHub release for the version.
* Push the release to PyPI.
* Compile the documentation and push the compiled documentation to the repository so that the new documentation is viewable at github.io.

## Reporting issues

Expand Down
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@

FROM continuumio/miniconda3:4.8.2

ARG VERSION=2.5.1
ARG VERSION="0.0.1"
ARG SIMULATOR_VERSION=2.5.1

# metadata
LABEL \
org.opencontainers.image.title="BioNetGen" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.version="${SIMULATOR_VERSION}" \
org.opencontainers.image.description="Open-source software package for rule-based modeling of complex biochemical systems" \
org.opencontainers.image.url="https://bionetgen.org/" \
org.opencontainers.image.documentation="https://bionetgen.org/" \
Expand All @@ -37,9 +38,9 @@ LABEL \
org.opencontainers.image.licenses="MIT" \
\
base_image="continuumio/miniconda3:4.8.2" \
version="0.0.1" \
version="${VERSION}" \
software="BioNetGen" \
software.version="${VERSION}" \
software.version="${SIMULATOR_VERSION}" \
about.summary="Open-source software package for rule-based modeling of complex biochemical systems" \
about.home="https://bionetgen.org/" \
about.documentation="https://bionetgen.org/" \
Expand All @@ -66,7 +67,7 @@ RUN apt-get update -y \
perl \
vim \
\
&& git clone https://github.com/RuleWorld/bionetgen.git --branch BioNetGen-${VERSION} --depth 1 /root/bionetgen \
&& git clone https://github.com/RuleWorld/bionetgen.git --branch BioNetGen-${SIMULATOR_VERSION} --depth 1 /root/bionetgen \
&& cd /root/bionetgen \
&& git submodule init \
&& git submodule update \
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
![Latest version](https://img.shields.io/github/v/tag/biosimulators/Biosimulators_BioNetGen)
[![Latest release](https://img.shields.io/github/v/tag/biosimulators/Biosimulators_BioNetGen)](https://github.com/biosimulations/Biosimulators_BioNetGen/releases)
[![PyPI](https://img.shields.io/pypi/v/biosimulators_bionetgen)](https://pypi.org/project/biosimulators_bionetgen/)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/biosimulators/Biosimulators_BioNetGen/workflow-id)](https://github.com/biosimulators/Biosimulators_BioNetGen/actions?query=workflow%3Aworkflow-id)
[![Documentation](https://img.shields.io/github/license/biosimulators/Biosimulators_BioNetGen?badges-awesome-green.svg)](https://biosimulators.github.io/Biosimulators_BioNetGen/)
[![Issues](https://img.shields.io/github/issues/biosimulators/Biosimulators_BioNetGen)](https://github.com/biosimulators/Biosimulators_BioNetGen/issues)
[![License](https://img.shields.io/github/license/biosimulators/Biosimulators_BioNetGen?badges-awesome-green.svg)](https://github.com/biosimulators/Biosimulators_BioNetGen/blob/dev/LICENSE)
[![CI status](https://github.com/biosimulators/Biosimulators_BioNetGen/workflows/Continuous%20integration/badge.svg)](https://github.com/biosimulators/Biosimulators_BioNetGen/actions?query=workflow%3A%22Continuous+integration%22)
[![Test coverage](https://codecov.io/gh/biosimulators/Biosimulators_BioNetGen/branch/dev/graph/badge.svg)](https://codecov.io/gh/biosimulators/Biosimulators_BioNetGen)

# BioSimulators-BioNetGen
BioSimulators-compliant command-line interface and Docker image for the [BioNetGen](https://bionetgen.org/) simulation program.
Expand Down
2 changes: 1 addition & 1 deletion biosimulators_bionetgen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._version import __version__ # noqa: F401
# :obj:`str`: version

from .core import exec_combine_archive # noqa: F401
from .core import exec_sedml_docs_in_combine_archive # noqa: F401
48 changes: 8 additions & 40 deletions biosimulators_bionetgen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,14 @@
:License: MIT
"""

from .core import exec_combine_archive
import biosimulators_bionetgen
import cement


class BaseController(cement.Controller):
""" Base controller for command line application """

class Meta:
label = 'base'
description = "BioSimulators-compliant command-line interface to the BioNetGen simulation program <https://bionetgen.org>."
help = "bionetgen"
arguments = [
(['-i', '--archive'], dict(type=str,
required=True,
help='Path to OMEX file which contains one or more SED-ML-encoded simulation experiments')),
(['-o', '--out-dir'], dict(type=str,
default='.',
help='Directory to save outputs')),
(['-v', '--version'], dict(action='version',
version=biosimulators_bionetgen.__version__)),
]

@cement.ex(hide=True)
def _default(self):
args = self.app.pargs
try:
exec_combine_archive(args.archive, args.out_dir)
except Exception as exception:
raise SystemExit(str(exception)) from exception


class App(cement.App):
""" Command line application """
class Meta:
label = 'bionetgen'
base_controller = 'base'
handlers = [
BaseController,
]
from ._version import __version__
from .core import get_bionetgen_version, exec_sedml_docs_in_combine_archive
from biosimulators_utils.simulator.cli import build_cli
import subprocess

App = build_cli('bionetgen', __version__,
'BioNetGen', get_bionetgen_version(), 'https://bionetgen.org',
exec_sedml_docs_in_combine_archive)


def main():
Expand Down
43 changes: 21 additions & 22 deletions biosimulators_bionetgen/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,42 @@
:License: MIT
"""

from Biosimulations_utils.biomodel.data_model import BiomodelVariable # noqa: F401
from Biosimulations_utils.simulation.data_model import TimecourseSimulation, SimulationResultsFormat
from Biosimulations_utils.simulator.utils import exec_simulations_in_archive
from biosimulations_utils.biomodel.data_model import BiomodelVariable # noqa: F401
from biosimulators_utils import TimecourseSimulation, TimecourseSimulationexec_sed_tasks_in_combine_archive
import os
import pandas
import re
import shutil
import subprocess
import tempfile

__all__ = ['exec_combine_archive', 'BioNetGenSimulationRunner']
__all__ = ['get_bionetgen_version', 'exec_sedml_docs_in_combine_archive', 'BioNetGenSimulationRunner']


def exec_combine_archive(archive_file, out_dir):
BIONETGEN_PATH = os.getenv(BIONETGEN_PATH, 'BNG2.pl')


def get_bionetgen_version():
""" Get the version of BioNetGen
Returns:
:obj:`str`: version
"""
return subprocess.check_output([BIONETGEN_PATH, '--version']).decode().strip().split(' ')[2]


def exec_sedml_docs_in_combine_archive(archive_file, out_dir):
""" Execute the SED tasks defined in a COMBINE archive and save the outputs
Args:
archive_file (:obj:`str`): path to COMBINE archive
out_dir (:obj:`str`): directory to store the outputs of the tasks
"""
exec_simulations_in_archive(archive_file, BioNetGenSimulationRunner().run, out_dir)
exec_sed_tasks_in_combine_archive(archive_file, BioNetGenSimulationRunner().run, out_dir)


class BioNetGenSimulationRunner(object):
def run(self, model_filename, model_sed_urn, simulation, working_dir, out_filename, out_format):
def run(self, model_filename, model_sed_urn, simulation, working_dir, out_filename):
""" Execute a simulation and save its results
Args:
Expand All @@ -40,7 +51,6 @@ def run(self, model_filename, model_sed_urn, simulation, working_dir, out_filena
simulation (:obj:`TimecourseSimulation`): simulation
working_dir (:obj:`str`): directory of the SED-ML file
out_filename (:obj:`str`): path to save the results of the simulation
out_format (:obj:`SimulationResultsFormat`): format to save the results of the simulation (e.g., `HDF5`)
"""
# check that model is encoded in BGNL
if model_sed_urn != "urn:sedml:language:bngl":
Expand All @@ -50,10 +60,6 @@ def run(self, model_filename, model_sed_urn, simulation, working_dir, out_filena
if not isinstance(simulation, TimecourseSimulation):
raise NotImplementedError('{} is not supported'.format(simulation.__class__.__name__))

# check that the desired output format is supported
if out_format != SimulationResultsFormat.HDF5:
raise NotImplementedError("Simulation results format '{}' is not supported".format(out_format))

# read the model from the BNGL file
model_lines = self.read_model(model_filename, model_sed_urn)

Expand All @@ -70,11 +76,11 @@ def run(self, model_filename, model_sed_urn, simulation, working_dir, out_filena
out_dir = tempfile.mkdtemp()

# simulate the modified model
subprocess.check_call(['BNG2.pl', modified_model_filename, '--outdir', out_dir])
subprocess.check_call([BIONETGEN_PATH, modified_model_filename, '--outdir', out_dir])

# put files into output path
gdat_results_filename = os.path.join(out_dir, os.path.splitext(os.path.basename(modified_model_filename))[0] + '.gdat')
self.convert_simulation_results(gdat_results_filename, out_filename, out_format)
self.convert_simulation_results(gdat_results_filename, out_filename)

# cleanup temporary files
os.remove(modified_model_filename)
Expand Down Expand Up @@ -348,24 +354,17 @@ def replace_model_block(self, model_lines, i_old_block_start, i_old_block_end, n
+ new_block_lines \
+ model_lines[i_old_block_end:]

def convert_simulation_results(self, gdat_filename, out_filename, out_format):
def convert_simulation_results(self, gdat_filename, out_filename):
""" Convert simulation results from gdat to the desired output format
Args:
gdat_filename (:obj:`str`): path to simulation results in gdat format
out_filename (:obj:`str`): path to save the results of the simulation
out_format (:obj:`str`): format to save the results of the simulation (e.g., `csv`)
Raises:
:obj:`NotImplementedError`: if the desired output format is not supported
"""
data = self.read_simulation_results(gdat_filename)
if out_format == 'csv':
data.to_csv(out_filename)
elif out_format == 'tsv':
data.to_csv(out_filename, sep='\t')
else:
raise NotImplementedError('Unsupported output format {}'.format(out_format))

def read_simulation_results(self, gdat_filename):
""" Read the results of a simulation
Expand Down
2 changes: 1 addition & 1 deletion docs-src/about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ About BioSimulators-BioNetGen

License
-------
This package is released under the `MIT License <https://github.com/biosimulators/BioSimulators_BioNetGen/blob/dev/LICENSE>`_. BioNetGen is released under the `MIT License <https://github.com/RuleWorld/bionetgen/blob/master/LICENSE>`_.
This package is released under the `MIT License <https://github.com/biosimulators/Biosimulators_BioNetGen/blob/dev/LICENSE>`_. BioNetGen is released under the `MIT License <https://github.com/RuleWorld/bionetgen/blob/master/LICENSE>`_.

Development team
----------------
Expand Down
4 changes: 2 additions & 2 deletions docs-src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

# -- Project information -----------------------------------------------------
source_base_url = 'https://github.com/biosimulators/BioSimulators_BioNetGen/blob/dev/'
source_base_url = 'https://github.com/biosimulators/Biosimulators_BioNetGen/blob/dev/'
project = 'BioSimulators-BioNetGen'
copyright = '{}, BioSimulators Team'.format(datetime.datetime.now().year)
author = 'BioSimulators Team'
Expand Down Expand Up @@ -103,7 +103,7 @@ def linkcode_resolve(domain, info):

html_theme_options = {
'github_user': 'biosimulators',
'github_repo': 'BioSimulators_BioNetGen',
'github_repo': 'Biosimulators_BioNetGen',
'github_banner': True,
'github_button': True,
'description': 'BioSimulators-compliant interface to BioNetGen',
Expand Down
2 changes: 1 addition & 1 deletion docs-src/installation.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Installation instructions
=========================

BioSimulators-BioNetGen is available as command-line program and as a command-line program encapsulated into a Docker image.
BioSimulators-BioNetGen is available as a command-line program and as a command-line program encapsulated into a Docker image.

Command-line program
--------------------
Expand Down
2 changes: 1 addition & 1 deletion docs-src/tutorial.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Tutorial
========

BioSimulators-BioNetGen is available as command-line program and as a command-line program encapsulated into a Docker image.
BioSimulators-BioNetGen is available as a command-line program and as a command-line program encapsulated into a Docker image.


Creating COMBINE/OMEX archives and encoding simulation experiments into SED-ML
Expand Down
2 changes: 1 addition & 1 deletion requirements.optional.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[test-docker]
Biosimulations_utils[docker]
biosimulations_utils[docker]
docker
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
Biosimulations_utils
cement
biosimulations_utils
pandas
2 changes: 1 addition & 1 deletion tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from biosimulators_bionetgen import __main__
from unittest import mock
try:
from Biosimulations_utils.simulator.testing import SimulatorValidator
from biosimulations_utils.simulator.testing import SimulatorValidator
except ModuleNotFoundError:
pass
import biosimulators_bionetgen
Expand Down

0 comments on commit ff1a9d1

Please sign in to comment.