bayflux

Subpackages

Package Contents

Classes

ReactionNetwork

ReactionNetwork contains a genome scale model with atom transitions.

EnhancedReaction

like a cobra.Reaction, but with atom transitions.

AtomTransition

Class for storing atom transitions associated with a reaction.

EMU

A class for representing EMUs that cross-references a metabolite object.

EMUTransition

A class for representing an EMU reaction.

FluxVector

Class to store a flux vector associated with a ReactionNetwork.

MassDistribution

Functions

executeCompiledEMUTransitionList(operations, ...)

Execute the matrix addition operations specified in the compiled EMU decomposition

pruneTransitionList(transitionList, metabolitesToKeep)

mergeDuplicates(transitionList)

findProducingReactions(metabolite[, ignoreNoTransitions])

Find all reactions which can produce a given metabolite in the forward

findProducingEMUTransitions(inputEMU)

Find all EMUTransition objects that directly produce the inputEMU.

emuDecomposition(inputEMUs[, transitionLimit])

Perform a full EMU decomposition of the input EMUs.

EMUsizes(EMUTransitionList)

Identify which size EMUs are found in a list of EMUtransitions.

splitBySize(EMUTransitionList)

Split apart an EMU transition list by size.

constructMatrixCoords(EMUTransitionList)

Computes human readable and hash versions of the list of internal EMUs

constructZeroMatrices(matrixCoords)

Constructs the A and B zero matrices from the results of constructMatrixCoords.

compileEMUTransitionList(EMUTransitionList, ...)

Compiles an EMU transition list into a set of matrix addition operations indexed by position.

extractSubstrateEMU(inputEMU, substrateLabelingDict)

Compute the MDV for a given EMU from a set of labeled substrates.

executeCompiledMatrixY(substrateMDVs, operationsY, ...)

emuCompile(emusToSimulate, model, substrateLabelingDict)

Pre-deconstructs an EMU network, for later simulation of specific

compileMatrixY(compiledData, matrixCoords, size, ...)

Returns: 1) a set of input MDVs in tuple of tuples form

simulateLabeling(compiledData, fluxes, ...)

Simulates the Mass Distribution Vector (MDV) for a set of inputEMUs given

readMassDistribution(model, inputFileName[, format])

Attributes

__version__

bayflux.__version__ = '1.0'
class bayflux.ReactionNetwork(cobrapyModel)

Bases: cobra.Model

ReactionNetwork contains a genome scale model with atom transitions.

This inherits from a cobra.Model but reactions are replaced with EnhancedReaction to add in atom transitions.

Args:

cobrapyModel (cobra.Model): A cobra.Model to inherit from.

copy()

Provides a partial ‘deepcopy’ of the Model. All of the Metabolite, Gene, and Reaction objects are created anew but in a faster fashion than deepcopy

This code was taken verbatim from cobrapy, but modified to add EnhancedReactions.

writeFluxConstraints(outputFileName, format='csv', exchangesOnly=True)
readFluxConstraints(inputFileName, format='csv')
writeAtomTransitions(outputFileName, format='bayflux')
readAtomTransitions(inputFileName, format='bayflux')
class bayflux.EnhancedReaction(cobrapyReaction, transitions=None)

Bases: cobra.Reaction

like a cobra.Reaction, but with atom transitions.

See the attributes for cobra.Reaction in cobrapy

Args:
cobrapyReaction (cobra.Reaction): a cobra.Reaction object to

inherit from.

transitions (list, optional): a list of AtomTransition objects.

Attributes:

transitions (list, optional): a list of AtomTransition objects.

_repr_html_()
class bayflux.AtomTransition(reactants, products)

Class for storing atom transitions associated with a reaction.

Overview reactant and product transitions are stored as a tuple of two value tuples where the first value of each two value tuple is a cobra.Metabolite and the second value is a tuple of integers where the position in the tuple represents an atom (in left to right order) from the canonical SMILES representation of the metabolite, and the values in the tuples are integers, whereby the same atom in a product and reactant have the same integer label. Specific values of the integers are arbitrary.

Special cases:

Reactions with multiple atom transitions MetaCyc reaction SUCCCOASYN-RXN is an example with multiple atom transitions. We accommodate this by associating multiple atom transition objects with the same EnhancedReaction.

Equivalent atoms Biochemically indistinguishable atoms should be represented with the same integer value in the atom transition tuple. This will be used to generate a set of equivalent EMUs.

Args:

reactants (tuple): A tuple of two valued tuples as described above. products (tuple): A tuple of two valued tuples as described above.

Attributes:

reactants (tuple): A tuple of two valued tuples as described above. products (tuple): A tuple of two valued tuples as described above.

reverse()
__repr__()

Return repr(self).

bayflux.executeCompiledEMUTransitionList(operations, zeroMatrices, fluxes)
Execute the matrix addition operations specified in the compiled EMU decomposition

and return the new A and B matrices.

Args:
operations (list): A list of compiled operations as produced by

compileEMUTransitionList.

zeroMatrices (tuple): A tuple of length 2, where each element is a numpy.ndarray representing

an all zeros version of the appropriately sized A or B matrices for EMU simulation for later ‘injection’ of fluxes by addition.

fluxes (bayflux.FluxVector): A flux vector or numpy array with a flux value for each variable in the genome scale model.

The order of values in fluxVector should match that used to generate the operations list.

Returns:
tuple: A tuple of length 2, where each element is a numpy.ndarray representing

the A and B matrices respectively, after execution of the specified addition operations.

bayflux.pruneTransitionList(transitionList, metabolitesToKeep)
bayflux.mergeDuplicates(transitionList)
class bayflux.EMU(metabolite, indices)

A class for representing EMUs that cross-references a metabolite object.

Args:
metabolite (cobra.Metabolite): A COBRApy metabolite object, which

this EMU is a subset of.

indices (list): A list of integers representing the 1-indexed

atoms in the metabolite to include in this EMU. Our standard is to use canonical smiles, and represent atoms from left to right.

Attributes:
metabolite (cobra.Metabolite): A COBRApy metabolite object, which

this EMU is a subset of.

indices (list): A list of integers representing the 1-indexed

atoms in the metabolite to include in this EMU. Our standard is to use canonical smiles, and represent atoms from left to right.

__repr__()

Return repr(self).

size()
__hash__()

Return hash(self).

__eq__(other)

Return self==value.

__ne__(other)

Return self!=value.

class bayflux.EMUTransition(reactants, product, parentReaction, forward=True, contribution=1.0)

A class for representing an EMU reaction.

Args:

reactants (list): A list of EMU objects representing all reactants. product (EMU): A single EMU object representing the product. parentReaction (cobra.Reaction): The parent reaction this EMU reaction

is derived from. Used for applying the correct flux later on.

forward (bool): True if this reaction comes from the forward direction

of the parent reaction.

contribution (float): The fraction of the parent reaction flux carried

by this EMU reaction within a set of equivalent EMU reactions.

Attributes:

reactants (list): A list of EMU objects representing all reactants. product (EMU): A single EMU object representing the product. parentReaction (cobra.Reaction): The parent reaction this EMU reaction

is derived from. Used for applying the correct flux later on.

forward (bool): True if this reaction comes from the forward direction

of the parent reaction.

contribution (float): The fraction of the parent reaction flux carried

by this EMU reaction within a set of equivalent EMU reactions.

__repr__()

Return repr(self).

copy()

Copies EMU transition without copying the parent reaction or metabolites.

bayflux.findProducingReactions(metabolite, ignoreNoTransitions=True)
Find all reactions which can produce a given metabolite in the forward

and reverse directions.

Args:

metabolite (cobra.Metabolite): A metabolite to look up. ignoreNoTransitions (bool, optional): If True, only EnhancedReaction

objects that have 1 or more atom transitions will be returned.

Returns:
list: A list of tuples (bayflux.EnhancedReaction, bool) representing each

reaction that can produce the input metabolite. The bool value is true if and only if the metabolite is produced in the forward direction. If a metabolite can be produced in both directions it will occur twice, once with a True, and once with a False value.

bayflux.findProducingEMUTransitions(inputEMU)

Find all EMUTransition objects that directly produce the inputEMU.

Args:

inputEMU (EMU): An EMU to look up.

Returns:

list: A list of EMUtransition objects.

bayflux.emuDecomposition(inputEMUs, transitionLimit=5000000)

Perform a full EMU decomposition of the input EMUs.

Args:

inputEMUs (list): A list of target EMUs to analyze. transitionLimit (int): The maximum number of atom transitions to allow

in the deconstruction. This should be increased for very large models on high memory systems.

Returns:

list: A list of EMUTransition objects representing the full decomposition.

bayflux.EMUsizes(EMUTransitionList)

Identify which size EMUs are found in a list of EMUtransitions.

Args:

EMUTransitionList (list): A list of EMUtransition objects.

Returns:
list: A list of integers in sorted increasing order, which represents

all EMU sizes found in the products and reactants of the input list.

bayflux.splitBySize(EMUTransitionList)

Split apart an EMU transition list by size.

Args:

EMUTransitionList (list): A list of EMUtransition objects.

Returns:
dict: A dict where keys represent EMU transition product sizes in the

input list, and values are a list of EMUTransition objects from the input which produce a product of this size.

bayflux.constructMatrixCoords(EMUTransitionList)
Computes human readable and hash versions of the list of internal EMUs

and external EMUs for a list of EMUTransitions.

Args:
EMUTransitionList (list): A list of EMUtransition objects, typically

of equal product size.

Returns:
dict: A dict of dicts representing the internal and external EMUs

with the keys ‘internalEMUs’ and ‘externalEMUs’ respectively. Each of these values is a dict which has three keys ‘text’, ‘hashes’, and ‘objects’ with list values (in the same order for all 3) representing human readable text, a hash value, and the EMU objects themselves respectively. For condensation EMUs, the ‘externalEMUs’ objects will be list form, where each element is an EMU object.

bayflux.constructZeroMatrices(matrixCoords)

Constructs the A and B zero matrices from the results of constructMatrixCoords.

Args:

matrixCoords (dict): the result of running constructMatrixCoords()

Returns:
tuple: A tuple of length 2, where each element is a numpy.ndarray representing

an all zeros version of the appropriately sized A or B matrices for EMU simulation for later ‘injection’ of fluxes by addition.

bayflux.compileEMUTransitionList(EMUTransitionList, matrixCoords, model)

Compiles an EMU transition list into a set of matrix addition operations indexed by position.

Args:
EMUTransitionList (list): A list of EMUtransition objects, typically

of equal product size.

matrixCoords (dict): the result of running constructMatrixCoords()

on the above list.

model (bayflux.ReactionNetwork): A genome scale model, used to determine the order of variables in a flux vector.

Returns:

list: A list of tuples, where each inner tuple represents a matrix addition operation to the A or B matrix and has the following structure:

-matrix selector (0: matrix A, 1: matrix B) -row: row number to inject to into in the above matrix -column: column number to inject into in the above matrix -reaction selector: a column number in the flux vector -multiplier: a float: multiply flux by this before injecting

bayflux.extractSubstrateEMU(inputEMU, substrateLabelingDict)

Compute the MDV for a given EMU from a set of labeled substrates.

Args:
inputEMU (EMU): An EMU object representing a subset of one of the labeled

substrate metabolites.

substrateLabelingDict (dict): A dict where keys are cobra.Metabolite

objects, and values a tuple of length 2 tuples each representing a fractional labeling pattern on an input substrate. The first value in the length 2 tuple is a float representing a fractional contribution and the second is a list of integers representing the number of extra neutrons at each atom location. The standard index is left to right in the canonical SMILES structure of the metabolite. Fractional contributions must sum to 1.0.

Returns:
list: A list of float values, representing the mass distribution vector

for the inputEMU, starting from the fraction with 0 extra neutrons in the first position.

bayflux.executeCompiledMatrixY(substrateMDVs, operationsY, results, size)
bayflux.emuCompile(emusToSimulate, model, substrateLabelingDict, merge=False, prune=False)
Pre-deconstructs an EMU network, for later simulation of specific

flux vectors.

Args:
emusToSimulate (list): A list of EMU objects, representing the

metabolites we would like to predict MDVs for.

reactions (list): A list of ‘str’ objects representing the names

of reactions in our flux vector in order.

Returns:
list: A list of dicts representing each EMU size sub-network with the
following keys and values:

‘matrixCoords’: (dict) the output of constructMatrixCoords ‘size’: (int) the EMU sub-network size ‘operations’: (list) the output of compileEMUTransitionList

bayflux.compileMatrixY(compiledData, matrixCoords, size, substrateLabelingDict)

Returns: 1) a set of input MDVs in tuple of tuples form

  1. A set of compiled operations with the following syntax:

A list where each element corresponds to a row in matY in order.

Each of these is a length 2 list with: -result size, representing a matrix X EMU of a particular size, or an input emu (called size 0) -MDV number: a row number from that size EMU result, or from the input MDVs in tuple form

Execution instructions: convolve together all MDVs with the same row #, and inject the result into that row

bayflux.simulateLabeling(compiledData, fluxes, substrateLabelingDict)
Simulates the Mass Distribution Vector (MDV) for a set of inputEMUs given

a specific flux vector.

Args:

compiledData (list): The output of emuCompile. fluxes (numpy.matrix): A matrix of fluxes where columns represent

reactions, the first row is forward fluxes, and the second row is backwards fluxes. Non-reversible reactions should always have a flux of 0 in the second row. The order of columns should match that used to generate the operations list.

substrateLabelingDict (dict): See bayflux.extractSubstrateEMU for

a detailed description.

Returns:
dict: A dict of results where each key is an integer specifying

an EMU sub-network size, and each value is an EMU simulation X numpy.matrix which contains simulated MDVs. Columns represent number of extra neutrons starting at 0, while rows represent the ‘internalEMUs’ from ‘matrixCoords’ in the compiledData.

class bayflux.FluxVector(model, fluxes=False)

Class to store a flux vector associated with a ReactionNetwork.

Args:

model (bayflux.ReactionNetwork): The model this flux vector is associated with. fluxes (numpy.array, optional): An array of np.float64 fluxes in the same order as model.variables. Can also optionally be a dict of 2-tuples, where keys are reaction ids and values represent (forward flux, backwards flux)

Attributes:

model (bayflux.ReactionNetwork): The model this flux vector is associated with. fluxes (numpy.array, optional): An array of np.float64 fluxes in the same order as model.variables.

to_Series()

convert the flux vector into a Pandas Series object.

Returns:

A pandas.Series object where each index represents a model variable name, and each value is a 64 bit flux for that variable.

__getitem__(key)
__repr__()

Return repr(self).

_repr_html_()
class bayflux.MassDistribution(model, data=None)
__repr__()

Return repr(self).

toDF()
writeToFile(outputFileName)
bayflux.readMassDistribution(model, inputFileName, format='csv')