Module fia_analysis :: Class FtblFile
[hide private]
[frames] | no frames]

Class FtblFile

source code

This class is the main object of the FIA algorithm. Its main purposes are:

  1. Conversion of FIA and FTBL files into python mathematical objects.
  2. Solution of the MFA optimization problem
Instance Methods [hide private]
 
__init__(self, projname, inpfiletype) source code
 
save_ftblfile(self, filename)
This function saves the entire FtblFile class to a file using python's pickle packge.
source code
 
save_data(self)
MATLAB debugging function.
source code
string
get_flux_name(self, flux_num)
returns the name of fluxer whose index is flux_num.
source code
list
load_file(self, filename)
This function loads the input file into the FtblClass object by:
source code
list
find_segment(self, seg_name)
This function finds the block "seg_name" block segment in the parsed input file self.ftbl_file object.
source code
 
create_pools_dict(self)
This function creates the initial metabolic pools dictionary object by analyzing the NETWORK section of the input file.
source code
 
create_flux_dict(self)
This function creates and updates the main building blocks objects used for the metabolic pathway analysis.
source code
number
get_metabolic_flux_index(self, flux_name)
This function returns the index of the global metabolic flux "flux_name".
source code
 
create_flux_meas_mat(self)
This function parses the FLUX_MEASUREMENTS segment of the ftbl file.
source code
 
create_global_meas_mat(self)
This function creates the objective function for the MFA optmization problem (the global "G" measurement matrix).
source code
CSR matrix
trnasform_eq_into_matrix(self, eq)
This function transforms string equation of fluxes into a fluxomers stoichiometric matrix.
source code
 
create_label_meas_eq(self)
This function parses the LABEL_MEASUREMENTS segment of the ftbl file.
source code
 
create_ms_meas_eq(self)
This function parses the MASS_SPECTROMETRY segment of the ftbl file.
source code
 
create_U_matrix(self)
This function constructs the U matrix, which transforms the fluxomers vector into the metaoblic fluxes vector.
source code
 
create_inp_eq_matrix(self)
This function parses the LABEL_INPUT segment.
source code
 
create_label_transition_mat(self)
This function creates the propogation transition matrix:
source code
 
create_lu_trans_matrix(self)
This function computes the LU decomposition of the propogation transition matrices.
source code
 
evaluate(self)
This function runs the main optimization process.
source code
Class Variables [hide private]
  filename = ''
Instance Variables [hide private]
  ProjName
Project's name
  labelinp_var
Label input variance (it is not supplied with FTBL files).
  InputFileType
input file type (fia or ftbl)
  excell_pools
Dictionary of the external (global input or output) metabolic pools
  ftbl_file = ''
Parsed input file object (TAB spliited lists for the various lines of the input file)
  pools
Metabolic pools dictionary (Keys are pools names, values are the number of carbon atoms for each pool)
Method Details [hide private]

__init__(self, projname, inpfiletype)
(Constructor)

source code 
Parameters:
  • projname (string) - Name of the project to be analyzed.
  • inpfiletype (string) - Type of the input file to be analyzed. Can be either 'fia' (for fia input files) or 'ftbl' (for ftbl input files)

save_ftblfile(self, filename)

source code 

This function saves the entire FtblFile class to a file using python's pickle packge. This enables the user to use the data analyzed later without the need of recalculating the transition or LU matrices (which can take a bit of a time).

save_data(self)

source code 

MATLAB debugging function. This function saves the mathematical objects used for the optimizaiton process in files in order to be analyzed by MATLAB.

get_flux_name(self, flux_num)

source code 

returns the name of fluxer whose index is flux_num.

Parameters:
  • flux_num (number) - The number of the fluxomer we are looking for.
Returns: string
The name of the fluxomer.

load_file(self, filename)

source code 

This function loads the input file into the FtblClass object by:

  1. Dropping comments (lines starting with "//")
  2. Replacing EOL "\n" or "\r" with ""
  3. Erasing spaces

Eventually we are left with a file containing only TABs. This object is then transformed into an array of lists - every array element is a line of the parsed file, and splitted by TABs into a list object.

Parameters:
  • filename (string) - Name of the input file to be examined.
Returns: list
List of lists containing the TAB splitted parsed version of the input file.

find_segment(self, seg_name)

source code 

This function finds the block "seg_name" block segment in the parsed input file self.ftbl_file object. New segments begin with every non-idented line in the input file. Their names are the first string in these lines.

Parameters:
  • seg_name (string) - Name of the segment to be analyzed
Returns: list
A list containing the segment's rows, tab seperated.

create_pools_dict(self)

source code 

This function creates the initial metabolic pools dictionary object by analyzing the NETWORK section of the input file. The function creates the self.pools dictrionary object - Metabolic pools dictionary for which the keys are pools names, and the values are the number of carbon atoms for each pool.

create_flux_dict(self)

source code 

This function creates and updates the main building blocks objects used for the metabolic pathway analysis.

Classification of fluxes

Classifiction of fluxes into: uni-directional fluxes, bi-directional fluxes (FTBL files only) and input/output fluxes. The uni and bi direictional analysis is only needed for FTBL files (FIA assumes all the fluxes are uni-directional). The decision is made by looking for 0 constrained exchange fluxes in the FLUXES section of the FTBL file.

Re-generation of the NETWORK section - adding necessary virtual fluxes

When we are given with a chemical reaction that transforms two elements of the same metabolic pool into others, we translate it into a regular multi-input chmecial reaction by adding a virtual pool and flux to our system:

As an example:

   f: A + A -> B + C     (flux "f" transforms A+A into B+C)

is transformed into:

   f: A + A_s -> B + C   (flux "f" transofmrs A+A_s ito B+C)
   f_A: A -> A_s         (flux "f_A" transforms A into A_s)

This transformation is being done on the input file object itself (hence by changing the parsed NETWORK segment of the input file). The same applies for reversed fluxes of bi-diredctional FTBL files fluxes.

Analysis of extra-cellular pools

Finding pools which are global input or output to the system, and save them in the self.excell_pools object. These pools are recognized as pools with no input / output fluxes going into / exiting them.

Re-generation of the NETWORK section - adding necessary reversed fluxes

The mathematical analysis of the problem consists of flux vector representing uni-directional fluxes. Due to this reason, we need to transform the NETWORK section to contain only uni-directional fluxes by adding to it necessary reversed fluxes. This only applies when FTBL input files are supplied (since again, FIA files are assumed to contain only uni-diretional fluxes in anyway).

Generation of the global fluxes vector

Generation of the global fluxes (as opposed to fluxomers) vector dictionary object. The dictrionary self.flux_nw_vec keys are the names of the global fluxes in our system, and the values are the number of carbon atoms each of them transforms.

Generation of the equality matrix

The equality matrix self.S and its associated equality vector self.S_b are the mathematical constraints of the global optimization problem That should apply on the global fluxes vector (hence self.S * x == self.S_b). The equality matrix is constructed out of 2 main elements:

  1. The stoichiometric equations - as analyzed from the parsed NETWORK section of the input file
  2. The eqaulities constraints from the EQUALITIES section of the input file.

Generation of the equality measurements

Equalities arised from the constraints section of the FLUXES section (only applies to FTBL files) are added to the system as measurements and not as constraints (as opposed to equalities from the EQUALITIES section). Note that this only relevant for FTBL files. The python relevant objects are self.FCM and self.FCv, and we have FCM*x = FCv .

Generation of the global equation list

The entire metabolic network is defined by a set of fluxomeric equations defined in self.eq_list. The structure of this list is:

   [ [ poolname : ([input fluxes], [output fluxes])], ... ]

where the input and output fluxes are list of the names of the incoming and outgoing fluxes.

get_metabolic_flux_index(self, flux_name)

source code 

This function returns the index of the global metabolic flux "flux_name".

Parameters:
  • flux_name (string) - The name of the flux we want to find.
Returns: number
The index of the global metabolic flux "flux_name".

create_flux_meas_mat(self)

source code 

This function parses the FLUX_MEASUREMENTS segment of the ftbl file. It creates the following matrices:

  1. self.flux_meas_mat - The matrix choosing the measured metabolic fluxes out of the fluxomer vector.
  2. self.flux_meas_values - The measured values.
  3. self.flux_meas_variance - The measurement variance vector.

Eventually we will search for:

   M{min [ (self.flux_meas_mat * x - self.flux_meas_values_).T * diag(self.flux_meas_variance) * (self.flux_meas_mat * x - self.flux_meas_values_)] }

create_global_meas_mat(self)

source code 

This function creates the objective function for the MFA optmization problem (the global "G" measurement matrix).

The objective of the MFA problem is to minimize:

   M{|| tG * x - tB ||^2}

The matrix self.tG is created by concatanation of the 3 possible measurments matrices:

  1. Label measurements (self.labelinp_num and self.labelinp_denom).
  2. Fluxes measurement (self.labelmeas_num and self.labelmeas_denom).
  3. Mass-Spectrometry measurements (self.ms_meas_num and self.ms_meas_denom).

The vector self.tB is created by concatanation of appropriate values of the above.

trnasform_eq_into_matrix(self, eq)

source code 

This function transforms string equation of fluxes into a fluxomers stoichiometric matrix. For example:

   "*+flux1/0*-flux2/1" -> [1 0 0 0; 0 0 0 -1]) 
Parameters:
  • eq (string) - An string equation. Every equation element is seperated by either "*+" or "*-" with the fluxomer name following it. No preciding numbers are allowed, only plain fluxomer names. For multiple instances of the same fluxomer, simply add/substract it more than once to the equation.
Returns: CSR matrix
The fluxomer stoichiometric matrix represented by eq.

create_label_meas_eq(self)

source code 

This function parses the LABEL_MEASUREMENTS segment of the ftbl file. The output of the function is the matrices and vectors:

  1. self.labelmeas_num - The label measurements numerator matrix
  2. self.labelmeas_denom - The label measurements denominator matrix
  3. self.labelmeas_value - The label measurements values vector
  4. self.labelmeas_var - The label measurements values vector

The objective function will be to minimize:

   M{ ||diag(self.labelmeas_var) * [self.labelmeas_num - diag(self.labelmeas_value) * self.labelmeas_denom]*x ||^2 }

create_ms_meas_eq(self)

source code 

This function parses the MASS_SPECTROMETRY segment of the ftbl file. The output of the function is the matrices and vectors:

  1. self.ms_meas_num - The MS measurements numerator matrix
  2. self.ms_meas_denom - The MS measurements denominator matrix
  3. self.ms_meas_value - The MS measurements values vector
  4. self.ms_meas_var - The MS measurements values vector

We always treat these measurement as a ratio measurement between the MS values, relative to the 0 MS measurement (hence we add to the objective the ratios: mass1/mass0, mass2/mass0 etc').

The objective function will be to minimize:

   M{ ||diag(self.ms_meas_var) * [self.ms_meas_num - diag(self.ms_meas_value) * self.ms_meas_denom]*x ||^2 }

create_U_matrix(self)

source code 

This function constructs the U matrix, which transforms the fluxomers vector into the metaoblic fluxes vector. hence:

   M{u = U*x}

where:

   u - the metabolic flux vector
   x - the fluxomers vector        

create_inp_eq_matrix(self)

source code 

This function parses the LABEL_INPUT segment. The output of the function is the matrices and vectors:

  1. self.labelinp_num - The flux value measurements numerator matrix
  2. self.labelinp_denom - The flux value measurements denominator matrix
  3. self.labelinp_value - The flux value measurements values vector

The objective function will be to minimize:

   M{ ||diag(self.labelinp_var) * [self.labelinp_num - diag(self.labelinp_value) * self.labelinp_denom]*x ||^2 }

Note: since not supplied by the FTBL files, the value of self.labelinp_value is a global assigned constant.

create_label_transition_mat(self)

source code 

This function creates the propogation transition matrix:

   \M{x(t) = P x(t-1)} .

P is provided using the following sub matrices:

  1. self.trans_mat_a - the H_1 matrix (in CSR format).
  2. self.trans_mat_b - the H_2 matrix (in CSR format).
  3. self.trans_mat_a_gamma - the g_1 matrix (in CSR format).
  4. self.trans_mat_a_beta - the g_2 matrix (in CSR format).
  5. self.trans_mat_b_beta - the g_3 matrix (in CSR format)

In addition, this function creates the beta (ratios) vector:

  1. self.beta_vec - the text names of the beta vector elements
  2. self.beta_vec_M - the numerator for construction of the beta vec.
  3. self.beta_vec_N - the denominator for constuction of the beta vec.

eventually, we have:

   M{beta_vec = (self.beta_vec_M * u) / (self.beta_vec_N * u)}

create_lu_trans_matrix(self)

source code 

This function computes the LU decomposition of the propogation transition matrices. We find a factorization for:

   L{self.trans_mat_a} and L{self.trans_mat_b}

by finding the LU factorizaiton of the matix constructed out of concatanation of the two above.

The result are the matrices:

  1. self.al1 - the left side of the pseudo LU of self.trans_mat_a
  2. self.al2 - the left side of the pseudo LU of self.trans_mat_b
  3. self.au - the right side of the pseudo LU factorizaiton of both self.trans_mat_a and self.trans_mat_b .

evaluate(self)

source code 

This function runs the main optimization process. It uses the scipy.optimize.fmin_slsqp for the actual optimization process, and prints out the results in a TABed formatted table.