Working with PEtab

PEtab is a standard file format, describing parameter estimation problems. While COPASI does not support the full feature set of PEtab, with basico we can import PEtab problems, and analyze them. THis is an optional dependency, that is only installed, when basico is installed using:

pip install copasi-basico[petab]

assuming this is done, and that a petab problem is in the local directory, you can load it and analyze it like so:

from basico import *
import basico.petab
using COPASI: 4.37.264 (Source)

within the basico.petab module we define a PetabSimulator, that automatically imports a PEtab file, and transforms the experimental data files as needed by COPASI. It implementes the petab.simulate.Simulator interface that can be used for other libraries using libpetab.

So lets start by loading a PEtab problem

from petab import Problem
pp = Problem.from_yaml('./Elowitz_Nature2000/Elowitz_Nature2000.yaml')

now lets instantiate the simulator with:

  • pp: the petab problem

  • working_dir: the directory where temp files can be stored

we are not specifying any additional optimization settings, so the parameter estimation task will be set to ‘Current Solution Statistics’, meaning that no actual optimization will be performed:

sim = basico.petab.PetabSimulator(pp, working_dir='./temp_dir/')

now lets simulate it:

df = sim.simulate()

At this point the file can be opened directly in COPASI using open_copasi(), or here I use the visualization library from libpetab, to plot the problem and simulation obtained:

import petab.visualize
petab.visualize.plot_problem(pp, simulations_df=df)
{'plot1': <AxesSubplot: xlabel='time', ylabel='values'>}

Model Selection

Using the petab_select library, model selection is also wrapped within basico. It will instantiate the petab problem, and explore all models according to the specified method:

import petab_select
problem = petab_select.Problem.from_yaml('./model_selection/petab_select_problem.yaml')

evaluating the problem will perform the calibrations. While COPASI uses different errorscaling than other PEtab scales, we would expect the same models being chosen:

best = basico.petab.evaluate_problem(problem, temp_dir='./temp_dir/', delete_temp_files=False)


at this point the best model returned could be turned into its own PEtab problem, and simulated as above:

pp = best.to_petab()['petab_problem']
sim = basico.petab.PetabSimulator(pp, working_dir='./temp_dir/')
petab.visualize.plot_problem(pp, simulations_df=sim.simulate())
{'plot1': <AxesSubplot: xlabel='time', ylabel='values'>}

finally lets clean up after ourselfes and delete all the temp files generated:

import shutil