Skip to content

Commit

Permalink
including corrected arviz branch, fix next arviz release
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasCowie committed Jun 21, 2024
1 parent 1e7f392 commit 752a4f6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
6 changes: 6 additions & 0 deletions maud/getting_stan_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def get_network_properties_input(
metabolite_codes = codify_maud_object(kinetic_model.metabolites)
mic_codes = codify_maud_object(mics)
enzyme_codes = codify_maud_object(enzymes)
er_codes = codify_maud_object(kinetic_model.ers)
km_ids = parameters.km.ids[0]
km_codes = dict(zip(km_ids, range(1, len(km_ids) + 1)))
if len(kinetic_model.left_nullspace) > 0:
Expand Down Expand Up @@ -187,6 +188,9 @@ def get_network_properties_input(
enzyme_codes[er.enzyme_id] if isinstance(er, EnzymeReaction) else 0
for er in edges
]
edge_er_code = [
er_codes[er.id] if isinstance(er, EnzymeReaction) else 0 for er in edges
]
edge_drain_code = [
drain_codes[d.id] if isinstance(d, Reaction) else 0 for d in edges
]
Expand Down Expand Up @@ -355,6 +359,7 @@ def get_network_properties_input(
"N_independent": len(independent_mic_codes),
"N_dependent": len(dependent_mic_codes),
"N_enzyme": len(enzymes),
"N_er": len(kinetic_model.ers),
"N_phosphorylation": len(phosphorylation_codes),
"N_pme": len(pme_codes),
"N_competitive_inhibition": len(ci_ix_long),
Expand All @@ -374,6 +379,7 @@ def get_network_properties_input(
"ci_mic_ix": ci_mic_codes,
"edge_type": edge_mechanism_code,
"edge_to_enzyme": edge_enzyme_code,
"edge_to_er": edge_er_code,
"edge_to_tc": edge_tc_code,
"edge_to_drain": edge_drain_code,
"edge_to_reaction": edge_reaction_code,
Expand Down
37 changes: 26 additions & 11 deletions maud/stan/functions.stan
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ functions {
}

vector get_vmax_by_edge(vector enzyme, vector kcat,
array[] int edge_to_enzyme, array[] int edge_type) {
array[] int edge_to_enzyme, array[] int edge_to_er, array[] int edge_type) {
int N_edge = size(edge_to_enzyme);
vector[N_edge] out = rep_vector(1, N_edge);
for (f in 1 : N_edge) {
if (edge_type[f] != 3) {
out[f] = enzyme[edge_to_enzyme[f]] * kcat[edge_to_enzyme[f]];
out[f] = enzyme[edge_to_enzyme[f]] * kcat[edge_to_er[f]];
}
}
return out;
Expand All @@ -313,7 +313,7 @@ functions {
vector kcat_pme, vector conc_pme, vector drain,
real temperature, real drain_small_conc_corrector,
matrix S, vector subunits, array[] int edge_type,
array[] int edge_to_enzyme, array[] int edge_to_drain,
array[] int edge_to_enzyme, array[] int edge_to_er, array[] int edge_to_drain,
array[] int ci_mic_ix,
array[] int sub_km_ix_by_edge_long,
array[,] int sub_km_ix_by_edge_bounds,
Expand All @@ -332,7 +332,7 @@ functions {
array[] int phosphorylation_type,
array[] int phosphorylation_pme) {
int N_edge = cols(S);
vector[N_edge] vmax = get_vmax_by_edge(enzyme, kcat, edge_to_enzyme,
vector[N_edge] vmax = get_vmax_by_edge(enzyme, kcat, edge_to_enzyme, edge_to_er,
edge_type);
vector[N_edge] reversibility = get_reversibility(dgr, temperature, S,
conc, edge_type);
Expand Down Expand Up @@ -371,6 +371,18 @@ functions {
sub_by_edge_bounds,
edge_type,
drain_small_conc_corrector);
// Paste these lines into the function get_edge_flux to debug.
print("free_enzyme_ratio: ", free_enzyme_ratio);
print("vmax: ", vmax);
print("kcat: ", kcat);
print("reversibility: ", reversibility);
print("saturation: ", saturation);
print("allostery: ", allostery);
print("phosphorylation: ", phosphorylation);
print("drain_by_edge: ", drain_by_edge);
print("drain_by_edge: ", drain_by_edge);
print("conc: ", conc);
print("flux: ", vmax .* saturation .* reversibility .* allostery.* phosphorylation .* drain_by_edge);
return vmax .* saturation .* reversibility .* allostery
.* phosphorylation .* drain_by_edge;
}
Expand All @@ -383,7 +395,7 @@ functions {
vector conc_pme, vector drain, real temperature,
real drain_small_conc_corrector, matrix S, matrix left_nullspace_independent,
vector subunits, array[] int edge_type,
array[] int edge_to_enzyme, array[] int edge_to_drain,
array[] int edge_to_enzyme, array[] int edge_to_er, array[] int edge_to_drain,
array[] int ci_mic_ix,
array[] int sub_km_ix_by_edge_long,
array[,] int sub_km_ix_by_edge_bounds,
Expand Down Expand Up @@ -412,7 +424,7 @@ functions {
temperature,
drain_small_conc_corrector, S,
subunits, edge_type,
edge_to_enzyme, edge_to_drain,
edge_to_enzyme, edge_to_er, edge_to_drain,
ci_mic_ix,
sub_km_ix_by_edge_long,
sub_km_ix_by_edge_bounds,
Expand Down Expand Up @@ -445,6 +457,7 @@ functions {
matrix S, vector subunits,
array[] int edge_type,
array[] int edge_to_enzyme,
array[] int edge_to_er,
array[] int edge_to_drain,
array[] int ci_mic_ix,
array[] int sub_km_ix_by_edge_long,
Expand All @@ -469,6 +482,7 @@ functions {
int N_edge = cols(S);
complex_vector[N_edge] vmax = get_complex_vmax_by_edge(enzyme, kcat,
edge_to_enzyme,
edge_to_er,
edge_type);
vector[N_edge] reversibility = get_reversibility(dgr, temperature, S,
conc, edge_type);
Expand Down Expand Up @@ -512,13 +526,13 @@ functions {
}

complex_vector get_complex_vmax_by_edge(complex_vector enzyme, vector kcat,
array[] int edge_to_enzyme,
array[] int edge_to_enzyme, array[] int edge_to_er,
array[] int edge_type) {
int N_edge = size(edge_to_enzyme);
complex_vector[N_edge] out = rep_vector(1, N_edge);
for (f in 1 : N_edge) {
if (edge_type[f] != 3) {
out[f] = enzyme[edge_to_enzyme[f]] * kcat[edge_to_enzyme[f]];
out[f] = enzyme[edge_to_enzyme[f]] * kcat[edge_to_er[f]];
}
}
return out;
Expand Down Expand Up @@ -554,6 +568,7 @@ functions {
matrix S, vector subunits,
array[] int edge_type,
array[] int edge_to_enzyme,
array[] int edge_to_er,
array[] int edge_to_drain,
array[] int ci_mic_ix,
array[] int sub_km_ix_by_edge_long,
Expand All @@ -576,7 +591,7 @@ functions {
array[] int phosphorylation_type,
array[] int phosphorylation_pme) {
int N_edge = cols(S);
vector[N_edge] vmax = get_vmax_by_edge(enzyme, kcat, edge_to_enzyme,
vector[N_edge] vmax = get_vmax_by_edge(enzyme, kcat, edge_to_enzyme, edge_to_er,
edge_type);
complex_vector[N_edge] reversibility = get_reversibility_complex(dgr,
temperature,
Expand Down Expand Up @@ -814,7 +829,7 @@ vector maud_ae_system(vector conc_ind,
vector conc_pme, vector drain, real temperature,
real drain_small_conc_corrector, matrix S,
vector subunits, array[] int edge_type,
array[] int edge_to_enzyme, array[] int edge_to_drain,
array[] int edge_to_enzyme, array[] into edge_to_er, array[] int edge_to_drain,
array[] int ci_mic_ix,
array[] int sub_km_ix_by_edge_long,
array[,] int sub_km_ix_by_edge_bounds,
Expand Down Expand Up @@ -858,7 +873,7 @@ vector maud_ae_system(vector conc_ind,
temperature,
drain_small_conc_corrector, S,
subunits, edge_type,
edge_to_enzyme, edge_to_drain,
edge_to_enzyme, edge_to_er, edge_to_drain,
ci_mic_ix, sub_km_ix_by_edge_long,
sub_km_ix_by_edge_bounds,
prod_km_ix_by_edge_long,
Expand Down
8 changes: 6 additions & 2 deletions maud/stan/model.stan
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data {
int<lower=1> N_prod_km;
int<lower=1> N_reaction;
int<lower=1> N_enzyme;
int<lower=1> N_er;
int<lower=0> N_drain;
int<lower=1> N_edge;
int<lower=0> N_allostery;
Expand All @@ -30,6 +31,7 @@ data {
array[N_competitive_inhibition] int<lower=1, upper=N_mic> ci_mic_ix;
array[N_edge] int<lower=1, upper=3> edge_type; // 1 = reversible modular rate law, 2 = drain
array[N_edge] int<lower=0, upper=N_enzyme> edge_to_enzyme; // 0 if drain
array[N_edge] int<lower=0, upper=N_enzyme> edge_to_er; // 0 if drain
array[N_edge] int<lower=0, upper=N_allostery> edge_to_tc; // 0 if non-allosteric
array[N_edge] int<lower=0, upper=N_drain> edge_to_drain; // 0 if enzyme
array[N_edge] int<lower=0, upper=N_reaction> edge_to_reaction;
Expand Down Expand Up @@ -220,7 +222,7 @@ transformed parameters {
drain_small_conc_corrector, S,
left_nullspace_independent,
subunits, edge_type,
edge_to_enzyme, edge_to_drain,
edge_to_enzyme, edge_to_er, edge_to_drain,
ci_mic_ix, sub_km_ix_by_edge_long,
sub_km_ix_by_edge_bounds,
prod_km_ix_by_edge_long,
Expand Down Expand Up @@ -251,7 +253,7 @@ transformed parameters {
temperature_train[e],
drain_small_conc_corrector, S,
subunits, edge_type,
edge_to_enzyme, edge_to_drain,
edge_to_enzyme, edge_to_er, edge_to_drain,
ci_mic_ix,
sub_km_ix_by_edge_long,
sub_km_ix_by_edge_bounds,
Expand Down Expand Up @@ -407,6 +409,7 @@ generated quantities {
subunits,
edge_type,
edge_to_enzyme,
edge_to_er,
edge_to_drain,
ci_mic_ix,
sub_km_ix_by_edge_long,
Expand Down Expand Up @@ -450,6 +453,7 @@ generated quantities {
subunits,
edge_type,
edge_to_enzyme,
edge_to_er,
edge_to_drain,
ci_mic_ix,
sub_km_ix_by_edge_long,
Expand Down
8 changes: 5 additions & 3 deletions maud/stan/out_of_sample_model.stan
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data {
int<lower=1> N_prod_km;
int<lower=1> N_reaction;
int<lower=1> N_enzyme;
int<lower=1> N_er;
int<lower=0> N_drain;
int<lower=1> N_edge;
int<lower=0> N_allostery;
Expand All @@ -29,6 +30,7 @@ data {
array[N_competitive_inhibition] int<lower=1, upper=N_mic> ci_mic_ix;
array[N_edge] int<lower=1, upper=3> edge_type; // 1 = reversible modular rate law, 2 = drain
array[N_edge] int<lower=0, upper=N_enzyme> edge_to_enzyme; // 0 if drain
array[N_edge] int<lower=0, upper=N_er> edge_to_er; // 0 if drain
array[N_edge] int<lower=0, upper=N_allostery> edge_to_tc; // 0 if non-allosteric
array[N_edge] int<lower=0, upper=N_drain> edge_to_drain; // 0 if enzyme
array[N_edge] int<lower=0, upper=N_reaction> edge_to_reaction;
Expand Down Expand Up @@ -158,7 +160,7 @@ generated quantities {
drain_small_conc_corrector, S,
left_nullspace_independent,
subunits, edge_type,
edge_to_enzyme, edge_to_drain,
edge_to_enzyme, edge_to_er, edge_to_drain,
ci_mic_ix, sub_km_ix_by_edge_long,
sub_km_ix_by_edge_bounds,
prod_km_ix_by_edge_long,
Expand All @@ -176,7 +178,7 @@ generated quantities {
phosphorylation_type,
phosphorylation_pme)[1];
conc_test[e, independent_bal_ix] = conc_independent_balanced_experiment;
conc_test[e, dependent_bal_ix] = conc_moiety_pool_test[e]- left_nullspace_independent * conc_independent_balanced_experiment;
conc_test[e, dependent_bal_ix] = conc_moiety_pool_test[e]- left_nullspace_independent * conc_independent_balanced_experiment;
conc_test[e, unbalanced_mic_ix] = conc_unbalanced_test[e];
vector[N_edge] edge_flux = get_edge_flux(conc_test[e],
conc_enzyme_experiment,
Expand All @@ -188,7 +190,7 @@ generated quantities {
temperature_test[e],
drain_small_conc_corrector, S,
subunits, edge_type,
edge_to_enzyme, edge_to_drain,
edge_to_enzyme, edge_to_er, edge_to_drain,
ci_mic_ix,
sub_km_ix_by_edge_long,
sub_km_ix_by_edge_bounds,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ readme = "README.rst"
requires-python = ">=3.10"
dependencies = [
"pip >= 20",
"arviz>=0.18.0",
"arviz@git+https://github.com/arviz-devs/arviz#egg=39eddd6",
"importlib_resources >= 3.2",
"numpy",
"scipy",
Expand Down

0 comments on commit 752a4f6

Please sign in to comment.