Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dgfs #449

Merged
merged 20 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run_tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
workflow_dispatch: {}

env:
CMDSTAN_VERSION: "2.32.2"
CMDSTAN_VERSION: "2.33.1"

jobs:
build:
Expand Down
31 changes: 31 additions & 0 deletions docs/inputting.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,34 @@ kcat = [
{enzyme = "PROT1", reaction = "PROT", init = 0.264744},
]
```

## Fixing parameter values

Sometimes it is useful to model a parameter as if its value were known exactly.
For example, the formation energies of metabolites that are only involved in
irreversible reactions are typically not identified by Maud's statistical
model. Fixing these unidentified parameters can improve computational
performance without loss of any information. Another use might be to test
whether a particular parameter value is feasible at all.

Maud currently supports fixing the values of `dgf` parameters. This can be done
for independent parameter inputs by adding a `fixed_value` field to the
relevant items as shown here:

```toml
dgf = [
{location = -1, metabolite = "M1", scale = 0.05, fixed_value = -1},
]
```

If a multivariate input is used for `dgf`, fixed values can be specified using
a separate table, like this:

```toml
[dgf]
ids = ["M1", "M2", "M3"]
mean_vector = [1, 2, 3]
covariance_matrix = [[1, 2, 3], [1, 2, 1], [3, 2, 1]]
[dgf.fixed_values]
M1 = -1
```
8 changes: 8 additions & 0 deletions maud/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

"""Functions that are exposed to the command line interface live here."""

import json
import os
import shutil
from datetime import datetime
Expand Down Expand Up @@ -102,6 +103,13 @@ def do_sample(data_path, output_dir):
stanfit = sample(mi, samples_path)
print(stanfit.diagnose())
print(stanfit.summary())
if stanfit.metric is not None:
for i, chain_metric in enumerate(stanfit.metric):
chain_metric_dict = {"inv_metric": chain_metric.tolist()}
with open(
os.path.join(samples_path, f"metric-{str(i)}.json"), "w"
) as f:
json.dump(chain_metric_dict, f)
idata = get_idata(stanfit.runset.csv_files, mi, "train")
idata.to_json(os.path.join(output_path, "idata.json"))
return output_path
Expand Down
119 changes: 1 addition & 118 deletions maud/data/example_inputs/example_ode/inits.json
Original file line number Diff line number Diff line change
@@ -1,118 +1 @@
{
"dgf": [
10.0,
2.0,
5.0,
0.0
],
"km": [
0.5,
1.0,
2.0,
0.5,
1.0,
2.0,
0.5,
2.0,
1.0,
3.0000000000000004
],
"kcat": [
0.5,
2.0,
1.0,
2.0,
1.0
],
"kcat_phos": [],
"ki": [
1.0
],
"psi": [
0.0
],
"dissociation_constant": [
0.3,
0.9
],
"transfer_constant": [
1.0,
1.0
],
"conc_unbalanced_train": [
[
4.999999999999999,
0.5
]
],
"drain_train": [
[]
],
"conc_enzyme_train": [
[
1.0,
2.0,
3.0000000000000004,
2.0,
3.0000000000000004
]
],
"conc_phos_train": [
[]
],
"log_km_z": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
],
"log_kcat_z": [
0.0,
0.0,
0.0,
0.0,
0.0
],
"log_kcat_phos_z": [],
"log_ki_z": [
0.0
],
"psi_z": [
0.0
],
"log_dissociation_constant_z": [
0.0,
0.0
],
"log_transfer_constant_z": [
0.0,
0.0
],
"log_conc_unbalanced_train_z": [
[
0.0,
0.0
]
],
"drain_train_z": [
[]
],
"log_conc_enzyme_train_z": [
[
0.0,
0.0,
0.0,
0.0,
0.0
]
],
"log_conc_phos_train_z": [
[]
]
}
{"dgf": [10.0, 2.0, 5.0, 0.0], "dgf_free": [10.0, 2.0, 5.0, 0.0], "km": [0.5, 1.0, 2.0, 0.5, 1.0, 2.0, 0.5, 2.0, 1.0, 3.0000000000000004], "log_km_z": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], "ki": [1.0], "log_ki_z": [0.0], "kcat": [0.5, 2.0, 1.0, 2.0, 1.0], "log_kcat_z": [0.0, 0.0, 0.0, 0.0, 0.0], "dissociation_constant": [0.3, 0.9], "log_dissociation_constant_z": [0.0, 0.0], "transfer_constant": [1.0, 1.0], "log_transfer_constant_z": [0.0, 0.0], "kcat_pme": [], "log_kcat_pme_z": [], "drain_train": [[]], "drain_train_z": [[]], "drain_test": [[]], "drain_test_z": [[]], "conc_enzyme_train": [[1.0, 2.0, 3.0000000000000004, 2.0, 3.0000000000000004]], "log_conc_enzyme_train_z": [[0.0, 0.0, 0.0, 0.0, 0.0]], "conc_enzyme_test": [[1.0, 2.0, 3.0000000000000004, 2.0, 3.0000000000000004]], "log_conc_enzyme_test_z": [[0.0, 0.0, 0.0, 0.0, 0.0]], "conc_unbalanced_train": [[4.999999999999999, 0.5]], "log_conc_unbalanced_train_z": [[0.0, 0.0]], "conc_unbalanced_test": [[4.999999999999999, 0.5]], "log_conc_unbalanced_test_z": [[0.0, 0.0]], "conc_pme_train": [[]], "log_conc_pme_train_z": [[]], "conc_pme_test": [[]], "log_conc_pme_test_z": [[]], "psi_train": [0.0], "psi_train_z": [0.0], "psi_test": [0.0], "psi_test_z": [0.0]}
2 changes: 1 addition & 1 deletion maud/data/example_inputs/example_ode/input_data_train.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"N_mic": 4, "N_edge_sub": 5, "N_edge_prod": 5, "N_edge": 5, "N_unbalanced": 2, "N_enzyme": 5, "N_phosphorylation": 0, "N_pme": 0, "N_competitive_inhibition": 1, "N_allostery": 2, "N_allosteric_enzyme": 2, "N_drain": 0, "N_km": 10, "N_sub_km": 5, "N_prod_km": 5, "S": [[-1, -1, -1, 0, 0], [1, 0, 0, -1, 0], [0, 1, 1, 0, -1], [0, 0, 0, 1, 1]], "N_reaction": 4, "N_metabolite": 4, "balanced_mic_ix": [2, 3], "unbalanced_mic_ix": [1, 4], "ci_mic_ix": [4], "edge_type": [1, 1, 1, 1, 1], "edge_to_enzyme": [1, 2, 3, 4, 5], "edge_to_tc": [0, 1, 2, 0, 0], "edge_to_drain": [0, 0, 0, 0, 0], "edge_to_reaction": [1, 2, 2, 3, 4], "water_stoichiometry": [0.0, 0.0, 0.0, 0.0, 0.0], "transported_charge": [0.0, 0.0, 0.0, 0.0, 0.0], "mic_to_met": [1, 2, 3, 4], "subunits": [1, 1, 1, 1, 1], "sub_by_edge_long": [1, 1, 1, 2, 3], "sub_by_edge_bounds": [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]], "prod_by_edge_long": [2, 3, 3, 4, 4], "prod_by_edge_bounds": [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]], "sub_km_ix_by_edge_long": [1, 3, 5, 7, 9], "sub_km_ix_by_edge_bounds": [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]], "prod_km_ix_by_edge_long": [2, 4, 6, 8, 10], "prod_km_ix_by_edge_bounds": [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]], "ci_ix_long": [1], "ci_ix_bounds": [[1, 1], [2, 1], [2, 1], [2, 1], [2, 1]], "allostery_ix_long": [1, 2], "allostery_ix_bounds": [[1, 0], [1, 1], [2, 2], [3, 2], [3, 2]], "allostery_type": [1, 2], "allostery_mic": [3, 3], "phosphorylation_ix_long": [], "phosphorylation_ix_bounds": [[1, 0], [1, 0], [1, 0], [1, 0], [1, 0]], "phosphorylation_type": [], "phosphorylation_pme": [], "priors_km": [[-0.6931471805599453, 0.0, 0.6931471805599453, -0.6931471805599453, 0.0, 0.6931471805599453, -0.6931471805599453, 0.6931471805599453, 0.0, 1.0986122886681098], [0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2]], "priors_ki": [[0.0], [0.2]], "priors_kcat": [[-0.6931471805599453, 0.6931471805599453, 0.0, 0.6931471805599453, 0.0], [0.2, 0.2, 0.2, 0.2, 0.2]], "priors_dissociation_constant": [[-1.2039728043259361, -0.10536051565782628], [0.2, 0.2]], "priors_transfer_constant": [[0.0, 0.0], [0.2, 0.2]], "priors_kcat_pme": [[], []], "priors_drain_train": [[[]], [[]]], "priors_conc_enzyme_train": [[[0.0, 0.6931471805599453, 1.0986122886681098, 0.6931471805599453, 1.0986122886681098]], [[0.2, 0.2, 0.2, 0.2, 0.2]]], "priors_conc_unbalanced_train": [[[1.6094379124341003, -0.6931471805599453]], [[0.2, 0.2]]], "priors_conc_pme_train": [[[]], [[]]], "priors_psi_train": [[0.0], [2.0]], "prior_loc_dgf": [10.0, 2.0, 5.0, 0.0], "prior_cov_dgf": [[0.2, 0.0, 0.0, 0.0], [0.0, 0.2, 0.0, 0.0], [0.0, 0.0, 0.2, 0.0], [0.0, 0.0, 0.0, 0.2]], "N_experiment_train": 1, "N_flux_measurement_train": 2, "N_enzyme_measurement_train": 0, "N_conc_measurement_train": 2, "N_enzyme_knockout_train": 0, "N_pme_knockout_train": 0, "temperature_train": [298.15], "enzyme_knockout_train_long": [], "enzyme_knockout_train_bounds": [[1, 0]], "pme_knockout_train_long": [], "pme_knockout_train_bounds": [[1, 0]], "yconc_train": [0.323117, 3.02187], "sigma_yconc_train": [0.1, 0.1], "experiment_yconc_train": [1, 1], "mic_ix_yconc_train": [2, 3], "yflux_train": [0.421816, 2.11674], "sigma_yflux_train": [0.01, 0.01], "experiment_yflux_train": [1, 1], "reaction_yflux_train": [3, 4], "yenz_train": [], "sigma_yenz_train": [], "experiment_yenz_train": [], "enzyme_yenz_train": [], "likelihood": 1, "drain_small_conc_corrector": 1e-06, "reject_non_steady": 1, "penalize_non_steady": 0, "steady_state_threshold_abs": 1e-08, "steady_state_threshold_rel": 0.001, "steady_state_penalty_rel": 1e-08, "rel_tol_ode": 1e-09, "abs_tol_ode": 1e-09, "max_num_steps_ode": 1000000000, "rel_tol_alg": 1e-07, "abs_tol_alg": 1e-07, "max_num_steps_alg": 1000000, "conc_init": [[0.323117, 3.02187]]}
{"N_mic": 4, "N_edge_sub": 5, "N_edge_prod": 5, "N_edge": 5, "N_unbalanced": 2, "N_enzyme": 5, "N_phosphorylation": 0, "N_pme": 0, "N_competitive_inhibition": 1, "N_allostery": 2, "N_allosteric_enzyme": 2, "N_drain": 0, "N_km": 10, "N_sub_km": 5, "N_prod_km": 5, "S": [[-1, -1, -1, 0, 0], [1, 0, 0, -1, 0], [0, 1, 1, 0, -1], [0, 0, 0, 1, 1]], "N_reaction": 4, "N_metabolite": 4, "balanced_mic_ix": [2, 3], "unbalanced_mic_ix": [1, 4], "ci_mic_ix": [4], "edge_type": [1, 1, 1, 1, 1], "edge_to_enzyme": [1, 2, 3, 4, 5], "edge_to_tc": [0, 1, 2, 0, 0], "edge_to_drain": [0, 0, 0, 0, 0], "edge_to_reaction": [1, 2, 2, 3, 4], "water_stoichiometry": [0.0, 0.0, 0.0, 0.0, 0.0], "transported_charge": [0.0, 0.0, 0.0, 0.0, 0.0], "mic_to_met": [1, 2, 3, 4], "subunits": [1, 1, 1, 1, 1], "sub_by_edge_long": [1, 1, 1, 2, 3], "sub_by_edge_bounds": [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]], "prod_by_edge_long": [2, 3, 3, 4, 4], "prod_by_edge_bounds": [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]], "sub_km_ix_by_edge_long": [1, 3, 5, 7, 9], "sub_km_ix_by_edge_bounds": [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]], "prod_km_ix_by_edge_long": [2, 4, 6, 8, 10], "prod_km_ix_by_edge_bounds": [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]], "ci_ix_long": [1], "ci_ix_bounds": [[1, 1], [2, 1], [2, 1], [2, 1], [2, 1]], "allostery_ix_long": [1, 2], "allostery_ix_bounds": [[1, 0], [1, 1], [2, 2], [3, 2], [3, 2]], "allostery_type": [1, 2], "allostery_mic": [3, 3], "phosphorylation_ix_long": [], "phosphorylation_ix_bounds": [[1, 0], [1, 0], [1, 0], [1, 0], [1, 0]], "phosphorylation_type": [], "phosphorylation_pme": [], "N_dgf_fixed": 0, "dgf_fixed": [], "ix_dgf_free": [1, 2, 3, 4], "ix_dgf_fixed": [], "priors_km": [[-0.6931471805599453, 0.0, 0.6931471805599453, -0.6931471805599453, 0.0, 0.6931471805599453, -0.6931471805599453, 0.6931471805599453, 0.0, 1.0986122886681098], [0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2]], "priors_ki": [[0.0], [0.2]], "priors_kcat": [[-0.6931471805599453, 0.6931471805599453, 0.0, 0.6931471805599453, 0.0], [0.2, 0.2, 0.2, 0.2, 0.2]], "priors_dissociation_constant": [[-1.2039728043259361, -0.10536051565782628], [0.2, 0.2]], "priors_transfer_constant": [[0.0, 0.0], [0.2, 0.2]], "priors_kcat_pme": [[], []], "priors_drain_train": [[[]], [[]]], "priors_conc_enzyme_train": [[[0.0, 0.6931471805599453, 1.0986122886681098, 0.6931471805599453, 1.0986122886681098]], [[0.2, 0.2, 0.2, 0.2, 0.2]]], "priors_conc_unbalanced_train": [[[1.6094379124341003, -0.6931471805599453]], [[0.2, 0.2]]], "priors_conc_pme_train": [[[]], [[]]], "priors_psi_train": [[0.0], [2.0]], "prior_loc_dgf": [10.0, 2.0, 5.0, 0.0], "prior_cov_dgf": [[0.2, 0.0, 0.0, 0.0], [0.0, 0.2, 0.0, 0.0], [0.0, 0.0, 0.2, 0.0], [0.0, 0.0, 0.0, 0.2]], "N_experiment_train": 1, "N_flux_measurement_train": 2, "N_enzyme_measurement_train": 0, "N_conc_measurement_train": 2, "N_enzyme_knockout_train": 0, "N_pme_knockout_train": 0, "temperature_train": [298.15], "enzyme_knockout_train_long": [], "enzyme_knockout_train_bounds": [[1, 0]], "pme_knockout_train_long": [], "pme_knockout_train_bounds": [[1, 0]], "yconc_train": [0.323117, 3.02187], "sigma_yconc_train": [0.1, 0.1], "experiment_yconc_train": [1, 1], "mic_ix_yconc_train": [2, 3], "yflux_train": [0.421816, 2.11674], "sigma_yflux_train": [0.01, 0.01], "experiment_yflux_train": [1, 1], "reaction_yflux_train": [3, 4], "yenz_train": [], "sigma_yenz_train": [], "experiment_yenz_train": [], "enzyme_yenz_train": [], "likelihood": 1, "drain_small_conc_corrector": 1e-06, "reject_non_steady": 1, "penalize_non_steady": 0, "steady_state_threshold_abs": 1e-08, "steady_state_threshold_rel": 0.001, "steady_state_penalty_rel": 1e-08, "rel_tol_ode": 1e-09, "abs_tol_ode": 1e-09, "max_num_steps_ode": 1000000000, "rel_tol_alg": 1e-07, "abs_tol_alg": 1e-07, "max_num_steps_alg": 1000000, "conc_init": [[0.323117, 3.02187]]}
Binary file added maud/data/example_inputs/linear.zip
Binary file not shown.
8 changes: 4 additions & 4 deletions maud/data/example_inputs/linear/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ save_warmup = true
seed = 1234

[ode_solver_config]
abs_tol = 1e-7
rel_tol = 1e-7
abs_tol = 1e-4
rel_tol = 1e-6
max_num_steps = 1e6

[algebra_solver_config]
abs_tol = 1e-5
rel_tol = 1e-5
abs_tol = 1e-4
rel_tol = 1e-6
max_num_steps = 1e6
Loading
Loading