Utilities (Python)¶
raven-toolbox objects in raven_toolbox.utils, collected from the source of the tracked branch.
Functions¶
| Function | Summary |
|---|---|
check_model |
Run curation checks on a model and return the issues found. |
ElementalBalance |
Balance result for one reaction. |
find_non_dnf_grrules |
Find reactions whose GPR is not in disjunctive normal form ("OR of AND-complexes"). |
get_elemental_balance |
Check whether reactions are elementally balanced. |
GPRIssue |
A reaction whose GPR is flagged by the linter. |
is_dnf |
Return whether a GPR is in disjunctive normal form (OR of AND-complexes). |
ModelIssue |
One curation issue found in a model. |
parse_name_comp |
Split a name[comp] token into (name, compartment). |
resolve_aggregators |
Validate the scoring-mode names and return (isozyme_fn, complex_fn). |
sort_identifiers |
Sort reactions, metabolites and genes alphabetically by ID, in place. |
subsystem_to_str |
Coerce a reaction subsystem to cobra's canonical str form. |
Reference¶
check_model¶
Run curation checks on a model and return the issues found.
Does not
raise; returns a (possibly empty) list of :class:ModelIssue.
ElementalBalance¶
Balance result for one reaction.
Attributes:
| Name | Type | Description |
|---|---|---|
reaction_id |
str
|
ID of the reaction. |
status |
str
|
|
imbalance |
dict[str, float]
|
Element → net coefficient (products − reactants), only for
|
find_non_dnf_grrules¶
Find reactions whose GPR is not in disjunctive normal form ("OR of AND-complexes").
Uses cobra's GPR AST. Reactions with no GPR are skipped.
Returns:
| Type | Description |
|---|---|
list of GPRIssue
|
One entry per flagged reaction, in model reaction order. Empty if all GPRs are simple OR-of-AND-complexes. |
get_elemental_balance¶
Check whether reactions are elementally balanced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reactions
|
Reaction IDs/objects to check; default all reactions. (Boundary
reactions exchange mass with the environment and will read as
|
None
|
Returns:
| Type | Description |
|---|---|
list of ElementalBalance
|
One entry per checked reaction, in model order. |
GPRIssue¶
A reaction whose GPR is flagged by the linter.
Attributes:
| Name | Type | Description |
|---|---|---|
reaction_id |
str
|
ID of the reaction. |
gpr |
str
|
The (already cobra-normalised) grRule string. |
reason |
str
|
Human-readable explanation of why it was flagged. |
is_dnf¶
Return whether a GPR is in disjunctive normal form (OR of AND-complexes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gpr
|
GPR | str | None
|
A cobra :class: |
required |
Examples:
ModelIssue¶
One curation issue found in a model.
Attributes:
| Name | Type | Description |
|---|---|---|
category |
str
|
Machine-readable kind, e.g. |
object_id |
str | None
|
ID of the offending object, or |
message |
str
|
Human-readable description. |
parse_name_comp¶
Split a name[comp] token into (name, compartment).
This is the one genuinely cobra-absent sliver of RAVEN getIndexes'
metcomps mode and addRxns eqnType 3: resolving a metabolite written
as its name plus a compartment in square brackets, e.g. "ATP[c]".
Returns (name, None) when there is no trailing [...].
Examples:
resolve_aggregators¶
Validate the scoring-mode names and return (isozyme_fn, complex_fn).
Raises ValueError naming the offending argument if either mode is not one
of :data:AGGREGATORS.
sort_identifiers¶
Sort reactions, metabolites and genes alphabetically by ID, in place.
Returns the same (mutated) model for convenience. Compartments are a plain dict and are emitted sorted by writers as needed.
subsystem_to_str¶
Coerce a reaction subsystem to cobra's canonical str form.
cobra defines Reaction.subsystem as a plain string, but RAVEN/MATLAB and
"messy" YAML sometimes deliver a list/tuple of subsystem names (a reaction can
belong to several). This collapses any such value to a single ;-joined
string of its parts — losing no data, unlike taking only the first — and returns
"" for an empty/None subsystem. Used wherever a subsystem is rendered or
compared so the handling is identical across modules.
Examples: