Model

Models wrap around a simulation engine (such as Morpheus) and making their results accessible to the parameter inference routine (such as pyABC).

class fitmulticell.model.MorpheusModel(model_file: str, par_map: Dict[str, str], sumstat: SummaryStatistics = None, par_scale: Dict[str, str] | str = 'lin', exp_cond_map: Dict = None, executable: str = 'morpheus', gui_executable: str = 'morpheus-gui', suffix: str = None, prefix: str = 'morpheus_model_', dir: str = None, clean_simulation: bool = False, show_stdout: bool = False, show_stderr: bool = True, raise_on_error: bool = False, timeout: float = None, name: str = None, time_var: str = 'time', outputdir: str = None, ss_post_processing: Callable | dict = None)[source]

Bases: ExternalModel

Derived from pyabc.ExternalModel. Allows pyABC to call morpheus in order to do the model simulation, and then record the results for further processing.

Parameters:
  • model_file – The XML file containing the morpheus model.

  • par_map – A dictionary from string to string, the keys being the parameter ids to be used in pyabc, and the values xpaths in the morpheus_file.

  • par_scale – A dictionary or string to state the scale used to define the parameter space, e.g., lin, log10, log2

  • exp_cond_map

    A dictionary where the keys are the xpath for the consition in the

    Morpheus model and the values of the conditions.

  • sumstat_funs – List of functions to calculate summary statistics. The list entries are instances of fitmulticell.sumstat.SumstatFun.

  • executable – The path to the morpheus executable. If None given, ‘morpheus’ is used.

  • suffix – Suffix and prefix to use for the temporary folders created.

  • prefix – Suffix and prefix to use for the temporary folders created.

  • dir – Directory to put the temporary folders into. The default is the system’s temporary files location. Note that these files are usually deleted upon system shutdown.

  • clean_simulation – Whether to remove simulation files when they are no longer needed.

  • show_stdout – Whether to show or hide the stdout and stderr streams.

  • show_stderr – Whether to show or hide the stdout and stderr streams.

  • raise_on_error – Whether to raise on an error in the model execution, or just continue.

  • name – A name that can be used to identify the model, as it is saved to db. If None is passed, the model_file name is used.

  • time_var – The name of the time variable as define in Morpheus model.

  • ignore_list – A list of columns to ignore from Morpheus output. This is introduced to solve the issue with result that cannot be eliminated from morpheus output but yet are not used in the fitting process.

  • timeout – Maximum execution time in seconds, after which Morpheus is stopped.

  • ss_post_processing – A callable function to perform post processing on Morpheus output. If a dict is passed, then specific function will be applied to each summary statistics.

  • output_file – A name of the file containing the simulation output.

__call__(pars: Parameter)[source]

Simulate data for parameters.

This function is used in ABCSMC (or rather the sample() function, which redirects here) to simulate data for given parameters pars.

__init__(model_file: str, par_map: Dict[str, str], sumstat: SummaryStatistics = None, par_scale: Dict[str, str] | str = 'lin', exp_cond_map: Dict = None, executable: str = 'morpheus', gui_executable: str = 'morpheus-gui', suffix: str = None, prefix: str = 'morpheus_model_', dir: str = None, clean_simulation: bool = False, show_stdout: bool = False, show_stderr: bool = True, raise_on_error: bool = False, timeout: float = None, name: str = None, time_var: str = 'time', outputdir: str = None, ss_post_processing: Callable | dict = None)[source]

Initialize the model.

Parameters:
  • name (str, optional (default = "ExternalModel")) – As in pyabc.Model.name.

  • ExternalHandler. (All other parameters as in) –

compute_sumstats(loc: str) dict[source]

Compute summary statistics from the simulated data according to the provided list of summary statistics functions.

get_expcondmap_xpath_attr(key, attrib='value')[source]

Get the xpath and for the experimental conditions of interest

Parameters:
  • key (str) – name of experimental condition of interest.

  • attrib (str) – the type of attribute that need to be changed on the xml file.

get_par_value_form_xml_file(file_, param)[source]

Get a parameter value from the model’s xml file. This is currently being used for testing purposes.

get_parmap_xpath_attr(key, attrib='value')[source]

Get the xpath and for the parameter of interest

Parameters:
  • key (str) – name of parameter of interest.

  • attrib (str) – the type of attribute that need to be changed on the xml file.

sanity_check(par: Parameter = None)[source]

Sanity check of the model.

In particular executes the model once.

Parameters:

par – Parameters at which to evaluate. If not specified, parameters are as in the model file.

write_modified_model_file(file_: str, pars: Dict[str, float])[source]

Write a modified version of the morpheus xml file to the target directory.

class fitmulticell.model.MorpheusModels(models: Sequence[MorpheusModel], name: str = None)[source]

Bases: ExternalModel

Derived from pyabc.ExternalModel. Allows pyABC to call morpheus in order to do the models simulation, and then record the results for further processing.

Parameters:
  • models (A list of MorpheusModel objects.) –

  • name (Name of the joint model.) –

__call__(pars: Parameter)[source]

This function is used in ABCSMC (or rather the sample() function, which redirects here) to simulate data for given parameters pars and given experimental conditions.

__init__(models: Sequence[MorpheusModel], name: str = None)[source]

Initialize the model.

Parameters:
  • name (str, optional (default = "ExternalModel")) – As in pyabc.Model.name.

  • ExternalHandler. (All other parameters as in) –

get_parmap_xpath_attr(key, attrib='value')[source]

Get the xpath and for the parameter of interest

Parameters:
  • key (str) – name of parameter of interest.

  • attrib (str) – the type of attribute that need to be changed on the xml file.

write_modified_models_file(file_, pars, exp_cod)[source]

Write a modified version of the morpheus xml file to the target directory.