Biomass (Python)#
raven-toolbox objects in raven_toolbox.biomass.
Functions#
Function |
Summary |
|---|---|
One component of the biomass equation (protein, carbohydrate, and so on). |
|
Container for the per-organism biomass layout. |
|
Fit stoichiometric parameters against experimental flux data. |
|
Result of a |
|
The model coefficients that one fitted parameter sets. |
|
Multiply the substrate coefficients of one component pseudoreaction |
|
Rescale a component to a new mass fraction and optionally rescale a |
|
Set GAM (and optionally NGAM) on a model in place. |
|
Return the mass fraction (g/gDW) of each biomass component and the total. |
Reference#
BiomassComponent#
One component of the biomass equation (protein, carbohydrate, and so on).
Attributes
nameShort name of the component. It is also the
model.metabolitesname of the metabolite that the pseudoreaction produces, whichrescale_pseudoreactionuses to identify the product.pseudoreaction_namemodel.reactions[*].nameof the pseudoreaction. The reaction is looked up byname, not byid, following the yeast-GEM naming convention.mass_strategyHow to convert the pseudoreaction's substrates into a mass fraction.
MassStrategylists 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.rescale_pseudoreactionsets its coefficient so that each pseudoreaction is 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. It is not modified; the fitted model is returned in the result.
x_rxns:Ids of the reactions whose lower and upper bounds are fixed to a measured value at each data point.
x_values:Measured values for
x_rxns, shaped as the number of data points bylen(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:When True (default), the residual is the predicted flux divided by the measured value minus 1. When False, it is the predicted minus the measured flux.
initial_guess:Starting value for each parameter (default 1 for every parameter).
Returns
FitParametersResult
:
FitParametersResult#
Result of a fit_parameters call.
Parameters
parameters:Fitted parameter magnitudes, same order as
parameter_positions. Always non-negative; the sign of each coefficient comes fromParameterPosition.negative.fitness_score:The residual sum of squares at the fitted parameters.
success:Whether the optimiser reports convergence (
scipy.optimize.OptimizeResult.success). RAVEN'sexitFlag(thefminsearchcodes 1, 0 and -1) has no counterpart.model:Copy of the input model with the fitted parameters applied.
resulting_fluxes:Flux of the fitted model at
rxns_to_fit, one row per data point and one column per reaction inrxns_to_fitorder.
ParameterPosition#
The model coefficients that one fitted parameter sets.
Attributes
entries:(reaction_id, metabolite_id)pairs whose coefficient is set from this parameter.negative:Per entry, whether the coefficient is
-parameter(consumption) or+parameter(production). 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. A substrate is any
metabolite whose name differs from the component's product name; the
component's own metabolite (for example protein for the protein
pseudoreaction) keeps its coefficient. After the rescaling the
coefficient of config.proton_met is recomputed so that the
total ionic charge of the reaction is zero.
Parameters
model: cobra.ModelModel that holds the pseudoreaction. It is modified in place.
config: BiomassConfigBiomass components and the id of the proton metabolite (
config.proton_met).component_name: strName of the component in
configwhose pseudoreaction is rescaled. A name that is not inconfigraisesKeyError.factor: floatMultiplier for the coefficients of the substrates. A factor of 1 leaves the substrate coefficients unchanged, and the proton coefficient is still recomputed.
Raises
ValueErrorIf a metabolite of the reaction other than the proton has no charge (
charge is None), because the charge balance is then unknown. Nothing is changed in that case.KeyErrorIf the pseudoreaction or the proton metabolite is not in the model.
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 and optionally rescale a
second component so that the biomass total becomes target_total g/gDW.
Ports scaleBioMass.m. The rescaling factor is derived from
sum_biomass on the current state of model, which is modified in place.
A ValueError is raised, before the model is changed, when the current fraction of the
component or of balance_out is 0, or when the fraction of balance_out would become
0 or negative. Both rescalings are first applied to a scratch copy of the
pseudoreactions, so an error leaves the model unchanged. The H+ rebalance adds to the
fractions, so they are not linear in the scaling factor.
Parameters
model: cobra.ModelModel that holds the biomass pseudoreactions. It is modified in place.
config: BiomassConfigBiomass components, their pseudoreaction names and the proton metabolite id.
component_name: strName of the component to rescale. A name that is not in
configraisesKeyError.new_value: floatTarget mass fraction of the component in g/gDW.
balance_out: str or NoneName of a second component that is rescaled so the components sum to
target_totalg/gDW, whatever the total was before. The sum equalstarget_totalwhen the rescaled pseudoreaction needs no change of its H+ coefficient; otherwise the H+ rebalance adds to its fraction and the total exceedstarget_totalby that amount. DefaultNone, which rescales onlycomponent_name.target_total: floatTotal mass fraction in g/gDW that
balance_outaims for. Default 1.0. It has no effect whenbalance_outisNone.
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 (for example ATP, ADP, H2O,
H+, phosphate) to ±value, keeping 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). An empty
ngam_rxn counts as not given, and ngam_value without an ngam_rxn is an
error. A given ngam_rxn must be in the model, also when no ngam_value is given.
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 is 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 modified model (the input object).
Raises
KeyErrorIf
biomass_rxn, or a givenngam_rxn, is not in the model. Both reactions are looked up before anything is changed.ValueErrorIf
ngam_valueis given without anngam_rxn.
sum_biomass#
sum_biomass(model: cobra.Model, config: BiomassConfig)
Return the mass fraction (g/gDW) of each biomass component and the total.
Mirrors yeast-GEM's sumBioMass.m. The dict has one key per
BiomassComponent name and the key "total". Components whose
pseudoreaction is missing from the model contribute 0.
Parameters
model: cobra.ModelModel that holds the biomass pseudoreactions. It is not modified.
config: BiomassConfigBiomass components, their pseudoreaction names and their mass strategies.
Raises
ValueErrorIf a substrate of a component whose mass strategy is not
"grams"has an empty formula or a formula with an element missing from the atomic-weight table.