API Reference

PEtab global

petab.ENV_NUM_THREADS

Name of environment variable to set number of threads or processes PEtab should use for operations that can be performed in parallel. By default, all operations are performed sequentially.

class petab.CompositeProblem(parameter_df: Optional[pandas.core.frame.DataFrame] = None, problems: Optional[List[petab.problem.Problem]] = None)[source]

Bases: object

Representation of a PEtab problem consisting of multiple models

problems

List of petab.Problem s

parameter_df

PEtab parameter DataFrame

static from_yaml(yaml_config: Union[Dict, str]) petab.composite_problem.CompositeProblem[source]

Create from YAML file

Factory method to create a CompositeProblem instance from a PEtab YAML config file

Parameters

yaml_config – PEtab configuration as dictionary or YAML file name

class petab.Problem(sbml_model: Optional[libsbml.Model] = None, sbml_reader: Optional[libsbml.SBMLReader] = None, sbml_document: Optional[libsbml.SBMLDocument] = None, condition_df: Optional[pandas.core.frame.DataFrame] = None, measurement_df: Optional[pandas.core.frame.DataFrame] = None, parameter_df: Optional[pandas.core.frame.DataFrame] = None, visualization_df: Optional[pandas.core.frame.DataFrame] = None, observable_df: Optional[pandas.core.frame.DataFrame] = None)[source]

Bases: object

PEtab parameter estimation problem as defined by

  • SBML model

  • condition table

  • measurement table

  • parameter table

  • observables table

Optionally it may contain visualization tables.

condition_df

PEtab condition table

measurement_df

PEtab measurement table

parameter_df

PEtab parameter table

observable_df

PEtab observable table

visualization_df

PEtab visualization table

sbml_reader

Stored to keep object alive.

sbml_document

Stored to keep object alive.

sbml_model

PEtab SBML model

_apply_mask(v: List, free: bool = True, fixed: bool = True)[source]

Apply mask of only free or only fixed values.

Parameters
  • v – The full vector the mask is to be applied to.

  • free – Whether to return free parameters, i.e. parameters to estimate.

  • fixed – Whether to return fixed parameters, i.e. parameters not to estimate.

Return type

The reduced vector with applied mask.

create_parameter_df(*args, **kwargs)[source]

Create a new PEtab parameter table

See create_parameter_df().

static from_combine(filename: Union[pathlib.Path, str]) petab.problem.Problem[source]

Read PEtab COMBINE archive (http://co.mbine.org/documents/archive).

See also petab.create_combine_archive().

Parameters

filename – Path to the PEtab-COMBINE archive

Returns

A petab.Problem instance.

static from_files(sbml_file: Optional[Union[str, pathlib.Path]] = None, condition_file: Optional[Union[str, pathlib.Path]] = None, measurement_file: Optional[Union[str, pathlib.Path, Iterable[Union[str, pathlib.Path]]]] = None, parameter_file: Optional[Union[str, pathlib.Path, Iterable[Union[str, pathlib.Path]]]] = None, visualization_files: Optional[Union[str, pathlib.Path, Iterable[Union[str, pathlib.Path]]]] = None, observable_files: Optional[Union[str, pathlib.Path, Iterable[Union[str, pathlib.Path]]]] = None) petab.problem.Problem[source]

Factory method to load model and tables from files.

Parameters
  • sbml_file – PEtab SBML model

  • condition_file – PEtab condition table

  • measurement_file – PEtab measurement table

  • parameter_file – PEtab parameter table

  • visualization_files – PEtab visualization tables

  • observable_files – PEtab observables tables

static from_folder(folder: str, model_name: Optional[str] = None) petab.problem.Problem[source]

Factory method to use the standard folder structure and file names, i.e.

${model_name}/
  +-- experimentalCondition_${model_name}.tsv
  +-- measurementData_${model_name}.tsv
  +-- model_${model_name}.xml
  +-- parameters_${model_name}.tsv
Parameters
  • folder – Path to the directory in which the files are located.

  • model_name – If specified, overrides the model component in the file names. Defaults to the last component of folder.

static from_yaml(yaml_config: Union[Dict, pathlib.Path, str]) petab.problem.Problem[source]

Factory method to load model and tables as specified by YAML file.

Parameters

yaml_config – PEtab configuration as dictionary or YAML file name

get_lb(free: bool = True, fixed: bool = True, scaled: bool = False)[source]

Generic function to get lower parameter bounds.

Parameters
  • free – Whether to return free parameters, i.e. parameters to estimate.

  • fixed – Whether to return fixed parameters, i.e. parameters not to estimate.

  • scaled – Whether to scale the values according to the parameter scale, or return them on linear scale.

Return type

The lower parameter bounds.

get_model_parameters()[source]

See petab.sbml.get_model_parameters()

get_noise_distributions()[source]

See petab.get_noise_distributions().

get_observable_ids()[source]

Returns dictionary of observable ids.

get_observables(remove: bool = False)[source]

Returns dictionary of observables definitions.

See petab.assignment_rules_to_dict() for details.

get_optimization_parameter_scales()[source]

Return list of optimization parameter scaling strings.

See petab.parameters.get_optimization_parameters().

get_optimization_parameters()[source]

Return list of optimization parameter IDs.

See petab.parameters.get_optimization_parameters().

get_optimization_to_simulation_parameter_mapping(warn_unmapped: bool = True, scaled_parameters: bool = False, allow_timepoint_specific_numeric_noise_parameters: bool = False)[source]

See get_simulation_to_optimization_parameter_mapping.

get_sigmas(remove: bool = False)[source]

Return dictionary of observableId => sigma as defined in the SBML model.

This does not include parameter mappings defined in the measurement table.

get_simulation_conditions_from_measurement_df()[source]

See petab.get_simulation_conditions

get_ub(free: bool = True, fixed: bool = True, scaled: bool = False)[source]

Generic function to get upper parameter bounds.

Parameters
  • free – Whether to return free parameters, i.e. parameters to estimate.

  • fixed – Whether to return fixed parameters, i.e. parameters not to estimate.

  • scaled – Whether to scale the values according to the parameter scale, or return them on linear scale.

Return type

The upper parameter bounds.

get_x_ids(free: bool = True, fixed: bool = True)[source]

Generic function to get parameter ids.

Parameters
  • free – Whether to return free parameters, i.e. parameters to estimate.

  • fixed – Whether to return fixed parameters, i.e. parameters not to estimate.

Return type

The parameter IDs.

get_x_nominal(free: bool = True, fixed: bool = True, scaled: bool = False)[source]

Generic function to get parameter nominal values.

Parameters
  • free – Whether to return free parameters, i.e. parameters to estimate.

  • fixed – Whether to return fixed parameters, i.e. parameters not to estimate.

  • scaled – Whether to scale the values according to the parameter scale, or return them on linear scale.

Return type

The parameter nominal values.

property lb: List

Parameter table lower bounds.

property lb_scaled: List

Parameter table lower bounds with applied parameter scaling

sample_parameter_startpoints(n_starts: int = 100)[source]

Create starting points for optimization

See petab.sample_parameter_startpoints().

scale_parameters(x_dict: Dict[str, float]) Dict[str, float][source]

Scale parameter values.

Parameters

x_dict – Keys are parameter IDs in the PEtab problem, values are unscaled parameter values.

Return type

The scaled parameter values.

to_files(sbml_file: Optional[Union[str, pathlib.Path]] = None, condition_file: Optional[Union[str, pathlib.Path]] = None, measurement_file: Optional[Union[str, pathlib.Path]] = None, parameter_file: Optional[Union[str, pathlib.Path]] = None, visualization_file: Optional[Union[str, pathlib.Path]] = None, observable_file: Optional[Union[str, pathlib.Path]] = None, yaml_file: Optional[Union[str, pathlib.Path]] = None, prefix_path: Optional[Union[str, pathlib.Path]] = None, relative_paths: bool = True) None[source]

Write PEtab tables to files for this problem

Writes PEtab files for those entities for which a destination was passed.

NOTE: If this instance was created from multiple measurement or visualization tables, they will be merged and written to a single file.

Parameters
  • sbml_file – SBML model destination

  • condition_file – Condition table destination

  • measurement_file – Measurement table destination

  • parameter_file – Parameter table destination

  • visualization_file – Visualization table destination

  • observable_file – Observables table destination

  • yaml_file – YAML file destination

  • prefix_path – Specify a prefix to all paths, to avoid specifying the prefix for all paths individually. NB: the prefix is added to paths before relative_paths is handled.

  • relative_paths – whether all paths in the YAML file should be relative to the location of the YAML file. If False, then paths are left unchanged.

Raises

ValueError – If a destination was provided for a non-existing entity.

to_files_generic(prefix_path: Union[str, pathlib.Path]) str[source]

Save a PEtab problem to generic file names.

The PEtab problem YAML file is always created. PEtab data files are only created if the PEtab problem contains corresponding data (e.g. a PEtab visualization TSV file is only created if the PEtab problem has one).

Parameters

prefix_path – Specify a prefix to all paths, to avoid specifying the prefix for all paths individually. NB: the prefix is added to paths before relative_paths is handled downstream in petab.yaml.create_problem_yaml.

Returns

The path to the PEtab problem YAML file.

property ub: List

Parameter table upper bounds

property ub_scaled: List

Parameter table upper bounds with applied parameter scaling

unscale_parameters(x_dict: Dict[str, float]) Dict[str, float][source]

Unscale parameter values.

Parameters

x_dict – Keys are parameter IDs in the PEtab problem, values are scaled parameter values.

Return type

The unscaled parameter values.

property x_fixed_ids: List[str]

Parameter table parameter IDs, for fixed parameters.

property x_fixed_indices: List[int]

Parameter table non-estimated parameter indices.

property x_free_ids: List[str]

Parameter table parameter IDs, for free parameters.

property x_free_indices: List[int]

Parameter table estimated parameter indices.

property x_ids: List[str]

Parameter table parameter IDs

property x_nominal: List

Parameter table nominal values

property x_nominal_fixed: List

Parameter table nominal values, for fixed parameters.

property x_nominal_fixed_scaled: List

Parameter table nominal values with applied parameter scaling, for fixed parameters.

property x_nominal_free: List

Parameter table nominal values, for free parameters.

property x_nominal_free_scaled: List

Parameter table nominal values with applied parameter scaling, for free parameters.

property x_nominal_scaled: List

Parameter table nominal values with applied parameter scaling

class petab.Simulator(petab_problem: petab.problem.Problem, working_dir: Optional[Union[str, pathlib.Path]] = None)[source]

Bases: abc.ABC

Base class that specific simulators should inherit.

Specific simulators should minimally implement the simulate_without_noise method. Example (AMICI): https://bit.ly/33SUSG4

noise_formulas

The formulae that will be used to calculate the scale of noise distributions.

petab_problem

A PEtab problem, which will be simulated.

rng

A NumPy random generator, used to sample from noise distributions.

temporary_working_dir

Whether working_dir is a temporary directory, which can be deleted without significant consequence.

working_dir

All simulator-specific output files will be saved here. This directory and its contents may be modified and deleted, and should be considered ephemeral.

add_noise(simulation_df: pandas.core.frame.DataFrame, noise_scaling_factor: float = 1, **kwargs) pandas.core.frame.DataFrame[source]

Add noise to simulated data.

Parameters
  • simulation_df – A PEtab measurements table that contains simulated data.

  • noise_scaling_factor – A multiplier of the scale of the noise distribution.

  • **kwargs – Additional keyword arguments are passed to sample_noise.

Returns

Simulated data with noise, as a PEtab measurements table.

remove_working_dir(force: bool = False, **kwargs) None[source]

Remove the simulator working directory, and all files within.

See the __init__ method arguments.

Parameters
  • force – If True, the working directory is removed regardless of whether it is a temporary directory.

  • **kwargs – Additional keyword arguments are passed to shutil.rmtree.

simulate(noise: bool = False, noise_scaling_factor: float = 1, **kwargs) pandas.core.frame.DataFrame[source]

Simulate a PEtab problem, optionally with noise.

Parameters
  • noise – If True, noise is added to simulated data.

  • noise_scaling_factor – A multiplier of the scale of the noise distribution.

  • **kwargs – Additional keyword arguments are passed to simulate_without_noise.

Returns

Simulated data, as a PEtab measurements table.

abstract simulate_without_noise() pandas.core.frame.DataFrame[source]

Simulate the PEtab problem.

This is an abstract method that should be implemented with a simulation package. Examples of this are referenced in the class docstring.

Returns

Simulated data, as a PEtab measurements table, which should be equivalent to replacing all values in the petab.C.MEASUREMENT column of the measurements table (of the PEtab problem supplied to the __init__ method), with simulated values.

petab.add_global_parameter(sbml_model: libsbml.Model, parameter_id: str, parameter_name: Optional[str] = None, constant: bool = False, units: str = 'dimensionless', value: float = 0.0) libsbml.Parameter[source]

Add new global parameter to SBML model

Parameters
  • sbml_model – SBML model

  • parameter_id – ID of the new parameter

  • parameter_name – Name of the new parameter

  • constant – Is parameter constant?

  • units – SBML unit ID

  • value – parameter value

Returns

The created parameter

petab.add_model_output(sbml_model: libsbml.Model, observable_id: str, formula: str, observable_name: Optional[str] = None) None[source]

Add PEtab-style output to model

We expect that all formula parameters are added to the model elsewhere.

Parameters
  • sbml_model – Model to add output to

  • formula – Formula string for model output

  • observable_id – ID without “observable_” prefix

  • observable_name – Any observable name

petab.add_model_output_sigma(sbml_model: libsbml.Model, observable_id: str, formula: str) None[source]

Add PEtab-style sigma for the given observable id

We expect that all formula parameters are added to the model elsewhere.

Parameters
  • sbml_model – Model to add to

  • observable_id – Observable id for which to add sigma

  • formula – Formula for sigma

petab.add_model_output_with_sigma(sbml_model: libsbml.Model, observable_id: str, observable_formula: str, observable_name: Optional[str] = None) None[source]

Add PEtab-style output and corresponding sigma with single (newly created) parameter

We expect that all formula parameters are added to the model elsewhere.

Parameters
  • sbml_model – Model to add output to

  • observable_formula – Formula string for model output

  • observable_id – ID without “observable_” prefix

  • observable_name – Any name

petab.assert_all_parameters_present_in_parameter_df(parameter_df: pandas.core.frame.DataFrame, sbml_model: libsbml.Model, observable_df: pandas.core.frame.DataFrame, measurement_df: pandas.core.frame.DataFrame, condition_df: pandas.core.frame.DataFrame) None[source]

Ensure all required parameters are contained in the parameter table with no additional ones

Parameters
  • parameter_df – PEtab parameter DataFrame

  • sbml_model – PEtab SBML Model

  • observable_df – PEtab observable table

  • measurement_df – PEtab measurement table

  • condition_df – PEtab condition table

Raises

AssertionError – in case of problems

petab.assert_measured_observables_defined(measurement_df: pandas.core.frame.DataFrame, observable_df: pandas.core.frame.DataFrame) None[source]

Check if all observables in the measurement table have been defined in the observable table

Parameters
  • measurement_df – PEtab measurement table

  • observable_df – PEtab observable table

Raises

AssertionError – in case of problems

petab.assert_measurement_conditions_present_in_condition_table(measurement_df: pandas.core.frame.DataFrame, condition_df: pandas.core.frame.DataFrame) None[source]

Ensure that all entries from measurement_df.simulationConditionId and measurement_df.preequilibrationConditionId are present in condition_df.index.

Parameters
  • measurement_df – PEtab measurement table

  • condition_df – PEtab condition table

Raises

AssertionError – in case of problems

petab.assert_measurements_not_null(measurement_df: pandas.core.frame.DataFrame) None[source]

Check whether all measurements are not null.

Parameters

measurement_df – PEtab measurement table.

Raises

AssertionError – Some measurement value(s) are null (missing).

petab.assert_measurements_numeric(measurement_df: pandas.core.frame.DataFrame) None[source]

Check whether all measurements are numeric.

Note that null (missing) measurements are ignored.

Parameters

measurement_df – PEtab measurement table.

Raises

AssertionError – Some measurement value(s) are not numeric.

petab.assert_model_parameters_in_condition_or_parameter_table(sbml_model: libsbml.Model, condition_df: pandas.core.frame.DataFrame, parameter_df: pandas.core.frame.DataFrame) None[source]

Model parameters that are targets of AssignmentRule must not be present in parameter table or in condition table columns. Other parameters must only be present in either in parameter table or condition table columns. Check that.

Parameters
  • parameter_df – PEtab parameter DataFrame

  • sbml_model – PEtab SBML Model

  • condition_df – PEtab condition table

Raises

AssertionError – in case of problems

petab.assert_no_leading_trailing_whitespace(names_list: Iterable[str], name: str) None[source]

Check that there is no trailing whitespace in elements of Iterable

Parameters
  • names_list – strings to check for whitespace

  • name – name of names_list for error messages

Raises

AssertionError – if there is trailing whitespace

petab.assert_noise_distributions_valid(observable_df: pandas.core.frame.DataFrame) None[source]

Ensure that noise distributions and transformations for observables are valid.

Parameters

observable_df – PEtab observable table

Raises

AssertionError – in case of problems

petab.assert_overrides_match_parameter_count(measurement_df: pandas.core.frame.DataFrame, observable_df: pandas.core.frame.DataFrame) None[source]

Ensure that number of parameters in the observable definition matches the number of overrides in measurement_df

Parameters
  • measurement_df – PEtab measurement table

  • observable_df – PEtab observable table

petab.assert_parameter_bounds_are_numeric(parameter_df: pandas.core.frame.DataFrame) None[source]

Check if all entries in the lowerBound and upperBound columns of the parameter table are numeric.

Parameters

parameter_df – PEtab parameter DataFrame

Raises

AssertionError – in case of problems

petab.assert_parameter_estimate_is_boolean(parameter_df: pandas.core.frame.DataFrame) None[source]

Check if all entries in the estimate column of the parameter table are 0 or 1.

Parameters

parameter_df – PEtab parameter DataFrame

Raises

AssertionError – in case of problems

petab.assert_parameter_id_is_string(parameter_df: pandas.core.frame.DataFrame) None[source]

Check if all entries in the parameterId column of the parameter table are string and not empty.

Parameters

parameter_df – PEtab parameter DataFrame

Raises

AssertionError – in case of problems

petab.assert_parameter_prior_parameters_are_valid(parameter_df: pandas.core.frame.DataFrame) None[source]

Check that the prior parameters are valid.

Parameters

parameter_df – PEtab parameter table

Raises

AssertionError – in case of invalid prior parameters

petab.assert_parameter_prior_type_is_valid(parameter_df: pandas.core.frame.DataFrame) None[source]

Check that valid prior types have been selected

Parameters

parameter_df – PEtab parameter table

Raises

AssertionError – in case of invalid prior

petab.assert_parameter_scale_is_valid(parameter_df: pandas.core.frame.DataFrame) None[source]

Check if all entries in the parameterScale column of the parameter table are ‘lin’ for linear, ‘log’ for natural logarithm or ‘log10’ for base 10 logarithm.

Parameters

parameter_df – PEtab parameter DataFrame

Raises

AssertionError – in case of problems

petab.assert_single_condition_and_sbml_file(problem_config: Dict) None[source]

Check that there is only a single condition file and a single SBML file specified.

Parameters

problem_config – Dictionary as defined in the YAML schema inside the problems list.

Raises

NotImplementedError – If multiple condition or SBML files specified.

petab.assert_unique_observable_ids(observable_df: pandas.core.frame.DataFrame) None[source]

Check if the observableId column of the observable table is unique.

Parameters

observable_df – PEtab observable DataFrame

Raises

AssertionError – in case of problems

petab.assert_unique_parameter_ids(parameter_df: pandas.core.frame.DataFrame) None[source]

Check if the parameterId column of the parameter table is unique.

Parameters

parameter_df – PEtab parameter DataFrame

Raises

AssertionError – in case of problems

petab.assignment_rules_to_dict(sbml_model: libsbml.Model, filter_function=<function <lambda>>, remove: bool = False) Dict[str, Dict[str, Any]][source]

Turn assignment rules into dictionary.

Parameters
  • sbml_model – a sbml model instance.

  • filter_function – callback function taking assignment variable as input and returning True/False to indicate if the respective rule should be turned into an observable.

  • remove – Remove the all matching assignment rules from the model

Returns

{
    assigneeId:
    {
        'name': assigneeName,
        'formula': formulaString
    }
}

petab.calculate_chi2(measurement_dfs: Union[List[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame], simulation_dfs: Union[List[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame], observable_dfs: Union[List[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame], parameter_dfs: Union[List[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame], normalize: bool = True, scale: bool = True) float[source]

Calculate the chi2 value.

Parameters
  • measurement_dfs – The problem measurement tables.

  • simulation_dfs – Simulation tables corresponding to the measurement tables.

  • observable_dfs – The problem observable tables.

  • parameter_dfs – The problem parameter tables.

  • normalize – Whether to normalize residuals by the noise standard deviation terms.

  • scale – Whether to calculate residuals of scaled values.

Returns

The aggregated chi2 value.

petab.calculate_chi2_for_table_from_residuals(residual_df: pandas.core.frame.DataFrame) float[source]

Compute chi2 value for a single residual table.

petab.calculate_llh(measurement_dfs: Union[List[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame], simulation_dfs: Union[List[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame], observable_dfs: Union[List[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame], parameter_dfs: Union[List[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame]) float[source]

Calculate total log likelihood.

Parameters
  • measurement_dfs – The problem measurement tables.

  • simulation_dfs – Simulation tables corresponding to the measurement tables.

  • observable_dfs – The problem observable tables.

  • parameter_dfs – The problem parameter tables.

Returns

The log-likelihood.

petab.calculate_llh_for_table(measurement_df: pandas.core.frame.DataFrame, simulation_df: pandas.core.frame.DataFrame, observable_df: pandas.core.frame.DataFrame, parameter_df: pandas.core.frame.DataFrame) float[source]

Calculate log-likelihood for one set of tables. For the arguments, see calculate_llh.

petab.calculate_residuals(measurement_dfs: Union[List[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame], simulation_dfs: Union[List[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame], observable_dfs: Union[List[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame], parameter_dfs: Union[List[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame], normalize: bool = True, scale: bool = True) List[pandas.core.frame.DataFrame][source]

Calculate residuals.

Parameters
  • measurement_dfs – The problem measurement tables.

  • simulation_dfs – Simulation tables corresponding to the measurement tables.

  • observable_dfs – The problem observable tables.

  • parameter_dfs – The problem parameter tables.

  • normalize – Whether to normalize residuals by the noise standard deviation terms.

  • scale – Whether to calculate residuals of scaled values.

Returns

List of DataFrames in the same structure as measurement_dfs with a field residual instead of measurement.

petab.calculate_residuals_for_table(measurement_df: pandas.core.frame.DataFrame, simulation_df: pandas.core.frame.DataFrame, observable_df: pandas.core.frame.DataFrame, parameter_df: pandas.core.frame.DataFrame, normalize: bool = True, scale: bool = True) pandas.core.frame.DataFrame[source]

Calculate residuals for a single measurement table. For the arguments, see calculate_residuals.

petab.calculate_single_llh(measurement: float, simulation: float, scale: str, noise_distribution: str, noise_value: float) float[source]

Calculate a single log likelihood.

Parameters
  • measurement – The measurement value.

  • simulation – The simulated value.

  • scale – The scale on which the noise model is to be applied.

  • noise_distribution – The noise distribution.

  • noise_value – The considered noise models possess a single noise parameter, e.g. the normal standard deviation.

Returns

The computed likelihood for the given values.

petab.check_condition_df(df: pandas.core.frame.DataFrame, sbml_model: Optional[libsbml.Model] = None) None[source]

Run sanity checks on PEtab condition table

Parameters
  • df – PEtab condition DataFrame

  • sbml_model – SBML Model for additional checking of parameter IDs

Raises

AssertionError – in case of problems

petab.check_ids(ids: Iterable[str], kind: str = '') None[source]

Check IDs are valid

Parameters
  • ids – Iterable of IDs to check

  • kind – Kind of IDs, for more informative error message

Raises

ValueError – in case of invalid IDs

petab.check_measurement_df(df: pandas.core.frame.DataFrame, observable_df: Optional[pandas.core.frame.DataFrame] = None) None[source]

Run sanity checks on PEtab measurement table

Parameters
  • df – PEtab measurement DataFrame

  • observable_df – PEtab observable DataFrame for checking if measurements are compatible with observable transformations.

Raises

AssertionError, ValueError – in case of problems

petab.check_observable_df(observable_df: pandas.core.frame.DataFrame) None[source]

Check validity of observable table

Parameters

observable_df – PEtab observable DataFrame

Raises

AssertionError – in case of problems

petab.check_parameter_bounds(parameter_df: pandas.core.frame.DataFrame) None[source]

Check if all entries in the lowerBound are smaller than upperBound column in the parameter table and that bounds are positive for parameterScale log|log10.

Parameters

parameter_df – PEtab parameter DataFrame

Raises

AssertionError – in case of problems

petab.check_parameter_df(df: pandas.core.frame.DataFrame, sbml_model: Optional[libsbml.Model] = None, observable_df: Optional[pandas.core.frame.DataFrame] = None, measurement_df: Optional[pandas.core.frame.DataFrame] = None, condition_df: Optional[pandas.core.frame.DataFrame] = None) None[source]

Run sanity checks on PEtab parameter table

Parameters
  • df – PEtab condition DataFrame

  • sbml_model – SBML Model for additional checking of parameter IDs

  • observable_df – PEtab observable table for additional checks

  • measurement_df – PEtab measurement table for additional checks

  • condition_df – PEtab condition table for additional checks

Raises

AssertionError – in case of problems

petab.concat_tables(tables: Union[str, pathlib.Path, pandas.core.frame.DataFrame, Iterable[Union[pandas.core.frame.DataFrame, str, pathlib.Path]]], file_parser: Optional[Callable] = None) pandas.core.frame.DataFrame[source]

Concatenate DataFrames provided as DataFrames or filenames, and a parser

Parameters
  • tables – Iterable of tables to join, as DataFrame or filename.

  • file_parser – Function used to read the table in case filenames are provided, accepting a filename as only argument.

Returns

The concatenated DataFrames

petab.condition_table_is_parameter_free(condition_df: pandas.core.frame.DataFrame) bool[source]

Check if all entries in the condition table are numeric (no parameter IDs)

Parameters

condition_df – PEtab condition table

Returns

True if there are no parameter overrides in the condition table, False otherwise.

petab.create_assigment_rule(sbml_model: libsbml.Model, assignee_id: str, formula: str, rule_id: Optional[str] = None, rule_name: Optional[str] = None) libsbml.AssignmentRule[source]

Create SBML AssignmentRule

Parameters
  • sbml_model – Model to add output to

  • assignee_id – Target of assignment

  • formula – Formula string for model output

  • rule_id – SBML id for created rule

  • rule_name – SBML name for created rule

Returns

The created AssignmentRule

petab.create_combine_archive(yaml_file: Union[str, pathlib.Path], filename: Union[str, pathlib.Path], family_name: Optional[str] = None, given_name: Optional[str] = None, email: Optional[str] = None, organization: Optional[str] = None) None[source]

Create COMBINE archive (https://co.mbine.org/documents/archive) based on PEtab YAML file.

Parameters
  • 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

  • organization – Organization of archive creator

petab.create_condition_df(parameter_ids: Iterable[str], condition_ids: Optional[Iterable[str]] = None) pandas.core.frame.DataFrame[source]

Create empty condition DataFrame

Parameters
  • parameter_ids – the columns

  • condition_ids – the rows

Returns

A pandas.DataFrame with empty given rows and columns and all nan values

petab.create_measurement_df() pandas.core.frame.DataFrame[source]

Create empty measurement dataframe

Returns

Created DataFrame

petab.create_observable_df() pandas.core.frame.DataFrame[source]

Create empty observable dataframe

Returns

Created DataFrame

petab.create_parameter_df(sbml_model: libsbml.Model, condition_df: pandas.core.frame.DataFrame, observable_df: pandas.core.frame.DataFrame, measurement_df: pandas.core.frame.DataFrame, include_optional: bool = False, parameter_scale: str = 'log10', lower_bound: Optional[Iterable] = None, upper_bound: Optional[Iterable] = None) pandas.core.frame.DataFrame[source]

Create a new PEtab parameter table

All table entries can be provided as string or list-like with length matching the number of parameters

Parameters
  • sbml_model – SBML Model

  • condition_df – PEtab condition DataFrame

  • observable_df – PEtab observable DataFrame

  • measurement_df – PEtab measurement DataFrame

  • include_optional – By default this only returns parameters that are required to be present in the parameter table. If set to True, this returns all parameters that are allowed to be present in the parameter table (i.e. also including parameters specified in the SBML model).

  • parameter_scale – parameter scaling

  • lower_bound – lower bound for parameter value

  • upper_bound – upper bound for parameter value

Returns

The created parameter DataFrame

petab.create_problem_yaml(sbml_files: Union[str, pathlib.Path, List[Union[str, pathlib.Path]]], condition_files: Union[str, pathlib.Path, List[Union[str, pathlib.Path]]], measurement_files: Union[str, pathlib.Path, List[Union[str, pathlib.Path]]], parameter_file: Union[str, pathlib.Path], observable_files: Union[str, pathlib.Path, List[Union[str, pathlib.Path]]], yaml_file: Union[str, pathlib.Path], visualization_files: Optional[Union[str, pathlib.Path, List[Union[str, pathlib.Path]]]] = None, relative_paths: bool = True) None[source]

Create and write default YAML file for a single PEtab problem

Parameters
  • sbml_files – Path of SBML model file or list of such

  • condition_files – Path of condition file or list of such

  • measurement_files – Path of measurement file or list of such

  • parameter_file – Path of parameter file

  • observable_files – Path of observable file or list of such

  • yaml_file – Path to which YAML file should be written

  • visualization_files – Optional Path to visualization file or list of such

  • relative_paths – whether all paths in the YAML file should be relative to the location of the YAML file. If False, then paths are left unchanged.

petab.evaluate_noise_formula(measurement: pandas.core.series.Series, noise_formulas: dict, parameter_df: pandas.core.frame.DataFrame, simulation: numbers.Number) float[source]

Fill in parameters for measurement and evaluate noise_formula.

Parameters
  • measurement – A measurement table row.

  • noise_formulas – The noise formulas as computed by get_symbolic_noise_formulas.

  • parameter_df – The parameter table.

  • simulation – The simulation corresponding to the measurement, scaled.

Returns

The noise value.

petab.flatten_timepoint_specific_output_overrides(petab_problem: petab.problem.Problem) None[source]

Flatten timepoint-specific output parameter overrides.

If the PEtab problem definition has timepoint-specific observableParameters or noiseParameters for the same observable, replace those by replicating the respective observable.

This is a helper function for some tools which may not support such timepoint-specific mappings. The observable table and measurement table are modified in place.

Parameters

petab_problem – PEtab problem to work on

petab.get_condition_df(condition_file: Optional[Union[str, pandas.core.frame.DataFrame, pathlib.Path]]) pandas.core.frame.DataFrame[source]

Read the provided condition file into a pandas.Dataframe

Conditions are rows, parameters are columns, conditionId is index.

Parameters

condition_file – File name of PEtab condition file or pandas.Dataframe

petab.get_default_condition_file_name(model_name: str, folder: str = '')[source]

Get file name according to proposed convention

petab.get_default_measurement_file_name(model_name: str, folder: str = '')[source]

Get file name according to proposed convention

petab.get_default_parameter_file_name(model_name: str, folder: str = '')[source]

Get file name according to proposed convention

petab.get_default_sbml_file_name(model_name: str, folder: str = '')[source]

Get file name according to proposed convention

petab.get_formula_placeholders(formula_string: str, observable_id: str, override_type: str) List[str][source]

Get placeholder variables in noise or observable definition for the given observable ID.

Parameters
  • formula_string – observable formula

  • observable_id – ID of current observable

  • override_type – ‘observable’ or ‘noise’, depending on whether formula is for observable or for noise model

Returns

List of placeholder parameter IDs in the order expected in the observableParameter column of the measurement table.

petab.get_measurement_df(measurement_file: Union[None, str, pathlib.Path, pandas.core.frame.DataFrame]) pandas.core.frame.DataFrame[source]

Read the provided measurement file into a pandas.Dataframe.

Parameters

measurement_file – Name of file to read from or pandas.Dataframe

Returns

Measurement DataFrame

petab.get_measurement_parameter_ids(measurement_df: pandas.core.frame.DataFrame) List[str][source]

Return list of ID of parameters which occur in measurement table as observable or noise parameter overrides.

Parameters

measurement_df – PEtab measurement DataFrame

Returns

List of parameter IDs

petab.get_model_for_condition(petab_problem: petab.problem.Problem, sim_condition_id: Optional[str] = None, preeq_condition_id: Optional[str] = None) Tuple[libsbml.SBMLDocument, libsbml.Model][source]

Create an SBML model for the given condition.

Creates a copy of the model and updates parameters according to the PEtab files. Estimated parameters are set to their nominalValue. Observables defined in the observables table are not added to the model.

Parameters
  • petab_problem – PEtab problem

  • sim_condition_id – Simulation conditionId for which to generate a model

  • preeq_condition_id – Preequilibration conditionId of the settings for which to generate a model. This is only used to determine the relevant output parameter overrides. Preequilibration is not encoded in the resulting model.

Returns

The generated SBML document, and SBML model

petab.get_model_parameters(sbml_model: libsbml.Model, with_values=False) Union[List[str], Dict[str, float]][source]

Return SBML model parameters which are not AssignmentRule targets for observables or sigmas

Parameters
  • 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.

petab.get_noise_distributions(measurement_df: pandas.core.frame.DataFrame) dict[source]

Returns dictionary of cost definitions per observable, if specified.

Looks through all parameters satisfying sbml_parameter_is_cost and return as dictionary.

Parameters

measurement_df – PEtab measurement table

Returns

Dictionary with observableId => cost definition

petab.get_notnull_columns(df: pandas.core.frame.DataFrame, candidates: Iterable)[source]

Return list of df-columns in candidates which are not all null/nan.

The output can e.g. be used as input for pandas.DataFrame.groupby.

Parameters
  • df – Dataframe

  • candidates – Columns of df to consider

petab.get_observable_df(observable_file: Optional[Union[str, pandas.core.frame.DataFrame, pathlib.Path]]) pandas.core.frame.DataFrame[source]

Read the provided observable file into a pandas.Dataframe.

Parameters

observable_file – Name of the file to read from or pandas.Dataframe.

Returns

Observable DataFrame

petab.get_observable_id(parameter_id: str) str[source]

Get PEtab observable ID from PEtab-style sigma or observable AssignmentRule-target parameter_id.

e.g. for ‘observable_obs1’ -> ‘obs1’, for ‘sigma_obs1’ -> ‘obs1’

Parameters

parameter_id – Some parameter ID

Returns

Observable ID

petab.get_observables(sbml_model: libsbml.Model, remove: bool = False) dict[source]

Get observables defined in SBML model according to PEtab format.

Returns

Dictionary of observable definitions. See assignment_rules_to_dict for details.

petab.get_optimization_parameter_scaling(parameter_df: pandas.core.frame.DataFrame) Dict[str, str][source]

Get Dictionary with optimization parameter IDs mapped to parameter scaling strings.

Parameters

parameter_df – PEtab parameter DataFrame

Returns

Dictionary with optimization parameter IDs mapped to parameter scaling strings.

petab.get_optimization_parameters(parameter_df: pandas.core.frame.DataFrame) List[str][source]

Get list of optimization parameter IDs from parameter table.

Parameters

parameter_df – PEtab parameter DataFrame

Returns

List of IDs of parameters selected for optimization.

petab.get_optimization_to_simulation_parameter_mapping(condition_df: pandas.core.frame.DataFrame, measurement_df: pandas.core.frame.DataFrame, parameter_df: Optional[pandas.core.frame.DataFrame] = None, observable_df: Optional[pandas.core.frame.DataFrame] = None, sbml_model: Optional[libsbml.Model] = None, simulation_conditions: Optional[pandas.core.frame.DataFrame] = None, warn_unmapped: Optional[bool] = True, scaled_parameters: bool = False, fill_fixed_parameters: bool = True, allow_timepoint_specific_numeric_noise_parameters: bool = False) List[Tuple[Dict[str, Union[str, numbers.Number]], Dict[str, Union[str, numbers.Number]], Dict[str, str], Dict[str, str]]][source]

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.

Parameters
  • condition_df – The dataframes in the PEtab format.

  • measurement_df – The dataframes in the PEtab format.

  • parameter_df – The dataframes in the PEtab format.

  • observable_df – The dataframes in the PEtab format.

  • sbml_model – The sbml model with observables and noise specified according to the PEtab format.

  • simulation_conditions – Table of simulation conditions as created by petab.get_simulation_conditions.

  • 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

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. The first two dicts map simulation parameter IDs to optimization parameter IDs or values (where values are fixed) for preequilibration and simulation condition, respectively. The last two dicts map simulation parameter IDs to the parameter scale of the respective parameter, again for preequilibration and simulation condition. If no preequilibration condition is defined, the respective dicts will be empty. NaN is used where no mapping exists.

petab.get_output_parameters(observable_df: pandas.core.frame.DataFrame, sbml_model: libsbml.Model, observables: bool = True, noise: bool = True) List[str][source]

Get output parameters

Returns IDs of parameters used in observable and noise formulas that are not defined in the SBML model.

Parameters
  • observable_df – PEtab observable table

  • sbml_model – SBML model

  • observables – Include parameters from observableFormulas

  • noise – Include parameters from noiseFormulas

Returns

List of output parameter IDs

petab.get_parameter_df(parameter_file: Optional[Union[str, pathlib.Path, List[str], pandas.core.frame.DataFrame]]) pandas.core.frame.DataFrame[source]

Read the provided parameter file into a pandas.Dataframe.

Parameters

parameter_file – Name of the file to read from or pandas.Dataframe.

Returns

Parameter DataFrame

petab.get_parameter_mapping_for_condition(condition_id: str, is_preeq: bool, cur_measurement_df: Optional[pandas.core.frame.DataFrame], sbml_model: libsbml.Model, condition_df: pandas.core.frame.DataFrame, parameter_df: Optional[pandas.core.frame.DataFrame] = None, simulation_parameters: Optional[Dict[str, str]] = None, warn_unmapped: bool = True, scaled_parameters: bool = False, fill_fixed_parameters: bool = True, allow_timepoint_specific_numeric_noise_parameters: bool = False) Tuple[Dict[str, Union[str, numbers.Number]], Dict[str, str]][source]

Create dictionary of parameter value and parameter scale mappings from PEtab-problem to SBML parameters for the given condition.

Parameters
  • condition_id – Condition ID for which to perform mapping

  • is_preeq – If True, output parameters will not be mapped

  • cur_measurement_df – Measurement sub-table for current condition, can be None if not relevant for parameter mapping

  • condition_df – PEtab condition DataFrame

  • parameter_df – PEtab parameter DataFrame

  • sbml_model – The sbml model with observables and noise specified according to the PEtab format used to retrieve simulation parameter IDs.

  • simulation_parameters – Model simulation parameter IDs mapped to parameter values (output of petab.sbml.get_model_parameters(.., with_values=True)). 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 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.

petab.get_parametric_overrides(condition_df: pandas.core.frame.DataFrame) List[str][source]

Get parametric overrides from condition table

Parameters

condition_df – PEtab condition table

Returns

List of parameter IDs that are mapped in a condition-specific way

petab.get_placeholders(observable_df: pandas.core.frame.DataFrame, observables: bool = True, noise: bool = True) List[str][source]

Get all placeholder parameters from observable table observableFormulas and noiseFormulas

Parameters
  • observable_df – PEtab observable table

  • observables – Include parameters from observableFormulas

  • noise – Include parameters from noiseFormulas

Returns

List of placeholder parameters from observable table observableFormulas and noiseFormulas.

petab.get_priors_from_df(parameter_df: pandas.core.frame.DataFrame, mode: str) List[Tuple][source]

Create list with information about the parameter priors

Parameters
  • parameter_df – PEtab parameter table

  • mode – ‘initialization’ or ‘objective’

Returns

List with prior information.

petab.get_required_parameters_for_parameter_table(sbml_model: libsbml.Model, condition_df: pandas.core.frame.DataFrame, observable_df: pandas.core.frame.DataFrame, measurement_df: pandas.core.frame.DataFrame) Set[str][source]

Get set of parameters which need to go into the parameter table

Parameters
  • sbml_model – PEtab SBML model

  • condition_df – PEtab condition table

  • observable_df – PEtab observable table

  • measurement_df – PEtab measurement table

Returns

Set of parameter IDs which PEtab requires to be present in the parameter table. That is all {observable,noise}Parameters from the measurement table as well as all parametric condition table overrides that are not defined in the SBML model.

petab.get_rows_for_condition(measurement_df: pandas.core.frame.DataFrame, condition: Union[pandas.core.series.Series, pandas.core.frame.DataFrame, Dict]) pandas.core.frame.DataFrame[source]

Extract rows in measurement_df for condition according to ‘preequilibrationConditionId’ and ‘simulationConditionId’ in condition.

Parameters
  • measurement_df – PEtab measurement DataFrame

  • condition – DataFrame with single row (or Series) and columns ‘preequilibrationConditionId’ and ‘simulationConditionId’. Or dictionary with those keys.

Returns

The subselection of rows in measurement_df for the condition condition.

petab.get_sbml_model(filepath_or_buffer) Tuple[libsbml.SBMLReader, libsbml.SBMLDocument, libsbml.Model][source]

Get an SBML model from file or URL or file handle

Parameters

filepath_or_buffer – File or URL or file handle to read the model from

Returns

The SBML document, model and reader

petab.get_sigmas(sbml_model: libsbml.Model, remove: bool = False) dict[source]

Get sigmas defined in SBML model according to PEtab format.

Returns

Dictionary of sigma definitions.

Keys are observable IDs, for values see assignment_rules_to_dict for details.

petab.get_simulation_conditions(measurement_df: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame[source]

Create a table of separate simulation conditions. A simulation condition is a specific combination of simulationConditionId and preequilibrationConditionId.

Parameters

measurement_df – PEtab measurement table

Returns

Dataframe with columns ‘simulationConditionId’ and ‘preequilibrationConditionId’. All-null columns will be omitted. Missing ‘preequilibrationConditionId’s will be set to ‘’ (empty string).

petab.get_simulation_df(simulation_file: str) pandas.core.frame.DataFrame[source]

Read PEtab simulation table

Parameters

simulation_file – URL or filename of PEtab simulation table

Returns

Simulation DataFrame

petab.get_symbolic_noise_formulas(observable_df) dict[source]

Sympify noise formulas.

Parameters

observable_df – The observable table.

Returns

{noise_formula}.

Return type

Dictionary of {observable_id}

petab.get_valid_parameters_for_parameter_table(sbml_model: libsbml.Model, condition_df: pandas.core.frame.DataFrame, observable_df: pandas.core.frame.DataFrame, measurement_df: pandas.core.frame.DataFrame) Set[str][source]

Get set of parameters which may be present inside the parameter table

Parameters
  • sbml_model – PEtab SBML model

  • condition_df – PEtab condition table

  • observable_df – PEtab observable table

  • measurement_df – PEtab measurement table

Returns

Set of parameter IDs which PEtab allows to be present in the parameter table.

petab.get_visualization_df(visualization_file: Union[str, pathlib.Path]) pandas.core.frame.DataFrame[source]

Read PEtab visualization table

Parameters

visualization_file – URL or filename of PEtab visualization table

Returns

Visualization DataFrame

petab.globalize_parameters(sbml_model: libsbml.Model, prepend_reaction_id: bool = False) None[source]

Turn all local parameters into global parameters with the same properties

Local parameters are currently ignored by other PEtab functions. Use this function to convert them to global parameters. There may exist local parameters with identical IDs within different kinetic laws. This is not checked here. If in doubt that local parameter IDs are unique, enable prepend_reaction_id to create global parameters named ${reaction_id}_${local_parameter_id}.

Parameters
  • sbml_model – The SBML model to operate on

  • prepend_reaction_id – Prepend reaction id of local parameter when creating global parameters

petab.handle_missing_overrides(mapping_par_opt_to_par_sim: Dict[str, Union[str, numbers.Number]], warn: bool = True, condition_id: Optional[str] = None) None[source]

Find all observable parameters and noise parameters that were not mapped and set their mapping to np.nan.

Assumes that parameters matching “(noise|observable)Parameter[0-9]+_” were all supposed to be overwritten.

Parameters
  • mapping_par_opt_to_par_sim – Output of get_parameter_mapping_for_condition()

  • warn – If True, log warning regarding unmapped parameters

  • condition_id – Optional condition ID for more informative output

petab.is_composite_problem(yaml_config: Union[Dict, str, pathlib.Path]) bool[source]

Does this YAML file comprise multiple models?

Parameters

yaml_config – PEtab configuration as dictionary or YAML file name

petab.is_empty(val) bool[source]

Check if the value val, e.g. a table entry, is empty.

Parameters

val – The value to check.

Returns

Whether the field is to be considered empty.

petab.is_sbml_consistent(sbml_document: libsbml.SBMLDocument, check_units: bool = False) bool[source]

Check for SBML validity / consistency

Parameters
  • sbml_document – SBML document to check

  • check_units – Also check for unit-related issues

Returns

False if problems were detected, otherwise True

petab.is_scalar_float(x: Any)[source]

Checks whether input is a number or can be transformed into a number via float

Parameters

x – input

Returns

True if is or can be converted to number, False otherwise.

petab.is_valid_identifier(x: str) bool[source]

Check whether x is a valid identifier

Check whether x is a valid identifier for conditions, parameters, observables… . Identifiers may contain upper and lower case letters, digits and underscores, but must not start with a digit.

Parameters

x – string to check

Returns

True if valid, False otherwise

petab.lint_problem(problem: petab.problem.Problem) bool[source]

Run PEtab validation on problem

Parameters

problem – PEtab problem to check

Returns

True if errors occurred, False otherwise

petab.load_sbml_from_file(sbml_file: str) Tuple[libsbml.SBMLReader, libsbml.SBMLDocument, libsbml.Model][source]

Load SBML model from file

Parameters

sbml_file – Filename of the SBML file

Returns

The SBML document, model and reader

petab.load_sbml_from_string(sbml_string: str) Tuple[libsbml.SBMLReader, libsbml.SBMLDocument, libsbml.Model][source]

Load SBML model from string

Parameters

sbml_string – Model as XML string

Returns

The SBML document, model and reader

petab.load_yaml(yaml_config: Union[Dict, pathlib.Path, str]) Dict[source]

Load YAML

Convenience function to allow for providing YAML inputs as filename, URL or as dictionary.

Parameters

yaml_config – PEtab YAML config as filename or dict or URL.

Returns

The unmodified dictionary if yaml_config was dictionary. Otherwise the parsed the YAML file.

petab.log_sbml_errors(sbml_document: libsbml.SBMLDocument, minimum_severity=1) None[source]

Log libsbml errors

Parameters
  • sbml_document – SBML document to check

  • minimum_severity – Minimum severity level to report (see libsbml)

petab.map_scale(parameters: Iterable[numbers.Number], scale_strs: Union[Iterable[str], str]) Iterable[numbers.Number][source]

Scale the parameters, i.e. as scale(), but for Iterables.

Parameters
  • parameters – Parameters to be scaled.

  • scale_strs – Scales to apply. Broadcast if a single string.

Returns

The scaled parameters.

petab.map_unscale(parameters: Iterable[numbers.Number], scale_strs: Union[Iterable[str], str]) Iterable[numbers.Number][source]

Unscale the parameters, i.e. as unscale(), but for Iterables.

Parameters
  • parameters – Parameters to be unscaled.

  • scale_strs – Scales that the parameters are currently on. Broadcast if a single string.

Returns

The unscaled parameters.

petab.measurement_table_has_observable_parameter_numeric_overrides(measurement_df: pandas.core.frame.DataFrame) bool[source]

Are there any numbers to override observable parameters?

Parameters

measurement_df – PEtab measurement table

Returns

True if there are any numbers to override observable/noise parameters, False otherwise.

petab.measurement_table_has_timepoint_specific_mappings(measurement_df: Optional[pandas.core.frame.DataFrame], allow_scalar_numeric_noise_parameters: bool = False, allow_scalar_numeric_observable_parameters: bool = False) bool[source]

Are there time-point or replicate specific parameter assignments in the measurement table.

Parameters
  • measurement_df – PEtab measurement table

  • allow_scalar_numeric_noise_parameters – ignore scalar numeric assignments to noiseParameter placeholders

  • allow_scalar_numeric_observable_parameters – ignore scalar numeric assignments to observableParameter placeholders

Returns

True if there are time-point or replicate specific (non-numeric) parameter assignments in the measurement table, False otherwise.

petab.measurements_have_replicates(measurement_df: pandas.core.frame.DataFrame) bool[source]

Tests whether the measurements come with replicates

Parameters

measurement_df – Measurement table

Returns

True if there are replicates, False otherwise

petab.merge_preeq_and_sim_pars(parameter_mappings: Iterable[Tuple[Dict[str, Union[str, numbers.Number]], Dict[str, Union[str, numbers.Number]]]], scale_mappings: Iterable[Tuple[Dict[str, str], Dict[str, str]]]) Tuple[List[Tuple[Dict[str, Union[str, numbers.Number]], Dict[str, Union[str, numbers.Number]]]], List[Tuple[Dict[str, str], Dict[str, str]]]][source]

Merge preequilibration and simulation parameters and scales for a list of conditions while checking for compatibility.

Parameters
Returns

The parameter and scale simulation mappings, modified and checked.

petab.merge_preeq_and_sim_pars_condition(condition_map_preeq: Dict[str, Union[str, numbers.Number]], condition_map_sim: Dict[str, Union[str, numbers.Number]], condition_scale_map_preeq: Dict[str, str], condition_scale_map_sim: Dict[str, str], condition: Any) None[source]

Merge preequilibration and simulation parameters and scales for a single condition while checking for compatibility.

This function is meant for the case where we cannot have different parameters (and scales) for preequilibration and simulation. Therefore, merge both and ensure matching scales and parameters. condition_map_sim and condition_scale_map_sim will ne modified in place.

Parameters
petab.normalize_parameter_df(parameter_df: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame[source]

Add missing columns and fill in default values.

petab.observable_table_has_nontrivial_noise_formula(observable_df: Optional[pandas.core.frame.DataFrame]) bool[source]

Does any observable have a noise formula that is not just a single parameter?

Parameters

observable_df – PEtab observable table

Returns

True if any noise formula does not consist of a single identifier, False otherwise.

petab.sample_from_prior(prior: Tuple[str, list, str, list], n_starts: int) numpy.array[source]

Creates samples for one parameter based on prior

Parameters
  • prior – A tuple as obtained from petab.parameter.get_priors_from_df

  • n_starts – Number of samples

Returns

Array with sampled values

petab.sample_noise(petab_problem: petab.problem.Problem, measurement_row: pandas.core.series.Series, simulated_value: float, noise_formulas: Optional[Dict[str, sympy.core.expr.Expr]] = None, rng: Optional[numpy.random._generator.Generator] = None, noise_scaling_factor: float = 1, zero_bounded: bool = False) float[source]

Generate a sample from a PEtab noise distribution.

Parameters
  • petab_problem – The PEtab problem used to generate the simulated value. Instance of petab.Problem.

  • measurement_row – The row in the PEtab problem measurement table that corresponds to the simulated value.

  • simulated_value – A simulated value without noise.

  • noise_formulas – Processed noise formulas from the PEtab observables table, in the form output by the petab.calculate.get_symbolic_noise_formulas method.

  • rng – A NumPy random generator.

  • noise_scaling_factor – A multiplier of the scale of the noise distribution.

  • zero_bounded – Return zero if the sign of the return value and simulated_value differ. Can be used to ensure non-negative and non-positive values, if the sign of simulated_value should not change.

Returns

The sample from the PEtab noise distribution.

petab.sample_parameter_startpoints(parameter_df: pandas.core.frame.DataFrame, n_starts: int = 100, seed: Optional[int] = None) numpy.array[source]

Create numpy.array with starting points for an optimization

Parameters
  • parameter_df – PEtab parameter DataFrame

  • n_starts – Number of points to be sampled

  • seed – Random number generator seed (see numpy.random.seed)

Returns

Array of sampled starting points with dimensions n_startpoints x n_optimization_parameters

petab.sbml_parameter_is_observable(sbml_parameter: libsbml.Parameter) bool[source]

Returns whether the libsbml.Parameter sbml_parameter matches the defined observable format.

petab.sbml_parameter_is_sigma(sbml_parameter: libsbml.Parameter) bool[source]

Returns whether the libsbml.Parameter sbml_parameter matches the defined sigma format.

petab.scale(parameter: numbers.Number, scale_str: str) numbers.Number[source]

Scale parameter according to scale_str.

Parameters
  • parameter – Parameter to be scaled.

  • scale_str – One of ‘lin’ (synonymous with ‘’), ‘log’, ‘log10’.

Returns

The scaled parameter.

petab.split_parameter_replacement_list(list_string: Union[str, numbers.Number], delim: str = ';') List[Union[str, numbers.Number]][source]

Split values in observableParameters and noiseParameters in measurement table.

Parameters
  • list_string – delim-separated stringified list

  • delim – delimiter

Returns

List of split values. Numeric values may be converted to float, and parameter IDs are kept as strings.

petab.to_float_if_float(x: Any) Any[source]

Return input as float if possible, otherwise return as is

Parameters

x – Anything

Returns

x as float if possible, otherwise x

petab.unique_preserve_order(seq: Sequence) List[source]

Return a list of unique elements in Sequence, keeping only the first occurrence of each element

Parameters

seq – Sequence to prune

Returns

List of unique elements in seq

petab.unscale(parameter: numbers.Number, scale_str: str) numbers.Number[source]

Unscale parameter according to scale_str.

Parameters
  • parameter – Parameter to be unscaled.

  • scale_str – One of ‘lin’ (synonymous with ‘’), ‘log’, ‘log10’.

Returns

The unscaled parameter.

petab.validate(yaml_config: Union[Dict, str, pathlib.Path], path_prefix: Optional[Union[str, pathlib.Path]] = None)[source]

Validate syntax and semantics of PEtab config YAML

Parameters
  • yaml_config – PEtab YAML config as filename or dict.

  • path_prefix – Base location for relative paths. Defaults to location of YAML file if a filename was provided for yaml_config or the current working directory.

petab.validate_yaml_semantics(yaml_config: Union[Dict, str, pathlib.Path], path_prefix: Optional[Union[str, pathlib.Path]] = None)[source]

Validate PEtab YAML file semantics

Check for existence of files. Assumes valid syntax.

Version number and contents of referenced files are not yet checked.

Parameters
  • yaml_config – PEtab YAML config as filename or dict.

  • path_prefix – Base location for relative paths. Defaults to location of YAML file if a filename was provided for yaml_config or the current working directory.

Raises

AssertionError – in case of problems

petab.validate_yaml_syntax(yaml_config: Union[Dict, str, pathlib.Path], schema: Union[None, Dict, str] = None)[source]

Validate PEtab YAML file syntax

Parameters
  • yaml_config – PEtab YAML file to validate, as file name or dictionary

  • schema – Custom schema for validation

Raises

see jsonschema.validate

petab.write_condition_df(df: pandas.core.frame.DataFrame, filename: Union[str, pathlib.Path]) None[source]

Write PEtab condition table

Parameters
  • df – PEtab condition table

  • filename – Destination file name

petab.write_measurement_df(df: pandas.core.frame.DataFrame, filename: Union[str, pathlib.Path]) None[source]

Write PEtab measurement table

Parameters
  • df – PEtab measurement table

  • filename – Destination file name

petab.write_observable_df(df: pandas.core.frame.DataFrame, filename: Union[str, pathlib.Path]) None[source]

Write PEtab observable table

Parameters
  • df – PEtab observable table

  • filename – Destination file name

petab.write_parameter_df(df: pandas.core.frame.DataFrame, filename: Union[str, pathlib.Path]) None[source]

Write PEtab parameter table

Parameters
  • df – PEtab parameter table

  • filename – Destination file name

petab.write_sbml(sbml_doc: libsbml.SBMLDocument, filename: Union[pathlib.Path, str]) None[source]

Write PEtab visualization table

Parameters
  • sbml_doc – SBML document containing the SBML model

  • filename – Destination file name

petab.write_simulation_df(df: pandas.core.frame.DataFrame, filename: str) None[source]

Write PEtab simulation table

Parameters
  • df – PEtab simulation table

  • filename – Destination file name

petab.write_visualization_df(df: pandas.core.frame.DataFrame, filename: Union[str, pathlib.Path]) None[source]

Write PEtab visualization table

Parameters
  • df – PEtab visualization table

  • filename – Destination file name

petab.write_yaml(yaml_config: Dict[str, Any], filename: Union[str, pathlib.Path]) None[source]

Write PEtab YAML file

Parameters
  • yaml_config – Data to write

  • filename – File to create

Modules

petab.C

This file contains constant definitions.

petab.calculate

Functions performing various calculations.

petab.composite_problem

PEtab problems consisting of multiple models

petab.conditions

Functions operating on the PEtab condition table

petab.core

PEtab core functions (or functions that don't fit anywhere else)

petab.lint

Integrity checks and tests for specific features used

petab.measurements

Functions operating on the PEtab measurement table

petab.observables

Functions for working with the PEtab observables table

petab.parameter_mapping

Functions related to mapping parameter from model to parameter estimation problem

petab.parameters

Functions operating on the PEtab parameter table

petab.problem

PEtab Problem class

petab.sampling

Functions related to parameter sampling

petab.sbml

Functions for interacting with SBML models

petab.simulate

PEtab simulator base class and related functions.

petab.visualize

Visualize

petab.yaml

Code regarding the PEtab YAML config files