Biomass (Python)#
raven-toolbox objects in raven_toolbox.biomass.
Functions#
Function |
Summary |
|---|---|
One component of the biomass equation (protein, carbohydrate, …). |
|
Container for the per-organism biomass layout. |
|
Fit stoichiometric parameters against experimental flux data. |
|
Outcome of a |
|
Where one fitted parameter's coefficient goes in the model. |
|
Multiply the substrate coefficients of one component pseudoreaction |
|
Rescale a component to a new mass fraction, optionally balancing |
|
Set GAM (and optionally NGAM) on a model in place. |
|
Mass-fraction (g/gDW) per biomass component plus the total. |
Reference#
BiomassComponent#
One component of the biomass equation (protein, carbohydrate, …).
Attributes
nameCanonical short name — also the
model.metabolitesname of the metabolite that the pseudoreaction produces. Used byrescale_pseudoreactionto identify the product side.pseudoreaction_namemodel.reactions[*].nameof the pseudoreaction. cobrapy reactions are looked up byname(notid) because that is how the yeast-GEM convention names them.mass_strategyHow to convert the pseudoreaction's substrates into a mass fraction. See
MassStrategyfor the choices and their offsets.
BiomassConfig#
Container for the per-organism biomass layout.
Attributes
biomass_rxnmodel.reactions[*].idof the top-level biomass pseudoreaction (the one whose flux is the growth rate).proton_metmodel.metabolites[*].idof the cytosolic H+ metabolite — used byrescale_pseudoreactionto keep each pseudoreaction charge-balanced after rescaling.componentsOrdered tuple of
BiomassComponentdescribing every non-top-level pseudoreaction that contributes to mass.
fit_parameters#
fit_parameters(model: cobra.Model, x_rxns: Sequence[str], x_values: np.ndarray, rxns_to_fit: Sequence[str], values_to_fit: np.ndarray, parameter_positions: Sequence[ParameterPosition], *, fit_to_ratio: bool=True, initial_guess: Sequence[float] | None=None)
Fit stoichiometric parameters against experimental flux data.
Parameters
model:Model to fit against. Never modified — the fitted model is returned separately.
x_rxns:Ids of the reactions that get fixed (both bounds) to a measured value at each data point.
x_values:Measured values for
x_rxns, shaped data points × len(x_rxns), columns inx_rxnsorder.rxns_to_fit:Ids of the reactions whose predicted flux is compared against measurements.
values_to_fit:Measured values for
rxns_to_fit, shaped data points × len(rxns_to_fit), columns inrxns_to_fitorder.parameter_positions:One
ParameterPositionper fitted parameter.fit_to_ratio:Fit the ratio of predicted to measured value instead of the absolute difference, so a large flux does not dominate the residual sum of squares just by being large (default True).
initial_guess:Starting value for each parameter (default all ones).
Returns
FitParametersResult
:
FitParametersResult#
Outcome of a fit_parameters call.
Parameters
parameters:Fitted parameter magnitudes, same order as
parameter_positions. Always non-negative — sign is carried entirely byParameterPosition.negative.fitness_score:The residual sum of squares at the fitted parameters.
success:Whether the optimizer reports convergence (
scipy.optimize.OptimizeResult.success). RAVEN's ownexitFlag(fminsearch's 1/0/-1 codes) has no equivalent worth carrying over: different optimizer, different convergence bookkeeping.model:Copy of the input model with the fitted parameters applied.
resulting_fluxes:The fitted model's own predicted flux at
rxns_to_fit, one row per data point, columns inrxns_to_fitorder — what a caller would plot againstvalues_to_fitto see the fit.
ParameterPosition#
Where one fitted parameter's coefficient goes in the model.
Attributes
entries:(reaction_id, metabolite_id)pairs this parameter's magnitude is written to.negative:Per entry, whether that coefficient is
-parameterrather than+parameter(to tell production from consumption at the same magnitude) — same length and order asentries.
rescale_pseudoreaction#
rescale_pseudoreaction(model: cobra.Model, config: BiomassConfig, component_name: str, factor: float)
Multiply the substrate coefficients of one component pseudoreaction
by factor and rebalance H+ to preserve charge neutrality.
Ports rescalePseudoReaction.m. "Substrate" here means any
metabolite whose name is not the component's product name; the
component's own metabolite (e.g. protein for the protein
pseudoreaction) is left untouched. After the rescaling the
coefficient of config.proton_met is recomputed so the
reaction's total ionic charge sums to zero.
scale_biomass#
scale_biomass(model: cobra.Model, config: BiomassConfig, component_name: str, new_value: float, *, balance_out: str | None=None, target_total: float=1.0)
Rescale a component to a new mass fraction, optionally balancing
out a second component so the biomass total becomes target_total
g/gDW.
Ports scaleBioMass.m. The rescaling factor is derived from
sum_biomass on the current model state, so call this with
an in-place model mutation, not on a stale snapshot.
With balance_out, that component is rescaled so the components sum
to exactly target_total g/gDW (default 1), whatever the total was
before. It must be large enough to absorb the difference: a
ValueError is raised, before the model is changed, when its
fraction is 0 or would become 0 or negative. target_total has no
effect without balance_out.
set_gam#
set_gam(model: cobra.Model, value: float, *, biomass_rxn: str, cofactor_met_names: Iterable[str], ngam_rxn: str | None=None, ngam_value: float | None=None)
Set GAM (and optionally NGAM) on a model in place.
Scales every metabolite participating in the biomass pseudoreaction
whose name is in cofactor_met_names (e.g. ATP, ADP, H2O,
H+, phosphate) to ±value, preserving the sign of its current
coefficient.
If both ngam_rxn and ngam_value are given, the NGAM
reaction's bounds are fixed at (ngam_value, ngam_value).
Parameters
modelcobra model to mutate.
valueNew GAM value (mmol ATP / gDW per growth unit).
biomass_rxnReaction id of the biomass pseudoreaction whose stoichiometry carries the GAM coefficients.
cofactor_met_namesIterable of metabolite names (not ids) — every metabolite in the biomass pseudoreaction whose name is in this set will be rescaled. yeast-GEM uses
{"ATP", "ADP", "H2O", "H+", "phosphate"}.ngam_rxn, ngam_valueOptional NGAM update. If both are provided, the reaction's bounds are set to
(ngam_value, ngam_value)(equality constraint).
Returns
cobra.ModelThe (mutated) model, for chaining.
sum_biomass#
sum_biomass(model: cobra.Model, config: BiomassConfig)
Mass-fraction (g/gDW) per biomass component plus the total.
Mirrors yeast-GEM's sumBioMass.m. Returns a dict keyed by each
BiomassComponent name plus "total". Components whose
pseudoreaction is missing from the model contribute 0 (logged as a
warning).