Top-level (Python)#
geckopy objects in geckopy.
Functions#
Function |
Summary |
|---|---|
List, or with --apply carry out, the steps that bring a GECKO 3 |
|
Shadow prices of the named constraints, on every solver, as one array. |
|
Convert |
|
Run structural edits of |
|
Make models created inside the block on a solver that builds large models quickly. |
|
True if |
|
|
|
Make the scipy problem of |
|
Move |
|
Turn the protein usage and pool reactions of a GECKO 3 ecModel forward. |
|
Bring a GECKO 3 project to the GECKO 4 layout ( |
Reference#
cmd_brenda_refresh#
cmd_brenda_refresh(args: argparse.Namespace)
cmd_init#
cmd_init(args: argparse.Namespace)
cmd_kegg_download#
cmd_kegg_download(args: argparse.Namespace)
cmd_uniprot_download#
cmd_uniprot_download(args: argparse.Namespace)
cmd_upgrade#
cmd_upgrade(args: argparse.Namespace)
List, or with --apply carry out, the steps that bring a GECKO 3
project to the GECKO 4 layout (see geckopy.upgrade.upgrade_project).
constraint_shadow_prices#
constraint_shadow_prices(model, constraint_ids: Iterable[str])
Shadow prices of the named constraints, on every solver, as one array.
The shadow price of a constraint is the change of the optimum, in the direction of the
model objective, per unit rise of its right-hand side: for a metabolite balance
S v = 0 it is the optimum gained per unit of the metabolite supplied. It is the value
of cobra.Metabolite.shadow_price for the glpk, gurobi and cplex interfaces, and for the
scipy interface (which raises) it is computed from the HiGHS row marginals of the last
solve.
The model must have been solved. On the scipy interface the stored result is used only if it is an optimum of the problem as it is now; otherwise the model is solved once more. If that solve is not optimal, the function raises.
Parameters
modelAn EcModel or
cobra.Modelthat has been optimized.constraint_idsIDs of constraints of the model, for example
prot_<uniprot>.
Returns
numpy.ndarrayOne shadow price per ID, in the order given.
Raises
RuntimeErrorIf the scipy problem has no optimal solution to read the marginals from.
KeyErrorIf an ID is not a constraint of the model.
convert_custom_kcats#
convert_custom_kcats(model: 'EcModel', *, custom_kcats: Optional[str | Path]=None, out_file: Optional[str | Path]=None, adapter: Optional['ModelAdapter']=None)
Convert data/customKcats.tsv into data/kcats/custom.tsv.
The kcats are those geckopy.ec_model.pipeline.apply_custom_kcats
gives the ecModel, including which of two entries for the same reaction
wins: one row per reaction, keyed by conventional reaction and enzyme set
(see geckopy.gather_kcats.ec_rxn_keys), with the entry's notes in
the note column. The stoicho column is left out: complex
stoichiometry comes from apply_complex_data. Unlike
apply_custom_kcats, custom.tsv also applies to light ecModels.
Parameters
modelThe full ecModel the custom kcats are for.
custom_kcats, out_fileThe file to convert and the file to write (default:
data/customKcats.tsvanddata/kcats/custom.tsvin the project). An existingout_fileis not overwritten.adapterModel adapter (default:
model.adapter).
Returns
(path, report)The file written, and a report with
rows(rows written).
edit_on_fast_solver#
edit_on_fast_solver(model)
Run structural edits of model on glpk when it is on the scipy solver.
Removing reactions and metabolites, or rewriting the coefficients of thousands of
reactions, is quick on glpk and slow on the scipy interface, where optlang rewrites the
constraint expressions (and the rows) for each edit. Inside the block a scipy model is on
glpk; on exit it is converted back with switch_to_scipy. The block changes nothing
for a model on another solver, for a model inside a with model: context (its
rollbacks hold the solver objects) and when glpk is unavailable. The optlang solver of
the model is a different object inside the block and after it.
fast_solver_while_building#
fast_solver_while_building()
Make models created inside the block on a solver that builds large models quickly.
When cobra's default solver is scipy the block runs with glpk as the default, which
builds a genome-scale model in seconds; the default is restored on exit. Models created
inside are on glpk; convert them with switch_to_scipy. With any other default
solver, or when glpk is unavailable, the block changes nothing.
is_scipy_interface#
is_scipy_interface(interface)
True if interface (a solver name, an optlang interface module or a model's
problem attribute) is optlang's scipy interface.
main#
main(argv: list[str] | None=None)
optimize_model#
optimize_model(model, **kwargs)
model.optimize() that returns the solution of an infeasible LP on every solver.
Gurobi holds no primal values for an LP that it presolved as infeasible and optlang's
scipy interface returns None for them, and cobra reads them while it builds the
solution, so model.optimize() raises GurobiError or TypeError there. When
the solver status is not optimal this function returns a Solution with that status,
a NaN objective and NaN fluxes instead; with an optimal status every error is raised.
repair_scipy_problem#
repair_scipy_problem(model)
Make the scipy problem of model correct and fast to edit.
Does nothing and returns False when the solver of model is not optlang's scipy
interface. Otherwise it moves the problem to a class that renumbers the variable columns
correctly after a removal and stores the coefficients sparsely (see the module docstring),
applies the pending changes, restores the column map and the coefficient matrix if a
removal had already left the map stale, and returns True. Once the problem is switched, a
call is a type check.
Parameters
modelA
cobra.Model(or EcModel). Readingmodel.solverof an EcModel calls this function already; call it yourself for a plaincobra.Modelbefore you remove variables (remove_reactions,Reaction.delete,remove_cons_vars).
switch_to_scipy#
switch_to_scipy(model)
Move model to the scipy solver, fast, with the sparse problem of this module.
model.solver = "scipy" clones the problem through optlang, which grows a dense matrix
row by row. This builds the problem the way cobra.Model does when it is created, on
the sparse class, so a genome-scale model switches in seconds. The objective and its
direction are kept. A model whose solver holds anything besides one forward and one
reverse variable per reaction and one constraint per metabolite (an extra constraint or
variable of your own) is switched with optlang's clone instead and then repaired.
upgrade_ec_model#
upgrade_ec_model(model: 'EcModel')
Turn the protein usage and pool reactions of a GECKO 3 ecModel forward.
GECKO 3 defined usage_prot_<id> (prot_<id> -> prot_pool) and
prot_pool_exchange (prot_pool ->) in the reverse direction, used
with negative flux; GECKO 4 defines them forward. Each reaction that is
still reverse gets the opposite stoichiometry, bounds and objective
coefficient; calling it again changes nothing. In place.
geckopy.load_ec_model already does this for the files it
reads; this is for models from other sources, such as SBML.
Returns
list of strThe reactions that were turned.
upgrade_project#
upgrade_project(project: str | Path, *, dry_run: bool=True, ec_model: Optional['EcModel']=None)
Bring a GECKO 3 project to the GECKO 4 layout (geckopy upgrade).
Lists, and with dry_run=False carries out:
custom kcats:
data/customKcats.tsvbecomesdata/kcats/custom.tsv(convert_custom_kcats);stored predictions:
data/DLKcat.tsvand stored OpenKineticsPredictor results become kcat source files (kcats_from_dlkcat,kcats_from_okpwithuse_stored), without running anything;saved ecModels:
models/*.ymlecModels made with GECKO 3 get their protein reactions turned forward (upgrade_ec_model);project_format = 4inmodel_adapter.toml;scripts: lines of the project's
.pyfiles that call renamed or replaced functions are listed, not changed.
Steps 1 and 2 need the full ecModel the custom kcats and predictions are
for (ec_model); without it they are listed and skipped. A project
with an adapter class instead of model_adapter.toml is converted by
GECKO's upgradeGECKOproject. A file that is replaced or converted is
first moved to legacy/<yyyy-mm-dd>/, keeping its place in the folder
tree. Steps already done are left out, so it can run again.
Returns
pandas.DataFrameOne row per step:
step,status(to do, done, skipped, failed, by hand) andnote.