Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/biosustain/Maud
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasCowie committed Jun 20, 2024
2 parents 51ae0e9 + 99ecc35 commit bbab870
Show file tree
Hide file tree
Showing 22 changed files with 306 additions and 74 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/run_tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions maud/data/example_inputs/linear_multidgf/config.toml
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions maud/data/example_inputs/linear_multidgf/experiments.toml
Original file line number Diff line number Diff line change
@@ -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},
]
66 changes: 66 additions & 0 deletions maud/data/example_inputs/linear_multidgf/kinetic_model.toml
Original file line number Diff line number Diff line change
@@ -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"
37 changes: 37 additions & 0 deletions maud/data/example_inputs/linear_multidgf/parameters.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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"},
]

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] ]
37 changes: 37 additions & 0 deletions maud/data/example_inputs/linear_multidgf/priors.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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"},
]

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] ]
Empty file.
8 changes: 5 additions & 3 deletions maud/data_model/maud_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
6 changes: 4 additions & 2 deletions maud/data_model/maud_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
53 changes: 31 additions & 22 deletions maud/getting_idatas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for creating InferenceData objects from Maud outputs."""

from typing import List

import arviz as az
Expand Down Expand Up @@ -36,31 +37,39 @@ 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
],
"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]),
Expand Down Expand Up @@ -103,7 +112,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",
Expand Down
Loading

0 comments on commit bbab870

Please sign in to comment.