petab.core

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

Functions

concat_tables(tables[, file_parser])

Concatenate DataFrames provided as DataFrames or filenames, and a parser

create_combine_archive(yaml_file, filename)

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

flatten_timepoint_specific_output_overrides(...)

Flatten timepoint-specific output parameter overrides.

get_flattened_id_mappings(petab_problem)

Get mapping from unflattened to flattened observable IDs.

get_hyperparameter_replacement_id(...)

Get the full ID for a replaced hyperparameter.

get_notnull_columns(df, candidates)

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

get_observable_replacement_id(groupvars, ...)

Get the replacement ID for an observable.

get_simulation_df(simulation_file)

Read PEtab simulation table

get_visualization_df(visualization_file)

Read PEtab visualization table

is_empty(val)

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

to_float_if_float(x)

Return input as float if possible, otherwise return as is

unflatten_simulation_df(simulation_df, ...)

Unflatten simulations from a flattened PEtab problem.

unique_preserve_order(seq)

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

write_simulation_df(df, filename)

Write PEtab simulation table

write_visualization_df(df, filename)

Write PEtab visualization table

petab.core.concat_tables(tables: str | Path | DataFrame | Iterable[DataFrame | str | Path], file_parser: Callable | None = None) 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.core.create_combine_archive(yaml_file: str | Path, filename: str | Path, family_name: str | None = None, given_name: str | None = None, email: str | None = None, organization: str | None = 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.core.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. Modified in place.

petab.core.get_notnull_columns(df: 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.core.get_simulation_df(simulation_file: str | Path) DataFrame[source]

Read PEtab simulation table

Parameters:

simulation_file – URL or filename of PEtab simulation table

Returns:

Simulation DataFrame

petab.core.get_visualization_df(visualization_file: str | Path | DataFrame | None) DataFrame | None[source]

Read PEtab visualization table

Parameters:

visualization_file – URL or filename of PEtab visualization table to read from, or a DataFrame or None that will be returned as is.

Returns:

Visualization DataFrame

petab.core.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.core.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.core.unflatten_simulation_df(simulation_df: DataFrame, petab_problem: petab.problem.Problem) DataFrame[source]

Unflatten simulations from a flattened PEtab problem.

A flattened PEtab problem is the output of applying flatten_timepoint_specific_output_overrides() to a PEtab problem.

Parameters:
  • simulation_df – The simulation dataframe. A dataframe in the same format as a PEtab measurements table, but with the measurement column switched with a simulation column.

  • petab_problem – The unflattened PEtab problem.

Returns:

The simulation dataframe for the unflattened PEtab problem.

petab.core.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.core.write_simulation_df(df: DataFrame, filename: str | Path) None[source]

Write PEtab simulation table

Parameters:
  • df – PEtab simulation table

  • filename – Destination file name

petab.core.write_visualization_df(df: DataFrame, filename: str | Path) None[source]

Write PEtab visualization table

Parameters:
  • df – PEtab visualization table

  • filename – Destination file name