Skip to content

Commit

Permalink
Merge pull request #183 from PEtab-dev/release_0.1.30
Browse files Browse the repository at this point in the history
Release 0.1.30
  • Loading branch information
dweindl authored Oct 13, 2022
2 parents ff1bdde + 23bc37a commit 2ba5c52
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 112 deletions.
11 changes: 0 additions & 11 deletions .ci_pip_reqs.txt

This file was deleted.

13 changes: 5 additions & 8 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install -r .ci_pip_reqs.txt
pip install .[reports,combine,tests]
pip install -r requirements-dev.txt
- name: Run flake8
run: |
python -m flake8
- name: Quality tests
run: tox -e quality
if: matrix.platform == 'ubuntu-latest'

- name: Run tests
run: |
pytest --cov --cov-report=xml tests
- name: Unit tests
run: tox -e unit

- name: Coverage
uses: codecov/codecov-action@v1
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@

## 0.1 series

### 0.1.30

Various smaller fixes:

* Vis: Handle missing data more gracefully by @dweindl
in https://github.com/PEtab-dev/libpetab-python/pull/175
* Fix test dependencies: scipy by @dweindl
in https://github.com/PEtab-dev/libpetab-python/pull/177
* Add `petab.Problem.__str__` by @dweindl
in https://github.com/PEtab-dev/libpetab-python/pull/178
* Fix deprecated tight layout matplotlib by @yannikschaelte
in https://github.com/PEtab-dev/libpetab-python/pull/180
* Move tests to tox by @yannikschaelte
in https://github.com/PEtab-dev/libpetab-python/pull/182
* Update deprecated functions in tests by @yannikschaelte
in https://github.com/PEtab-dev/libpetab-python/pull/181
* Use petab identifier for combine archives by @fbergmann
in https://github.com/PEtab-dev/libpetab-python/pull/179

New Contributors
* @fbergmann made their first contribution
in https://github.com/PEtab-dev/libpetab-python/pull/179

**Full Changelog**:
https://github.com/PEtab-dev/libpetab-python/compare/v0.1.29...v0.1.30

### 0.1.29

Features:
Expand Down
2 changes: 1 addition & 1 deletion petab/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def _add_file_metadata(location: str, description: str = ""):
archive.addFile(
str(yaml_file),
os.path.basename(yaml_file),
libcombine.KnownFormats.lookupFormat("yaml"),
"http://identifiers.org/combine.specifications/petab.version-1",
True
)
_add_file_metadata(location=os.path.basename(yaml_file),
Expand Down
27 changes: 26 additions & 1 deletion petab/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,31 @@ def __setattr__(self, name, value):
else:
super().__setattr__(name, value)

def __str__(self):
model = f"with model ({self.model})" if self.model else "without model"
conditions = f"{self.condition_df.shape[0]} conditions" \
if self.condition_df is not None else "without conditions table"

observables = f"{self.observable_df.shape[0]} observables" \
if self.observable_df is not None else "without observables table"

measurements = f"{self.measurement_df.shape[0]} measurements" \
if self.measurement_df is not None \
else "without measurements table"

if self.parameter_df is not None:
num_estimated_parameters = sum(self.parameter_df[ESTIMATE] == 1) \
if ESTIMATE in self.parameter_df \
else self.parameter_df.shape[0]
parameters = f"{num_estimated_parameters} estimated parameters"
else:
parameters = "without parameter_df table"

return (
f"PEtab Problem {model}, {conditions}, {observables}, "
f"{measurements}, {parameters}"
)

@staticmethod
def from_files(
sbml_file: Union[str, Path] = None,
Expand Down Expand Up @@ -386,7 +411,7 @@ def to_files(
visualization tables, they will be merged and written to a single file.
Arguments:
sbml_file: SBML model destination
sbml_file: SBML model destination (deprecated)
model_file: Model destination
condition_file: Condition table destination
measurement_file: Measurement table destination
Expand Down
2 changes: 1 addition & 1 deletion petab/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""PEtab library version"""
__version__ = '0.1.29'
__version__ = '0.1.30'
13 changes: 9 additions & 4 deletions petab/visualize/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def generate_lineplot(

label_base = dataplot.legendEntry

if measurements_to_plot is not None:
if measurements_to_plot is not None \
and not measurements_to_plot.data_to_plot.empty:
# plotting all measurement data

if plotTypeData == REPLICATE:
Expand Down Expand Up @@ -361,7 +362,7 @@ def generate_figure(

fig, axes = plt.subplots(num_row, num_col, squeeze=False,
figsize=self.figure.size)
fig.set_tight_layout(True)
fig.set_layout_engine("tight")

for ax in axes.flat[self.figure.num_subplots:]:
ax.remove()
Expand All @@ -372,11 +373,15 @@ def generate_figure(
for subplot in self.figure.subplots:
if subplot_dir is not None:
fig, ax = plt.subplots(figsize=self.figure.size)
fig.set_tight_layout(True)
fig.set_layout_engine("tight")
else:
ax = axes[subplot.plotId]

self.generate_subplot(ax, subplot)
try:
self.generate_subplot(ax, subplot)
except Exception as e:
raise RuntimeError(
f"Error plotting {getattr(subplot, PLOT_ID)}.") from e

if subplot_dir is not None:
# TODO: why this doesn't work?
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tox >= 3.26.0
118 changes: 64 additions & 54 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ def read(fname):
def absolute_links(txt):
"""Replace relative petab github links by absolute links."""

raw_base = "(https://raw.githubusercontent.com/"\
"petab-dev/libpetab-python/master/"
embedded_base = "(https://github.com/petab-dev/libpetab-python/"\
"tree/master/"
raw_base = \
"(https://raw.githubusercontent.com/petab-dev/libpetab-python/master/"
embedded_base = \
"(https://github.com/petab-dev/libpetab-python/tree/master/"
# iterate over links
for var in re.findall(r'\[.*?\]\((?!http).*?\)', txt):
if re.match(r'.*?.(png|svg)\)', var):
for var in re.findall(r"\[.*?\]\((?!http).*?\)", txt):
if re.match(r".*?.(png|svg)\)", var):
# link to raw file
rep = var.replace("(", raw_base)
else:
Expand All @@ -30,62 +30,72 @@ def absolute_links(txt):

# Python version check. We need >= 3.6 due to e.g. f-strings
if sys.version_info < (3, 8, 0):
sys.exit('PEtab requires at least Python version 3.8')
sys.exit("PEtab requires at least Python version 3.8")

# read version from file
__version__ = ''
version_file = os.path.join('petab', 'version.py')
__version__ = ""
version_file = os.path.join("petab", "version.py")
# sets __version__
exec(read(version_file)) # pylint: disable=W0122 # nosec

ENTRY_POINTS = {
'console_scripts': [
'petablint = petab.petablint:main',
'petab_visualize = petab.visualize.cli:_petab_visualize_main',
"console_scripts": [
"petablint = petab.petablint:main",
"petab_visualize = petab.visualize.cli:_petab_visualize_main",
]
}

# project metadata
# noinspection PyUnresolvedReferences
setup(name='petab',
version=__version__,
description='Parameter estimation tabular data',
long_description=absolute_links(read('README.md')),
long_description_content_type="text/markdown",
author='The PEtab developers',
author_email='daniel.weindl@helmholtz-muenchen.de',
url='https://github.com/PEtab-dev/libpetab-python',
packages=find_packages(exclude=['doc*', 'test*']),
install_requires=['numpy>=1.15.1',
'pandas>=1.2.0',
'matplotlib>=3.5.0',
'python-libsbml>=5.17.0',
'sympy',
'colorama',
'seaborn',
'pyyaml',
'jsonschema',
],
include_package_data=True,
python_requires='>=3.8.0',
entry_points=ENTRY_POINTS,
extras_require={
'tests': [
'flake8',
'pytest',
'python-libcombine',
'simplesbml'
],
'reports': ['Jinja2'],
'combine': ['python-libcombine>=0.2.6'],
'doc': [
'sphinx>=3.5.3, !=5.1.0',
'sphinxcontrib-napoleon>=0.7',
'sphinx-markdown-tables>=0.0.15',
'sphinx-rtd-theme>=0.5.1',
'm2r2',
'myst-nb>=0.14.0',
'ipython>=7.21.0',
]
}
)
setup(
name="petab",
version=__version__,
description="Parameter estimation tabular data",
long_description=absolute_links(read("README.md")),
long_description_content_type="text/markdown",
author="The PEtab developers",
author_email="daniel.weindl@helmholtz-muenchen.de",
url="https://github.com/PEtab-dev/libpetab-python",
packages=find_packages(exclude=["doc*", "test*"]),
install_requires=[
"numpy>=1.15.1",
"pandas>=1.2.0",
"matplotlib>=3.6.0",
"python-libsbml>=5.17.0",
"sympy",
"colorama",
"seaborn",
"pyyaml",
"jsonschema",
],
include_package_data=True,
python_requires=">=3.8.0",
entry_points=ENTRY_POINTS,
extras_require={
"tests": [
"pytest",
"pytest-cov",
"simplesbml",
"scipy",
],
"quality": [
"flake8>=3.8.3",
],
"reports": [
# https://github.com/spatialaudio/nbsphinx/issues/641
"Jinja2==3.0.3",
],
"combine": [
"python-libcombine>=0.2.6",
],
"doc": [
"sphinx>=3.5.3, !=5.1.0",
"sphinxcontrib-napoleon>=0.7",
"sphinx-markdown-tables>=0.0.15",
"sphinx-rtd-theme>=0.5.1",
"m2r2",
"myst-nb>=0.14.0",
"ipython>=7.21.0",
],
},
)
58 changes: 58 additions & 0 deletions tests/test_deprecated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Check that deprecated functionality raises but still works."""
import pytest
import tempfile
from pathlib import Path

import petab

from .test_sbml import create_test_data, check_model
from .test_petab import petab_problem # noqa: F401


def test_problem_with_sbml_model():
"""Test that a problem can be correctly created from sbml model."""
# retrieve test data
ss_model, condition_df, observable_df, measurement_df, parameter_df = \
create_test_data()

with pytest.deprecated_call():
petab_problem = petab.Problem( # noqa: F811
sbml_model=ss_model.model,
condition_df=condition_df,
measurement_df=measurement_df,
parameter_df=parameter_df,
)

_, condition_model = petab.get_model_for_condition(
petab_problem, "condition_1")

check_model(condition_model)


def test_to_files_with_sbml_model(petab_problem): # noqa: F811
"""Test problem.to_files."""
with tempfile.TemporaryDirectory() as outdir:
# create target files
sbml_file = Path(outdir, "model.xml")
condition_file = Path(outdir, "conditions.tsv")
measurement_file = Path(outdir, "measurements.tsv")
parameter_file = Path(outdir, "parameters.tsv")
observable_file = Path(outdir, "observables.tsv")

# write contents to files
with pytest.deprecated_call():
petab_problem.to_files(
sbml_file=sbml_file,
condition_file=condition_file,
measurement_file=measurement_file,
parameter_file=parameter_file,
visualization_file=None,
observable_file=observable_file,
yaml_file=None,
)

# exemplarily load some
parameter_df = petab.get_parameter_df(parameter_file)
same_nans = parameter_df.isna() == petab_problem.parameter_df.isna()
assert ((parameter_df == petab_problem.parameter_df) | same_nans) \
.all().all()
Loading

0 comments on commit 2ba5c52

Please sign in to comment.