From 1f7ade43d6195baf1ce8e8eaad199c4f1c3f13ab Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 22 Mar 2021 15:08:39 +0100 Subject: [PATCH 1/6] Parameter mapping: Add option to ignore time-point specific noiseParameters (#51) Parameter mapping: Add option to ignore time-point specific noiseParameters... ... in case those are fixed values and noiseFormula consists only of one single parameter. --- petab/lint.py | 5 ++- petab/parameter_mapping.py | 70 +++++++++++++++++++++++++++++++------- petab/problem.py | 12 +++++-- 3 files changed, 70 insertions(+), 17 deletions(-) diff --git a/petab/lint.py b/petab/lint.py index 9ef3c646..63620fc5 100644 --- a/petab/lint.py +++ b/petab/lint.py @@ -558,10 +558,10 @@ def measurement_table_has_timepoint_specific_mappings( PEtab measurement table allow_scalar_numeric_noise_parameters: - ignore scalar numeric assignments to noiseParamater placeholders + ignore scalar numeric assignments to noiseParameter placeholders allow_scalar_numeric_observable_parameters: - ignore scalar numeric assignments to observableParamater + ignore scalar numeric assignments to observableParameter placeholders Returns: @@ -601,7 +601,6 @@ def measurement_table_has_timepoint_specific_mappings( SIMULATION_CONDITION_ID, PREEQUILIBRATION_CONDITION_ID]) grouped_df2 = measurement_df.groupby(grouping_cols) - # data frame has timepoint specific overrides if grouping by noise # parameters and observable parameters in addition to observable, # condition and preeq id yields more groups diff --git a/petab/parameter_mapping.py b/petab/parameter_mapping.py index 91d6b87c..6e4b99b9 100644 --- a/petab/parameter_mapping.py +++ b/petab/parameter_mapping.py @@ -42,6 +42,7 @@ def get_optimization_to_simulation_parameter_mapping( warn_unmapped: Optional[bool] = True, scaled_parameters: bool = False, fill_fixed_parameters: bool = True, + allow_timepoint_specific_numeric_noise_parameters: bool = False ) -> List[ParMappingDictQuadruple]: """ Create list of mapping dicts from PEtab-problem to SBML parameters. @@ -65,6 +66,13 @@ def get_optimization_to_simulation_parameter_mapping( fill_fixed_parameters: Whether to fill in nominal values for fixed parameters (estimate=0 in parameters table). + allow_timepoint_specific_numeric_noise_parameters: + Mapping of timepoint-specific parameters overrides is generally + not supported. If this option is set to True, this function will + not fail in case of timepoint-specific fixed noise parameters, + if the noise formula consists only of one single parameter. + It is expected that the respective mapping is performed elsewhere. + The value mapped to the respective parameter here is undefined. Returns: Parameter value and parameter scale mapping for all conditions. @@ -84,7 +92,10 @@ def get_optimization_to_simulation_parameter_mapping( """ # Ensure inputs are okay - _perform_mapping_checks(measurement_df) + _perform_mapping_checks( + measurement_df, + allow_timepoint_specific_numeric_noise_parameters= # noqa: E251,E501 + allow_timepoint_specific_numeric_noise_parameters) if simulation_conditions is None: simulation_conditions = measurements.get_simulation_conditions( @@ -109,7 +120,8 @@ def get_optimization_to_simulation_parameter_mapping( _map_condition_arg_packer( simulation_conditions, measurement_df, condition_df, parameter_df, sbml_model, simulation_parameters, warn_unmapped, - scaled_parameters, fill_fixed_parameters)) + scaled_parameters, fill_fixed_parameters, + allow_timepoint_specific_numeric_noise_parameters)) return list(mapping) # Run multi-threaded @@ -120,19 +132,29 @@ def get_optimization_to_simulation_parameter_mapping( _map_condition_arg_packer( simulation_conditions, measurement_df, condition_df, parameter_df, sbml_model, simulation_parameters, warn_unmapped, - scaled_parameters, fill_fixed_parameters)) + scaled_parameters, fill_fixed_parameters, + allow_timepoint_specific_numeric_noise_parameters)) return list(mapping) -def _map_condition_arg_packer(simulation_conditions, measurement_df, - condition_df, parameter_df, sbml_model, - simulation_parameters, warn_unmapped, - scaled_parameters, fill_fixed_parameters): +def _map_condition_arg_packer( + simulation_conditions, + measurement_df, + condition_df, + parameter_df, + sbml_model, + simulation_parameters, + warn_unmapped, + scaled_parameters, + fill_fixed_parameters, + allow_timepoint_specific_numeric_noise_parameters +): """Helper function to pack extra arguments for _map_condition""" for _, condition in simulation_conditions.iterrows(): yield(condition, measurement_df, condition_df, parameter_df, sbml_model, simulation_parameters, warn_unmapped, - scaled_parameters, fill_fixed_parameters) + scaled_parameters, fill_fixed_parameters, + allow_timepoint_specific_numeric_noise_parameters) def _map_condition(packed_args): @@ -142,7 +164,8 @@ def _map_condition(packed_args): (condition, measurement_df, condition_df, parameter_df, sbml_model, simulation_parameters, warn_unmapped, scaled_parameters, - fill_fixed_parameters) = packed_args + fill_fixed_parameters, + allow_timepoint_specific_numeric_noise_parameters) = packed_args cur_measurement_df = measurements.get_rows_for_condition( measurement_df, condition) @@ -164,6 +187,8 @@ def _map_condition(packed_args): warn_unmapped=warn_unmapped, scaled_parameters=scaled_parameters, fill_fixed_parameters=fill_fixed_parameters, + allow_timepoint_specific_numeric_noise_parameters= # noqa: E251,E501 + allow_timepoint_specific_numeric_noise_parameters ) par_map_sim, scale_map_sim = get_parameter_mapping_for_condition( @@ -177,6 +202,8 @@ def _map_condition(packed_args): warn_unmapped=warn_unmapped, scaled_parameters=scaled_parameters, fill_fixed_parameters=fill_fixed_parameters, + allow_timepoint_specific_numeric_noise_parameters= # noqa: E251,E501 + allow_timepoint_specific_numeric_noise_parameters ) return par_map_preeq, par_map_sim, scale_map_preeq, scale_map_sim @@ -193,6 +220,7 @@ def get_parameter_mapping_for_condition( warn_unmapped: bool = True, scaled_parameters: bool = False, fill_fixed_parameters: bool = True, + allow_timepoint_specific_numeric_noise_parameters: bool = False, ) -> Tuple[ParMappingDict, ScaleMappingDict]: """ Create dictionary of parameter value and parameter scale mappings from @@ -218,9 +246,18 @@ def get_parameter_mapping_for_condition( Optional, saves time if precomputed. warn_unmapped: If ``True``, log warning regarding unmapped parameters + scaled_parameters: + Whether parameter values should be scaled. fill_fixed_parameters: Whether to fill in nominal values for fixed parameters (estimate=0 in parameters table). + allow_timepoint_specific_numeric_noise_parameters: + Mapping of timepoint-specific parameters overrides is generally + not supported. If this option is set to True, this function will + not fail in case of timepoint-specific fixed noise parameters, + if the noise formula consists only of one single parameter. + It is expected that the respective mapping is performed elsewhere. + The value mapped to the respective parameter here is undefined. Returns: Tuple of two dictionaries. First dictionary mapping model parameter IDs @@ -229,7 +266,10 @@ def get_parameter_mapping_for_condition( Second dictionary mapping model parameter IDs to their scale. NaN is used where no mapping exists. """ - _perform_mapping_checks(cur_measurement_df) + _perform_mapping_checks( + cur_measurement_df, + allow_timepoint_specific_numeric_noise_parameters= # noqa: E251,E501 + allow_timepoint_specific_numeric_noise_parameters) if simulation_parameters is None: simulation_parameters = sbml.get_model_parameters(sbml_model, @@ -426,11 +466,17 @@ def _apply_parameter_table(par_mapping: ParMappingDict, scale_mapping[problem_par] = scale -def _perform_mapping_checks(measurement_df: pd.DataFrame) -> None: +def _perform_mapping_checks( + measurement_df: pd.DataFrame, + allow_timepoint_specific_numeric_noise_parameters: bool = False +) -> None: """Check for PEtab features which we can't account for during parameter mapping.""" - if lint.measurement_table_has_timepoint_specific_mappings(measurement_df): + if lint.measurement_table_has_timepoint_specific_mappings( + measurement_df, + allow_scalar_numeric_noise_parameters= # noqa: E251,E501 + allow_timepoint_specific_numeric_noise_parameters): # we could allow that for floats, since they don't matter in this # function and would be simply ignored raise ValueError( diff --git a/petab/problem.py b/petab/problem.py index 68658882..57f27bad 100644 --- a/petab/problem.py +++ b/petab/problem.py @@ -608,7 +608,12 @@ def get_simulation_conditions_from_measurement_df(self): return measurements.get_simulation_conditions(self.measurement_df) def get_optimization_to_simulation_parameter_mapping( - self, warn_unmapped: bool = True, scaled_parameters: bool = False): + self, + warn_unmapped: bool = True, + scaled_parameters: bool = False, + allow_timepoint_specific_numeric_noise_parameters: + bool = False, + ): """ See get_simulation_to_optimization_parameter_mapping. """ @@ -620,7 +625,10 @@ def get_optimization_to_simulation_parameter_mapping( self.observable_df, self.sbml_model, warn_unmapped=warn_unmapped, - scaled_parameters=scaled_parameters) + scaled_parameters=scaled_parameters, + allow_timepoint_specific_numeric_noise_parameters= # noqa: E251,E501 + allow_timepoint_specific_numeric_noise_parameters + ) def create_parameter_df(self, *args, **kwargs): """Create a new PEtab parameter table From eb893c62974252361b8ce729c7962239ba1afc66 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 22 Mar 2021 20:53:20 +0100 Subject: [PATCH 2/6] Doc: Cleanup RTD config (#52) * Add .readthedocs.yaml * petab * add_stylesheet * ipython * rm doc/editorial_board.rst * excludes * link all examples * set dep versions * fix docstring * ignore numpy warnings * fix docstring * ignore recommonmark warnings * Fix collections.Counter issues * move deps to setup.py * py38 --- .readthedocs.yaml | 17 +++++++++++++++++ .rtd_pip_reqs.txt | 7 ------- doc/conf.py | 39 ++++++++++++++++++++++++++++++++------- doc/editorial_board.rst | 28 ---------------------------- doc/example.rst | 2 ++ petab/lint.py | 1 + petab/observables.py | 2 +- petab/sbml.py | 9 +++++---- setup.py | 16 ++++++++++++++-- 9 files changed, 72 insertions(+), 49 deletions(-) create mode 100644 .readthedocs.yaml delete mode 100644 .rtd_pip_reqs.txt delete mode 100644 doc/editorial_board.rst diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 00000000..7103d3df --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,17 @@ +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +version: 2 + +sphinx: + configuration: doc/conf.py + fail_on_warning: true + + +python: + version: 3.8 + install: + - method: pip + path: . + extra_requirements: + - doc diff --git a/.rtd_pip_reqs.txt b/.rtd_pip_reqs.txt deleted file mode 100644 index b496f95f..00000000 --- a/.rtd_pip_reqs.txt +++ /dev/null @@ -1,7 +0,0 @@ -sphinx -sphinxcontrib-napoleon -sphinx-markdown-tables -sphinx-rtd-theme -recommonmark -nbsphinx -m2r diff --git a/doc/conf.py b/doc/conf.py index e7ead109..a28acf69 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -4,20 +4,23 @@ # list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html +import os +import subprocess +import sys +import warnings + # -- Path setup -------------------------------------------------------------- # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # -import os -import sys sys.path.insert(0, os.path.abspath('..')) # -- Project information ----------------------------------------------------- project = 'PEtab' -copyright = '2018-2021, the PEtab developers' +copyright = '2018, the PEtab developers' author = 'PEtab developers' # The full version, including alpha/beta/rc tags @@ -25,7 +28,6 @@ # -- Custom pre-build -------------------------------------------------------- -import subprocess subprocess.run(['python', 'md2rst.py']) @@ -49,7 +51,12 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ['build/doctrees', 'build/html'] +exclude_patterns = [ + 'build/doctrees', + 'build/html', + '**.ipynb_checkpoints', + 'logo/LICENSE.md', +] master_doc = 'index' @@ -72,14 +79,21 @@ '.md': 'markdown', } +# ignore numpy warnings +warnings.filterwarnings("ignore", message="numpy.dtype size changed") +warnings.filterwarnings("ignore", message="numpy.ufunc size changed") +# ignore recommonmark warnings +# https://github.com/readthedocs/recommonmark/issues/177 +warnings.filterwarnings("ignore", + message="Container node skipped: type=document") + # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'sphinx_rtd_theme' -def setup(app): - app.add_stylesheet('custom.css') + # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". @@ -94,3 +108,14 @@ def setup(app): } html_logo = 'logo/PEtab.png' + + +def skip_some_objects(app, what, name, obj, skip, options): + """Exclude some objects from the documentation""" + if getattr(obj, '__module__', None) == 'collections': + return True + + +def setup(app): + """Sphinx setup""" + app.connect('autodoc-skip-member', skip_some_objects) diff --git a/doc/editorial_board.rst b/doc/editorial_board.rst deleted file mode 100644 index 6f5f2eea..00000000 --- a/doc/editorial_board.rst +++ /dev/null @@ -1,28 +0,0 @@ -Editorial board -=============== - -The development of PEtab is overseen by an editorial board. The editorial board -is elected by the PEtab community as described on the -:ref:`PEtab development ` page. - -The current board members are: - -.. |JH| image:: https://avatars.githubusercontent.com/u/12297214?s=128 - -.. |DW| image:: https://avatars.githubusercontent.com/u/18048784?s=128 - -.. |FB| image:: https://avatars.githubusercontent.com/u/949059?s=128 - -.. |SK| image:: https://avatars.githubusercontent.com/u/18700932?s=128 - -.. |FF| image:: https://avatars.githubusercontent.com/u/14923969?s=128 - -+--------------------+-------------------------+--------------------------+------------------------+------------------------+ -| |JH| | |DW| | |FB| | |SK| | |FF| | -| | | | | | -| Jan Hasenauer | Daniel Weindl | Frank Bergmann | Svenja Kemmer | Fabian Fröhlich | -| | | | | | -| University of Bonn | Helmholtz Centre Munich | University of Heidelberg | University of Freiburg | Harvard Medical School | -| | | | | | -| 2021-2024 | 2021-2024 | 2021-2023 | 2021-2023 | 2021-2022 | -+--------------------+-------------------------+--------------------------+------------------------+------------------------+ diff --git a/doc/example.rst b/doc/example.rst index 6fe6dab5..f3383103 100644 --- a/doc/example.rst +++ b/doc/example.rst @@ -10,6 +10,8 @@ The following examples should help to get a better idea of how to use the PEtab example/example_petablint.ipynb example/example_visualization.ipynb + example/example_visualization_without_visspec.ipynb + example/example_visualization_with_visspec.ipynb Examples of systems biology parameter estimation problems specified in PEtab can be found in the `systems biology benchmark model collection `_. diff --git a/petab/lint.py b/petab/lint.py index 63620fc5..b32f6c02 100644 --- a/petab/lint.py +++ b/petab/lint.py @@ -530,6 +530,7 @@ def is_scalar_float(x: Any): """ Checks whether input is a number or can be transformed into a number via float + :param x: input :return: diff --git a/petab/observables.py b/petab/observables.py index 54653020..bf181d2c 100644 --- a/petab/observables.py +++ b/petab/observables.py @@ -1,6 +1,6 @@ """Functions for working with the PEtab observables table""" -from _collections import OrderedDict +from collections import OrderedDict from typing import Union, List import libsbml diff --git a/petab/sbml.py b/petab/sbml.py index 7ba26e6d..266d5f54 100644 --- a/petab/sbml.py +++ b/petab/sbml.py @@ -380,10 +380,11 @@ def get_model_parameters(sbml_model: libsbml.Model, with_values=False Arguments: sbml_model: SBML model - with_values: If false, returns list of SBML model parameter IDs which - are not AssignmentRule targets for observables or sigmas. If true, - returns a dictionary with those parameter IDs as keys and parameter - values from the SBML model as values. + with_values: + If False, returns list of SBML model parameter IDs which + are not AssignmentRule targets for observables or sigmas. If True, + returns a dictionary with those parameter IDs as keys and parameter + values from the SBML model as values. """ if not with_values: return [p.getId() for p in sbml_model.getListOfParameters() diff --git a/setup.py b/setup.py index f3779ba1..af3fe9d0 100644 --- a/setup.py +++ b/setup.py @@ -69,6 +69,18 @@ def absolute_links(txt): tests_require=['flake8', 'pytest', 'python-libcombine'], python_requires='>=3.7.1', entry_points=ENTRY_POINTS, - extras_require={'reports': ['Jinja2'], - 'combine': ['python-libcombine>=0.2.6']}, + extras_require={ + 'reports': ['Jinja2'], + 'combine': ['python-libcombine>=0.2.6'], + 'doc': [ + 'sphinx>=3.5.3', + 'sphinxcontrib-napoleon>=0.7', + 'sphinx-markdown-tables>=0.0.15', + 'sphinx-rtd-theme>=0.5.1', + 'recommonmark>=0.7.1', + 'nbsphinx>=0.8.2', + 'm2r>=0.2.1', + 'ipython>=7.21.0', + ] + } ) From fd0d1aa154b97cdb57e693e4e0590c4c976020b9 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 22 Mar 2021 22:47:21 +0100 Subject: [PATCH 3/6] Doc: Cleanup / fixup (#53) * Doc: Intersphinx and source references * some docstring fixes * fix some more * sphinx-autodoc-typehints * Revert "sphinx-autodoc-typehints" This reverts commit 997f07fc8494347daef6468a70d69513b4e047f4. --- doc/conf.py | 11 ++++++++++- petab/composite_problem.py | 2 +- petab/conditions.py | 4 ++-- petab/core.py | 3 ++- petab/lint.py | 6 +++--- petab/parameter_mapping.py | 33 +++++++++++++++++++-------------- petab/parameters.py | 6 ++---- petab/problem.py | 24 +++++++++++++----------- 8 files changed, 52 insertions(+), 37 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index a28acf69..84810a47 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -39,12 +39,21 @@ extensions = [ 'sphinx.ext.napoleon', 'sphinx.ext.autodoc', - 'recommonmark', 'sphinx.ext.autosummary', + 'sphinx.ext.intersphinx', + 'sphinx.ext.viewcode', + 'recommonmark', 'sphinx_markdown_tables', 'nbsphinx', ] +intersphinx_mapping = { + 'pandas': ('https://pandas.pydata.org/docs/', None), + 'numpy': ('https://numpy.org/devdocs/', None), + 'sympy': ('https://docs.sympy.org/latest/', None), + 'python': ('https://docs.python.org/3', None), +} + # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] diff --git a/petab/composite_problem.py b/petab/composite_problem.py index eb490a2f..ab08d314 100644 --- a/petab/composite_problem.py +++ b/petab/composite_problem.py @@ -15,7 +15,7 @@ class CompositeProblem: Attributes: problems: - List ``petab.Problems`` + List of :py:class:`petab.Problem` s parameter_df: PEtab parameter DataFrame """ diff --git a/petab/conditions.py b/petab/conditions.py index ffaca423..f0b0918c 100644 --- a/petab/conditions.py +++ b/petab/conditions.py @@ -61,8 +61,8 @@ def create_condition_df(parameter_ids: Iterable[str], parameter_ids: the columns condition_ids: the rows Returns: - A ``pandas.DataFrame`` with empty given rows and columns and all nan - values + A :py:class:`pandas.DataFrame` with empty given rows and columns and + all nan values """ condition_ids = [] if condition_ids is None else list(condition_ids) diff --git a/petab/core.py b/petab/core.py index 215f7834..94a31780 100644 --- a/petab/core.py +++ b/petab/core.py @@ -355,7 +355,8 @@ def unique_preserve_order(seq: Sequence) -> List: """Return a list of unique elements in Sequence, keeping only the first occurrence of each element - seq: Sequence to prune + Parameters: + seq: Sequence to prune Returns: List of unique elements in ``seq`` diff --git a/petab/lint.py b/petab/lint.py index b32f6c02..8a7d6578 100644 --- a/petab/lint.py +++ b/petab/lint.py @@ -448,7 +448,7 @@ def assert_parameter_prior_type_is_valid( parameter_df: PEtab parameter table Raises: - AssertionError in case of invalid prior + AssertionError: in case of invalid prior """ for col in [INITIALIZATION_PRIOR_TYPE, OBJECTIVE_PRIOR_TYPE]: if col not in parameter_df.columns: @@ -468,7 +468,7 @@ def assert_parameter_prior_parameters_are_valid( parameter_df: PEtab parameter table Raises: - AssertionError in case of invalide prior parameters + AssertionError: in case of invalid prior parameters """ prior_type_cols = [INITIALIZATION_PRIOR_TYPE, OBJECTIVE_PRIOR_TYPE] @@ -534,7 +534,7 @@ def is_scalar_float(x: Any): :param x: input :return: - True if is or can be converted to number, False otherwise. + ``True`` if is or can be converted to number, ``False`` otherwise. """ if isinstance(x, numbers.Number): return True diff --git a/petab/parameter_mapping.py b/petab/parameter_mapping.py index 6e4b99b9..25b2ede9 100644 --- a/petab/parameter_mapping.py +++ b/petab/parameter_mapping.py @@ -48,7 +48,8 @@ def get_optimization_to_simulation_parameter_mapping( Create list of mapping dicts from PEtab-problem to SBML parameters. Mapping can be performed in parallel. The number of threads is controlled - by the environment variable with the name of petab.ENV_NUM_THREADS. + by the environment variable with the name of + :py:data:`petab.ENV_NUM_THREADS`. Parameters: condition_df, measurement_df, parameter_df, observable_df: @@ -78,9 +79,9 @@ def get_optimization_to_simulation_parameter_mapping( Parameter value and parameter scale mapping for all conditions. The length of the returned array is the number of unique combinations - of ``simulationConditionId``s and ``preequilibrationConditionId``s from - the measurement table. Each entry is a tuple of four dicts of length - equal to the number of model parameters. + of ``simulationConditionId`` s and ``preequilibrationConditionId`` s + from the measurement table. Each entry is a tuple of four dicts of + length equal to the number of model parameters. The first two dicts map simulation parameter IDs to optimization parameter IDs or values (where values are fixed) for preequilibration and simulation condition, respectively. @@ -160,7 +161,9 @@ def _map_condition_arg_packer( def _map_condition(packed_args): """Helper function for parallel condition mapping. - For arguments see get_optimization_to_simulation_parameter_mapping""" + For arguments see + :py:func:`get_optimization_to_simulation_parameter_mapping`. + """ (condition, measurement_df, condition_df, parameter_df, sbml_model, simulation_parameters, warn_unmapped, scaled_parameters, @@ -264,7 +267,7 @@ def get_parameter_mapping_for_condition( to mapped parameters IDs to be estimated or to filled-in values in case of non-estimated parameters. Second dictionary mapping model parameter IDs to their scale. - NaN is used where no mapping exists. + ``NaN`` is used where no mapping exists. """ _perform_mapping_checks( cur_measurement_df, @@ -323,7 +326,7 @@ def _apply_output_parameter_overrides( Arguments: mapping: parameter mapping dict as obtained from - ``get_parameter_mapping_for_condition`` + :py:func:`get_parameter_mapping_for_condition`. cur_measurement_df: Subset of the measurement table for the current condition """ @@ -376,7 +379,7 @@ def _apply_condition_parameters(par_mapping: ParMappingDict, table parameter values (in-place). Arguments: - par_mapping: see get_parameter_mapping_for_condition + par_mapping: see :py:func:`get_parameter_mapping_for_condition` condition_id: ID of condition to work on condition_df: PEtab condition table """ @@ -410,7 +413,8 @@ def _apply_parameter_table(par_mapping: ParMappingDict, Arguments: par_mapping: - mapping dict obtained from ``get_parameter_mapping_for_condition`` + mapping dict obtained from + :py:func:`get_parameter_mapping_for_condition` parameter_df: PEtab parameter table """ @@ -495,7 +499,7 @@ def handle_missing_overrides(mapping_par_opt_to_par_sim: ParMappingDict, Parameters: mapping_par_opt_to_par_sim: - Output of get_parameter_mapping_for_condition + Output of :py:func:`get_parameter_mapping_for_condition` warn: If True, log warning regarding unmapped parameters condition_id: @@ -538,10 +542,10 @@ def merge_preeq_and_sim_pars_condition( Arguments: condition_map_preeq, condition_map_sim: Parameter mapping as obtained from - `get_parameter_mapping_for_condition` + :py:func:`get_parameter_mapping_for_condition` condition_scale_map_preeq, condition_scale_map_sim: Parameter scale mapping as obtained from - `get_get_scale_mapping_for_condition` + :py:func:`get_parameter_mapping_for_condition` condition: Condition identifier for more informative error messages """ if not condition_map_preeq: @@ -610,9 +614,10 @@ def merge_preeq_and_sim_pars( Parameters: parameter_mappings: As returned by - petab.get_optimization_to_simulation_parameter_mapping + :py:func:`petab.get_optimization_to_simulation_parameter_mapping`. scale_mappings: - As returned by petab.get_optimization_to_simulation_scale_mapping. + As returned by + :py:func:`petab.get_optimization_to_simulation_parameter_mapping`. Returns: The parameter and scale simulation mappings, modified and checked. diff --git a/petab/parameters.py b/petab/parameters.py index 766f3429..99d82352 100644 --- a/petab/parameters.py +++ b/petab/parameters.py @@ -364,8 +364,7 @@ def scale(parameter: numbers.Number, scale_str: 'str') -> numbers.Number: One of 'lin' (synonymous with ''), 'log', 'log10'. Returns: - parameter: - The scaled parameter. + The scaled parameter. """ if scale_str == LIN or not scale_str: @@ -387,8 +386,7 @@ def unscale(parameter: numbers.Number, scale_str: 'str') -> numbers.Number: One of 'lin' (synonymous with ''), 'log', 'log10'. Returns: - parameter: - The unscaled parameter. + The unscaled parameter. """ if scale_str == LIN or not scale_str: diff --git a/petab/problem.py b/petab/problem.py index 57f27bad..7325b32d 100644 --- a/petab/problem.py +++ b/petab/problem.py @@ -233,13 +233,13 @@ def from_folder(folder: str, model_name: str = None) -> 'Problem': def from_combine(filename: str) -> 'Problem': """Read PEtab COMBINE archive (http://co.mbine.org/documents/archive). - See also ``create_combine_archive``. + See also :py:func:`petab.create_combine_archive`. Arguments: filename: Path to the PEtab-COMBINE archive Returns: - A ``petab.Problem`` instance. + A :py:class:`petab.Problem` instance. """ # function-level import, because module-level import interfered with # other SWIG interfaces @@ -291,8 +291,8 @@ def to_files(self, yaml_file: YAML file destination Raises: - ValueError: If a destination was provided for a non-existing - entity. + ValueError: + If a destination was provided for a non-existing entity. """ if sbml_file: @@ -350,7 +350,7 @@ def get_optimization_parameters(self): """ Return list of optimization parameter IDs. - See ``petab.parameters.get_optimization_parameters``. + See :py:func:`petab.parameters.get_optimization_parameters`. """ return parameters.get_optimization_parameters(self.parameter_df) @@ -358,18 +358,19 @@ def get_optimization_parameter_scales(self): """ Return list of optimization parameter scaling strings. - See ``petab.parameters.get_optimization_parameters``. + See :py:func:`petab.parameters.get_optimization_parameters`. """ return parameters.get_optimization_parameter_scaling(self.parameter_df) def get_model_parameters(self): - """See `petab.sbml.get_model_parameters`""" + """See :py:func:`petab.sbml.get_model_parameters`""" return sbml.get_model_parameters(self.sbml_model) def get_observables(self, remove: bool = False): """ Returns dictionary of observables definitions. - See `assignment_rules_to_dict` for details. + + See :py:func:`petab.assignment_rules_to_dict` for details. """ warn("This function will be removed in future releases.", DeprecationWarning) @@ -386,6 +387,7 @@ def get_sigmas(self, remove: bool = False): """ Return dictionary of observableId => sigma as defined in the SBML model. + This does not include parameter mappings defined in the measurement table. """ @@ -396,7 +398,7 @@ def get_sigmas(self, remove: bool = False): def get_noise_distributions(self): """ - See `get_noise_distributions`. + See :py:func:`petab.get_noise_distributions`. """ return measurements.get_noise_distributions( measurement_df=self.measurement_df) @@ -633,7 +635,7 @@ def get_optimization_to_simulation_parameter_mapping( def create_parameter_df(self, *args, **kwargs): """Create a new PEtab parameter table - See create_parameter_df + See :py:func:`create_parameter_df`. """ return parameters.create_parameter_df( self.sbml_model, @@ -645,7 +647,7 @@ def create_parameter_df(self, *args, **kwargs): def sample_parameter_startpoints(self, n_starts: int = 100): """Create starting points for optimization - See sample_parameter_startpoints + See :py:func:`petab.sample_parameter_startpoints`. """ return sampling.sample_parameter_startpoints( self.parameter_df, n_starts=n_starts) From 42cb1f494d1c236475a1b005efd061db7ab554f7 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Tue, 23 Mar 2021 16:12:32 +0100 Subject: [PATCH 4/6] Fix status badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 561aedcc..a400d163 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![CI tests](https://github.com/PEtab-dev/libpetab-python/workflows/CI%20tests/badge.svg) +[![CI](https://github.com/PEtab-dev/libpetab-python/actions/workflows/ci_tests.yml/badge.svg?branch=master)](https://github.com/PEtab-dev/libpetab-python/actions/workflows/ci_tests.yml) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/fd7dd5cee68e449983be5c43f230c7f3)](https://www.codacy.com/gh/PEtab-dev/libpetab-python) [![codecov](https://codecov.io/gh/PEtab-dev/libpetab-python/branch/master/graph/badge.svg)](https://codecov.io/gh/PEtab-dev/libpetab-python) [![PyPI version](https://badge.fury.io/py/petab.svg)](https://badge.fury.io/py/petab) From 3ab681f4a3ac8fdd85c3bec53a425eb88a1ab841 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Tue, 23 Mar 2021 17:04:22 +0100 Subject: [PATCH 5/6] Doc: misc (#54) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Link docs * docstring * raise * format * Remove PEtab process * Apply suggestions from code review Co-authored-by: Yannik Schälte <31767307+yannikschaelte@users.noreply.github.com> Co-authored-by: Yannik Schälte <31767307+yannikschaelte@users.noreply.github.com> --- README.md | 16 ++-- doc/conf.py | 2 +- doc/development.rst | 222 -------------------------------------------- doc/index.rst | 1 - petab/calculate.py | 4 + petab/core.py | 4 +- petab/lint.py | 4 +- 7 files changed, 19 insertions(+), 234 deletions(-) delete mode 100644 doc/development.rst diff --git a/README.md b/README.md index a400d163..0939edcc 100644 --- a/README.md +++ b/README.md @@ -34,16 +34,18 @@ Development versions of the PEtab library can be installed using When setting up a new parameter estimation problem, the most useful tools will be: - - The **PEtab validator**, which is now automatically installed using Python - entrypoints to be available as a shell command from anywhere called + - The [PEtab validator](https://petab.readthedocs.io/projects/libpetab-python/en/latest/example/example_petablint.html), + which is automatically installed using Python + entrypoints to be available as a shell command from anywhere, called `petablint` - - `petab.create_parameter_df` to create the parameter table, once you - have set up the model, condition table, observable table and measurement - table + - [`petab.create_parameter_df`](https://petab.readthedocs.io/projects/libpetab-python/en/latest/build/_autosummary/petab.parameters.html#petab.parameters.create_parameter_df) + to create the parameter table, once you have set up the model, + condition table, observable table and measurement table - - `petab.create_combine_archive` to create a - [COMBINE Archive](https://combinearchive.org/index/) from PEtab files + - [`petab.create_combine_archive`](https://petab.readthedocs.io/projects/libpetab-python/en/latest/build/_autosummary/petab.core.html#petab.core.create_combine_archive) + to create a [COMBINE Archive](https://combinearchive.org/index/) from PEtab + files ## Examples diff --git a/doc/conf.py b/doc/conf.py index 84810a47..311bb523 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -19,7 +19,7 @@ # -- Project information ----------------------------------------------------- -project = 'PEtab' +project = 'libpetab-python' copyright = '2018, the PEtab developers' author = 'PEtab developers' diff --git a/doc/development.rst b/doc/development.rst deleted file mode 100644 index 8c9f29c0..00000000 --- a/doc/development.rst +++ /dev/null @@ -1,222 +0,0 @@ -.. _development: - -PEtab development process -========================= - -Motivation for this document / general remarks -++++++++++++++++++++++++++++++++++++++++++++++ - -Reproducibility and reusability of the results of data-based modeling -studies are essential. Yet, until recently, there was no broadly supported -format for the specification of parameter estimation problems in systems -biology. Therefore, we developed PEtab. Having released the specifications -for PEtab version 1.0, we would like to keep development of PEtab active by -attracting more users and tool developers. We acknowledge that it is -important for any potential contributors to know how PEtab is managed and -developed, which we will explain in the remainder of this document. - -Values -++++++ - -We are committed to diversity, open communication, transparent processes, -democratic decision-making by the community and fostering a welcoming -environment. While we want to have clear processes, we don’t want to -overformalize things to avoid unnecessary slowdowns. - -Roles within the PEtab community -++++++++++++++++++++++++++++++++ - -The following subsections describe the different roles in the development of -PEtab. - -Anybody interested in PEtab ---------------------------- - -Input from every interested person is welcome. - -Anyone may... - -* propose changes to PEtab - -PEtab forum ------------ - -The PEtab forum includes anybody who is interested in PEtab and is -subscribed to the `PEtab mailing list `_ -using their real name. (Although anybody is invited to subscribe to the -mailing list with any name or email address, we require the use of real -names for participation in any votes. This is to ensure that every person -has only one vote.) - -The PEtab forum ... - -* votes for changes to PEtab -* nominates editors -* elects editors - -PEtab editors -------------- - -PEtab is meant to be a community effort. Decisions should therefore be made -as far as possible by a broad community interested in the use and -development of PEtab. Nevertheless, such a project cannot run fully -autonomously, but requires a core team of editors to take care of certain -management tasks. The PEtab editorial board is a team of 5 representatives -nominated and elected by the PEtab forum. - -The duties / privileges of the editors include the following: - -* organizing polls -* writing/updating specifications -* organizing and announcing annual meetings / hackathons -* promoting PEtab -* deciding minor PEtab issues among themselves - ("minor" as defined by the editors but reasons for the decision need to be communicated) -* managing the PEtab mailing lists -* managing the PEtab GitHub organization and respective repositories -* delegating any of the above - -Other ------ - -Other roles may be created as required based on the decision of the editors by majority vote. - -Communication channels -++++++++++++++++++++++ - -The main discussion channel should be the GitHub -`issues `_ / -`discussion `_ pages. -Additionally, the `mailing list `_ -is used for the announcement of new releases, polls, and the likes and can be -used for discussions that seem unfit for GitHub. An archive of the mailing list -shall be publicly accessible. -The PEtab Editors can be contacted through -`https://groups.google.com/g/petab-editors `_, -which is only readable by the current Editors. -Regular, ideally non-virtual, PEtab hackathons are planned to happen at least -annually, e.g., in combination with -`COMBINE events `_. - -Election of Editors -+++++++++++++++++++ - -Editors are elected for 3 years by the PEtab forum. Editors may serve -multiple terms, but there needs to be a break of 1 year between subsequent -terms. To maintain continuity, not all editors shall be replaced at the same -time. Editors may resign any time before the end of their term. - -Whenever an Editor position becomes vacant: - -* Editors announce upcoming elections and request nominations via the PEtab - mailing list. The time given for nominations shall be no shorter than 10 days. -* Interested parties submit nominations including a short statement on the - reason for nomination before the deadline. Self-nominations are allowed. -* Editors ask the nominees whether they accept the nomination (nominees are - given 5 days to accept). This step may start already during the nomination - phase. -* Editors announce the nominees who accepted their nomination along with the - submitted statements and open the poll via the PEtab mailing list. The - editors choose a sensible medium and deadline for the poll. -* The PEtab forum casts their votes secretly. (Votes may have to be open to the - editors, as they need to verify that only qualified votes are counted. - However, the editors are required to maintain confidentiality.) Every - participant has 1 vote per vacant position. -* After passing the deadline, the editors count the votes and ask the - editor-elect to accept or decline the election. No acceptance before the end - of the deadline set by the editors, which shall not be less than 3 days, is - considered decline. -* If an editor-elect declines, the position will be offered to the next - candidate according to the number of votes. (If there is no candidate left - with at least one vote, the election for the vacant position needs to be - repeated. -* If there is a tie between candidates of which only a subset can become an - editor, run-off elections including only those candidates have to be - organized by the PEtab editors as soon as possible. Voters will again have a - number of votes equal to the number of vacant positions. -* If the editor-elect accepts, the other editors announce the new editor on the - PEtab mailing list. The editors shall furthermore announce the number of - votes each nominee, elected or not, has received. - -Special procedure for the first election (February, 2021): ----------------------------------------------------------- - -The first election was held among the authors of the original PEtab -publication. Nominees were not required to be among the authors. The election -was managed by two persons who were not among the candidates and were -coming from two different labs. To avoid a simultaneous replacement of all -of the editors elected during the first election, the first election was -subject to the following special rules: 2 persons were elected for 3 -years, 2 persons for 2 years and one person for 1 year. The persons with -more votes were elected for a longer period (if they accepted -for the longer period). In case of an equal number of votes among any of the -top 5 candidates, there would have been run-off elections between those -candidates with equal numbers of votes. The editors-elect were given 3 working -days to accept the election. -If an editor would decide to hand over his editorial role before the end of -their term, an editor elected for a shorter term period could decide to take -over and extend their term to the end of the leaving editor's original term. - -PEtab format development process -++++++++++++++++++++++++++++++++ - -We acknowledge that PEtab cannot accommodate everybody’s needs, but we are -committed to addressing current and future requirements in upcoming versions of -the PEtab format. Although we value backwards-compatibility, we don’t want to -exclude breaking changes if justified by the benefits. - -Anybody is welcomed to propose changes or additions to PEtab. Any proposals -shall be made using GitHub issues. Benefits, problems, and potential -alternatives shall be discussed in the respective thread. - -A proposal is considered accepted for inclusion in the next version of PEtab -if it’s endorsed by the majority of the PEtab editors and if distinct -developers of at least 2 tools provide a prototype implementation. For any -changes, respective test cases sufficiently covering the changes are to be -added to the `PEtab test suite `_ -prior to release. - -Requirements for new releases: - -* Updated format specifications -* Updated converter -* Updated validator -* Updated test suite -* Updated changelog - -The PEtab editors jointly decide whether these requirements are met. - -Upon a new release, the PEtab editors ensure that - -* a new release is created in the GitHub repository -* the new version of the specifications is deposited at Zenodo -* the new release is announced on the PEtab mailing list - -Versioning of the PEtab format ------------------------------- - -The PEtab specifications follow `semantic versioning `_. -Any changes to the PEtab specifications require a new release. Any necessary -clarifications or corrections shall be collected on an Errata page until a new -version is released. - -The time for a new PEtab release is left to the discretion of the editors. -However, accepted changes should be released within 2 months after acceptance. - -With any new PEtab version it shall be ensured that a converter between the new -and the previous version(s) is available. Parallel maintenance of multiple -versions is not intended. - -Generally, any parameter estimation problem that could have been specified -in an earlier version should be specifiable in a new version (potentially -requiring different syntax). Any changes to the PEtab specifications that -would remove certain features without adequate replacement require the -support of at least 4 out of the 5 editors. - -Changes to these processes -++++++++++++++++++++++++++ - -Changes to the processes specified above require a public vote with -agreement of the majority of voters. Any other changes not directly -affecting those processes, such as changes to structure, orthography, -grammar, formatting, the preamble can be made by the editors any time. diff --git a/doc/index.rst b/doc/index.rst index 6f8a007f..f4abafc7 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -12,7 +12,6 @@ :caption: About Changelog - Development how_to_cite license diff --git a/petab/calculate.py b/petab/calculate.py index e9193bf6..1fbe3b1d 100644 --- a/petab/calculate.py +++ b/petab/calculate.py @@ -363,5 +363,9 @@ def calculate_single_llh( nllh = log(2*sigma*m) + abs((log(s)-log(m))/sigma) elif noise_distribution == LAPLACE and scale == LOG10: nllh = log(2*sigma*m*log(10)) + abs((log10(s)-log10(m))/sigma) + else: + raise NotImplementedError( + "Unsupported combination of noise_distribution and scale " + f"specified: {noise_distribution}, {scale}.") llh = - nllh return llh diff --git a/petab/core.py b/petab/core.py index 94a31780..114dfb4a 100644 --- a/petab/core.py +++ b/petab/core.py @@ -238,7 +238,8 @@ def is_empty(val) -> bool: def create_combine_archive( - yaml_file: str, filename: str, + yaml_file: str, + filename: str, family_name: Optional[str] = None, given_name: Optional[str] = None, email: Optional[str] = None, @@ -249,6 +250,7 @@ def create_combine_archive( Arguments: yaml_file: Path to PEtab YAML file + filename: Destination file name family_name: Family name of archive creator given_name: Given name of archive creator email: E-mail address of archive creator diff --git a/petab/lint.py b/petab/lint.py index 8a7d6578..4291d8bf 100644 --- a/petab/lint.py +++ b/petab/lint.py @@ -307,8 +307,8 @@ def assert_all_parameters_present_in_parameter_df( def assert_measured_observables_defined( measurement_df: pd.DataFrame, observable_df: pd.DataFrame) -> None: - """Check if all observables in the measurement table have been defined in the - observable table + """Check if all observables in the measurement table have been defined in + the observable table Arguments: measurement_df: PEtab measurement table From e4733ad27e9fafcaab4736e02c553856e56653f2 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Tue, 23 Mar 2021 17:09:19 +0100 Subject: [PATCH 6/6] Update changelog, bump version number --- CHANGELOG.md | 6 ++++++ petab/version.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a9ca15e..a8a6cbf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## 0.1 series +### 0.1.18 + +* Fixed various documentation issues +* Parameter mapping: Added option to ignore time-point specific + noiseParameters (#51) + ### 0.1.17 * Updated package URL diff --git a/petab/version.py b/petab/version.py index 5a4bd065..12eba4c7 100644 --- a/petab/version.py +++ b/petab/version.py @@ -1,2 +1,2 @@ """PEtab library version""" -__version__ = '0.1.17' +__version__ = '0.1.18'