<jupyter_start><jupyter_text>Last Check-ups  Observing the Default State of the Model<jupyter_code>print model.medium
print model.objective<jupyter_output>Maximize
-1.0*BIOMASS_REACTION_reverse_42726 + 1.0*BIOMASS_REACTION<jupyter_text>Specic growth rate in default conditions (1/h)<jupyter_code>max_growth = model.solve().f
print max_growth
model.reactions.EX_ch4_p.lower_bound = - 18.46
max_growth = model.solve().f
print max_growth<jupyter_output>0.260266144209<jupyter_text>Specic growth rate of E. coli in LB-medium (1/h)<jupyter_code>import math
math.log(2)/0.5<jupyter_output><empty_output><jupyter_text>Doubling time of the model in default conditions (in minutes)<jupyter_code>(math.log(2)/max_growth) * 60<jupyter_output><empty_output><jupyter_text>Double check reaction and formula identity with BiGG Database<jupyter_code>import pandas as pd
def bigg_web_query(url,filename):
    from requests import get
    import json
    
    try: 
        response = get(url)
        response.ok
        
        with open(filename, 'w') as f:
            json.dump(response.json()['results'],f)
    except Exception as e:
        print(e)
    
    return 
url = 'http://bigg.ucsd.edu/api/v2/universal/reactions'
filename = 'bigg_universal_reaction_dump.json'
bigg_web_query(url,filename)
bigg_uni_rxn_dump = pd.read_json('bigg_universal_reaction_dump.json',orient='column')
bigg_uni_rxn_dump_dict = bigg_uni_rxn_dump.set_index('bigg_id').to_dict('index')<jupyter_output><empty_output><jupyter_text>Identify reaction IDs that match BiGG standards and those that don't<jupyter_code>def ident_BiGG_rxn_id_matches(model_reactions,database_dict):
    BiGG_ID_y_n = []
    temp_storage = ''

    for i,rxn in enumerate(model_reactions):
        if not rxn.id.startswith('EX_'):
            if '_' in rxn.id:
                temp_storage = rxn.id.rpartition('_')[0] 
            else:
                temp_storage = rxn.id
            if temp_storage in database_dict.keys():
                BiGG_ID_y_n.append('matched')
                # TODO: Pull all annotations
                # HERE: Sort them into the model
            else:
                BiGG_ID_y_n.append(rxn.id)
    return BiGG_ID_y_n

BiGG_ID_y_n = ident_BiGG_rxn_id_matches(model.reactions,bigg_uni_rxn_dump_dict)

non_bigg_ids = filter(lambda x: x != 'matched', BiGG_ID_y_n)

len(non_bigg_ids)
BiGG_ID_y_n
for rxn in model.reactions:
    if not (rxn.id.startswith('EX_') or rxn.id.startswith('DM_')):
        if rxn.id.endswith('_p'):
            rxn.id = rxn.id.rpartition('_')[0] + 'pp'
        if rxn.id.endswith('_im'):
            rxn.id = rxn.id.rpartition('_')[0] + 'pp'
        if rxn.id.endswith('_c'):
            rxn.id = rxn.id.rpartition('_')[0]
        if rxn.id.endswith('_e'):
            rxn.id = rxn.id.rpartition('_')[0] + 'e'
        if rxn.id.endswith('_Gapfilling'):
            rxn.id = rxn.id.rpartition('_')[0] + '_GAPFILLING'
model.solver.update()
BiGG_ID_y_n = ident_BiGG_rxn_id_matches(model.reactions,bigg_uni_rxn_dump_dict)

non_bigg_ids = filter(lambda x: x != 'matched', BiGG_ID_y_n)

len(non_bigg_ids)
for rxnid in non_bigg_ids:
    if '__' in rxnid:
        model.reactions.get_by_id(rxnid).id = model.reactions.get_by_id(rxnid).id.replace('__','_')
BiGG_ID_y_n = ident_BiGG_rxn_id_matches(model.reactions,bigg_uni_rxn_dump_dict)

non_bigg_ids = filter(lambda x: x != 'matched', BiGG_ID_y_n)

len(non_bigg_ids)
for rxn in non_bigg_ids[2:]:
    if not model.reactions.get_by_id(rxn).reversibility:
        if not rxn.endswith('i'):
            model.reactions.get_by_id(rxn).id = model.reactions.get_by_id(rxn).id + 'i'
BiGG_ID_y_n = ident_BiGG_rxn_id_matches(model.reactions,bigg_uni_rxn_dump_dict)

non_bigg_ids = filter(lambda x: x != 'matched', BiGG_ID_y_n)

len(non_bigg_ids)
model.reactions.ALCD2if.id = 'ALCD2ir'<jupyter_output><empty_output><jupyter_text>'ALCD2ir' is the id in the BiGG Database, but the reaction is irreversible in all three models and hence should not bear the 'r' suffix which implies it is reversible.<jupyter_code>model.reactions.G6PDH2 = 'G6PDH2i'<jupyter_output><empty_output><jupyter_text>'G6PDH2r' is the id in the Universal BiGG Database. It is reversible in many of the Ecoli models, but not in the iND750 yeast model. I am making the decision to keep this one irreversible (in order to keep the model functional as it is right now), but this should probably be looked at later!<jupyter_code>model.reactions.PHI.id = 'AH6PI'
model.reactions.PRAGSi<jupyter_output><empty_output><jupyter_text>'PRAGSr' is the id in the Universal BiGG Database. It is reversible in many of the Ecoli models. I am making the decision to keep this one irreversible (in order to keep the model functional as it is right now), but this should probably be looked at later!<jupyter_code>model.reactions.ADSL2.id = 'ADSL2r'
model.reactions.ADSL1i<jupyter_output><empty_output><jupyter_text>'ADSL1r' is the id in the Universal BiGG Database. It is reversible in many of the Ecoli models. I am making the decision to keep this one irreversible (in order to keep the model functional as it is right now), but this should probably be looked at later!<jupyter_code>model.reactions.AGT.id = 'AGTi'<jupyter_output><empty_output><jupyter_text>This is reversible as a Universal reaction but irreversible in yeast and synechocystis.<jupyter_code>model.reactions.ALAD_Li.id = 'ALAD_L'<jupyter_output><empty_output><jupyter_text>'ALAD_L' is the ID in the Universal BiGG Database, however in each of the 5 models this reaction is actually irreversible (but missing the i in the ID).<jupyter_code>model.reactions.GHMT2.id = 'GHMT2r'
model.reactions.SERD_Li.id = 'SERD_L'
model.reactions.SHK3Di<jupyter_output><empty_output><jupyter_text>'SHK3Dr' in BiGG Universal. It is reversible in many of the Ecoli models. I am making the decision to keep this one irreversible (in order to keep the model functional as it is right now), but this should probably be looked at later!<jupyter_code>model.reactions.DHQDi.id = 'DQDHi'<jupyter_output><empty_output><jupyter_text>I am making the decision to keep this one irreversible (in order to keep the model functional as it is right now), but this should probably be looked at later!<jupyter_code>model.reactions.LDH_Di<jupyter_output><empty_output><jupyter_text>'LDH_D' in BiGG Universal and many of the models and reversible accordingly. Keeping it as it is for now, should be looked at later.<jupyter_code>model.reactions.MICITDi<jupyter_output><empty_output><jupyter_text>'MICITDr' in BiGG Universal and many of the models and reversible accordingly. Keeping it as it is for now, should be looked at later.<jupyter_code>model.reactions.NAD_H2i.id = 'NAD_H2'<jupyter_output><empty_output><jupyter_text>'NAD_H2' in and reversible BiGG Universal, but in the only other model that of Geobacter metallireducens iAF987 it is irreversible. So, I'm keeping it like this.<jupyter_code>model.reactions.FMFRDi.id = 'FMFRDHi'
model.reactions.sMMOi.id = 'SMMOi'
model.reactions.ACP1_FMNi.id = 'ACP1_FMN'<jupyter_output><empty_output><jupyter_text>'ACP1_FMN' in and reversible BiGG Universal, but in the other models it is irreversible. So, I'm keeping it like this, even if it should have an 'i' tag.<jupyter_code>model.reactions.NNATi<jupyter_output><empty_output><jupyter_text>'NNATr' is the id in the Universal BiGG Database. It is reversible in many of models. I am making the decision to keep this one irreversible (in order to keep the model functional as it is right now), but this should probably be looked at later!<jupyter_code>model.reactions.NORppi.id = 'NORZ2pp'<jupyter_output><empty_output><jupyter_text>Similar to NORZpp but using Cytochrome C instead.<jupyter_code>print model.solve().f
model.remove_reactions([model.reactions.PAH])
model.reactions.GAPDH_nadp_hi.id = 'GAPDH_nadp'
model.reactions.VPAMTi<jupyter_output><empty_output><jupyter_text>'VPAMTr' is the id in the Universal BiGG Database. It is reversible in many of models. I am making the decision to keep this one irreversible (in order to keep the model functional as it is right now), but this should probably be looked at later!<jupyter_code>model.reactions.DHORD_NADi<jupyter_output><empty_output><jupyter_text>'DHORD_NAD' is the id in the Universal BiGG Database. It is reversible in many of models. I am making the decision to keep this one irreversible (in order to keep the model functional as it is right now), but this should probably be looked at later!<jupyter_code>model.genes.MCA1660.reactions
model.reactions.BIOMASS_REACTIONi.id = 'BIOMASS_Mcapsulatus'
model.reactions.pMMOppi.id = 'PMMOipp'
model.reactions.NADH5ppi = 'NADH5'
model.reactions.MEOHDH_cytppi.id = 'MEOHDHipp'
model.reactions.MEOHtpp.name = 'Methanol reversible transport via diffusion (periplasm)'
model.reactions.MEOHtpp.id = 'MEOHtrpp'
model.reactions.CH4tpp.id = 'CH4trpp'
model.reactions.FALDDHppi.id = 'FALDDHipp'
model.reactions.CyLCyHOxpp.id = 'CyLCyHORpp'
model.reactions.CYTCBDppi.id = 'CYTCBDipp'
model.reactions.CYTAA3ppi.id = 'CYTAA3ipp'
model.reactions.ATPShppi.id = 'ATPSipp'
model.reactions.ATPSNappi.id = 'ATPSNaipp'
model.reactions.PPAptppi.id = 'PPA3ipp'
model.reactions.NQRppi.id = 'NADHNQR2ipp'
model.reactions.h2otpp.id = 'H2Otpp'
model.reactions.o2tpp.id = 'O2tpp'
model.reactions.FeoBtpp.gene_reaction_rule = 'MCA1097'
model.reactions.DES_9_2_Modifiedi.id = 'DES_9i_Modified'
model.reactions.get_by_id('3OAR150_GAPFILLINGi').id = '3OAR150_Lumped'
model.reactions.get_by_id('3OAR170_GAPFILLINGi').id = '3OAR170_Lumped'
model.reactions.CFACPOA2H_Lumpedi.id = 'CFACPOA2H_Lumped'
model.reactions.OBDHi.id = 'OBDHc'<jupyter_output><empty_output><jupyter_text>This reaction is tagged with a 'c' which it technically shouldn't need. It is also reversible in the Universal reaction Database but not in any of the models uploaded.<jupyter_code>model.reactions.DM_4hba_ci.id = 'DM_4hba_c'
model.reactions.CLPNS_MCi.id = 'CLPNS_MC'
model.reactions.MC_AFAAi.id = 'MC_AFAA'
model.reactions.DM_doxopa_ci.id = 'DM_doxopa_c'
model.reactions.AMOsi.id = 'SAMMOi'
model.reactions.AMOpppi.id = 'PAMMOipp'
model.reactions.NH3pp.id = 'NH3tpp'
model.reactions.HAMpp.id = 'HAMtpp'
model.reactions.NO2pp.id = 'NO2tpp'
model.reactions.CYP460ppi.id = 'CYP460ipp'
model.reactions.HAOppi.id = 'HAORipp'
model.reactions.no3t_omi.id = 'NO3tex'
model.reactions.NO3abcppppi.id = 'NO3abcpp'
model.reactions.NO3t7pppp.id = 'NO3t7pp'
model.reactions.ALAD_L
model.remove_reactions([model.reactions.ALAD_Lyi])
model.reactions.pMMO_dir_couplppi.name = 'particulate Methane Monooxygenase - Direct Coupling' 
model.reactions.pMMO_dir_couplppi.id = 'PMMODCipp'
BiGG_ID_y_n = ident_BiGG_rxn_id_matches(model.reactions,bigg_uni_rxn_dump_dict)

non_bigg_ids = filter(lambda x: x != 'matched', BiGG_ID_y_n)

len(non_bigg_ids)
len([x for x in model.metabolites if x.formula == ''])
[x for x in model.metabolites if x.formula == '']
model.metabolites.dnac_c.formula = 'X'
model.metabolites.dna5mtc_c.formula = 'XCH2'
model.remove_reactions([model.reactions.EX_dna_c,
                        model.reactions.EX_pepd_c,
                        model.reactions.EX_sertrna_sec__c,
                        model.reactions.EX_focytb5_c,
                        model.reactions.EX_ficytb5_c],remove_orphans=True)
model.metabolites.no3_e.formula = 'NO3'
len([x for x in model.metabolites if x.formula == ''])
len(model.reactions)
len(non_bigg_ids)
len(model.genes)
len(model.essential_genes())
len(model.essential_reactions())
from cameo import flux_variability_analysis

cameo_model_fva = model.copy()

for rxn in cameo_model_fva.reactions:
    if rxn.id.startswith("DM_") or  rxn.id.startswith("EX_"):
        rxn.upper_bound = 1000
        rxn.lower_bound = -1000
fva_result = flux_variability_analysis(cameo_model_fva, reactions=cameo_model_fva.reactions)
blocked_reactions = fva_result.data_frame.query('lower_bound == 0 & upper_bound == 0')
len(blocked_reactions)
len([x for x in model.reactions if not x.id.startswith('EX_') and not x.id.startswith('DM_')])
import pytest
model.objective = model.reactions.EX_atp_c
model.reactions.EX_atp_c
name_dict = {}
for rxn in model.reactions:
    if '=' in rxn.name:
        if rxn.id in bigg_uni_rxn_dump_dict:
            if 'name' in bigg_uni_rxn_dump_dict[rxn.id]:
                name_dict[rxn.id] = bigg_uni_rxn_dump_dict[rxn.id]['name']
len(name_dict)
model.reactions.FeoBtpp.id = 'FE2tpp'
for rxn in model.reactions:
    if rxn.id in name_dict:
        print rxn, name_dict[rxn.id]
        model.reactions.get_by_id(rxn.id).name = name_dict[rxn.id]<jupyter_output>FBA: fdp_c <=> dhap_c + g3p_c Fructose-bisphosphate aldolase
ALCD2ir: etoh_c + nad_c --> acald_c + h_c + nadh_c Alcohol dehydrogenase  reverse rxn  acetaldehyde   ethanol 
PDHam1hi: h_c + pyr_c + thmpp_c --> 2ahethmpp_c + co2_c Pyruvate dehydrogenase (acetyl-transferring)
PYK: adp_c + h_c + pep_c --> atp_c + pyr_c Pyruvate kinase
ENO: 2pg_c <=> h2o_c + pep_c Enolase
PGM: 3pg_c <=> 2pg_c Phosphoglycerate mutase
GAPD: g3p_c + nad_c + pi_c --> 13dpg_c + h_c + nadh_c Glyceraldehyde-3-phosphate dehydrogenase
TPI: dhap_c <=> g3p_c Triose-phosphate isomerase
PGIA: f6p_c <=> g6p_A_c Glucose-6-phosphate isomerase (g6p-A)
PGCM: g6p_A_c <=> g1p_c Phosphoglucomutase
PGI: f6p_c <=> g6p_c Glucose-6-phosphate isomerase
G6PI_1: g6p_A_c <=> g6p_c Glucose-6-phosphate isomerase
GLUKA: Glc_aD_c + atp_c <=> adp_c + g6p_A_c + h_c Glucokinase/hexokinase (glc-A)
PGK: 13dpg_c + adp_c --> 3pg_c + atp_c Phosphoglycerate kinase
ACS: ac_c + atp_c + coa_c --> accoa_c + amp_c + ppi_c Acetyl-CoA synthetase
SUCOAS: at[...]<jupyter_text>Reaction Annotations<jupyter_code>filename_ecoli = '/Users/clie/Downloads/iJO1366.xml'
ecoli = load_model(filename_ecoli)
rxns_without_annotations = [rxn for rxn in model.reactions if rxn.annotation == {} and 'EX_' not in rxn.id]
len(rxns_without_annotations)
for rxn in rxns_without_annotations:
    source = ''
    
    if '_GAPFILLING' in rxn.id:
        query_id = rxn.id.split('_')[0]
    else:
        query_id = rxn.id
    
    try:
        source = ecoli.reactions.get_by_id(query_id)
    except:
        print 'Could not find the following reaction ID in iJO2366 {}'.format(query_id)
        
    if source != '' and source.annotation != {}:
            for key in source.annotation:
                if key not in rxn.annotation:
                    rxn.annotation[key] = source.annotation[key]
    else:
        print 'The source annotation is an empty dictionary'

rxns_without_annotations = [rxn for rxn in model.reactions if rxn.annotation == {} and 'EX_' not in rxn.id]
len(rxns_without_annotations)
clamy_file = '/Users/clie/Downloads/iRC1080.xml'
clamydomonas = load_model(clamy_file)
for rxn in rxns_without_annotations:
    source = ''
    
    if '_GAPFILLING' in rxn.id:
        query_id = rxn.id.split('_')[0]
    else:
        query_id = rxn.id
    
    try:
        source = clamydomonas.reactions.get_by_id(query_id)
    except:
        print 'Could not find the following reaction ID in iRC1080 {}'.format(query_id)
        
    if source != '' and source.annotation != {}:
            for key in source.annotation:
                if key not in rxn.annotation:
                    rxn.annotation[key] = source.annotation[key]
    else:
        print 'The source annotation is an empty dictionary'

rxns_without_annotations = [rxn for rxn in model.reactions if rxn.annotation == {} and 'EX_' not in rxn.id]
len(rxns_without_annotations)
synechocystis_file = '/Users/clie/Downloads/iJN678.xml'
synechocystis = load_model(synechocystis_file)
for rxn in rxns_without_annotations:
    source = ''
    
    if '_GAPFILLING' in rxn.id:
        query_id = rxn.id.split('_')[0]
    else:
        query_id = rxn.id
    
    try:
        source = synechocystis.reactions.get_by_id(query_id)
    except:
        print 'Could not find the following reaction ID in iJN678 {}'.format(query_id)
        
    if source != '' and source.annotation != {}:
            for key in source.annotation:
                if key not in rxn.annotation:
                    rxn.annotation[key] = source.annotation[key]
    else:
        print 'The source annotation is an empty dictionary'

rxns_without_annotations = [rxn for rxn in model.reactions if rxn.annotation == {} and 'EX_' not in rxn.id]
len(rxns_without_annotations)
ljungdahlii_file = '/Users/clie/Downloads/iHN637.xml'
ljungdahlii = load_model(ljungdahlii_file)
for rxn in rxns_without_annotations:
    source = ''
    
    if '_GAPFILLING' in rxn.id:
        query_id = rxn.id.split('_')[0]
    else:
        query_id = rxn.id
    
    try:
        source = ljungdahlii.reactions.get_by_id(query_id)
    except:
        print 'Could not find the following reaction ID in iHN637 {}'.format(query_id)
        
    if source != '' and source.annotation != {}:
            for key in source.annotation:
                if key not in rxn.annotation:
                    rxn.annotation[key] = source.annotation[key]
    else:
        print 'The source annotation is an empty dictionary'

rxns_without_annotations = [rxn for rxn in model.reactions if rxn.annotation == {} and 'EX_' not in rxn.id]
len(rxns_without_annotations)
model.reactions.CH4trpp.annotation = {u'metanetx.reaction': u'MNXR1138',u'biocyc': u'META:TRANS-RXN0-526'}
model.reactions.DES_9i_Modified.annotation = {u'metanetx.reaction': u'MNXR68672',u'brenda':u'1.14.19.1'}
model.reactions.DES_9i_Modified.id = 'DESAT14_Modified'
model.reactions.CLPNS_MC.annotation = {u'metanetx.reaction': u'MNXR68550'}
model.reactions.PPTGS_MC.annotation = {u'metanetx.reaction': u'MNXR69779'}
model.reactions.OBDHc.annotation = {u'metanetx.reaction': u'MNXR3937',u'biocyc': u'META:RXN-7790',u'rhea':[u'33223', u'33224', u'33225', u'33226']}
model.reactions.UREASE_GAPFILLING.annotation = {u'metanetx.reaction': u'MNXR5299',u'upa': [u'UPA:UCR00774', u'UPA:UER00371'], u'brenda' : u'6.3.4.6',u'kegg.reaction': u'R00774', u'rhea':[u'20896',u'20897',u'20898',u'20899']}
model.reactions.NH3tpp.annotation = {u'metanetx.reaction': u'MNXR82602'}
model.reactions.PFK_ppi.annotation = {u'metanetx.reaction': u'MNXR83628', u'brenda': u'172.16.31.10',u'kegg.reaction':u'R00764'}
model.reactions.PFK_3_ppi.annotation = {u'metanetx.reaction': u'MNXR4174', u'brenda': u'172.16.17.32',u'kegg.reaction':u'R01843', u'biocyc':u'META:RXN0-6541',u'rhea':[u'31443', u'31444', u'31445', u'31446']}
rxns_without_annotations = [rxn for rxn in model.reactions if rxn.annotation == {} and 'EX_' not in rxn.id]
len(rxns_without_annotations)
rxns_without_annotations<jupyter_output><empty_output><jupyter_text>Metabolite Annotations<jupyter_code>mets_without_annotations = [met for met in model.metabolites if met.annotation == {}]
len(mets_without_annotations)
mets_without_annotations
model.metabolites.get_by_id('2ombzl_c')
ecoli.metabolites.get_by_id('2ombzl_c').annotation
for met in mets_without_annotations:
    source = ''
    
    query_id = met.id
    
    try:
        source = ecoli.metabolites.get_by_id(query_id)
    except:
        print 'Could not find the following metabolite ID in iJO2366 {}'.format(query_id)
        
    if source != '' and source.annotation != {}:
            for key in source.annotation:
                if key not in met.annotation:
                    met.annotation[key] = source.annotation[key]
    else:
        print 'The source annotation is an empty dictionary'

mets_without_annotations = [met for met in model.metabolites if met.annotation == {}]
len(mets_without_annotations)
for met in mets_without_annotations:
    source = ''
    
    query_id = met.id
    
    try:
        source = ljungdahlii.metabolites.get_by_id(query_id)
    except:
        print 'Could not find the following metabolite ID in iRC1080 {}'.format(query_id)
        
    if source != '' and source.annotation != {}:
            for key in source.annotation:
                if key not in met.annotation:
                    met.annotation[key] = source.annotation[key]
    else:
        print 'The source annotation is an empty dictionary'

mets_without_annotations = [met for met in model.metabolites if met.annotation == {}]
len(mets_without_annotations)
model.metabolites.pme_c.id = 'pme_MC_c'
model.metabolites.pdme_c.id = 'pdme_MC_c'
subtilis_file = '/Users/clie/Downloads/iYO844.xml'
subtilis = load_model(subtilis_file)
mets_without_annotations = [met for met in model.metabolites if met.annotation == {}]
len(mets_without_annotations)
for met in mets_without_annotations:
    source = ''
    
    query_id = met.id
    
    try:
        source = subtilis.metabolites.get_by_id(query_id)
    except:
        print 'Could not find the following metabolite ID in iYO844 {}'.format(query_id)
        
    if source != '' and source.annotation != {}:
            for key in source.annotation:
                if key not in met.annotation:
                    met.annotation[key] = source.annotation[key]
    else:
        print 'The source annotation is an empty dictionary'

mets_without_annotations = [met for met in model.metabolites if met.annotation == {}]
len(mets_without_annotations)
model.metabolites.cpoa2h_c.annotation = {u'inchi': u'InChI=1S/C17H32O2/c1-2-3-4-8-11-15-14-16(15)12-9-6-5-7-10-13-17(18)19/h15-16H,2-14H2,1H3,(H,18,19)'}
model.metabolites.get_by_id('1agpgafa_c').id = '1agpgafa_MC_c'
model.metabolites.get_by_id('4hba_c').annotation = {u'bigg.metabolite': u'4hba',
 u'biocyc': u'META:4-HYDROXY-BENZYL-ALCOHOL',
 u'chebi': u'CHEBI:67410',
 u'kegg.compound': u'C17467',
 u'metanetx.chemical': u'MNXM107505',
 u'seed.compound': [u'cpd15378', u'cpd17595']}
model.metabolites.doxopa_c.annotation = {u'metanetx.chemical': u'MNXM148580'}<jupyter_output><empty_output><jupyter_text>Add proper transport reactions for relevant metabolites<jupyter_code>model.change_objective(model.reactions.BIOMASS_Mcapsulatus)
model.medium
solution = model.solve()
model.reactions.EX_rdmbzi_c.id = 'DM_rdmbzi_c'
relevant_exchanges = [rxn for rxn in model.reactions if rxn.id.startswith('EX_') and abs(rxn.flux) != 0]
relevant_exchanges.pop(4)
len(relevant_exchanges)
exchanges_to_be_removed = []

for rxn in model.reactions:
    if rxn.id.startswith('EX_') and rxn not in relevant_exchanges:
        exchanges_to_be_removed.append(rxn)
        
model.remove_reactions(exchanges_to_be_removed)
solution = model.solve()
[rxn for rxn in model.reactions if rxn.id.startswith('EX_')]
from cameo.util import TimeMachine
from cameo.exceptions import Infeasible
def test_autonomous_metabolite_production(model):
    with TimeMachine() as tm:
        producable_from_nothing = []    
        for rxn in model.reactions:
            
            if rxn.id.startswith("DM_") or  rxn.id.startswith("EX_"):
                rxn.change_bounds(0,0,tm)
                
        for met in model.metabolites:
            
            try:
                ex_rxn = model.reactions.get_by_id('EX_' + met.id)
                ex_rxn.change_bounds(0,1000,tm)
                model.objective = ex_rxn
            except:
                model.add_demand(met,'TestDM_',tm)
                ex_rxn = model.reactions.get_by_id('TestDM_' + met.id)
                ex_rxn.change_bounds(0,1000,tm)
                model.objective = ex_rxn
                
            with pytest.raises(Infeasible):
                sol = model.solve()
                if sol.f != 0:
                    producable_from_nothing.append(met.id)
        
        return producable_from_nothing
                
producable_from_nothing = test_autonomous_metabolite_production(model)
len(producable_from_nothing)
import cobra

target_filename_json = relative_directory + '/Reconstructions/MethylococcusModel12.json'
target_filename_xml = relative_directory + '/Reconstructions/MethylococcusModel12.xml'
cobra.io.write_sbml_model(model, target_filename_xml, use_fbc_package=True)
cobra.io.save_json_model(model, target_filename_json,pretty = True)
import escher
        
maps = escher.Builder(
                    model=model,
                    map_name = 'Methylococcus capsulatus genome-scale metabolic model',
                    map_json='/Users/clie/Desktop/EFPro2/Reconstructions/Metabolic Map/16UpdateDuplicateAndParallelReactions.json',
                    show_gene_reaction_rules=True,
                    use_3d_transform = True
                    )

maps.set_reaction_scale([ { 'type': 'min', 'color': 'rgb(235,89,162)', 'size': 12 },
   { 'type': 'median', 'color': 'rgb(200,200,200)', 'size': 20 },
   { 'type': 'max', 'color': 'rgb(255,255,109)', 'size': 25 } ])
maps.display_in_browser()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup