Skip to content

Commit

Permalink
fix: introduce a edge_to_er mapping for kcats
Browse files Browse the repository at this point in the history
  • Loading branch information
carrascomj committed Jun 20, 2024
1 parent bbab870 commit 191b85b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
7 changes: 7 additions & 0 deletions maud/getting_stan_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,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)
ers_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 allosteries is not None:
Expand Down Expand Up @@ -177,6 +178,10 @@ def get_network_properties_input(
enzyme_codes[er.enzyme_id] if isinstance(er, EnzymeReaction) else 0
for er in edges
]
edge_ers_code = [
ers_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 @@ -338,6 +343,7 @@ def get_network_properties_input(
"N_edge": len(S.columns),
"N_unbalanced": len(unbalanced_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 @@ -355,6 +361,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_ers_code,
"edge_to_tc": edge_tc_code,
"edge_to_drain": edge_drain_code,
"edge_to_reaction": edge_reaction_code,
Expand Down
23 changes: 14 additions & 9 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 @@ -333,6 +333,7 @@ functions {
array[] int phosphorylation_pme) {
int N_edge = cols(S);
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 @@ -382,7 +383,7 @@ functions {
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 Down Expand Up @@ -410,7 +411,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 @@ -443,6 +444,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 @@ -467,6 +469,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 @@ -511,12 +514,13 @@ functions {

complex_vector get_complex_vmax_by_edge(complex_vector enzyme, vector kcat,
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 @@ -552,6 +556,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 @@ -574,7 +579,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 @@ -810,7 +815,7 @@ vector maud_ae_system(vector conc,
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 Down Expand Up @@ -843,7 +848,7 @@ vector maud_ae_system(vector conc,
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 @@ -11,6 +11,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 @@ -25,6 +26,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 @@ -201,7 +203,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,
prod_km_ix_by_edge_long,
Expand Down Expand Up @@ -231,7 +233,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 @@ -388,6 +390,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 @@ -431,6 +434,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
6 changes: 4 additions & 2 deletions maud/stan/out_of_sample_model.stan
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data {
int<lower=1> N_sub_km;
int<lower=1> N_prod_km;
int<lower=1> N_reaction;
int<lower=1> N_er; // enzyme reactions
int<lower=1> N_enzyme;
int<lower=0> N_drain;
int<lower=1> N_edge;
Expand All @@ -24,6 +25,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 @@ -152,7 +154,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,
prod_km_ix_by_edge_long,
Expand Down Expand Up @@ -181,7 +183,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

0 comments on commit 191b85b

Please sign in to comment.