コード例 #1
0
ファイル: cobra_methods.py プロジェクト: SBRG/sbaas
    def make_net_reaction(self,cobra_model_I, rxn_id_I, rxn_list_I,stoich_list_I):
        '''generate a net reaction from a list of individual reactions'''
        # input: rxn_list_I = list of reaction IDs
        # output: rxn_net_O = net reaction (cobra Reaction object)
        from cobra.core.Reaction import Reaction

        #rxn_net_O = cobra_model_I.reactions.get_by_id(rxn_list_I[0]);
        #for r in rxn_list_I[1:]:
        #    if cobra_model_I.reactions.get_by_id(r).reversibility:
        #        print r + " is reversible!";
        #        print "continue?"
        #    rxn_net_O += cobra_model_I.reactions.get_by_id(r);

        # check input:
        if not len(stoich_list_I) == len(rxn_list_I):
            print("error in " + rxn_id_I + ": there are " + str(len(rxn_list_I)) + " rxn ids and " + str(len(stoich_list_I)) + " coefficients");
            exit(-1);

        rxn_net_O = Reaction(rxn_id_I);
        for i,r in enumerate(rxn_list_I):
            mets = {};
            metlist = [];
            metlist = cobra_model_I.reactions.get_by_id(r).products + cobra_model_I.reactions.get_by_id(r).reactants;
            for met in metlist:
                mets[met] = cobra_model_I.reactions.get_by_id(r).get_coefficient(met)*stoich_list_I[i];
            rxn_net_O.add_metabolites(mets);
            rxn_net_O.subsystem = cobra_model_I.reactions.get_by_id(r).subsystem; #copy over the subsystem
    
        # check net reaction
        #if not rxn_net_O.check_mass_balance():  
            #print "error: " + rxn_id_I + " is not elementally balanced";

        #print rxn_net_O.id;
        #print rxn_net_O.build_reaction_string();
        return rxn_net_O;
コード例 #2
0
ファイル: modify.py プロジェクト: fmitha/cobrapy
def convert_to_irreversible(cobra_model):
    """Will break all of the reversible reactions into two separate irreversible reactions with
    different directions.  Useful for some modeling problems.

    cobra_model: A Model object which will be modified in place.

    
    TODO: Can we just use a -1*guided_copy or something else?
    """
    reactions_to_add = []
    for reaction in cobra_model.reactions:
        # Potential bug because a reaction might run backwards naturally
        # and this would result in adding an empty reaction to the
        # model in addition to the reverse reaction.
        if reaction.lower_bound < 0:
            reverse_reaction = Reaction(reaction.id + "_reverse")
            reverse_reaction.lower_bound = 0
            reverse_reaction.upper_bound = reaction.lower_bound * -1
            reaction.lower_bound = 0
            # Make the directions aware of each other
            reaction.reflection = reverse_reaction
            reverse_reaction.reflection = reaction
            reaction.reversibility = reverse_reaction.reversibility = 0
            reaction_dict = dict([(k, v * -1) for k, v in reaction._metabolites.items()])
            reverse_reaction.add_metabolites(reaction_dict)
            reverse_reaction._model = reaction._model
            reverse_reaction._genes = reaction._genes
            reverse_reaction.gene_reaction_rule = reaction.gene_reaction_rule
            reactions_to_add.append(reverse_reaction)
    cobra_model.add_reactions(reactions_to_add)
コード例 #3
0
ファイル: modify.py プロジェクト: mp11/cobra_ext
def add_exchange_reaction(cobra_model, the_metabolites,
                          reaction_reversibility=False):
    """Adds exchange reactions to a model for a set of metabolites.

    cobra_model: A Model object.

    the_metabolites: A cobra.Metabolite or list of cobra.Metabolites

    reaction_reversibility: True or False.  Indicates whether the reactions
    should be reversible.


    #TODO:  This is not compliant with current 
    """
    if not isinstance(the_metabolites, list):
        the_metabolites = [the_metabolites]
    if reaction_reversibility:
        lower_bound = -1000
    else:
        lower_bound = 0
    the_reactions = []
    for the_metabolite in the_metabolites:
        the_reaction = Reaction('EX_' + the_metabolite.id)
        the_reaction.name = the_metabolite + ' exchange reaction'
        the_reaction.add_metabolites({the_metabolite: -1})
        the_reaction.reversibility = reaction_reversibility
        the_reaction.lower_bound = lower_bound
        the_reaction.upper_bound = 1000
        the_reaction.objective_coefficient = 0.
        the_reaction.boundary = True
        the_reactions.append(the_reaction)
    cobra_model.add_reactions(the_reactions)
コード例 #4
0
def make_net_reaction(cobra_model_I, rxn_id_I, rxn_list_I, stoich_list_I):
    '''generate a net reaction from a list of individual reactions'''
    # input: rxn_list_I = list of reaction IDs
    # output: rxn_net_O = net reaction (cobra Reaction object)
    from cobra.core.Reaction import Reaction

    #rxn_net_O = cobra_model_I.reactions.get_by_id(rxn_list_I[0]);
    #for r in rxn_list_I[1:]:
    #    if cobra_model_I.reactions.get_by_id(r).reversibility:
    #        print r + " is reversible!";
    #        print "continue?"
    #    rxn_net_O += cobra_model_I.reactions.get_by_id(r);

    # check input:
    if not len(stoich_list_I) == len(rxn_list_I):
        print("error in " + rxn_id_I + ": there are " + str(len(rxn_list_I)) +
              " rxn ids and " + str(len(stoich_list_I)) + " coefficients")
        exit(-1)

    rxn_net_O = Reaction(rxn_id_I)
    for i, r in enumerate(rxn_list_I):
        mets = {}
        metlist = []
        metlist = cobra_model_I.reactions.get_by_id(
            r).products + cobra_model_I.reactions.get_by_id(r).reactants
        for met in metlist:
            mets[met] = cobra_model_I.reactions.get_by_id(r).get_coefficient(
                met) * stoich_list_I[i]
        rxn_net_O.add_metabolites(mets)
        rxn_net_O.subsystem = cobra_model_I.reactions.get_by_id(r).subsystem
        #copy over the subsystem

    # check net reaction
    #if not rxn_net_O.check_mass_balance():
    #print "error: " + rxn_id_I + " is not elementally balanced";

    #print rxn_net_O.id;
    #print rxn_net_O.build_reaction_string();
    return rxn_net_O
コード例 #5
0
def convert_to_irreversible_with_indicators(cobra_model,reaction_id_list,metabolite_list, mutually_exclusive_directionality_constraint = False,label_model=None):
    #Function modified from the work by : """Schmidt BJ1, Ebrahim A, Metz TO, Adkins JN, Palsson B, Hyduke DR. GIM3E: condition-specific models of cellular metabolism developed from metabolomics and expression data Bioinformatics. 2013 Nov 15;29(22):2900-8. doi: 10.1093/bioinformatics/btt493. Epub 2013 Aug 23."""
    """Will break all of the reversible reactions into two separate irreversible
     reactions with different directions.  This function call modified from
     a version in the core cobra to facilitate the MILP formulation and
     include gene_reaction_rules with the reverse reaction
   
     Arguments:
      cobra_model: A model object which will be modified in place.
      mutually_exclusive_directionality_constraint: Boolean.  If True, turnover 
       reactions are constructed to serve as MILP constraints to prevent loops.
      
     Returns:
      None, cobra_model is modified in place
    
    
    
    
     """
    reactions_to_add = []
    from cobra.core.Reaction import Reaction
    from cobra.core import Metabolite
    reactions_to_make_irreversible=[]
    for x in reaction_id_list:
        reactions_to_make_irreversible.append(cobra_model.reactions.get_by_id(x))
    """for x in lexs:
        reactions_to_make_irreversible.append(cobra_model.reactions.get_by_id(x))"""
    
    #If a label model object  is provided make sure all experimentally measured metabolites (or at least one of the metabolites in the pool) is produced
    full_metabolite_list=copy.copy(metabolite_list)
    print full_metabolite_list
    if label_model!=None:
       emus=[]
       for condition in label_model.experimental_dict:
           for emu in label_model.experimental_dict[condition]:
               if emu not in emus:
                  emus.append(emu)
       measured_metabolite_dict={}
       
       for emu in emus:
           iso_id=str(label_model.emu_dict[emu]["met_id"])
           #print label_model.id_isotopomer_object_dict
           #isotopomer_object=label_model.id_isotopomer_object_dict[iso_id]
           metabolites=label_model.isotopomer_id_metabolite_id_dict[iso_id]
           print [iso_id,label_model.isotopomer_id_metabolite_id_dict[iso_id]]
           if isinstance(metabolites,list):
              for metabolite in metabolites:
                  full_metabolite_list.append(metabolite)
           else:
              full_metabolite_list.append(metabolites)
    
    for metabolites in full_metabolite_list:
       print metabolites
       if not isinstance(metabolites,list):
          metabolites=[metabolites]
       for metabolite in metabolites:
          print metabolite
          the_metabolite=cobra_model.metabolites.get_by_id(metabolite)
          for x in the_metabolite.reactions:
             if x not in reactions_to_make_irreversible:
              reactions_to_make_irreversible.append(x)    
                  
    for reaction in reactions_to_make_irreversible:
        # Potential artifact because a reaction might run backwards naturally
        # and this would result in adding an empty reaction to the
        # model in addition to the reverse reaction.
        if reaction.lower_bound < 0:
            #reverse_reaction = Reaction(reaction.id + "_reverse")
            reverse_reaction = reaction.copy()
            reverse_reaction.id = reaction.id + "_reverse"
            reverse_reaction.lower_bound = max(0,-1*reaction.upper_bound)
            reverse_reaction.upper_bound = reaction.lower_bound * -1.
            reaction.lower_bound = 0
            if reaction.upper_bound<0:
               reaction.upper_bound=0
            # Make the directions aware of each other
            reaction.notes["reflection"] = reverse_reaction.id
            reverse_reaction.notes["reflection"] = reaction.id
            reaction_dict = {}
            current_metabolites = [x for x in reaction.metabolites]
            for the_metabolite in current_metabolites:
                reaction_dict[the_metabolite] = -2 * reaction.get_coefficient(the_metabolite.id)
            reverse_reaction.add_metabolites(reaction_dict)
            reactions_to_add.append(reverse_reaction)
            # Also: GPRs should already copy
            # reverse_reaction.gene_reaction_rule = reaction.gene_reaction_rule
            # reverse_reaction._genes = reaction._genes
            
            if mutually_exclusive_directionality_constraint:
                # A continuous reaction bounded by 0., 1.
                # Serves as a source for the indicator metabolites
                tmp_source = Reaction('IRRMILP_direction_constraint_source_for_%s_and_%s'
                                                           %(reaction.id,
                                                             reverse_reaction.id))
                tmp_source.upper_bound = 1.
                tmp_source.lower_bound = 0.
                # The reverse indicator reaction is
                # an integer-valued reaction bounded by 0,1
                # that activates flux to the reverse reaction
                # and deactivates the forward reaction only when it is
                # turned on to 1
                tmp_indicator = Reaction('IRRMILP_reverse_indicator_for_%s_and_%s'
                                                           %(reaction.id,
                                                             reverse_reaction.id))
                tmp_indicator.upper_bound = 1
                tmp_indicator.lower_bound = 0
                tmp_indicator.variable_kind = 'integer'                    
                flux_constraint_forward = Metabolite(id = 
                     'IRRMILP_direction_constraint_for_%s'%reaction.id)
                flux_constraint_reverse = Metabolite(id = 
                     'IRRMILP_direction_constraint_for_%s'%reverse_reaction.id)
                flux_constraint_reverse._constraint_sense = 'G'
                flux_constraint_reverse._bound = 0.
                
                tmp_source.add_metabolites({flux_constraint_forward: 1})
                
                tmp_indicator.add_metabolites({flux_constraint_forward: -1,
                                      flux_constraint_reverse: 1})
                if reaction.upper_bound != 0:
                        reaction.add_metabolites({flux_constraint_forward: -1./reaction.upper_bound})
                else:
                    # could put 1.01 X the tolerance here,
                    # This is arbitrary.  Use 0.001
                    # since 1000 is a typical upper bound
                    reaction.add_metabolites({flux_constraint_forward: -0.001})
                if reverse_reaction.upper_bound != 0:
                    reverse_reaction.add_metabolites({flux_constraint_reverse: -1./reverse_reaction.upper_bound})
                else:
                    reverse_reaction.add_metabolites({flux_constraint_reverse: -0.001})
                reactions_to_add.append(tmp_indicator)
                reactions_to_add.append(tmp_source)
    cobra_model.add_reactions(reactions_to_add)
コード例 #6
0
def add_turnover_metabolites(cobra_model, metabolite_id_list=[], epsilon=1e-6,label_model=None):
    #Function based on the work by : """Schmidt BJ1, Ebrahim A, Metz TO, Adkins JN, Palsson B, Hyduke DR. GIM3E: condition-specific models of cellular metabolism developed from metabolomics and expression data Bioinformatics. 2013 Nov 15;29(22):2900-8. doi: 10.1093/bioinformatics/btt493. Epub 2013 Aug 23."""
    
    
    """ NOTE: Model must first be converted to irreversible!
    This entry creates a corresponding turnover metabolite
    that ensures flux through the metabolite of interest.
    
    Arguments:
     cobra_model: the model to be updated.
     metabolite_id_list: list of model metabolites for
                         which to add a turnover metabolites. If one element of the list contains several metabolites it will add a common turnover metabolites to all the metabolites in the list forcing at least one of the metabolites to be present. Example: [["pyr_c","pyr_m","pyr_e"]] will force pyruvate to be present regardless of the compartment 
     epsilon: minimal flux to force through turnover metabolites.
      recommend 1.01 X solver_tolerance    
    
    
    """
    
    maxupper_bound=max([x.upper_bound for x in cobra_model.reactions])
    # Set the minimum flux for metabolites equal to some factor larger than the solver's tolerance
    the_min_flux = epsilon
    turnover_metabolites = []
    sink_reactions = []
    full_metabolite_id_list=copy.copy(metabolite_id_list)
    single_metabolites=[]
    group_metabolites=[]
    #If a label model object  is provided make sure all experimentally measured metabolites (or at least one of the metabolites in the pool) is produced
    if label_model!=None:
       emus=[]
       for condition in label_model.experimental_dict:
           for emu in label_model.experimental_dict[condition]:
               if emu not in emus:
                  emus.append(emu)
       measured_metabolite_dict={}
       print emus
       for emu in emus:
           iso_id=label_model.emu_dict[emu]["met_id"]
           #isotopomer_object=label_model.id_isotopomer_object_dict[iso_id]
           if len(label_model.isotopomer_id_metabolite_id_dict[iso_id])>1:
              group_metabolites.append(label_model.isotopomer_id_metabolite_id_dict[iso_id])
           else:
              single_metabolites.append(str(label_model.isotopomer_id_metabolite_id_dict[iso_id][0]))
    for metabolite in metabolite_id_list:
        if isinstance(metabolite,list) and len(metabolite)>1:
           group_metabolites.append(metabolite)
        elif isinstance(metabolite,list):
           single_metabolites.apppend(metabolite[0])
        elif metabolite not in single_metabolites:  
            single_metabolites.apppend(metabolite)
    print group_metabolites
    for metabolites in  group_metabolites:
              met_id=""
              for metabolite in metabolites:
                  met_id+=metabolite+"_"
              met_id=str(met_id[:-1])
              #print isotopomer_object.ref_met
              sum_abs_source_reaction_bounds = 0
              v_metabolite = Metabolite("TM_" + met_id)
              if v_metabolite in cobra_model.metabolites:
                 continue
              #ref_met_id=[x for x in label_model.id_isotopomer_object_dict[iso_id]]
              for metabolite_id in metabolites:
                  r_metabolite = cobra_model.metabolites.get_by_id(metabolite_id)
                  the_reaction_id_list = [x.id for x in r_metabolite.reactions]
                  for the_reaction_id in the_reaction_id_list: 
                      the_reaction = cobra_model.reactions.get_by_id(the_reaction_id)
                      coefficient = (the_reaction.metabolites[r_metabolite])
                      the_reaction.add_metabolites({v_metabolite: coefficient})
                      sum_abs_source_reaction_bounds += maxupper_bound
              for the_reaction in v_metabolite.reactions:
                  if the_reaction.metabolites[v_metabolite]<0:
                     the_reaction.add_metabolites({v_metabolite:-2*the_reaction.metabolites[v_metabolite]})
              sink_reaction = Reaction("TMS_" +met_id)
              sink_reaction.add_metabolites({v_metabolite:-2})
              sink_reaction.lower_bound = the_min_flux
              sink_reaction.upper_bound = sum_abs_source_reaction_bounds / 2.
              turnover_metabolites.append(v_metabolite)
              sink_reactions.append(sink_reaction)
    print single_metabolites
    for metabolite_id in single_metabolites:
        print metabolite_id
        v_metabolite = Metabolite("TM_" + str(metabolite_id))
        # Now for reactions.  We include all reactions 
        # that create or consume the real metabolite.
        # These reactions therefore also drive creation of the
        # turnover metabolite, and we need to add a reaction
        # that is the sink.  By constraining this single
        # sink reaction, we ensure flux through the real reactions
        # to create the real metabolite.
        r_metabolite = cobra_model.metabolites.get_by_id(metabolite_id)
        sum_abs_source_reaction_bounds = 0
        
        the_reaction_id_list = [x.id for x in r_metabolite.reactions]
        for the_reaction_id in the_reaction_id_list:
            the_reaction = cobra_model.reactions.get_by_id(the_reaction_id)
            coefficient = abs(the_reaction.metabolites[r_metabolite])
            the_reaction.add_metabolites({v_metabolite:coefficient})
            #v_metabolite._reaction.add(the_reaction)
            # The model should be irreversible, and the upper bound
            # should be greater than the lower bound and positive.
            # Use 1000 for each reaction to be conservative.
            # E.g. might flip reactions back on later, don't
            # use the current upper bound for the reactions.
            #CFC Changed sum_abs_source_reaction_bounds += 1000.     
            sum_abs_source_reaction_bounds += maxupper_bound   
        # Add the sink reaction for the turnover metabolite
        # Since both creation and consumption of
        # the real metabolite drive the turnover,
        # we require 2 units of metabolite per
        # 1 unit of flux sink so this matches
        # the turnover through the real metabolite.
        sink_reaction = Reaction("TMS_" + metabolite_id)
        sink_reaction.add_metabolites({v_metabolite:-2})
        
        # Ensure a positive flux through the sink.
        # and maximum equal to maximal needed to
        # sustain reactions at their maximum.
        sink_reaction.lower_bound = the_min_flux
        sink_reaction.upper_bound = sum_abs_source_reaction_bounds / 2.
        v_metabolite._reaction.add(sink_reaction)        
        turnover_metabolites.append(v_metabolite)
        sink_reactions.append(sink_reaction)
    
    
    print sink_reactions
    #cobra_model.add_metabolites(turnover_metabolites)
    cobra_model.add_reactions(sink_reactions)
コード例 #7
0
def add_turnover_metabolites(cobra_model, metabolite_id_list=[], epsilon=1e-6,label_model=None):
    #Function based on the work by : """Schmidt BJ1, Ebrahim A, Metz TO, Adkins JN, Palsson B, Hyduke DR. GIM3E: condition-specific models of cellular metabolism developed from metabolomics and expression data Bioinformatics. 2013 Nov 15;29(22):2900-8. doi: 10.1093/bioinformatics/btt493. Epub 2013 Aug 23."""
    
    
    """ NOTE: Model must first be converted to irreversible!
    This entry creates a corresponding turnover metabolite
    that ensures flux through the metabolite of interest.
    
    Arguments:
     cobra_model: the model to be updated.
     metabolite_id_list: list of model metabolites for
                         which to add a turnover metabolites. If one element of the list contains several metabolites it will add a common turnover metabolites to all the metabolites in the list forcing at least one of the metabolites to be present. Example: [["pyr_c","pyr_m","pyr_e"]] will force pyruvate to be present regardless of the compartment 
     epsilon: minimal flux to force through turnover metabolites.
      recommend 1.01 X solver_tolerance    
    
    
    """
    
    maxupper_bound=max([x.upper_bound for x in cobra_model.reactions])
    # Set the minimum flux for metabolites equal to some factor larger than the solver's tolerance
    the_min_flux = epsilon
    turnover_metabolites = []
    sink_reactions = []
    full_metabolite_id_list=copy.copy(metabolite_id_list)
    single_metabolites=[]
    group_metabolites=[]
    #If a label model object  is provided make sure all experimentally measured metabolites (or at least one of the metabolites in the pool) is produced
    if label_model!=None:
       emus=[]
       for condition in label_model.experimental_dict:
           for emu in label_model.experimental_dict[condition]:
               if emu not in emus:
                  emus.append(emu)
       measured_metabolite_dict={}
       print emus
       for emu in emus:
           iso_id=label_model.emu_dict[emu]["met_id"]
           #isotopomer_object=label_model.id_isotopomer_object_dict[iso_id]
           if len(label_model.isotopomer_id_metabolite_id_dict[iso_id])>1:
              group_metabolites.append(label_model.isotopomer_id_metabolite_id_dict[iso_id])
           else:
              single_metabolites.append(str(label_model.isotopomer_id_metabolite_id_dict[iso_id][0]))
    for metabolite in metabolite_id_list:
        if isinstance(metabolite,list) and len(metabolite)>1:
           group_metabolites.append(metabolite)
        elif isinstance(metabolite,list):
           single_metabolites.apppend(metabolite[0])
        elif metabolite not in single_metabolites:  
            single_metabolites.apppend(metabolite)
    print group_metabolites
    for metabolites in  group_metabolites:
              met_id=""
              for metabolite in metabolites:
                  met_id+=metabolite+"_"
              met_id=str(met_id[:-1])
              #print isotopomer_object.ref_met
              sum_abs_source_reaction_bounds = 0
              v_metabolite = Metabolite("TM_" + met_id)
              if v_metabolite in cobra_model.metabolites:
                 continue
              #ref_met_id=[x for x in label_model.id_isotopomer_object_dict[iso_id]]
              for metabolite_id in metabolites:
                  r_metabolite = cobra_model.metabolites.get_by_id(metabolite_id)
                  the_reaction_id_list = [x.id for x in r_metabolite.reactions]
                  for the_reaction_id in the_reaction_id_list: 
                      the_reaction = cobra_model.reactions.get_by_id(the_reaction_id)
                      coefficient = (the_reaction.metabolites[r_metabolite])
                      the_reaction.add_metabolites({v_metabolite: coefficient})
                      sum_abs_source_reaction_bounds += maxupper_bound
              for the_reaction in v_metabolite.reactions:
                  if the_reaction.metabolites[v_metabolite]<0:
                     the_reaction.add_metabolites({v_metabolite:-2*the_reaction.metabolites[v_metabolite]})
              sink_reaction = Reaction("TMS_" +met_id)
              sink_reaction.add_metabolites({v_metabolite:-2})
              sink_reaction.lower_bound = the_min_flux
              sink_reaction.upper_bound = sum_abs_source_reaction_bounds / 2.
              turnover_metabolites.append(v_metabolite)
              sink_reactions.append(sink_reaction)
    print single_metabolites
    for metabolite_id in single_metabolites:
        print metabolite_id
        v_metabolite = Metabolite("TM_" + str(metabolite_id))
        if v_metabolite in cobra_model.metabolites:
                 continue
        # Now for reactions.  We include all reactions 
        # that create or consume the real metabolite.
        # These reactions therefore also drive creation of the
        # turnover metabolite, and we need to add a reaction
        # that is the sink.  By constraining this single
        # sink reaction, we ensure flux through the real reactions
        # to create the real metabolite.
        r_metabolite = cobra_model.metabolites.get_by_id(metabolite_id)
        sum_abs_source_reaction_bounds = 0
        
        the_reaction_id_list = [x.id for x in r_metabolite.reactions]
        for the_reaction_id in the_reaction_id_list:
            the_reaction = cobra_model.reactions.get_by_id(the_reaction_id)
            coefficient = abs(the_reaction.metabolites[r_metabolite])
            the_reaction.add_metabolites({v_metabolite:coefficient})
            #v_metabolite._reaction.add(the_reaction)
            # The model should be irreversible, and the upper bound
            # should be greater than the lower bound and positive.
            # Use 1000 for each reaction to be conservative.
            # E.g. might flip reactions back on later, don't
            # use the current upper bound for the reactions.
            #CFC Changed sum_abs_source_reaction_bounds += 1000.     
            sum_abs_source_reaction_bounds += maxupper_bound   
        # Add the sink reaction for the turnover metabolite
        # Since both creation and consumption of
        # the real metabolite drive the turnover,
        # we require 2 units of metabolite per
        # 1 unit of flux sink so this matches
        # the turnover through the real metabolite.
        sink_reaction = Reaction("TMS_" + metabolite_id)
        sink_reaction.add_metabolites({v_metabolite:-2})
        
        # Ensure a positive flux through the sink.
        # and maximum equal to maximal needed to
        # sustain reactions at their maximum.
        sink_reaction.lower_bound = the_min_flux
        sink_reaction.upper_bound = sum_abs_source_reaction_bounds / 2.
        v_metabolite._reaction.add(sink_reaction)        
        turnover_metabolites.append(v_metabolite)
        sink_reactions.append(sink_reaction)
    
    
    print sink_reactions
    #cobra_model.add_metabolites(turnover_metabolites)
    cobra_model.add_reactions(sink_reactions)
コード例 #8
0
ファイル: cobra_methods.py プロジェクト: SBRG/sbaas
    def load_ALEWt(self,anoxic = False, oxic = True, update_ampms2 = True, convert2irreversible = False):
        '''load iJO1366 with the following changes:
	    1. update to AMPMS2 to account for carbon monoxide
	    2. changes to uptake bounds for glucose M9 media
	    3. constrain the model to use 'PFK' instead of 'F6PA', 'DHAPT' when grown on glucose
	    4. constrain the model to use the physiologically perferred glutamate synthesis enzymes
	    5. depending on oxygen availability, constrain the model to use the correct RNR enzymes
	    6. depending on oxygen availability, constrain the model to use the correct Dihydroorotate dehydrogenase (PyrD) enzymes
	    7. constrain fatty acid biosynthesis to use the physiologically preferred enzymes'''
        ijo1366_sbml = settings.workspace_data+"/models/iJO1366.xml"
        # Read in the sbml file and define the model conditions
        cobra_model = create_cobra_model_from_sbml_file(ijo1366_sbml, print_time=True)
        if update_ampms2:
            # Update AMPMS2
            coc = Metabolite('co_c','CO','carbon monoxide','c');
            cop = Metabolite('co_p','CO','carbon monoxide','p');
            coe = Metabolite('co_e','CO','carbon monoxide','e');
            cobra_model.add_metabolites([coc,cop,coe])
            ampms2_mets = {};
            ampms2_mets[cobra_model.metabolites.get_by_id('air_c')] = -1;
            ampms2_mets[cobra_model.metabolites.get_by_id('amet_c')] = -1;
            ampms2_mets[cobra_model.metabolites.get_by_id('dad_DASH_5_c')] = 1;
            ampms2_mets[cobra_model.metabolites.get_by_id('met_DASH_L_c')] = 1;
            ampms2_mets[cobra_model.metabolites.get_by_id('4ampm_c')] = 1;
            ampms2_mets[cobra_model.metabolites.get_by_id('h_c')] = 3;
            ampms2_mets[cobra_model.metabolites.get_by_id('for_c')] = 1;
            ampms2_mets[cobra_model.metabolites.get_by_id('co_c')] = 1;
            ampms2 = Reaction('AMPMS3');
            ampms2.add_metabolites(ampms2_mets);
            copp_mets = {};
            copp_mets[cobra_model.metabolites.get_by_id('co_c')] = -1;
            copp_mets[cobra_model.metabolites.get_by_id('co_p')] = 1;
            copp = Reaction('COtpp');
            copp.add_metabolites(copp_mets);
            coex_mets = {};
            coex_mets[cobra_model.metabolites.get_by_id('co_p')] = -1;
            coex_mets[cobra_model.metabolites.get_by_id('co_e')] = 1;
            coex = Reaction('COtex');
            coex.add_metabolites(coex_mets);
            cotrans_mets = {};
            cotrans_mets[cobra_model.metabolites.get_by_id('co_e')] = -1;
            cotrans = Reaction('EX_co_LPAREN_e_RPAREN_');
            cotrans.add_metabolites(cotrans_mets);
            cobra_model.add_reactions([ampms2,copp,coex,cotrans]);
            cobra_model.remove_reactions(['AMPMS2']);
        # Define the model conditions:
        system_boundaries = [x.id for x in cobra_model.reactions if x.boundary == 'system_boundary'];
        for b in system_boundaries:
                cobra_model.reactions.get_by_id(b).lower_bound = 0.0;
                cobra_model.reactions.get_by_id(b).upper_bound = 0.0;
        # Reset demand reactions
        demand = ['DM_4CRSOL',
                'DM_5DRIB',
                'DM_AACALD',
                'DM_AMOB',
                'DM_MTHTHF',
                'DM_OXAM'];
        for d in demand:
                cobra_model.reactions.get_by_id(d).lower_bound = 0.0;
                cobra_model.reactions.get_by_id(d).upper_bound = 1000.0;
        # Change the objective
        update_objective(cobra_model,{'Ec_biomass_iJO1366_WT_53p95M':1.0})
        # Assign KOs

        # Specify media composition (M9 glucose):
        cobra_model.reactions.get_by_id('EX_glc_LPAREN_e_RPAREN_').lower_bound = -10.0;
        cobra_model.reactions.get_by_id('EX_o2_LPAREN_e_RPAREN_').lower_bound = -18.0;
        #uptake = ['EX_cl_LPAREN_e_RPAREN_',
        #            'EX_so4_LPAREN_e_RPAREN_',
        #            'EX_ca2_LPAREN_e_RPAREN_',
        #            'EX_pi_LPAREN_e_RPAREN_',
        #            'EX_fe2_LPAREN_e_RPAREN_',
        #            'EX_cu2_LPAREN_e_RPAREN_',
        #            'EX_zn2_LPAREN_e_RPAREN_',
        #            'EX_cbl1_LPAREN_e_RPAREN_',
        #            'EX_mobd_LPAREN_e_RPAREN_',
        #            'EX_ni2_LPAREN_e_RPAREN_',
        #            'EX_mn2_LPAREN_e_RPAREN_',
        #            'EX_k_LPAREN_e_RPAREN_',
        #            'EX_nh4_LPAREN_e_RPAREN_',
        #            'EX_cobalt2_LPAREN_e_RPAREN_',
        #            'EX_mg2_LPAREN_e_RPAREN_'];
        uptake = ['EX_ca2_LPAREN_e_RPAREN_',
                    'EX_cbl1_LPAREN_e_RPAREN_',
                    'EX_cl_LPAREN_e_RPAREN_',
                    'EX_co2_LPAREN_e_RPAREN_',
                    'EX_cobalt2_LPAREN_e_RPAREN_',
                    'EX_cu2_LPAREN_e_RPAREN_',
                    'EX_fe2_LPAREN_e_RPAREN_',
                    'EX_fe3_LPAREN_e_RPAREN_',
                    'EX_h_LPAREN_e_RPAREN_',
                    'EX_h2o_LPAREN_e_RPAREN_',
                    'EX_k_LPAREN_e_RPAREN_',
                    'EX_mg2_LPAREN_e_RPAREN_',
                    'EX_mn2_LPAREN_e_RPAREN_',
                    'EX_mobd_LPAREN_e_RPAREN_',
                    'EX_na1_LPAREN_e_RPAREN_',
                    'EX_nh4_LPAREN_e_RPAREN_',
                    'EX_ni2_LPAREN_e_RPAREN_',
                    'EX_pi_LPAREN_e_RPAREN_',
                    'EX_sel_LPAREN_e_RPAREN_',
                    'EX_slnt_LPAREN_e_RPAREN_',
                    'EX_so4_LPAREN_e_RPAREN_',
                    'EX_tungs_LPAREN_e_RPAREN_',
                    'EX_zn2_LPAREN_e_RPAREN_'];
        for u in uptake:
            cobra_model.reactions.get_by_id(u).lower_bound = -1000.0;
        # Specify allowed secretion products
        secrete = ['EX_meoh_LPAREN_e_RPAREN_',
                    'EX_5mtr_LPAREN_e_RPAREN_',
                    'EX_h_LPAREN_e_RPAREN_',
                    'EX_co2_LPAREN_e_RPAREN_',
                    'EX_co_LPAREN_e_RPAREN_',
                    'EX_h2o_LPAREN_e_RPAREN_',
                    'EX_ac_LPAREN_e_RPAREN_',
                    'EX_fum_LPAREN_e_RPAREN_',
                    'EX_for_LPAREN_e_RPAREN_',
                    'EX_etoh_LPAREN_e_RPAREN_',
                    'EX_lac_DASH_L_LPAREN_e_RPAREN_',
                    'EX_pyr_LPAREN_e_RPAREN_',
                    'EX_succ_LPAREN_e_RPAREN_'];
        for s in secrete:
            cobra_model.reactions.get_by_id(s).upper_bound = 1000.0;
        # Constrain specific reactions
        noFlux = ['F6PA', 'DHAPT'];
        ammoniaExcess = ['GLUDy']; # PMCID: 196288
        # RNR control (DOI:10.1111/j.1365-2958.2006.05493.x)
        # Dihydroorotate dehydrogenase (PyrD) (DOI:10.1016/S0076-6879(78)51010-0, PMID: 199252, DOI:S0969212602008316 [pii])
        aerobic = ['RNDR1', 'RNDR2', 'RNDR3', 'RNDR4', 'DHORD2', 'ASPO6','LCARR','PFL','FRD2','FRD3']; # see DOI:10.1111/j.1365-2958.2011.07593.x; see DOI:10.1089/ars.2006.8.773 for a review
        anaerobic = ['RNTR1c2', 'RNTR2c2', 'RNTR3c2', 'RNTR4c2', 'DHORD5', 'ASPO5','PDH','SUCDi']; # see DOI:10.1074/jbc.274.44.31291, DOI:10.1128/JB.00440-07
        if anoxic:
            rxnList = noFlux + ammoniaExcess + anaerobic;
            for rxn in rxnList:
                cobra_model.reactions.get_by_id(rxn).lower_bound = 0.0;
                cobra_model.reactions.get_by_id(rxn).upper_bound = 0.0;
        elif oxic:
            rxnList = noFlux + ammoniaExcess + aerobic;
            for rxn in rxnList:
                cobra_model.reactions.get_by_id(rxn).lower_bound = 0.0;
                cobra_model.reactions.get_by_id(rxn).upper_bound = 0.0;
        else:
            rxnList = noFlux + ammoniaExcess;
            for rxn in rxnList:
                cobra_model.reactions.get_by_id(rxn).lower_bound = 0.0;
                cobra_model.reactions.get_by_id(rxn).upper_bound = 0.0;
        # Set the direction for specific reactions
        # Fatty acid biosynthesis: DOI: 10.1016/j.ymben.2010.10.007, PMCID: 372925
        fattyAcidSynthesis = ['ACCOAC', 'ACOATA', 'HACD1', 'HACD2', 'HACD3', 'HACD4', 'HACD5', 'HACD6', 'HACD7', 'HACD8', 'KAS14', 'KAS15', 'MACPD', 'MCOATA', '3OAR100', '3OAR120', '3OAR121', '3OAR140', '3OAR141', '3OAR160', '3OAR161', '3OAR180', '3OAR181', '3OAR40', '3OAR60', '3OAR80']
        fattyAcidOxidation = ['ACACT1r', 'ACACT2r', 'ACACT3r', 'ACACT4r', 'ACACT5r', 'ACACT6r', 'ACACT7r', 'ACACT8r', 'ACOAD1f', 'ACOAD2f', 'ACOAD3f', 'ACOAD4f', 'ACOAD5f', 'ACOAD6f', 'ACOAD7f', 'ACOAD8f', 'CTECOAI6', 'CTECOAI7', 'CTECOAI8', 'ECOAH1', 'ECOAH2', 'ECOAH3', 'ECOAH4', 'ECOAH5', 'ECOAH6', 'ECOAH7', 'ECOAH8']
        ndpk = ['NDPK1','NDPK2','NDPK3','NDPK4','NDPK5','NDPK7','NDPK8'];
        rxnList = fattyAcidSynthesis + fattyAcidOxidation;
        for rxn in rxnList:
            cobra_model.reactions.get_by_id(rxn).lower_bound = 0.0;
            cobra_model.reactions.get_by_id(rxn).upper_bound = 1000.0;
        # convert to irreversible
        if convert2irreversible: convert_to_irreversible(cobra_model);

        return cobra_model;