pycotools3.tasks.ParameterEstimation¶
-
class
pycotools3.tasks.ParameterEstimation(config)[source]¶ Interface to COPASI’s parameter estimation task
Examples
Assuming a
ParameterEstimation.Configobject 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.ConfigclassExamples
See
ParameterEstimation.ConfigorParameterEstimation.Contextfor detailed information on how to produce aParameterEstimation.Configobject. Note that theParameterEstimation.Contextclass is higher level and should be the preferred way of constructing aParameterEstimation.Configobject while theParameterEstimation.Configclass gives you the same level of control as copasi but is bulkier to write.Assuming the
ParameterEstimation.Configclass 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_dirProperty holding the directory where the parameter estimation fitting occurs. global_quantitieslist of strings of global quantities present in the models local_parameterslist of strings of local parameters in the model metaboliteslist of strings of metabolites in the model modelsGet models models_dirA directory containing models problem_dirProperty holding the directory where the parameter estimation problem is stored :returns: str. results_directoryA directory containing results, parameter estimation report files from copasi schemavalid_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 objectReturns: Operates inplace and returns None
-
constraint_items¶ The constraint items as nested dict
Type: Returns
-
experiment_filenames¶ A list of experiment filesnames
Type: Returns
-
experiment_names¶ A list of experiment names
Type: Returns
-
experiments¶ The experiments property :returns: datasets.experiments as dict
-
fit_items¶ The fit items as nested dict
Type: Returns
-
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¶ A list of model objects for mapping
Type: Returns
-
models_affected_experiments¶ Get which experiment datasets affect which models
Returns: dict. Keys are model names, value are list of affected models
-
models_affected_validation_experiments¶ Get which experiment datasets affect which models
Returns: dict. Keys are model names, value are list of affected models
-
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¶ a list of validation filenames
Type: Returns
-
validation_names¶ A list of validation names
Type: Returns
-
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]¶ A high level interface to create a
ParameterEstimation.Configobject.Enables the construction of a
ParameterEstimation.Configobject 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)
Or for profile likelihoods on the first model mod1
-
set(parameter, value)[source]¶ Set the value of
parametertovalue.Looks for the first instance of
parameterand 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¶ list of strings of global quantities present in the models
Type: Returns
-
local_parameters¶ list of strings of local parameters in the model
Type: Returns
-
metabolites¶ list of strings of metabolites in the model
Type: Returns
-
models¶ Get models
Returns: the models entry of the ParameterEstimation.Configobject
-
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
-