petab.parameter_mapping

Functions related to mapping parameter from model to parameter estimation problem

Functions

get_optimization_to_simulation_parameter_mapping(…)

Create list of mapping dicts from PEtab-problem to SBML parameters.

get_parameter_mapping_for_condition(…[, …])

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

handle_missing_overrides(…[, warn, …])

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

merge_preeq_and_sim_pars(parameter_mappings, …)

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

merge_preeq_and_sim_pars_condition(…)

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

petab.parameter_mapping._apply_condition_parameters(par_mapping: Dict[str, Union[str, numbers.Number]], scale_mapping: Dict[str, str], condition_id: str, condition_df: pandas.core.frame.DataFrame, sbml_model: libsbml.Model)None[source]

Replace parameter IDs in parameter mapping dictionary by condition table parameter values (in-place).

Parameters
petab.parameter_mapping._apply_output_parameter_overrides(mapping: Dict[str, Union[str, numbers.Number]], cur_measurement_df: pandas.core.frame.DataFrame)None[source]

Apply output parameter overrides to the parameter mapping dict for a given condition as defined in the measurement table (observableParameter, noiseParameters).

Parameters
petab.parameter_mapping._apply_overrides_for_observable(mapping: Dict[str, Union[str, numbers.Number]], observable_id: str, override_type: str, overrides: List[str])None[source]

Apply parameter-overrides for observables and noises to mapping matrix.

Parameters
  • mapping – mapping dict to which to apply overrides

  • observable_id – observable ID

  • override_type – ‘observable’ or ‘noise’

  • overrides – list of overrides for noise or observable parameters

petab.parameter_mapping._apply_parameter_table(par_mapping: Dict[str, Union[str, numbers.Number]], scale_mapping: Dict[str, str], parameter_df: Optional[pandas.core.frame.DataFrame] = None, scaled_parameters: bool = False, fill_fixed_parameters: bool = True)None[source]

Replace parameters from parameter table in mapping list for a given condition and set the corresponding scale.

Replace non-estimated parameters by nominalValues (un-scaled / lin-scaled), replace estimated parameters by the respective ID.

Parameters
petab.parameter_mapping._map_condition(packed_args)[source]

Helper function for parallel condition mapping.

For arguments see get_optimization_to_simulation_parameter_mapping().

petab.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, allow_timepoint_specific_numeric_noise_parameters)[source]

Helper function to pack extra arguments for _map_condition

petab.parameter_mapping._output_parameters_to_nan(mapping: Dict[str, Union[str, numbers.Number]])None[source]

Set output parameters in mapping dictionary to nan

petab.parameter_mapping._perform_mapping_checks(measurement_df: pandas.core.frame.DataFrame, allow_timepoint_specific_numeric_noise_parameters: bool = False)None[source]

Check for PEtab features which we can’t account for during parameter mapping.

petab.parameter_mapping.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.parameter_mapping.get_parameter_mapping_for_condition(condition_id: str, is_preeq: bool, cur_measurement_df: 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

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