petab.visualize.cli
Command-line interface for visualization.
- class petab.visualize.cli.Path(*args, **kwargs)[source]
Bases:
PurePath
PurePath subclass that can make system calls.
Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa.
- _raw_open(flags, mode=511)[source]
Open the file pointed by this path and return a file descriptor, as os.open() does.
- absolute()[source]
Return an absolute version of this path. This function works even if the path doesn’t point to anything.
No normalization is done, i.e. all ‘.’ and ‘..’ will be kept along. Use resolve() to get the canonical path to a file.
- property anchor
The concatenation of the drive and root, or ‘’.
- as_posix()
Return the string representation of the path with forward (/) slashes.
- as_uri()
Return the path as a ‘file’ URI.
- classmethod cwd()[source]
Return a new path pointing to the current working directory (as returned by os.getcwd()).
- property drive
The drive prefix (letter or UNC path), if any.
- expanduser()[source]
Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)
- glob(pattern)[source]
Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.
- classmethod home()[source]
Return a new path pointing to the user’s home directory (as returned by os.path.expanduser(‘~’)).
- is_absolute()
True if the path is absolute (has both a root and, if applicable, a drive).
- is_file()[source]
Whether this path is a regular file (also True for symlinks pointing to regular files).
- is_relative_to(*other)
Return True if the path is relative to another path or False.
- is_reserved()
Return True if the path contains one of the special names reserved by the system, if any.
- iterdir()[source]
Iterate over the files in this directory. Does not yield any result for the special paths ‘.’ and ‘..’.
- joinpath(*args)
Combine this path with one or several arguments, and return a new path representing either a subpath (if all arguments are relative paths) or a totally different path (if one of the arguments is anchored).
- lchmod(mode)[source]
Like chmod(), except if the path points to a symlink, the symlink’s permissions are changed, rather than its target’s.
- link_to(target)[source]
Make the target path a hard link pointing to this path.
Note this function does not make this path a hard link to target, despite the implication of the function and argument names. The order of arguments (target, link) is the reverse of Path.symlink_to, but matches that of os.link.
- lstat()[source]
Like stat(), except if the path points to a symlink, the symlink’s status information is returned, rather than its target’s.
- match(path_pattern)
Return True if this path matches the given pattern.
- property name
The final path component, if any.
- open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)[source]
Open the file pointed by this path and return a file object, as the built-in open() function does.
- property parent
The logical parent of the path.
- property parents
A sequence of this path’s logical parents.
- property parts
An object providing sequence-like access to the components in the filesystem path.
- read_text(encoding=None, errors=None)[source]
Open the file in text mode, read it, and close the file.
- relative_to(*other)
Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not a subpath of the other path), raise ValueError.
- rename(target)[source]
Rename this path to the target path.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
- replace(target)[source]
Rename this path to the target path, overwriting if that path exists.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
- resolve(strict=False)[source]
Make the path absolute, resolving all symlinks on the way and also normalizing it (for example turning slashes into backslashes under Windows).
- rglob(pattern)[source]
Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.
- property root
The root of the path, if any.
- samefile(other_path)[source]
Return whether other_path is the same or not as this file (as returned by os.path.samefile()).
- property stem
The final path component, minus its last suffix.
- property suffix
The final component’s last suffix, if any.
This includes the leading period. For example: ‘.txt’
- property suffixes
A list of the final component’s suffixes, if any.
These include the leading periods. For example: [‘.tar’, ‘.gz’]
- symlink_to(target, target_is_directory=False)[source]
Make this path a symlink pointing to the target path. Note the order of arguments (link, target) is the reverse of os.symlink.
- touch(mode=438, exist_ok=True)[source]
Create this file with the given access mode, if it doesn’t exist.
- unlink(missing_ok=False)[source]
Remove this file or link. If the path is a directory, use rmdir() instead.
- with_name(name)
Return a new path with the file name changed.
- with_stem(stem)
Return a new path with the stem changed.
- with_suffix(suffix)
Return a new path with the file suffix changed. If the path has no suffix, add given suffix. If the given suffix is an empty string, remove the suffix from the path.
- class petab.visualize.cli.Problem(sbml_model: libsbml.Model = None, sbml_reader: libsbml.SBMLReader = None, sbml_document: libsbml.SBMLDocument = None, model: Model = None, model_id: str = None, condition_df: pd.DataFrame = None, measurement_df: pd.DataFrame = None, parameter_df: pd.DataFrame = None, visualization_df: pd.DataFrame = None, observable_df: pd.DataFrame = None, mapping_df: pd.DataFrame = None, extensions_config: Dict = None)[source]
Bases:
object
PEtab parameter estimation problem as defined by
model
condition table
measurement table
parameter table
observables table
mapping table
Optionally it may contain visualization tables.
- condition_df
PEtab condition table
- measurement_df
PEtab measurement table
- parameter_df
PEtab parameter table
- observable_df
PEtab observable table
- visualization_df
PEtab visualization table
- mapping_df
PEtab mapping table
- model
The underlying model
- sbml_reader
Stored to keep object alive (deprecated).
- sbml_document
Stored to keep object alive (deprecated).
- sbml_model
PEtab SBML model (deprecated)
- extensions_config
Information on the extensions used
- _apply_mask(v: List, free: bool = True, fixed: bool = True)[source]
Apply mask of only free or only fixed values.
- Parameters:
v – The full vector the mask is to be applied to.
free – Whether to return free parameters, i.e. parameters to estimate.
fixed – Whether to return fixed parameters, i.e. parameters not to estimate.
- Return type:
The reduced vector with applied mask.
- static from_combine(filename: Union[Path, str]) Problem [source]
Read PEtab COMBINE archive (http://co.mbine.org/documents/archive).
See also
petab.create_combine_archive()
.- Parameters:
filename – Path to the PEtab-COMBINE archive
- Returns:
A
petab.Problem
instance.
- static from_files(sbml_file: Optional[Union[Path, str]] = None, condition_file: Optional[Union[str, Path, Iterable[Union[str, Path]]]] = None, measurement_file: Optional[Union[str, Path, Iterable[Union[str, Path]]]] = None, parameter_file: Optional[Union[str, Path, Iterable[Union[str, Path]]]] = None, visualization_files: Optional[Union[str, Path, Iterable[Union[str, Path]]]] = None, observable_files: Optional[Union[str, Path, Iterable[Union[str, Path]]]] = None, model_id: Optional[str] = None, extensions_config: Optional[Dict] = None) Problem [source]
Factory method to load model and tables from files.
- Parameters:
sbml_file – PEtab SBML model
condition_file – PEtab condition table
measurement_file – PEtab measurement table
parameter_file – PEtab parameter table
visualization_files – PEtab visualization tables
observable_files – PEtab observables tables
model_id – PEtab ID of the model
extensions_config – Information on the extensions used
- static from_yaml(yaml_config: Union[Dict, Path, str]) Problem [source]
Factory method to load model and tables as specified by YAML file.
- Parameters:
yaml_config – PEtab configuration as dictionary or YAML file name
- get_lb(free: bool = True, fixed: bool = True, scaled: bool = False)[source]
Generic function to get lower parameter bounds.
- Parameters:
free – Whether to return free parameters, i.e. parameters to estimate.
fixed – Whether to return fixed parameters, i.e. parameters not to estimate.
scaled – Whether to scale the values according to the parameter scale, or return them on linear scale.
- Return type:
The lower parameter bounds.
- get_optimization_to_simulation_parameter_mapping(**kwargs)[source]
See
petab.parameter_mapping.get_optimization_to_simulation_parameter_mapping()
, to which all keyword arguments are forwarded.
- get_ub(free: bool = True, fixed: bool = True, scaled: bool = False)[source]
Generic function to get upper parameter bounds.
- Parameters:
free – Whether to return free parameters, i.e. parameters to estimate.
fixed – Whether to return fixed parameters, i.e. parameters not to estimate.
scaled – Whether to scale the values according to the parameter scale, or return them on linear scale.
- Return type:
The upper parameter bounds.
- get_x_ids(free: bool = True, fixed: bool = True)[source]
Generic function to get parameter ids.
- Parameters:
free – Whether to return free parameters, i.e. parameters to estimate.
fixed – Whether to return fixed parameters, i.e. parameters not to estimate.
- Return type:
The parameter IDs.
- get_x_nominal(free: bool = True, fixed: bool = True, scaled: bool = False)[source]
Generic function to get parameter nominal values.
- Parameters:
free – Whether to return free parameters, i.e. parameters to estimate.
fixed – Whether to return fixed parameters, i.e. parameters not to estimate.
scaled – Whether to scale the values according to the parameter scale, or return them on linear scale.
- Return type:
The parameter nominal values.
- sample_parameter_startpoints(n_starts: int = 100)[source]
Create 2D array with starting points for optimization
- sample_parameter_startpoints_dict(n_starts: int = 100) List[Dict[str, float]] [source]
Create dictionaries with starting points for optimization
See also
petab.sample_parameter_startpoints()
.- Returns:
A list of dictionaries with parameter IDs mapping to samples parameter values.
- scale_parameters(x_dict: Dict[str, float]) Dict[str, float] [source]
Scale parameter values.
- Parameters:
x_dict – Keys are parameter IDs in the PEtab problem, values are unscaled parameter values.
- Return type:
The scaled parameter values.
- to_files(sbml_file: Union[None, str, Path] = None, condition_file: Union[None, str, Path] = None, measurement_file: Union[None, str, Path] = None, parameter_file: Union[None, str, Path] = None, visualization_file: Union[None, str, Path] = None, observable_file: Union[None, str, Path] = None, yaml_file: Union[None, str, Path] = None, prefix_path: Union[None, str, Path] = None, relative_paths: bool = True, model_file: Union[None, str, Path] = None, mapping_file: Union[None, str, Path] = None) None [source]
Write PEtab tables to files for this problem
Writes PEtab files for those entities for which a destination was passed.
NOTE: If this instance was created from multiple measurement or visualization tables, they will be merged and written to a single file.
- Parameters:
sbml_file – SBML model destination (deprecated)
model_file – Model destination
condition_file – Condition table destination
measurement_file – Measurement table destination
parameter_file – Parameter table destination
visualization_file – Visualization table destination
observable_file – Observables table destination
mapping_file – Mapping table destination
yaml_file – YAML file destination
prefix_path – Specify a prefix to all paths, to avoid specifying the prefix for all paths individually. NB: the prefix is added to paths before
relative_paths
is handled.relative_paths – whether all paths in the YAML file should be relative to the location of the YAML file. If
False
, then paths are left unchanged.
- Raises:
ValueError – If a destination was provided for a non-existing entity.
- to_files_generic(prefix_path: Union[str, Path]) str [source]
Save a PEtab problem to generic file names.
The PEtab problem YAML file is always created. PEtab data files are only created if the PEtab problem contains corresponding data (e.g. a PEtab visualization TSV file is only created if the PEtab problem has one).
- Parameters:
prefix_path – Specify a prefix to all paths, to avoid specifying the prefix for all paths individually. NB: the prefix is added to paths before
relative_paths
is handled downstream inpetab.yaml.create_problem_yaml()
.- Returns:
The path to the PEtab problem YAML file.
- unscale_parameters(x_dict: Dict[str, float]) Dict[str, float] [source]
Unscale parameter values.
- Parameters:
x_dict – Keys are parameter IDs in the PEtab problem, values are scaled parameter values.
- Return type:
The unscaled parameter values.
- property x_nominal_fixed_scaled: List
Parameter table nominal values with applied parameter scaling, for fixed parameters.
- petab.visualize.cli._petab_visualize_main()[source]
Entrypoint for visualization command-line interface.
- petab.visualize.cli.get_simulation_df(simulation_file: Union[str, Path]) DataFrame [source]
Read PEtab simulation table
- Parameters:
simulation_file – URL or filename of PEtab simulation table
- Returns:
Simulation DataFrame
- petab.visualize.cli.get_visualization_df(visualization_file: Union[str, Path]) DataFrame [source]
Read PEtab visualization table
- Parameters:
visualization_file – URL or filename of PEtab visualization table
- Returns:
Visualization DataFrame
- petab.visualize.cli.plot_problem(petab_problem: Problem, simulations_df: Optional[Union[str, DataFrame]] = None, grouping_list: Optional[List[List[str]]] = None, group_by: str = 'observable', plotted_noise: str = 'MeanAndSD', subplot_dir: Optional[str] = None, plotter_type: str = 'mpl') Optional[Dict[str, Axes]] [source]
Visualization using petab problem. If Visualization table is part of the petab_problem, it will be used for visualization. Otherwise, grouping_list will be used. If neither Visualization table nor grouping_list are available, measurements (simulations) will be grouped by observable, i.e. all measurements for each observable will be visualized on one plot.
- Parameters:
petab_problem – A PEtab problem.
simulations_df – A simulation DataFrame in the PEtab format or path to the simulation output data file.
grouping_list – A list of lists. Each sublist corresponds to a plot, each subplot contains the Ids of datasets or observables or simulation conditions for this plot.
group_by – Possible values: ‘dataset’, ‘observable’, ‘simulation’.
plotted_noise – A string indicating how noise should be visualized: [‘MeanAndSD’ (default), ‘MeanAndSEM’, ‘replicate’, ‘provided’].
subplot_dir – A string which is taken as path to the folder where single subplots should be saved. PlotIDs will be taken as file names.
plotter_type – Specifies which library should be used for plot generation. Currently, only matplotlib is supported.
- Returns:
ax (Axis object of the created plot.)
None (In case subplots are saved to a file.)