Skip to content

Annotation (Python)

raven-toolbox objects in raven_toolbox.annotation, collected from the source of the tracked branch.

Functions

Function Summary
add_sbo_terms Assign SBO terms to metabolites and reactions in-place.
load_delta_g_csv Stamp note_key on each entity from a CSV of id → value.
save_delta_g_csv Dump entity.notes[note_key] for each entity to a CSV.

Reference

add_sbo_terms

Assign SBO terms to metabolites and reactions in-place.

Metabolite SBO assignment - SBO:0000649 (Biomass) for metabolites whose name is in biomass_met_names or ends with any of biomass_met_suffixes (default: " backbone" / " chain"). - SBO:0000247 (Simple chemical) otherwise.

Reaction SBO assignment - SBO:0000176 (Metabolic reaction) default. - Single-reactant reactions (exchange / sink / demand): * extracellular → SBO:0000627 (exchange) * coefficient < 0 → SBO:0000632 (sink) * else → SBO:0000628 (demand) - Transport reactions → SBO:0000655 (default detector: same metabolite name appearing in ≥ 2 compartments). - The reaction whose name matches biomass_rxn_name → SBO:0000629. - The reaction whose name matches ngam_rxn_name → SBO:0000630. - Other reactions whose name contains any pseudoreaction_name_substrings → SBO:0000395.

"fill" semantic: SBO is written to annotation['sbo'] only when that key is missing or empty — mirrors RAVEN's editMiriam(..., 'fill') mode.

Parameters:

Name Type Description Default
transport_detector Callable[[Model], set[str]] | None

Optional callable that takes the model and returns the set of reaction ids classified as transport. When None, the default same-met-name-in-two-compartments heuristic is used. Pass a custom detector to use a different convention (e.g. RAVEN's getTransportRxns via the MATLAB engine).

None
only_last_reaction_for_pseudo bool

Bug-compatibility flag, off by default. The legacy yeast-GEM MATLAB addSBOterms.m contains a typo (for i = numel(...) rather than for i = 1:numel(...)) that causes the pseudo- reaction SBO assignments to run only on the very last reaction in the model. When True, this flag replicates that bug so callers can migrate without altering the committed model. Leave False for new uses.

False

load_delta_g_csv

Stamp note_key on each entity from a CSV of id → value.

Parameters:

Name Type Description Default
entities Iterable

Cobra entities (model.metabolites or model.reactions).

required
path str | Path

Path to the CSV.

required
id_column str

Column labels in the CSV. Defaults match the yeast-GEM convention (Var1 / Var2 from MATLAB's array2table).

'Var1'
value_column str

Column labels in the CSV. Defaults match the yeast-GEM convention (Var1 / Var2 from MATLAB's array2table).

'Var1'
note_key str

Key under which the value is stored on entity.notes. Default "deltaG".

'deltaG'
verbose bool

Print a summary of unmatched entity ids.

False

Returns:

Type Description
The number of entities that were stamped (i.e. matched the CSV).

save_delta_g_csv

Dump entity.notes[note_key] for each entity to a CSV.

Entities without note_key set get NaN written, preserving one-row-per-entity ordering (mirrors MATLAB's array2table([ids, values]) behaviour).

Returns:

Type Description
The number of rows written (= number of entities).