Annotation (Python)#

raven-toolbox objects in raven_toolbox.annotation.

Functions#

Function

Summary

add_sbo_terms

Assign SBO terms to metabolites and reactions in-place.

load_delta_g_csv

Record 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#

add_sbo_terms(model: cobra.Model, *, biomass_met_names: Iterable[str]=DEFAULT_BIOMASS_MET_NAMES, biomass_met_suffixes: Iterable[str]=(' backbone', ' chain'), biomass_rxn_name: str=DEFAULT_BIOMASS_RXN_NAME, ngam_rxn_name: str=DEFAULT_NGAM_RXN_NAME, pseudoreaction_name_substrings: Iterable[str]=('pseudoreaction', 'SLIME rxn'), transport_detector: Callable[[cobra.Model], set[str]] | None=None, only_last_reaction_for_pseudo: bool=False)

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" and " chain").

  • SBO:0000247 (simple chemical) otherwise.

Reaction SBO assignment

  • SBO:0000176 (metabolic reaction) by default.

  • Single-metabolite reactions (exchange, sink or demand):

    • extracellular: SBO:0000627 (exchange)

    • coefficient < 0: SBO:0000632 (sink)

    • otherwise: SBO:0000628 (demand)

  • Transport reactions: SBO:0000655 (default detector: the same metabolite name appears in at least 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 of pseudoreaction_name_substrings: SBO:0000395.

The SBO term is written to annotation['sbo'] only when that key is missing or empty, as in RAVEN's editMiriam(..., 'fill') mode.

Parameters

model : cobra.Model

Model to annotate. It is modified in place and returned.

biomass_met_names : Iterable[str]

Metabolite names that receive SBO:0000649. Default DEFAULT_BIOMASS_MET_NAMES (biomass, DNA, RNA, protein, carbohydrate, lipid, cofactor and ion). Names are matched exactly.

biomass_met_suffixes : Iterable[str]

Name suffixes that mark a metabolite as biomass. Default (" backbone", " chain").

biomass_rxn_name : str

Name of the biomass pseudoreaction, which receives SBO:0000629. The match is exact. Default "biomass pseudoreaction".

ngam_rxn_name : str

Name of the non-growth associated maintenance reaction, which receives SBO:0000630. The match is exact. Default "non-growth associated maintenance reaction".

pseudoreaction_name_substrings : Iterable[str]

Reactions that are not the biomass or NGAM reaction and whose name contains any of these substrings receive SBO:0000395. Default ("pseudoreaction", "SLIME rxn").

transport_detector

Optional callable that takes the model and returns the set of reaction ids classified as transport. When None, the default heuristic is used: a reaction is transport when one metabolite name occurs in at least 2 compartments. A custom detector replaces this convention (for example RAVEN's getTransportRxns via the MATLAB engine).

only_last_reaction_for_pseudo

If True, the biomass, NGAM and pseudoreaction terms are assigned to the last reaction only, as in yeast-GEM's addSBOterms.m, whose loop header for i = numel(...) lacks 1:. Default False.

load_delta_g_csv#

load_delta_g_csv(entities: Iterable, path: str | Path, *, id_column: str='Var1', value_column: str='Var2', note_key: str='deltaG', verbose: bool=False)

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

Every matched value is recorded as the string of the value read from the CSV, including yeast-GEM's own "no measurement" placeholder (10000000.0, on 777 of its 4102 reaction rows). This function does not interpret CSV values, matching RAVEN's own loadDeltaGCSV; a caller that treats a particular value as absent filters it after loading.

Parameters

entities

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

path

Path to the CSV.

id_column, value_column

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

note_key

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

verbose

Print a summary of unmatched entity ids.

Returns

int

The number of entities that were recorded (that is, matched the CSV and carried a value).

save_delta_g_csv#

save_delta_g_csv(entities: Iterable, path: str | Path, *, id_column: str='Var1', value_column: str='Var2', note_key: str='deltaG')

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

Entities without note_key set, or with a string value that cannot be converted to a float, get NaN written, which keeps one row per entity in entity order (mirrors MATLAB's array2table([ids, values]) behaviour). A value of another type that float rejects (for example a list) raises TypeError.

Parameters

entities : Iterable

Cobra entities (model.metabolites or model.reactions). One CSV row is written per entity, in iteration order.

path : str or Path

Path of the CSV file to write. An existing file is overwritten. The file has a header row and no index column.

id_column : str

Header of the identifier column. Default "Var1".

value_column : str

Header of the value column. Default "Var2".

note_key : str

Key read from entity.notes. Default "deltaG".

Returns

int

The number of rows written (the number of entities).