API reference
This module serves as reference for the different classes and associated methods of the PhysioFit package.
fitter.py
PhysioFit software main module
- class physiofit.base.fitter.PhysioFitter(data: DataFrame, model: Model, mc: bool = True, iterations: int = 100, sd=None, debug_mode: bool = False)
Bases:
objectThis class is responsible for most of Physiofit’s heavy lifting. Features included are:
loading of data from csv or tsv file * **equation system
initialization** using the following analytical functions (in absence of lag and degradation):
X(t) = X0 * exp(mu * t) Mi(t) = qMi * (X0 / mu) * (exp(mu * t) - 1) + Mi0
simulation of data points from given initial parameters
cost calculation using the equation:
residuum = sum((sim - meas) / sd)²
optimization of the initial parameters using
scipy.optimize.minimize (‘Differential evolution’, with polish with ‘L-BFGS-B’ method) * sensitivity analysis, khi2 tests and plotting
- Parameters:
data (class: pandas.DataFrame :param model: Model to initialize) – DataFrame containing data and passed by IOstream object
parameters and optimize :type model: physiofit.models.base_model.Model :param mc: Should Monte-Carlo sensitivity analysis be performed ( default=True) :type mc: Boolean :param iterations: number of iterations for Monte-Carlo simulation (default=50) :type iterations: int :param sd: sd matrix used for residuum calculations. Can be:
a matrix with the same dimensions as the measurements
matrix (but without the time column) * a named vector containing sds for all the metabolites provided in the input file * 0 in which case the matrix is automatically constructed from default values * a dictionary with the data column headers as keys and the associated value as a scalar or list
- aic_test()
Calculate the Akaike Information Criterion (AIC) for the model
- initialize_sd_matrix()
Initialize the sd matrix from different types of inputs: single value, vector or matrix.
- Returns:
None
- khi2_test()
This method performs a chi-squared test to evaluate the goodness of fit of the model. It calculates the chi-squared statistic and the p-value and logs the results.
The chi-squared test is a statistical hypothesis test that is valid to perform when the test statistic is chi-squared distributed under the null hypothesis.
- monte_carlo_analysis()
Run a monte carlo analysis to calculate optimization standard deviations on parameters and simulated data points
- optimize()
Run optimization and build the simulated matrix from the optimized parameters
- verify_attrs()
Check that attributes are valid
io.py
Module to handle inputs and outputs for PhysioFit
- class physiofit.base.io.ConfigParser(selected_model, sds, mc, iterations, path_to_data=None)
Bases:
objectThe ConfigParser class is used to parse configuration files for the PhysioFit package. It reads a YAML file and extracts the necessary parameters for the model fitting process. It also includes methods to update the model with the parsed parameters and export the run parameters back to a yaml config file.
- AUTHORIZED_KEYS = ['path_to_data', 'model', 'sds', 'mc', 'iterations']
- check_data_path()
Check if the data path is valid :return: True if the path is valid, False otherwise, None if no path
- export_config(export_path)
- classmethod from_file(yaml_file)
- classmethod from_galaxy(galaxy_yaml)
- get_kwargs()
- update_model(model)
- class physiofit.base.io.IoHandler
Bases:
objectInput/Output class that handles the former and initializes the PhysioFitter component object. It is the preferred interface for interacting with the PhysioFit package.
- static add_model(model_file)
- allowed_keys = {'debug_mode', 'iterations', 'mc', 'model', 'sd'}
- static get_local_model_folder() str
Return the path towards the actual environment’s used models folder
- static get_model_list()
- get_models(data: DataFrame = None)
Read modules containing the different models and add them to models attribute
- Returns:
list containing the different model objects
- initialize_fitter(data: DataFrame, **kwargs) PhysioFitter
Initialize a PhysioFitter object
- Parameters:
data – input data
kwargs – Keyword arguments for fitter initialization
- Returns:
None
- output_pdf(fitter: PhysioFitter, export_path: str | Path = None)
Handle the creation and output of a pdf file containing fit results as a plot
- Parameters:
fitter
export_path – Path to exported pdf. In local mode, it is sent to the _res directory
- Returns:
None
- output_plots(fitter, export_path)
Handle the creation and export of the different plots in svg format :return: None
- output_recap(export_path: str, galaxy=False)
- static output_report(fitter, export_path: str | list = None)
Handle creation and export of the report containing stats from monte carlo analysis of optimization parameters
- Parameters:
export_path – Path to export the report
fitter – PhysioFitter object containing results from the optimization of parameters
export_path – list of paths to export the stats and fluxes. [ 0] is for stats and [1] for fluxes.
- plot_data(fitter, display: bool = False)
Plot the data
- Parameters:
display – Should plots be displayed or not on creation
fitter – PhysioFitter object after optimization of parameters
has been executed
- static read_data(data: str) DataFrame
Read initial data file (csv or tsv)
- Parameters:
data – str containing the relative or absolute path to the data
- Returns:
pandas DataFrame containing the data
- static read_model(model_file: str)
Import and return the model class from .py file containing the model.
code from untrusted sources can lead to propagation of viruses and compromised security.
- Parameters:
model_file – path to the model.py file to import
- static read_yaml(yaml_file: str | bytes) ConfigParser
Import yaml configuration file and parse keyword arguments
- Parameters:
yaml_file – path to the yaml file or json file :return
config_parser: Dictionary containing arguments parsed from yaml file
gui.py
- class physiofit.ui.gui.App
Bases:
objectPhysiofit Graphical User Interface
- check_uptodate()
Compare installed and most recent Physiofit versions.
- static clear_input_from_session_state()
- silent_sim()
- start_app()
Launch the application
base_model.py
- class physiofit.models.base_model.Bounds(mapping=None, **kwargs)
Bases:
dict
- class physiofit.models.base_model.Model(data: DataFrame)
Bases:
ABC- abstract get_params()
- Return params_to_estimate:
List of parameters to estimate
- Return fixed_parameters:
dict of constant parameters
- Return bounds:
dict of upper and lower bounds
- Return default_init_values:
dict containing default initial values for params
- abstract static simulate(parameters: list, data_matrix: ndarray | DataFrame, time_vector: ndarray, args: dict | list)
- exception physiofit.models.base_model.ModelError
Bases:
Exception