<jupyter_start><jupyter_text>A1: core module notebook  Introduction This notebook includes a description of the 'core' python module in the JBEI Quantitative Metabolic Modeling (QMM) library. A description and demonstration of the diffent classes can be found below.   Setup First, we need ot set the path and environment variable properly:<jupyter_code>%matplotlib inline

import sys, os
pythonPath = "/scratch/david.ando/quantmodel/code/core"
if pythonPath not in sys.path:
    sys.path.append('/scratch/david.ando/quantmodel/code/core')
os.environ["QUANTMODELPATH"] = '/scratch/david.ando/quantmodel'<jupyter_output><empty_output><jupyter_text>Importing the required modules for the demo:<jupyter_code>from IPython.display import Image
import core, FluxModels
import os<jupyter_output><empty_output><jupyter_text>Classes description  Metabolite related classes  metbolite class The *metabolite* class is used to store all information related to a metabolite. For example the following instantation:<jupyter_code>ala = core.Metabolite('ala-L', ncarbons=3, source=True, feed='100% 1-C', destination=False, formula='C3H7NO2')<jupyter_output><empty_output><jupyter_text>creates a metabolite with nbame 'ala-L', 3 carbon atoms, which is the source of labeling, is labeled in the first carbon, is not a destination (measured) metabolite and with a composition formula equal to 'C3H7NO2' the **generateEMU** function creates the corresponding Elementary Metabolite Unit (EMU):<jupyter_code>ala.generateEMU([2])<jupyter_output><empty_output><jupyter_text>In this case the EMU contains the first and last carbon in alanine. The input ([2]) specifies which carbons to exclude:<jupyter_code>ala.generateEMU([2,3])<jupyter_output><empty_output><jupyter_text>reactant and product classes *Reactant* and *product* are classes derived from metabolite and the only difference is that they represent metabolites in the context of a reaction. Hence, the stoichiometry of the metabolite and the labeling pattern in that reaction are included:<jupyter_code>R_ala = core.Reactant(ala, 1, 'abc')<jupyter_output><empty_output><jupyter_text>Notice that the stoichiometry information (1, meaning in the reaction only 1 molecule participates in the reaction) and the labeling data ('abc', one part of the labeling pattern, see below) only make sense in the context of a reaction, so they are not included in the metabolite class.Both classes are derived from metabolites, so they inherit their methods:<jupyter_code>R_ala.generateEMU([2,3])<jupyter_output><empty_output><jupyter_text>Reaction related classes  reaction class The *reaction* class produces a reaction instance:<jupyter_code># Create reactant metabolites
coa_c = core.Metabolite('coa_c')
nad_c = core.Metabolite('nad_c')
pyr_c = core.Metabolite('pyr_c')

# Convert into reactants
Rcoa_c = core.Reactant(coa_c, 1.0)
Rnad_c = core.Reactant(nad_c, 1.0)
Rpyr_c = core.Reactant(pyr_c, 1.0)

# Create product metabolites
accoa_c = core.Metabolite('accoa_c')
co2_c   = core.Metabolite('co2_c')
nadh_c  = core.Metabolite('nadh_c')

# Convert into products
Raccoa_c = core.Product(accoa_c, 1.0)
Rco2_c   = core.Product(co2_c, 1.0)
Rnadh_c  = core.Product(nadh_c, 1.0)

# Create reaction
PDH = core.Reaction('PDH',reactants=[Rcoa_c,Rnad_c,Rpyr_c] , products=[Raccoa_c,Rco2_c,Rnadh_c] 
                    ,subsystem='S_GlycolysisGluconeogenesis')<jupyter_output><empty_output><jupyter_text>Reactions can also initialized from a string:<jupyter_code>PDH2 = core.Reaction.from_string('PDH : coa_c + nad_c + pyr_c --> accoa_c  + co2_c   + nadh_c  ')<jupyter_output><empty_output><jupyter_text>The *reaction* class contains some useful functions such as: **stoichLine** to obtain the stoichiometric line for the reaction:<jupyter_code>print PDH.stoichLine()
print PDH2.stoichLine()<jupyter_output>PDH : coa_c + nad_c + pyr_c --> accoa_c + co2_c + nadh_c
PDH : coa_c + nad_c + pyr_c --> accoa_c + co2_c + nadh_c<jupyter_text>**getReactDict** produces a dictionary of reactants:<jupyter_code>PDH.getReactDict()<jupyter_output><empty_output><jupyter_text>**getProdDict** produces a dictionary of products:<jupyter_code>PDH.getProdDict()<jupyter_output><empty_output><jupyter_text>Elementary Metabolite Unit (EMU) related classes Elementary Metabolite Units (or EMUs) of a compound are the molecule parts (moieties) comprising any distinct subset of the compound’s atoms (Antoniewicz MR, <NAME>, Stephanopoulos G: Elementary metabolite units (EMU): a novel framework for modeling isotopic distributions. Metab Eng 2007, 9:68-86.). For example, cit$_{123}$ represents the first 3 carbon atoms in the citrate molecule.  EMU class The EMU class provides a class to hold and manipulate EMUs:<jupyter_code>cit321= core.EMU('cit_3_2_1')<jupyter_output><empty_output><jupyter_text>The method **findnCarbons** produces the number of carbons in the EMU:<jupyter_code>print cit321.findnCarbons()<jupyter_output>3.0<jupyter_text>The method **getMetName** produces the name of the corresponding metabolite:<jupyter_code>print cit321.getMetName()
str(cit321.getMetName()) == 'cit'<jupyter_output><empty_output><jupyter_text>The method **getIndices** produces the indices:<jupyter_code>print cit321.getIndices()<jupyter_output>[3, 2, 1]<jupyter_text>**getSortedName** sorts the indices in the EMU name:<jupyter_code>print cit321.getSortedName()<jupyter_output>cit_1_2_3<jupyter_text>**getEmuInSBML** produces the name of the EMU in SBML format:<jupyter_code>print cit321.getEmuInSBML()<jupyter_output>cit_c_3_2_1<jupyter_text>Transitions related classes Transitions contain the information on how carbon (or other) atoms are passed in each reaction. Atom transitions describe, for example, the fate of each carbon in a reaction, whereas EMU transitions describe this information by using EMUs, as described below.   AtomTransition class Atom transitions represent the fate of each carbon in a reaction (<NAME>. (2001) 13C metabolic flux analysis. Metabolic engineering 3: 195-206). For example, in:AKGDH	akg --> succoa + co2	abcde : bcde + aakg gets split into succoa and co2, with the first 4 carbons going to succoa and the remaining carbon going to co2.<jupyter_code>AT = core.AtomTransition('AKGDH	akg --> succoa + co2	abcde : bcde + a')
print AT<jupyter_output>AKGDH	akg --> succoa + co2	abcde : bcde + a<jupyter_text>The method **findEMUtransition** provides for a given input EMU (e.g. succoa_1_2_3_4), which EMU it comes from in the form of a EMU transition:<jupyter_code>emu1 = core.EMU('co2_1')
print AT.findEMUtransition(emu1)

emu2 = core.EMU('succoa_1_2_3_4')
print AT.findEMUtransition(emu2)<jupyter_output>['AKGDH, akg_1 --> co2_1']
['AKGDH, akg_2_3_4_5 --> succoa_1_2_3_4']<jupyter_text>This is done through the method **findEMUs**, which finds the emus from which the input emanates in the given atom transition:<jupyter_code>print emu2.name
print AT.findEMUs(emu2)
for emus in AT.findEMUs(emu2):
    for emu_ in emus:
        print emu_.name<jupyter_output>succoa_1_2_3_4
[[<core.EMU instance at 0x7fe7d68e1320>]]
akg_2_3_4_5<jupyter_text>which in turn, uses the method **getOriginDictionary** which provides for a given input EMU the originating metabolite and the correspondance in indices:<jupyter_code>AT.getOriginDictionary(emu2)<jupyter_output><empty_output><jupyter_text>EMUTransition class Class for EMU transitions that contain information on how different EMUs transform intto each other. For example:            TA1_b,  TAC3_c_1_2_3 + g3p_c_1_2_3 -->  f6p_c_1_2_3_4_5_6        indicating that TAC3_c_1_2_3 and g3p_c_1_2_3 combine to produce f6p_c_1_2_3_4_5_6 in reaction TA1_b (backward reaction of TA1), or:                SSALy, (0.5) sucsal_c_4 --> (0.5) succ_c_4        which indicates that the fourth atom of sucsal_c becomes the fourth atom of succ_c. The (0.5) contribution coefficient indicates that reaction SSALy contains a symmetric molecule and two labeling correspondences are equally likely. Hence this transition only contributes half the flux to the final labeling.<jupyter_code>emuTrans = core.EMUTransition('TA1_b,  TAC3_c_1_2_3 + g3p_c_1_2_3 -->  f6p_c_1_2_3_4_5_6')
print emuTrans
str(emuTrans) == 'TA1_b, TAC3_c_1_2_3 + g3p_c_1_2_3 --> f6p_c_1_2_3_4_5_6'<jupyter_output><empty_output><jupyter_text>Ranged number class The *rangedNumber* class describes floating point numbers for which a confidence interval is available. For example, fluxes obtained through 2S-$^{13}$C MFA are described through the flux that best fits the data and the highest and lowest values that are found to be compatible with labeling data (see equations 16-23 in Garcia Martin *et al* 2015). However, this class has been abstracted out so it can be used with other ranged intervals. Ranged numbers can used as follows:<jupyter_code>number = core.rangedNumber(0.3,0.6,0.9) # 0.3 lowest, 0.6 best fit, 0.9 highest<jupyter_output><empty_output><jupyter_text>Ranged numbers can be printed:<jupyter_code>print number<jupyter_output>[0.3 : 0.6 : 0.9]<jupyter_text>and added, substracted, multiplied and divided following the standard error propagation rules(https://en.wikipedia.org/wiki/Propagation_of_uncertainty):<jupyter_code>A = core.rangedNumber(0.3,0.6,0.9)
B = core.rangedNumber(0.1,0.15,0.18)
print A+B
print A-B
print 2*A
print B/3<jupyter_output>[0.0333333333333 : 0.05 : 0.06]<jupyter_text>Flux class The flux class describes fluxes attached to a reaction. For example, if the net flux is described by the ranged number A and the exchange flux by the ranged number B, the corresponding flux would be:<jupyter_code>netFlux      = A
exchangeFlux = B
flux1 = core.flux(net_exc_tup=(netFlux,exchangeFlux)) 
print flux1<jupyter_output>Forward: [0.445861873485 : 0.75 : 1.05149626863]
Backward: [0.1 : 0.15 : 0.18]
Net: [0.3 : 0.6 : 0.9]
Exchange: [0.1 : 0.15 : 0.18]<jupyter_text>Fluxes can easily multiplied:<jupyter_code>print 3*flux1<jupyter_output>Forward: [1.33758562046 : 2.25 : 3.1544888059]
Backward: [0.3 : 0.45 : 0.54]
Net: [0.9 : 1.8 : 2.7]
Exchange: [0.3 : 0.45 : 0.54]
StarcoderdataJupyterStructuredCleanDedup