pycotools3.tasks.ParameterEstimation¶
-
class
pycotools3.tasks.
ParameterEstimation
(config)[source]¶ Interface to COPASI’s parameter estimation task
Examples
Assuming a
ParameterEstimation.Config
object has been configured and is called config >>> pe = ParameterEstimation(config)-
__init__
(config)[source]¶ Configure a the parameter estimation task in copasi
Pycotools supports all the features of parameter estimation configuration as copasi, plus a few additional ones (such as the affected models setting).
Parameters: config (ParameterEstimation.Config) – An appropriately configured ParameterEstimation.Config
classExamples
See
ParameterEstimation.Config
orParameterEstimation.Context
for detailed information on how to produce aParameterEstimation.Config
object. Note that theParameterEstimation.Context
class is higher level and should be the preferred way of constructing aParameterEstimation.Config
object while theParameterEstimation.Config
class gives you the same level of control as copasi but is bulkier to write.Assuming the
ParameterEstimation.Config
class has already been created >>> pe = ParameterEstimation(config)
Methods
__init__
(config)Configure a the parameter estimation task in copasi check_integrity
(allowed, given)Method to raise an error when a wrong kwarg is passed to a subclass convert_bool_to_numeric
(dct)CopasiML uses 1’s and 0’s for True or False in some but not all places. convert_bool_to_numeric2
()CopasiML uses 1’s and 0’s for True or False in some but not all places. do_checks
()validate integrity of user input get_component
(model, component, string)Get component called string from model get_model_objects_from_strings
()Get model objects from the strings provided by the user in the Config class :return: list of model.Model objects get_variable_from_string
(m, v[, glob])Use model entity name to get the pycotools3 variable read_model
(m)param m: run
(models)Run a parameter estimation using command line copasi. update_properties
(kwargs)method for updating properties from kwargs Attributes
fit_dir
Property holding the directory where the parameter estimation fitting occurs. global_quantities
Returns – list of strings of global quantities present in the models local_parameters
Returns – list of strings of local parameters in the model metabolites
Returns – list of strings of metabolites in the model models
Get models models_dir
A directory containing models problem_dir
Property holding the directory where the parameter estimation problem is stored :returns: str. results_directory
A directory containing results, parameter estimation report files from copasi schema
valid_methods
-
class
Config
(models, datasets, items, settings={}, defaults=None)[source]¶ A class for holding a parameter estimation configuration
Stores all the settings needed for configuration of a parameter estimation using COPASI.
Examples
>>> ## create a model >>> antimony_string = ''' ... model TestModel1() ... R1: A => B; k1*A; ... R2: B => A; k2*B ... A = 1 ... B = 0 ... k1 = 4; ... k2 = 9; ... end ... ''' >>> copasi_filename = os.path.join(os.path.dirname(__file__), 'example_model.cps') >>> with model.BuildAntimony(copasi_filename) as loader: ... mod = loader.load(antimony_string) >>> ## Simulate some data from the model and write to file >>> fname = os.path.join(os.path.dirname(__file__), 'timeseries.txt') >>> data = self.model.simulate(0, 10, 11) >>> data.to_csv(fname) >>> ## create nested dict containing all the relevant arguments for your configuration >>> config_dict = dict( ... models=dict( ... ## model name is the users choice here ... example1=dict( ... copasi_file=copasi_filename ... ) ... ), ... datasets=dict( ... experiments=dict( ... ## experiment names are the users choice ... report1=dict( ... filename=self.TC1.report_name, ... ), ... ), ... ## our validations entry is empty here ... ## but if you have validation data this should ... ## be the same as the experiments section ... validations=dict(), ... ), ... items=dict( ... fit_items=dict( ... A=dict( ... affected_experiments='report1' ... ), ... B=dict( ... affected_validation_experiments=['report2'] ... ), ... k1={}, ... k2={}, ... ), ... constraint_items=dict( ... k1=dict( ... lower_bound=1e-2, ... upper_bound=10 ... ) ... ) ... ), ... settings=dict( ... method='genetic_algorithm_sr', ... population_size=2, ... number_of_generations=2, ... working_directory=os.path.dirname(__file__), ... copy_number=4, ... pe_number=2, ... weight_method='value_scaling', ... validation_weight=2.5, ... validation_threshold=9, ... randomize_start_values=True, ... calculate_statistics=False, ... create_parameter_sets=False ... ) ... ) >>> config = ParameterEstimation.Config(**config_dict)
-
configure
()[source]¶ Configure the class for production of parameter estimation config
Like a main method for this class. Uses the other methods in the class to configure a
ParameterEstimation.Config object
Returns: Operates inplace and returns None
-
constraint_items
¶ Returns – The constraint items as nested dict
-
experiment_filenames
¶ Returns – A list of experiment filesnames
-
experiment_names
¶ Returns – A list of experiment names
-
experiments
¶ The experiments property :returns: datasets.experiments as dict
-
fit_items
¶ Returns – The fit items as nested dict
-
from_json
(string)[source]¶ Create config object from json format :param string: a valid json string :type string: Str
Returns: ParameterEstimation.Config
-
from_yaml
(yml)[source]¶ Read config object from yaml file :param yml: full path to text file containing configuration arguments in yaml format :type yml: str
Returns: ParameterEstimation.Config
-
model_objects
¶ Returns – A list of model objects for mapping
-
set_default_fit_items_dct
()[source]¶ Configure missing entries for items.fit_items when they are in nested dict format
Returns: None. Method operates inplace on class attributes
-
set_default_fit_items_str
()[source]¶ Configure missing entries for items.fit_items when they are strings pointing towards model variables
Returns: None. Method operates inplace on class attributes
-
to_yaml
(filename=None)[source]¶ Output arguments as yaml
Parameters: filename (str, None) – If not None (default), path to write yaml configuration to Returns: Config object as string in yaml format
-
validation_filenames
¶ Returns – a list of validation filenames
-
validation_names
¶ Returns – A list of validation names
-
validations
¶ The validations property :returns: datasets.validations as dict
-
-
class
Context
(models, experiments, working_directory=None, context='s', parameters='mg', filename=None, validation_experiments={}, settings={})[source]¶ High level interface to create a
ParameterEstimation.Config
object.Enables the construction of a
ParameterEstimation.Config
object assuming one of several common patterns of usage.Examples
Assuming that we have two copasi models (mod1 and mod2) and two experimental data files (fname1, fname2), correctly formatted according to the copasi specification. We can generate a config object that specifies the fitting of both experiments to both models and to fit all global and local parameters parameters=’gl’ in each.
with ParameterEstimation.Context( [mod1, mod2], [fname1, fname2], context='s', parameters='gl') as context: context.set('method', 'genetic_algorithm_sr') context.set('number_of_generations', 25) context.set('population_size', 10) config = context.get_config() pe = ParameterEstimation(config)
-
add_experiments
(experiments: (<class 'str'>, <class 'list'>))[source]¶ Add list of experiments to class attributes :param experiments: Path pointing to experimental data file or list of paths pointing to experimental data files :type experiments: str, list
Returns: None
-
add_models
(models: (<class 'str'>, <class 'list'>))[source]¶ Add models to class attributes
Parameters: models (str, list) – Path to copasi file or list of paths to copasi files Returns: None
-
add_validation_experiments
(experiments: (<class 'str'>, <class 'list'>))[source]¶ Add experiments to validation_experiments attribute
Parameters: experiments (str, list) – path to validation data or list of paths to validation data Returns: None
-
add_working_directory
(working_directory: str)[source]¶ Add working_directory to class attributes. Put in same path as first copasi model if argument not specified. :param working_directory: Path to location on the system to store analysis :type working_directory: str
Returns: None
-
set
(parameter, value)[source]¶ Set the value of
parameter
tovalue
.Looks for the first instance of
parameter
and sets its value tovalue
. To set all values of a parameter, seeParameterEstimation.Config.set_all()
Parameters: - parameter – A key somewhere in the nested structure of the config object
- value – A value to replace the current value with
Returns: None
-
-
fit_dir
¶ Property holding the directory where the parameter estimation fitting occurs. This can be enumerated under a single problem directory to group similar parameter estimations :returns: str. A directory.
-
get_model_objects_from_strings
()[source]¶ Get model objects from the strings provided by the user in the Config class :return: list of model.Model objects
Returns: list of model objects
-
global_quantities
¶ Returns – list of strings of global quantities present in the models
-
local_parameters
¶ Returns – list of strings of local parameters in the model
-
metabolites
¶ Returns – list of strings of metabolites in the model
-
models
¶ Get models
Returns: the models entry of the ParameterEstimation.Config
object
-
models_dir
¶ A directory containing models
Each model will be configured in a different directory when multiple models are being configured simultaneously :returns: dct. Location of models directories
-
problem_dir
¶ Property holding the directory where the parameter estimation problem is stored :returns: str. A directory.
-
results_directory
¶ A directory containing results, parameter estimation report files from copasi
Each model configured will have their own results directory :returns: dict[model] = results_directory
-