petab.lint

Integrity checks and tests for specific features used

Functions

assert_all_parameters_present_in_parameter_df(…)

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

assert_measured_observables_defined(…)

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

assert_measurement_conditions_present_in_condition_table(…)

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

assert_model_parameters_in_condition_or_parameter_table(…)

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

assert_no_leading_trailing_whitespace(…)

Check that there is no trailing whitespace in elements of Iterable

assert_noise_distributions_valid(observable_df)

Ensure that noise distributions and transformations for observables are valid.

assert_parameter_bounds_are_numeric(parameter_df)

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

assert_parameter_estimate_is_boolean(…)

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

assert_parameter_id_is_string(parameter_df)

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

assert_parameter_prior_parameters_are_valid(…)

Check that the prior parameters are valid.

assert_parameter_prior_type_is_valid(…)

Check that valid prior types have been selected

assert_parameter_scale_is_valid(parameter_df)

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.

assert_unique_observable_ids(observable_df)

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

assert_unique_parameter_ids(parameter_df)

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

check_condition_df(df[, sbml_model])

Run sanity checks on PEtab condition table

check_ids(ids[, kind])

Check IDs are valid

check_measurement_df(df[, observable_df])

Run sanity checks on PEtab measurement table

check_observable_df(observable_df)

Check validity of observable table

check_parameter_bounds(parameter_df)

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.

check_parameter_df(df[, sbml_model, …])

Run sanity checks on PEtab parameter table

condition_table_is_parameter_free(condition_df)

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

get_non_unique(values)

is_valid_identifier(x)

Check whether x is a valid identifier

lint_problem(problem)

Run PEtab validation on problem

measurement_table_has_observable_parameter_numeric_overrides(…)

Are there any numbers to override observable parameters?

measurement_table_has_timepoint_specific_mappings(…)

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

class petab.lint.Counter(**kwds)

Bases: dict

Dict subclass for counting hashable items. Sometimes called a bag or multiset. Elements are stored as dictionary keys and their counts are stored as dictionary values.

>>> c = Counter('abcdeabcdabcaba')  # count elements from a string
>>> c.most_common(3)                # three most common elements
[('a', 5), ('b', 4), ('c', 3)]
>>> sorted(c)                       # list all unique elements
['a', 'b', 'c', 'd', 'e']
>>> ''.join(sorted(c.elements()))   # list elements with repetitions
'aaaaabbbbcccdde'
>>> sum(c.values())                 # total of all counts
15
>>> c['a']                          # count of letter 'a'
5
>>> for elem in 'shazam':           # update counts from an iterable
...     c[elem] += 1                # by adding 1 to each element's count
>>> c['a']                          # now there are seven 'a'
7
>>> del c['b']                      # remove all 'b'
>>> c['b']                          # now there are zero 'b'
0
>>> d = Counter('simsalabim')       # make another counter
>>> c.update(d)                     # add in the second counter
>>> c['a']                          # now there are nine 'a'
9
>>> c.clear()                       # empty the counter
>>> c
Counter()

Note: If a count is set to zero or reduced to zero, it will remain in the counter until the entry is deleted or the counter is cleared:

>>> c = Counter('aaabbc')
>>> c['b'] -= 2                     # reduce the count of 'b' by two
>>> c.most_common()                 # 'b' is still in, but its count is zero
[('a', 3), ('c', 1), ('b', 0)]
_keep_positive()

Internal method to strip elements with a negative or zero count

clear()None.  Remove all items from D.
copy()

Return a shallow copy.

elements()

Iterator over elements repeating each as many times as its count.

>>> c = Counter('ABCABC')
>>> sorted(c.elements())
['A', 'A', 'B', 'B', 'C', 'C']

# Knuth’s example for prime factors of 1836: 2**2 * 3**3 * 17**1 >>> prime_factors = Counter({2: 2, 3: 3, 17: 1}) >>> product = 1 >>> for factor in prime_factors.elements(): # loop over factors … product *= factor # and multiply them >>> product 1836

Note, if an element’s count has been set to zero or is a negative number, elements() will ignore it.

classmethod fromkeys(iterable, v=None)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items()a set-like object providing a view on D’s items
keys()a set-like object providing a view on D’s keys
most_common(n=None)

List the n most common elements and their counts from the most common to the least. If n is None, then list all element counts.

>>> Counter('abcdeabcdabcaba').most_common(3)
[('a', 5), ('b', 4), ('c', 3)]
pop(k[, d])v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem()(k, v), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

subtract(**kwds)

Like dict.update() but subtracts counts instead of replacing them. Counts can be reduced below zero. Both the inputs and outputs are allowed to contain zero and negative counts.

Source can be an iterable, a dictionary, or another Counter instance.

>>> c = Counter('which')
>>> c.subtract('witch')             # subtract elements from another iterable
>>> c.subtract(Counter('watch'))    # subtract elements from another counter
>>> c['h']                          # 2 in which, minus 1 in witch, minus 1 in watch
0
>>> c['w']                          # 1 in which, minus 1 in witch, minus 1 in watch
-1
update(**kwds)

Like dict.update() but add counts instead of replacing them.

Source can be an iterable, a dictionary, or another Counter instance.

>>> c = Counter('which')
>>> c.update('witch')           # add elements from another iterable
>>> d = Counter('watch')
>>> c.update(d)                 # add elements from another counter
>>> c['h']                      # four 'h' in which, witch, and watch
4
values()an object providing a view on D’s values
petab.lint._check_df(df: pandas.core.frame.DataFrame, req_cols: Iterable, name: str)None

Check if given columns are present in DataFrame

Parameters
  • df – Dataframe to check

  • req_cols – Column names which have to be present

  • name – Name of the DataFrame to be included in error message

Raises

AssertionError – if a column is missing

petab.lint.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

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.lint.assert_measured_observables_defined(measurement_df: pandas.core.frame.DataFrame, observable_df: pandas.core.frame.DataFrame)None

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.lint.assert_measurement_conditions_present_in_condition_table(measurement_df: pandas.core.frame.DataFrame, condition_df: pandas.core.frame.DataFrame)None

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.lint.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

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.lint.assert_no_leading_trailing_whitespace(names_list: Iterable[str], name: str)None

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.lint.assert_noise_distributions_valid(observable_df: pandas.core.frame.DataFrame)None

Ensure that noise distributions and transformations for observables are valid.

Parameters

observable_df – PEtab observable table

Raises

AssertionError – in case of problems

petab.lint.assert_parameter_bounds_are_numeric(parameter_df: pandas.core.frame.DataFrame)None

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.lint.assert_parameter_estimate_is_boolean(parameter_df: pandas.core.frame.DataFrame)None

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.lint.assert_parameter_id_is_string(parameter_df: pandas.core.frame.DataFrame)None

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.lint.assert_parameter_prior_parameters_are_valid(parameter_df: pandas.core.frame.DataFrame)None

Check that the prior parameters are valid.

Parameters

parameter_df – PEtab parameter table

Raises

AssertionError in case of invalide prior parameters

petab.lint.assert_parameter_prior_type_is_valid(parameter_df: pandas.core.frame.DataFrame)None

Check that valid prior types have been selected

Parameters

parameter_df – PEtab parameter table

Raises

AssertionError in case of invalid prior

petab.lint.assert_parameter_scale_is_valid(parameter_df: pandas.core.frame.DataFrame)None

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.lint.assert_unique_observable_ids(observable_df: pandas.core.frame.DataFrame)None

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

Parameters

observable_df – PEtab observable DataFrame

Raises

AssertionError – in case of problems

petab.lint.assert_unique_parameter_ids(parameter_df: pandas.core.frame.DataFrame)None

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

Parameters

parameter_df – PEtab parameter DataFrame

Raises

AssertionError – in case of problems

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

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.lint.check_ids(ids: Iterable[str], kind: str = '')None

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.lint.check_measurement_df(df: pandas.core.frame.DataFrame, observable_df: Optional[pandas.core.frame.DataFrame] = None)None

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.lint.check_observable_df(observable_df: pandas.core.frame.DataFrame)None

Check validity of observable table

Parameters

observable_df – PEtab observable DataFrame

Raises

AssertionError – in case of problems

petab.lint.check_parameter_bounds(parameter_df: pandas.core.frame.DataFrame)None

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.lint.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

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.lint.condition_table_is_parameter_free(condition_df: pandas.core.frame.DataFrame)bool

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.lint.is_valid_identifier(x: str)bool

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.lint_problem(problem: petab.problem.Problem)bool

Run PEtab validation on problem

Parameters

problem – PEtab problem to check

Returns

True is errors occurred, False otherwise

petab.lint.measurement_table_has_observable_parameter_numeric_overrides(measurement_df: pandas.core.frame.DataFrame)bool

Are there any numbers to override observable parameters?

Parameters

measurement_df – PEtab measurement table

Returns

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

petab.lint.measurement_table_has_timepoint_specific_mappings(measurement_df: pandas.core.frame.DataFrame)bool

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

Parameters

measurement_df – PEtab measurement table

Returns

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