2.1.6. fluxpy.utils

Provide utilities for metabolic modeling analysis tasks

Submodules

Classes

Models

Load a list of sbml models with cobra as attributes of a class.

NameIdConverter

A class to switch indexes of a dataframe from ids to names and vice versa for metabolites and reactions of a model.

CompareModels

Using mergem <https://mergem.readthedocs.io/> to compare a pair of models and returns a dataframe with

Functions

nonzero_fluxes(→ None)

Returns nonzero fluxes from a pandas Series.

get_rxns_producing_consuming_met(met_id[, model, ...])

Returns a DataFrame with the reaction IDs of those consuming and producing a given metabolite in a model.

extract_model_namespace(model)

Returns a model's namespace considering only ModelSEED and BiGG

convert_gbk_to_faa(gbk_input_filename, faa_output_filename)

A function to convert a .gbk file returned from the RAST annotation to

get_nutrients_gradient(...)

Assuming a single medium comound changes at a time, it returns FVA findings over the chaning envs.

parse_qfca(qfca_output[, model, ...])

Parses QFCA (Quantitative Fatty Acid Composition Analysis) output data into a networkx graph representation.

samples_on_qfca(qfca_graph, samples)

ongoing

producing_or_consuming_a_met(model, reaction_id, ...)

Returns whether a metabolite is being produced or consumed when model is optimized.

get_reactions_producing_a_met(model, metabolite_id)

Get reactions that produce a specific metabolite.

trace_path_with_backtracking_iterative(model, ...[, ...])

Trace a path from the start reaction to the target reaction through reactants,

map_namespace_to_ModelSEEDDatabase(seed_compounds, ...)

This function makes use of the ModelSEEDpy and the ModelSEEDDatabase libraries to map a list of ModelSEED compounds

map_to_namespace(compounds[, from_namespace, to_namespace])

compounds -- a list

sync_with_medium(model, medium)

Adds metabolites and reactions required to allow a medium to be assigned to a cobra.Model

Package Contents

fluxpy.utils.nonzero_fluxes(fluxes: cobra.Solution | pandas.Series) None[source]

Returns nonzero fluxes from a pandas Series.

This function takes a pandas Series containing flux values and returns a new Series with only the nonzero fluxes.

Parameters:

sol (pd.Series, mandatory) – A pandas Series representing flux values.

Returns:

A pandas Series containing only the nonzero flux values from the input Series.

Return type:

pd.Series

fluxpy.utils.get_rxns_producing_consuming_met(met_id, model: cobra.Model = None, flux_vector: pandas.Series = None)[source]

Returns a DataFrame with the reaction IDs of those consuming and producing a given metabolite in a model.

This function optimizes the given metabolic model to identify reactions involving a specified metabolite. It categorizes reactions into those producing and those consuming the metabolite and returns this information in a DataFrame.

Parameters:
  • model (cobra.Model, mandatory) – The metabolic model to be analyzed.

  • met_id (str, optional) – The ID of the metabolite of interest.

  • flux_vector (pd.Series, optional) –

Returns:

A DataFrame with two columns:
  • consuming_{met_id}: Reactions consuming the specified metabolite in flux vector provided

  • producing_{met_id}: Reactions producing the specified metabolite in flux vector provided

Return type:

pd.DataFrame

Examples

>>> import cobra
>>> model = cobra.io.read_sbml_model('e_coli_core.xml')
>>> df = get_reactions_producing_met(model, 'met_id')
>>> print(df)
    consuming_met_id producing_met_id
0  reaction1          reaction2

Notes

  • The function assumes the model is properly optimized and that each reaction’s flux can be accessed via the solution object.

  • Reactions with a flux less than 0 are considered to be consuming reactants and producing products in the reverse direction.

  • Reactions with a flux greater than 0 are considered to be producing reactants and consuming products in the forward direction.

  • This applies for the specific medium provided with the model

fluxpy.utils.extract_model_namespace(model)[source]

Returns a model’s namespace considering only ModelSEED and BiGG

Parameters:

model (cobra.Model, mandatory) –

Returns:

namespace (str) – a Literal[“modelseed”, “bigg”]

fluxpy.utils.convert_gbk_to_faa(gbk_input_filename, faa_output_filename)[source]

A function to convert a .gbk file returned from the RAST annotation to a .faa that can be used with ModelSEEDpy

fluxpy.utils.get_nutrients_gradient(model, nutrients=None, upper_bound=None, step=None) fluxpy.utils.utils.NestedDataFrameType[source]

Assuming a single medium comound changes at a time, it returns FVA findings over the chaning envs. The model.medium will be used, i.e. first set the medium you want to investigate to your model. Returns a df with as many rows as the model.medium and columns as many as their quotient by the step. Each cell of this df includes the fva result for the medium with the corresponding alteration. For example, df.loc[0,0] corresponds to the medium where the first compound has the lowest value possible.

model – a cobra model nutrients – list of reaction ids for which a gradient will be calculated upper_bound – maximum a flux can get step – increase of upper_bound in each iteration of the gradient

fluxpy.utils.parse_qfca(qfca_output, model=None, remove_exchange_routes=True, exclude_biomass=True, format='csv')[source]

Parses QFCA (Quantitative Fatty Acid Composition Analysis) output data into a networkx graph representation.

Parameters:
  • qfca_output (str) – Path to the QFCA output file in CSV or Excel format.

  • model (object, optional) – Metabolic model object. Default is None.

  • remove_exchange_routes (bool, optional) – Whether to remove exchange reactions from the graph. Default is True.

  • exclude_biomass (bool, optional) – Whether to exclude biomass reaction from the graph. Default is True.

  • format (str, optional) – Format of the QFCA output file. Can be ‘csv’ or ‘xlsx’. Default is ‘csv’.

Returns:

A networkx Graph representing the interactions between metabolic reactions based on QFCA data.

Return type:

nx.Graph

fluxpy.utils.samples_on_qfca(qfca_graph, samples)[source]

ongoing

fluxpy.utils.producing_or_consuming_a_met(model, reaction_id, metabolite_id)[source]

Returns whether a metabolite is being produced or consumed when model is optimized.

Parameters:
Returns:

‘producing | consuming’ (str)

fluxpy.utils.get_reactions_producing_a_met(model, metabolite_id)[source]

Get reactions that produce a specific metabolite.

Notes

Exloits the producing_or_consuming_a_met() function

Parameters:
Returns:

list of reactions (cobra.Reaction)

fluxpy.utils.trace_path_with_backtracking_iterative(model, start_reaction_id, target_reaction_id, ignore_mets=None)[source]

Trace a path from the start reaction to the target reaction through reactants, using an iterative DFS approach, with backtracking when exchange reactions are encountered.

Parameters:
  • model (cobra.Model) – COBRApy model object.

  • start_reaction_id (str) – The ID of the starting reaction.

  • target_reaction_id (str) – The ID of the target reaction.

  • ignore_mets – A list of metabolite IDs to ignore during tracing (optional).

Returns:

A set of reactions needed to go from start to target, avoiding dead-end exchange reactions.

Return type:

keep_rxns

fluxpy.utils.map_namespace_to_ModelSEEDDatabase(seed_compounds: List[str], path_to_modelSEEDDatabase: str, annotations_to_keep=['BiGG', 'BiGG1'])[source]

This function makes use of the ModelSEEDpy and the ModelSEEDDatabase libraries to map a list of ModelSEED compounds to their annotations returning a pandas dataframe with those

seed_compouds – a list with seed compound ids path_to_modelSEEDDatabase – path to the modelSEEDDatabase. To get it: git clone https://github.com/ModelSEED/ModelSEEDDatabase.git

fluxpy.utils.map_to_namespace(compounds, from_namespace='seed', to_namespace='bigg')[source]

compounds – a list from_namesapce – to_namespace –

fluxpy.utils.sync_with_medium(model: cobra.Model, medium: Dict)[source]

Adds metabolites and reactions required to allow a medium to be assigned to a cobra.Model

Parameters:
  • model (cobra.Model, mandatory) – model to which the new medium will be assigned to and to which metabolites and reactions will be added to

  • medium (Dict, mandatory) – a dictionary with the medium to be used with the metabolites as keys and their boundaries as values

Returns:

A cobra.Model with added metabolites and reactions to enable medium to be used

class fluxpy.utils.Models(model_list: List[str], model_names: List[str] = None)[source]

Load a list of sbml models with cobra as attributes of a class.

class fluxpy.utils.NameIdConverter(model, to_convert: pandas.DataFrame | Dict | List | cobra.Solution, convert: str, to: str)[source]

A class to switch indexes of a dataframe from ids to names and vice versa for metabolites and reactions of a model.

met_map_df
react_map_df
convert
to
model
isIndex
run_convert()[source]
_met_ids_to_met_names()[source]
_met_names_to_met_ids()[source]
_react_ids_to_react_names()[source]
_react_names_to_react_ids()[source]
class fluxpy.utils.CompareModels(model_list: List[str], trans_to_db=None)[source]

Using mergem <https://mergem.readthedocs.io/> to compare a pair of models and returns a dataframe with reactions unique in model1 and model2 and those they share.

Key arguments:

model_list – list of paths to model files to compare

trans_to_db – mergem allows to map metabolite and reaction ids to a series of namespaces.

number_of_models
model_names
models
namespace = None
res
metabolites_df
reactions_df
unique_metabolites(model_name)[source]

Returns: unique_mets – a pd.Index with the metabolites that are only present in model_name and not in any other of those in model_list

unique_reactions(model_name)[source]

Key arguments: model_name – the name (column name) of the model for which unique reactions will be found

Returns: model_unique_reactions – a pd.Index with the reactions that are only present in the model_name and not in any other of those in model_list

compare_model_pair(base_model=None, model_to_compare=None)[source]

Compare pairwise models

Key arguments: base_model – name of the model as in dataframe, i.e. filename without the extension model_to_compare – name of the model as in dataframe, i.e. filename without the extension

Returns: r1 – reactions only present in base model r2 – reactions only present in model_to_compare m1 – metabolites only present in base_model m2 – metabolites only present in model_to_compare

shared_metabolites(models_subset=None)[source]

Key arguments: models_subset – list of models to get shared metabolites and reactions

Returns: shared_reactions – a pd.Index with rearctions present among all models of models_subset

shared_reactions(models_subset=None)[source]

Key arguments: models_subset – list of models to get shared metabolites and reactions

Returns: shared_reactions – a pd.Index with rearctions present among all models of models_subset