From 55a350a5404525369f015b2d3d8ca2d103d21df2 Mon Sep 17 00:00:00 2001 From: teddygroves Date: Tue, 31 Oct 2023 09:31:07 +0100 Subject: [PATCH 01/15] bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 337c904e..c3afd075 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "maud-metabolic-models" -version = "0.7.0.1" +version = "0.7.1.0" authors = [ {name = "Novo Nordisk Foundation Center for Biosustainability, Technical University of Denmark"} ] From 5beeac6b9fbe4e598d0ed89a1cd20a87a1b30198 Mon Sep 17 00:00:00 2001 From: NicholasCowie Date: Mon, 19 Feb 2024 16:05:34 +0100 Subject: [PATCH 02/15] adding secondary edges axis --- maud/getting_idatas.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maud/getting_idatas.py b/maud/getting_idatas.py index c69aaa2f..1c13c335 100644 --- a/maud/getting_idatas.py +++ b/maud/getting_idatas.py @@ -36,6 +36,7 @@ def get_idata(csvs: List[str], mi: MaudInput, mode: str) -> az.InferenceData: "metabolites": [m.id for m in mi.kinetic_model.metabolites], "mics": [m.id for m in mi.kinetic_model.mics], "edges": [e.id for e in mi.kinetic_model.edges], + "edges1": [e.id for e in mi.kinetic_model.edges], "unbalanced_mics": [ m.id for m in mi.kinetic_model.mics if not m.balanced ], @@ -103,7 +104,7 @@ def get_idata(csvs: List[str], mi: MaudInput, mode: str) -> az.InferenceData: "balanced_mics", "edges", ], - "flux_control_matrix": ["experiments", "edges", "edges"], + "flux_control_matrix": ["experiments", "edges", "edges1"], "flux_response_coefficient": ["experiments", "edges", "enzymes"], "concentration_response_coefficient": [ "experiments", From 5af3cc7c08591e914bb0284353e25c6300235869 Mon Sep 17 00:00:00 2001 From: NicholasCowie Date: Mon, 19 Feb 2024 16:24:10 +0100 Subject: [PATCH 03/15] feat: updating cmdstanpy version --- maud/running_stan.py | 2 +- pyproject.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/maud/running_stan.py b/maud/running_stan.py index ba0bda86..e6128510 100644 --- a/maud/running_stan.py +++ b/maud/running_stan.py @@ -47,9 +47,9 @@ SIM_CONFIG = { "chains": 1, "fixed_param": True, - "iter_warmup": 0, "show_progress": False, "threads_per_chain": 1, + "adapt_engaged": False, } DEFAULT_OPTIMIZE_CONFIG = { "algorithm": "LBFGS", diff --git a/pyproject.toml b/pyproject.toml index c3afd075..7377a273 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools", "cmdstanpy >= 1.0.7", "wheel"] +requires = ["setuptools", "cmdstanpy >= 1.2.1", "wheel"] build-backend = "setuptools.build_meta" [project] @@ -32,7 +32,7 @@ dependencies = [ "pandas", "matplotlib", "toml", - "cmdstanpy >= 1.2.0", + "cmdstanpy >= 1.2.1", "click", "depinfo == 1.7.0", "pydantic >= 2.0", From f841c3a8273ccfb29664d1a9159a7f2c2ffff800 Mon Sep 17 00:00:00 2001 From: NicholasCowie Date: Mon, 19 Feb 2024 17:20:28 +0100 Subject: [PATCH 04/15] bug: updating ode test due to cmdstanpy --- tests/test_unit/test_model_ode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_unit/test_model_ode.py b/tests/test_unit/test_model_ode.py index 6893dfb3..47def181 100644 --- a/tests/test_unit/test_model_ode.py +++ b/tests/test_unit/test_model_ode.py @@ -63,7 +63,7 @@ def test_model_ode(test_case): inits=str(test_case.inits_path), chains=1, fixed_param=True, - iter_warmup=0, + adapt_engaged=False, iter_sampling=1, show_progress=False, show_console=True, From 650018e9ec94fecc441cb115e59be2df2bf17a61 Mon Sep 17 00:00:00 2001 From: NicholasCowie Date: Mon, 19 Feb 2024 17:43:47 +0100 Subject: [PATCH 05/15] bug: formatting files --- maud/data_model/maud_input.py | 6 ++-- maud/getting_idatas.py | 50 ++++++++++++++++------------- maud/getting_stan_inputs.py | 59 ++++++++++++++++++++++------------- tests/test_unit/test_utils.py | 1 - 4 files changed, 70 insertions(+), 46 deletions(-) diff --git a/maud/data_model/maud_input.py b/maud/data_model/maud_input.py index 40831c7c..c7757413 100644 --- a/maud/data_model/maud_input.py +++ b/maud/data_model/maud_input.py @@ -70,9 +70,9 @@ def inits_dict(self) -> Dict: inits_dict[param.name] = param.inits.inits_unscaled if param.inits.inits_scaled is not None: scaled_pref = "log_" if param.non_negative else "" - inits_dict[ - scaled_pref + param.name + "_z" - ] = param.inits.inits_scaled + inits_dict[scaled_pref + param.name + "_z"] = ( + param.inits.inits_scaled + ) if param.fixed_ids is not None: met_to_init = dict( zip(param.inits.ids[0], param.inits.inits_unscaled) diff --git a/maud/getting_idatas.py b/maud/getting_idatas.py index 1c13c335..dbb5aa67 100644 --- a/maud/getting_idatas.py +++ b/maud/getting_idatas.py @@ -1,4 +1,5 @@ """Functions for creating InferenceData objects from Maud outputs.""" + from typing import List import arviz as az @@ -41,27 +42,34 @@ def get_idata(csvs: List[str], mi: MaudInput, mode: str) -> az.InferenceData: m.id for m in mi.kinetic_model.mics if not m.balanced ], "balanced_mics": [m.id for m in mi.kinetic_model.mics if m.balanced], - "phosphorylations": [p.id for p in mi.kinetic_model.phosphorylations] - if mi.kinetic_model.phosphorylations is not None - else [], - "phosphorylation_modifying_enzymes": [ - pme.id for pme in mi.kinetic_model.phosphorylation_modifying_enzymes - ] - if mi.kinetic_model.phosphorylation_modifying_enzymes is not None - else [], - "allosteries": [p.id for p in mi.kinetic_model.allosteries] - if mi.kinetic_model.allosteries is not None - else [], - "allosteric_enzymes": [ - e.id for e in mi.kinetic_model.allosteric_enzymes - ] - if mi.kinetic_model.allosteric_enzymes is not None - else [], - "competitive_inhibitions": [ - p.id for p in mi.kinetic_model.competitive_inhibitions - ] - if mi.kinetic_model.competitive_inhibitions is not None - else [], + "phosphorylations": ( + [p.id for p in mi.kinetic_model.phosphorylations] + if mi.kinetic_model.phosphorylations is not None + else [] + ), + "phosphorylation_modifying_enzymes": ( + [ + pme.id + for pme in mi.kinetic_model.phosphorylation_modifying_enzymes + ] + if mi.kinetic_model.phosphorylation_modifying_enzymes is not None + else [] + ), + "allosteries": ( + [p.id for p in mi.kinetic_model.allosteries] + if mi.kinetic_model.allosteries is not None + else [] + ), + "allosteric_enzymes": ( + [e.id for e in mi.kinetic_model.allosteric_enzymes] + if mi.kinetic_model.allosteric_enzymes is not None + else [] + ), + "competitive_inhibitions": ( + [p.id for p in mi.kinetic_model.competitive_inhibitions] + if mi.kinetic_model.competitive_inhibitions is not None + else [] + ), "kms": mi.parameters.km.ids[0], "kis": mi.parameters.ki.ids[0], "dissociation_constants": (mi.parameters.dissociation_constant.ids[0]), diff --git a/maud/getting_stan_inputs.py b/maud/getting_stan_inputs.py index 53cc4ab1..9836970d 100644 --- a/maud/getting_stan_inputs.py +++ b/maud/getting_stan_inputs.py @@ -166,9 +166,11 @@ def get_network_properties_input( reaction_codes = codify_maud_object(reactions) reaction_to_mechanism = {rxn.id: rxn.mechanism for rxn in reactions} edge_mechanism_code = [ - int(reaction_to_mechanism[e.id].value) - if isinstance(e, Reaction) - else int(reaction_to_mechanism[e.reaction_id].value) + ( + int(reaction_to_mechanism[e.id].value) + if isinstance(e, Reaction) + else int(reaction_to_mechanism[e.reaction_id].value) + ) for e in edges ] edge_enzyme_code = [ @@ -179,21 +181,27 @@ def get_network_properties_input( drain_codes[d.id] if isinstance(d, Reaction) else 0 for d in edges ] edge_reaction_code = [ - reaction_codes[e.id] - if isinstance(e, Reaction) - else reaction_codes[e.reaction_id] + ( + reaction_codes[e.id] + if isinstance(e, Reaction) + else reaction_codes[e.reaction_id] + ) for e in edges ] edge_water_stoichiometry = [ - reaction_by_id[e.reaction_id].water_stoichiometry - if isinstance(e, EnzymeReaction) - else 0 + ( + reaction_by_id[e.reaction_id].water_stoichiometry + if isinstance(e, EnzymeReaction) + else 0 + ) for e in edges ] edge_transported_charge = [ - reaction_by_id[e.reaction_id].transported_charge - if isinstance(e, EnzymeReaction) - else 0 + ( + reaction_by_id[e.reaction_id].transported_charge + if isinstance(e, EnzymeReaction) + else 0 + ) for e in edges ] mic_met_code = [metabolite_codes[m.metabolite_id] for m in mics] @@ -207,9 +215,11 @@ def get_network_properties_input( else [] ) edge_tc_code = [ - tc_codes[e.enzyme_id] - if isinstance(e, EnzymeReaction) and e.enzyme_id in tc_codes.keys() - else 0 + ( + tc_codes[e.enzyme_id] + if isinstance(e, EnzymeReaction) and e.enzyme_id in tc_codes.keys() + else 0 + ) for e in edges ] # ragged arrays @@ -413,18 +423,25 @@ def get_experiments_input( ) enz_ko_by_experiment_train, enz_ko_by_experiment_test = ( [ - [enzyme_codes[eko.enzyme] for eko in experiment.enzyme_knockouts] - if experiment.enzyme_knockouts is not None - else [] + ( + [ + enzyme_codes[eko.enzyme] + for eko in experiment.enzyme_knockouts + ] + if experiment.enzyme_knockouts is not None + else [] + ) for experiment in exps ] for exps in (experiments_train, experiments_test) ) pme_ko_by_experiment_train, pme_ko_by_experiment_test = ( [ - [pme_codes[pko.pme] for pko in experiment.pme_knockouts] - if experiment.pme_knockouts is not None - else [] + ( + [pme_codes[pko.pme] for pko in experiment.pme_knockouts] + if experiment.pme_knockouts is not None + else [] + ) for experiment in exps ] for exps in (experiments_train, experiments_test) diff --git a/tests/test_unit/test_utils.py b/tests/test_unit/test_utils.py index f0127c1b..9aff2099 100644 --- a/tests/test_unit/test_utils.py +++ b/tests/test_unit/test_utils.py @@ -1,6 +1,5 @@ """Test functions from the utils module.""" - import numpy as np from maud.utility_functions import ( From 93b51de120a827da665e991f9ef51ddb8b537fba Mon Sep 17 00:00:00 2001 From: teddygroves Date: Tue, 26 Mar 2024 15:52:07 +0100 Subject: [PATCH 06/15] Fix case where multivariate dgfs don't initialise correctly --- maud/data_model/maud_input.py | 8 +++++--- maud/data_model/maud_parameter.py | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/maud/data_model/maud_input.py b/maud/data_model/maud_input.py index c7757413..50c3f0b8 100644 --- a/maud/data_model/maud_input.py +++ b/maud/data_model/maud_input.py @@ -70,9 +70,9 @@ def inits_dict(self) -> Dict: inits_dict[param.name] = param.inits.inits_unscaled if param.inits.inits_scaled is not None: scaled_pref = "log_" if param.non_negative else "" - inits_dict[scaled_pref + param.name + "_z"] = ( - param.inits.inits_scaled - ) + inits_dict[ + scaled_pref + param.name + "_z" + ] = param.inits.inits_scaled if param.fixed_ids is not None: met_to_init = dict( zip(param.inits.ids[0], param.inits.inits_unscaled) @@ -82,4 +82,6 @@ def inits_dict(self) -> Dict: for met, init in met_to_init.items() if met not in param.fixed_ids[0] ] + elif param.fixable: + inits_dict[param.name + "_free"] = param.inits.inits_unscaled return inits_dict diff --git a/maud/data_model/maud_parameter.py b/maud/data_model/maud_parameter.py index a22ea6f3..2f2ad0fb 100644 --- a/maud/data_model/maud_parameter.py +++ b/maud/data_model/maud_parameter.py @@ -31,12 +31,13 @@ class MaudParameter(BaseModel): init_input: Optional[List[InitAtomInput]] ids: List[List[str]] split_ids: List[List[List[str]]] + fixable: bool = False measurements: Optional[List[Measurement]] = None @computed_field def fixed_ids(self) -> Optional[List[List[str]]]: """Set the fixed_ids field.""" - if self.name != "dgf": + if not self.fixable: return None elif self.user_input is None: return None @@ -60,7 +61,7 @@ def fixed_ids(self) -> Optional[List[List[str]]]: @computed_field def fixed_values(self) -> Optional[List[List[float]]]: """Set the fixed_values field.""" - if self.name != "dgf": + if not self.fixable: return None elif self.user_input is None: return None @@ -244,6 +245,7 @@ class Dgf(MaudParameter): default_scale: float = 10 prior_in_test_model: bool = False prior_in_train_model: bool = True + fixable: bool = True class DissociationConstant(MaudParameter): From a3fe311c1a02a79e8304d3be71d3b0ef6d69ea67 Mon Sep 17 00:00:00 2001 From: teddygroves Date: Tue, 26 Mar 2024 16:05:55 +0100 Subject: [PATCH 07/15] Add test case for loading multivariate dgfs with inits --- .../linear_multidgf/config.toml | 24 +++++++ .../linear_multidgf/experiments.toml | 32 +++++++++ .../linear_multidgf/kinetic_model.toml | 66 +++++++++++++++++++ .../linear_multidgf/parameters.toml | 42 ++++++++++++ .../linear_multidgf/priors.toml | 42 ++++++++++++ tests/test_unit/test_load_maud_input.py | 9 ++- 6 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 maud/data/example_inputs/linear_multidgf/config.toml create mode 100644 maud/data/example_inputs/linear_multidgf/experiments.toml create mode 100644 maud/data/example_inputs/linear_multidgf/kinetic_model.toml create mode 100644 maud/data/example_inputs/linear_multidgf/parameters.toml create mode 100644 maud/data/example_inputs/linear_multidgf/priors.toml diff --git a/maud/data/example_inputs/linear_multidgf/config.toml b/maud/data/example_inputs/linear_multidgf/config.toml new file mode 100644 index 00000000..5e3aaabb --- /dev/null +++ b/maud/data/example_inputs/linear_multidgf/config.toml @@ -0,0 +1,24 @@ +name = "linear_multidgf" +kinetic_model_file = "kinetic_model.toml" +priors_file = "priors.toml" +experiments_file = "experiments.toml" +likelihood = true +steady_state_threshold_abs = 1e-6 + +[cmdstanpy_config] +refresh = 1 +iter_warmup = 300 +iter_sampling = 300 +chains = 4 +save_warmup = true +seed = 1234 + +[ode_solver_config] +abs_tol = 1e-4 +rel_tol = 1e-6 +max_num_steps = 1e6 + +[algebra_solver_config] +abs_tol = 1e-4 +rel_tol = 1e-6 +max_num_steps = 1e6 diff --git a/maud/data/example_inputs/linear_multidgf/experiments.toml b/maud/data/example_inputs/linear_multidgf/experiments.toml new file mode 100644 index 00000000..d0e8c9ea --- /dev/null +++ b/maud/data/example_inputs/linear_multidgf/experiments.toml @@ -0,0 +1,32 @@ +[[experiment]] +id = "condition1" +is_train = true +is_test = true +temperature = 299.0 +measurements = [ + {target_type = "mic", metabolite = "M1", compartment = "c", value = 0.59, error_scale = 0.1}, + {target_type = "mic", metabolite = "M1", compartment = "e", value = 1.09, error_scale = 0.05}, + {target_type = "mic", metabolite = "M2", compartment = "e", value = 1.05, error_scale = 0.05}, + {target_type = "flux", reaction = "r3", value = 0.19, error_scale = 0.1}, + {target_type = "enzyme", enzyme = "r1", value = 1.5, error_scale = 0.1}, + {target_type = "enzyme", enzyme = "r2", value = 1.5, error_scale = 0.1}, + {target_type = "enzyme", enzyme = "r3", value = 1.5, error_scale = 0.1}, +] +initial_state = [ + {metabolite = "M2", compartment = "c", value = 0.38}, +] + +[[experiment]] +id = "condition2" +is_train = true +is_test = true +measurements = [ + {target_type = "mic", metabolite = "M1", compartment = "c", value = 0.54, error_scale = 0.1}, + {target_type = "mic", metabolite = "M2", compartment = "c", value = 0.38, error_scale = 0.1}, + {target_type = "mic", metabolite = "M1", compartment = "e", value = 1.12, error_scale = 0.05}, + {target_type = "mic", metabolite = "M2", compartment = "e", value = 1.14, error_scale = 0.05}, + {target_type = "flux", reaction = "r3", value = 0.39, error_scale = 0.1}, + {target_type = "enzyme", enzyme = "r1", value = 1.5, error_scale = 0.1}, + {target_type = "enzyme", enzyme = "r2", value = 1.5, error_scale = 0.1}, + {target_type = "enzyme", enzyme = "r3", value = 1.5, error_scale = 0.1}, +] diff --git a/maud/data/example_inputs/linear_multidgf/kinetic_model.toml b/maud/data/example_inputs/linear_multidgf/kinetic_model.toml new file mode 100644 index 00000000..f24bd0e1 --- /dev/null +++ b/maud/data/example_inputs/linear_multidgf/kinetic_model.toml @@ -0,0 +1,66 @@ +name = "Example kinetic model" + +compartment = [ + {id = 'c', name = 'cytosol', volume = 1}, + {id = 'e', name = 'external', volume = 1}, +] + +metabolite = [ + {id = "M1", name = "Metabolite number 1"}, + {id = "M2", name = "Metabolite number 2"}, +] + +enzyme = [ + {id = "r1", name = "r1ase", subunits = 1}, + {id = "r2", name = "r2ase", subunits = 1}, + {id = "r3", name = "r3ase", subunits = 1}, +] + +metabolite_in_compartment = [ + {metabolite_id = "M1", compartment_id = "e", balanced = false}, + {metabolite_id = "M1", compartment_id = "c", balanced = true}, + {metabolite_id = "M2", compartment_id = "c", balanced = true}, + {metabolite_id = "M2", compartment_id = "e", balanced = false}, +] +enzyme_reaction = [ + {enzyme_id = "r1", reaction_id = "r1"}, + {enzyme_id = "r2", reaction_id = "r2"}, + {enzyme_id = "r3", reaction_id = "r3"}, +] + +[[reaction]] +id = "r1" +name = "Reaction number 1" +mechanism = "reversible_michaelis_menten" +stoichiometry = { M1_e = -1, M1_c = 1} + +[[reaction]] +id = "r2" +name = "Reaction number 2" +mechanism = "irreversible_michaelis_menten" +stoichiometry = { M1_c = -1, M2_c = 1} + +[[reaction]] +id = "r3" +name = "Reaction number 3" +mechanism = "reversible_michaelis_menten" +stoichiometry = { M2_c = -1, M2_e = 1} +transported_charge = 1 + +[[allostery]] +enzyme_id = "r1" +metabolite_id = "M2" +compartment_id = "c" +modification_type = "activation" + +[[allostery]] +enzyme_id = "r2" +metabolite_id = "M1" +compartment_id = "c" +modification_type = "inhibition" + +[[competitive_inhibition]] +enzyme_id = "r2" +reaction_id = "r2" +metabolite_id = "M1" +compartment_id = "c" diff --git a/maud/data/example_inputs/linear_multidgf/parameters.toml b/maud/data/example_inputs/linear_multidgf/parameters.toml new file mode 100644 index 00000000..2c8c448c --- /dev/null +++ b/maud/data/example_inputs/linear_multidgf/parameters.toml @@ -0,0 +1,42 @@ +kcat = [ + {exploc = 1, scale = 0.6, reaction = "r1", enzyme = "r1"}, + {exploc = 1, scale = 0.6, reaction = "r2", enzyme = "r2"}, + {exploc = 1, scale = 0.6, reaction = "r3", enzyme = "r3"}, +] + +km = [ + {exploc = 1, scale = 0.6, metabolite = "M1", compartment = "e", enzyme = "r1"}, + {exploc = 1, scale = 0.6, metabolite = "M1", compartment = "c", enzyme = "r1"}, + {exploc = 1, scale = 0.6, metabolite = "M1", compartment = "c", enzyme = "r2"}, + {exploc = 1, scale = 0.6, metabolite = "M2", compartment = "c", enzyme = "r3"}, + {exploc = 1, scale = 0.6, metabolite = "M2", compartment = "e", enzyme = "r3"}, +] + +transfer_constant = [ + {exploc = 1, scale = 0.6, enzyme = "r1"}, + {exploc = 1, scale = 0.6, enzyme = "r2"}, +] + +dissociation_constant = [ + {exploc = 1, scale = 0.6, enzyme = "r1", metabolite = "M2", compartment = "c", modification_type = "activation"}, + {exploc = 1, scale = 0.6, enzyme = "r2", metabolite = "M1", compartment = "c", modification_type = "inhibition"}, +] + +# dgf = [ +# {location = -1, metabolite = "M1", scale = 0.05}, +# {location = -2, metabolite = "M2", scale = 0.05}, +# ] + +psi = [ + {location = -0.95, scale = 0.2, experiment = "condition1"}, + {location = -0.95, scale = 0.2, experiment = "condition2"}, +] + +ki = [ + {exploc = 1, scale = 0.6, enzyme = "r2", reaction = "r2", metabolite = "M1", compartment = "c"}, +] + +[dgf] +ids = [ "M1", "M2" ] +mean_vector = [-1, -2] +covariance_matrix = [ [0.5, 0.5], [0.5, 0.5] ] diff --git a/maud/data/example_inputs/linear_multidgf/priors.toml b/maud/data/example_inputs/linear_multidgf/priors.toml new file mode 100644 index 00000000..68e50cb1 --- /dev/null +++ b/maud/data/example_inputs/linear_multidgf/priors.toml @@ -0,0 +1,42 @@ +kcat = [ + {exploc = 1, scale = 0.6, reaction = "r1", enzyme = "r1"}, + {exploc = 1, scale = 0.6, reaction = "r2", enzyme = "r2"}, + {exploc = 1, scale = 0.6, reaction = "r3", enzyme = "r3"}, +] + +km = [ + {exploc = 1, scale = 0.6, metabolite = "M1", compartment = "e", enzyme = "r1"}, + {exploc = 1, scale = 0.6, metabolite = "M1", compartment = "c", enzyme = "r1"}, + {exploc = 1, scale = 0.6, metabolite = "M1", compartment = "c", enzyme = "r2"}, + {exploc = 1, scale = 0.6, metabolite = "M2", compartment = "c", enzyme = "r3"}, + {exploc = 1, scale = 0.6, metabolite = "M2", compartment = "e", enzyme = "r3"}, +] + +transfer_constant = [ + {exploc = 1, scale = 0.6, enzyme = "r1"}, + {exploc = 1, scale = 0.6, enzyme = "r2"}, +] + +dissociation_constant = [ + {exploc = 1, scale = 0.6, enzyme = "r1", metabolite = "M2", compartment = "c", modification_type = "activation"}, + {exploc = 1, scale = 0.6, enzyme = "r2", metabolite = "M1", compartment = "c", modification_type = "inhibition"}, +] + +# dgf = [ +# {location = -1, metabolite = "M1", scale = 0.05, fixed_value = -1}, +# {location = -2, metabolite = "M2", scale = 0.05}, +# ] + +psi = [ + {location = -0.95, scale = 0.2, experiment = "condition1"}, + {location = -0.95, scale = 0.2, experiment = "condition2"}, +] + +ki = [ + {exploc = 1, scale = 0.6, enzyme = "r2", reaction = "r2", metabolite = "M1", compartment = "c"}, +] + +[dgf] +ids = [ "M1", "M2" ] +mean_vector = [ -10, -32] +covariance_matrix = [ [5,2], [2,4] ] diff --git a/tests/test_unit/test_load_maud_input.py b/tests/test_unit/test_load_maud_input.py index 2199bc25..990f5748 100644 --- a/tests/test_unit/test_load_maud_input.py +++ b/tests/test_unit/test_load_maud_input.py @@ -6,7 +6,7 @@ import numpy as np from numpy.testing import assert_equal -from maud.data.example_inputs import linear +from maud.data.example_inputs import linear, linear_multidgf from maud.loading_maud_inputs import load_maud_input @@ -36,3 +36,10 @@ def test_load_maud_input(): actual = v.tolist() if isinstance(v, np.ndarray) else v expected = expected_stan_input[k] assert_equal(actual, expected, err_msg=f"{k} different from expected.") + + +def test_load_multidgf(): + """Test that the multidgf input loads correctly.""" + files = importlib_resources.files(linear_multidgf) + mi = load_maud_input(data_path=files._paths[0]) # path 0 is package + assert mi.inits_dict["dgf_free"] == [-10.0, -32.0] From ffe57e5f3ea50cc81ae51ea01d1e03ae68859c51 Mon Sep 17 00:00:00 2001 From: teddygroves Date: Tue, 26 Mar 2024 17:08:06 +0100 Subject: [PATCH 08/15] fix black --- .pre-commit-config.yaml | 4 ++-- maud/data_model/maud_input.py | 6 +++--- pyproject.toml | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1e1f63c8..75eb069e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - id: check-merge-conflict - id: detect-private-key - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 24.3.0 hooks: - id: black - repo: https://github.com/pycqa/isort @@ -19,6 +19,6 @@ repos: name: isort (python) - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.0.278 + rev: v0.3.4 hooks: - id: ruff diff --git a/maud/data_model/maud_input.py b/maud/data_model/maud_input.py index 50c3f0b8..b5104414 100644 --- a/maud/data_model/maud_input.py +++ b/maud/data_model/maud_input.py @@ -70,9 +70,9 @@ def inits_dict(self) -> Dict: inits_dict[param.name] = param.inits.inits_unscaled if param.inits.inits_scaled is not None: scaled_pref = "log_" if param.non_negative else "" - inits_dict[ - scaled_pref + param.name + "_z" - ] = param.inits.inits_scaled + inits_dict[scaled_pref + param.name + "_z"] = ( + param.inits.inits_scaled + ) if param.fixed_ids is not None: met_to_init = dict( zip(param.inits.ids[0], param.inits.inits_unscaled) diff --git a/pyproject.toml b/pyproject.toml index 7377a273..4bb2ad14 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,7 +85,6 @@ packages = [ [tool.black] line-length = 80 -python-version = ['py38', 'py39'] exclude = ''' ( __init__.py From 785bfb605822ee05ef5392713579536830f260bc Mon Sep 17 00:00:00 2001 From: teddygroves Date: Tue, 26 Mar 2024 17:23:37 +0100 Subject: [PATCH 09/15] add linear_multidgf to list of packages --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 4bb2ad14..ef80d11b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,6 +76,7 @@ packages = [ "maud.data.example_inputs.example_ode", "maud.data.example_inputs.linear", "maud.data.example_inputs.methionine", + "maud.data.example_inputs.linear_multidgf", "maud.data.example_outputs", "maud.data.example_outputs.linear", "maud.data.example_outputs.linear.user_input", From 30c390729479736a771f8a7b2326ed1b3bcc7d13 Mon Sep 17 00:00:00 2001 From: teddygroves Date: Tue, 26 Mar 2024 17:41:34 +0100 Subject: [PATCH 10/15] add __init__.py to example input folders --- maud/data/example_inputs/__init__.py | 0 maud/data/example_inputs/example_ode/__init__.py | 0 maud/data/example_inputs/linear/__init__.py | 0 maud/data/example_inputs/linear_multidgf/__init__.py | 0 maud/data/example_inputs/methionine/__init__.py | 0 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 maud/data/example_inputs/__init__.py create mode 100644 maud/data/example_inputs/example_ode/__init__.py create mode 100644 maud/data/example_inputs/linear/__init__.py create mode 100644 maud/data/example_inputs/linear_multidgf/__init__.py create mode 100644 maud/data/example_inputs/methionine/__init__.py diff --git a/maud/data/example_inputs/__init__.py b/maud/data/example_inputs/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/maud/data/example_inputs/example_ode/__init__.py b/maud/data/example_inputs/example_ode/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/maud/data/example_inputs/linear/__init__.py b/maud/data/example_inputs/linear/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/maud/data/example_inputs/linear_multidgf/__init__.py b/maud/data/example_inputs/linear_multidgf/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/maud/data/example_inputs/methionine/__init__.py b/maud/data/example_inputs/methionine/__init__.py new file mode 100644 index 00000000..e69de29b From 79f5c1921cc55ac633ef0e92182927730c740985 Mon Sep 17 00:00:00 2001 From: teddygroves Date: Tue, 26 Mar 2024 17:58:47 +0100 Subject: [PATCH 11/15] make code in test a little nicer --- tests/test_unit/test_load_maud_input.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_unit/test_load_maud_input.py b/tests/test_unit/test_load_maud_input.py index 990f5748..f15212fc 100644 --- a/tests/test_unit/test_load_maud_input.py +++ b/tests/test_unit/test_load_maud_input.py @@ -22,7 +22,7 @@ def test_load_maud_input(): "dissociation_constant": [["r1_M2_c_activation", "r2_M1_c_inhibition"]], } linear_files = importlib_resources.files(linear) - mi = load_maud_input(data_path=linear_files._paths[0]) # path 0 is package + mi = load_maud_input(data_path=str(linear_files)) # path 0 is package r1 = next(r for r in mi.kinetic_model.reactions if r.id == "r1") assert r1.stoichiometry == {"M1_e": -1, "M1_c": 1} assert "r1_r1" in mi.parameters.kcat.ids[0] @@ -41,5 +41,5 @@ def test_load_maud_input(): def test_load_multidgf(): """Test that the multidgf input loads correctly.""" files = importlib_resources.files(linear_multidgf) - mi = load_maud_input(data_path=files._paths[0]) # path 0 is package + mi = load_maud_input(data_path=str(files)) # path 0 is package assert mi.inits_dict["dgf_free"] == [-10.0, -32.0] From 209c3ab5df7752326a279cfd46fdcaabd7cbc29e Mon Sep 17 00:00:00 2001 From: teddygroves Date: Thu, 4 Apr 2024 09:32:20 +0200 Subject: [PATCH 12/15] delete commented lines from parameters files --- maud/data/example_inputs/linear_multidgf/parameters.toml | 5 ----- maud/data/example_inputs/linear_multidgf/priors.toml | 5 ----- 2 files changed, 10 deletions(-) diff --git a/maud/data/example_inputs/linear_multidgf/parameters.toml b/maud/data/example_inputs/linear_multidgf/parameters.toml index 2c8c448c..85c7ae73 100644 --- a/maud/data/example_inputs/linear_multidgf/parameters.toml +++ b/maud/data/example_inputs/linear_multidgf/parameters.toml @@ -22,11 +22,6 @@ dissociation_constant = [ {exploc = 1, scale = 0.6, enzyme = "r2", metabolite = "M1", compartment = "c", modification_type = "inhibition"}, ] -# dgf = [ -# {location = -1, metabolite = "M1", scale = 0.05}, -# {location = -2, metabolite = "M2", scale = 0.05}, -# ] - psi = [ {location = -0.95, scale = 0.2, experiment = "condition1"}, {location = -0.95, scale = 0.2, experiment = "condition2"}, diff --git a/maud/data/example_inputs/linear_multidgf/priors.toml b/maud/data/example_inputs/linear_multidgf/priors.toml index 68e50cb1..b820eaa2 100644 --- a/maud/data/example_inputs/linear_multidgf/priors.toml +++ b/maud/data/example_inputs/linear_multidgf/priors.toml @@ -22,11 +22,6 @@ dissociation_constant = [ {exploc = 1, scale = 0.6, enzyme = "r2", metabolite = "M1", compartment = "c", modification_type = "inhibition"}, ] -# dgf = [ -# {location = -1, metabolite = "M1", scale = 0.05, fixed_value = -1}, -# {location = -2, metabolite = "M2", scale = 0.05}, -# ] - psi = [ {location = -0.95, scale = 0.2, experiment = "condition1"}, {location = -0.95, scale = 0.2, experiment = "condition2"}, From e0182f4ccbfa405c6504f0742209a27dd021475c Mon Sep 17 00:00:00 2001 From: teddygroves Date: Wed, 10 Apr 2024 09:42:31 +0200 Subject: [PATCH 13/15] Update pyproject.toml, increase min python version, fix ruff warnings --- pyproject.toml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ef80d11b..2496fa95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,10 +21,10 @@ classifiers = [ license = {text = "GNU General Public License version 3"} description = "Bayesian statistical models of metabolic networks" readme = "README.rst" -requires-python = ">=3.9" +requires-python = ">=3.10" dependencies = [ "pip >= 20", - "arviz >= 0.12.1", + "arviz >= 0.18.0", "importlib_resources >= 3.2", "numpy", "scipy", @@ -117,23 +117,23 @@ markers = ["raises"] [tool.ruff] # Enable the following rules: # pycodestyle (`E`), Pyflakes (`F`), pycodestyle (`W`), flake8-bugbear (`B`) -select = ["E", "F", "B", "W", "D"] -ignore = [ +lint.select = ["E", "F", "B", "W", "D"] +lint.ignore = [ "B905", # Use zip() without a `strict` parameter. "D107", # Init methods can be undocumented. "D203", # Class docstrints don't need blank lines before them. "D213", # https://beta.ruff.rs/docs/rules/multi-line-summary-second-line/ "D104", # __init__.py can be empty. ] -fixable = ["ALL"] -unfixable = [] +lint.fixable = ["ALL"] +lint.unfixable = [] line-length = 80 target-version = "py310" [tool.tox] legacy_tox_ini = """ [tox] - envlist = isort, black, ruff, safety, py3{9,10} + envlist = isort, black, ruff, safety, py3{10,11} [testenv] deps = @@ -143,11 +143,11 @@ legacy_tox_ini = """ commands = pytest --cov=maud --cov-report=term --ignore=tests/test_integration {posargs} - [testenv:py38] + [testenv:py310] passenv = CMDSTAN - [testenv:py39] + [testenv:py311] passenv = CMDSTAN @@ -171,7 +171,7 @@ legacy_tox_ini = """ deps= ruff commands= - ruff . + ruff check . [testenv:safety] deps= From 619fde26554a67e83211b17da4da4086b125d3b3 Mon Sep 17 00:00:00 2001 From: teddygroves Date: Wed, 10 Apr 2024 09:43:26 +0200 Subject: [PATCH 14/15] Document min python version --- docs/getting_started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting_started.md b/docs/getting_started.md index 68dca0aa..7979bc28 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -4,7 +4,7 @@ This page explains how to install Maud and use its command line interface. ## Installing Maud -Maud is compatible with Python versions 3.9 and above +Maud is compatible with Python versions 3.10 and above. We recommend using a fresh virtual environment to install Maud. To make one and then activate it, run the following commands: From ad35d8772ad2ea2030c84eed46ff33a0163e498e Mon Sep 17 00:00:00 2001 From: teddygroves Date: Wed, 10 Apr 2024 09:58:29 +0200 Subject: [PATCH 15/15] Update tox workflow python versions --- .github/workflows/run_tox.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run_tox.yml b/.github/workflows/run_tox.yml index 173ea765..25b08dff 100644 --- a/.github/workflows/run_tox.yml +++ b/.github/workflows/run_tox.yml @@ -23,15 +23,15 @@ jobs: - uses: actions/checkout@v2 - - name: Set up Python 3.9 + - name: Set up Python 3.10 uses: actions/setup-python@v2 with: - python-version: '3.9' + python-version: '3.10' - - name: Set up Python 3.10 + - name: Set up Python 3.11 uses: actions/setup-python@v2 with: - python-version: '3.10' + python-version: '3.11' - name: Install build dependencies run: |