### Define and Execute Community Model (Example 1) Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity_1.ipynb Loads a model and media from KBase, then uses MSCommunity to simulate, gap-fill, constrain, and visualize the community. This example computes and visualizes interactions. ```python # import the model # from modelseedpy.fbapkg import kbasemediapkg modelInfo_2 = ["CMM_iAH991V2_iML1515.kb",40576] mediaInfo_2 = ["Btheta_Ecoli_minimal_media",40576] model = kbase.get_from_ws(modelInfo_2[0],modelInfo_2[1]) media = kbase.get_from_ws(mediaInfo_2[0],mediaInfo_2[1]) # kmp = kbasemediapkg.KBaseMediaPkg(self.model) # kmp.build_package(media) # simulate and visualize the model cfba = MSCommunity(model) cfba.drain_fluxes(media) cfba.gapfill(media) cfba.constrain(media) solution = cfba.run() cfba.compute_interactions(solution) cfba.visualize() ``` -------------------------------- ### String Partitioning Example Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/bigg.ipynb Demonstrates the use of the rpartition method for splitting strings. ```python "omg_ggg_pl".rpartition('_') ``` -------------------------------- ### ATP Gapfilling Example Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Model Reconstruction/ATPGapfilling.ipynb This example shows how to configure and execute ATP gapfilling for a metabolic model. It involves defining media conditions and specifying thresholds for gapfilling objectives. ```python from modelseedpy.core.msmodel import MSModel from modelseedpy.core.msmedia import MSMedia from modelseedpy.core.gapfilling import Gapfilling # Assuming 'model' is an initialized MSModel object # model = MSModel.from_json('path/to/your/model.json') # Define media conditions and thresholds media_conditions = { 'e_coli_core': { 'media': MSMedia.from_dict({ 'name': 'e_coli_core', 'elements': {'C': 1, 'H': 2, 'O': 1, 'N': 1}, 'compartments': {'c': -1.0} }), 'is_max_threshold': True, 'threshold': 1e-05, 'objective': 'ATPM_c0' } } # Perform gapfilling # gapfilling_results = Gapfilling.gapfill( # model, # media_conditions=media_conditions, # # Other gapfilling parameters can be added here # ) # Example of expected output structure (actual execution not shown) result = [ {'media': '', 'is_max_threshold': True, 'threshold': 1e-05, 'objective': 'ATPM_c0'}, {'media': '', 'is_max_threshold': True, 'threshold': 3.3, 'objective': 'ATPM_c0'} ] ``` -------------------------------- ### Define and Execute Community Model (Example 3) Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity_1.ipynb Loads a different model and media from KBase, then performs community simulation and visualization. This example involves a community with three species. ```python # import the model # from modelseedpy.fbapkg import kbasemediapkg modelInfo_2 = ['electrosynth_comnty.mdl.gf.2021',93204] mediaInfo_2 = ["CO2_minimal",93204] model = kbase.get_from_ws(modelInfo_2[0],modelInfo_2[1]) media = kbase.get_from_ws(mediaInfo_2[0],mediaInfo_2[1]) # kmp = kbasemediapkg.KBaseMediaPkg(self.model) # kmp.build_package(media) # simulate and visualize the model cfba = MSCommunity(model) cfba.drain_fluxes(media) cfba.gapfill(media) cfba.constrain(media) solution = cfba.run() cfba.compute_interactions(solution) cfba.visualize() ``` -------------------------------- ### Define and Execute Community Model (Example 2) Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity_1.ipynb Similar to the first example, but includes an additional parameter `msdb_path_for_fullthermo` in the `constrain` method. This may affect thermodynamic calculations. ```python # import the model # from modelseedpy.fbapkg import kbasemediapkg modelInfo_2 = ["CMM_iAH991V2_iML1515.kb",40576] mediaInfo_2 = ["Btheta_Ecoli_minimal_media",40576] model = kbase.get_from_ws(modelInfo_2[0],modelInfo_2[1]) media = kbase.get_from_ws(mediaInfo_2[0],mediaInfo_2[1]) # kmp = kbasemediapkg.KBaseMediaPkg(self.model) # kmp.build_package(media) # simulate and visualize the model cfba = MSCommunity(model) cfba.drain_fluxes(media) cfba.gapfill(media) cfba.constrain(media, msdb_path_for_fullthermo = ftp_path, verbose = False) solution = cfba.run() cfba.compute_interactions(solution) cfba.visualize() ``` -------------------------------- ### Install ModelSEEDpy (GitHub Dev Build) Source: https://github.com/modelseed/modelseedpy/blob/dev/README.rst Clone the GitHub repository for the latest development version and install it locally. ```bash git clone https://github.com/ModelSEED/ModelSEEDpy.git cd path/to/modelseedpy pip install . ``` -------------------------------- ### Flux Fitting Parameters Example Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/fbapkg/fluxfitting_api.md Example of a default parameter dictionary for FluxFittingPkg. The target_flux sub-dictionary can specify fluxes for reaction IDs. ```json { "target_flux":{}, "totalflux":0, "set_objective":1, "default_rescaling":0.1, "rescale_vfit_by_flux":true } ``` -------------------------------- ### Initialize KBaseAPI Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/SteadyCom_final.ipynb Initializes the KBaseAPI client for interacting with KBase services. Ensure you have cobrakbase installed. ```python import cobrakbase from reframed import * kbase = cobrakbase.KBaseAPI() ``` -------------------------------- ### Initialize KBase API and Load Template Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Model Reconstruction/ATPGapfilling.ipynb Initializes the KBaseAPI and loads a core Archaea template from the KBase workspace. Ensure the cobrakbase library is installed. ```python import cobrakbase kbase = cobrakbase.KBaseAPI() template4 = kbase.get_from_ws('CoreArchaeaTemplateMPA_FIX', 82183) ``` -------------------------------- ### Initialize KBaseAPI and Load Model/Media Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/MSCommunity_thermo.ipynb Sets up the environment by configuring the home directory, initializing the KBaseAPI with a token, and loading a model and media from the KBase workspace. ```python # import kbase import os local_cobrakbase_path = os.path.join('C:', 'Users', 'Andrew Freiburger','Documents','Argonne','cobrakbase') os.environ["HOME"] = local_cobrakbase_path import cobrakbase token = 'MIXOUVGIFOUPQD2KSH6DQ5ARKDLBARCL' kbase = cobrakbase.KBaseAPI(token) model = kbase.get_from_ws("CMM_iAH991V2_iML1515.kb",40576) media = kbase.get_from_ws("Btheta_Ecoli_minimal_media",40576) %matplotlib inline ``` -------------------------------- ### Get Exchange Reactions Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/msmodelutils_api.md Retrieve a list of all exchange reactions in the model. Exchange reactions are identified by IDs starting with 'EX_'. ```python exchange_reactions = msutil.exchange_list() ``` -------------------------------- ### Get external metabolites from a model Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/SteadyCom_Example.ipynb Retrieves a list of external metabolites for a given model. This example indicates that the model has no metabolites defined as external. ```python model1.get_external_metabolites() ``` -------------------------------- ### Initialize KBaseMediaPkg Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/fbapkg/kbasemedia_api.md Instantiate the KBaseMediaPkg class with a CobraKBase model. ```python from modelseedpy.fbapkg import KBaseMediaPkg kbmedia = KBaseMediaPkg(model) ``` -------------------------------- ### Example: Computing molecular weight Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Flux Analysis/FBA Model functions.ipynb Demonstrates how to use the `compute_molecular_weight` function to get the formula weight of a metabolite. It also prints the chemical formula of the metabolite for reference. ```python model = cobra.io.load_json_model("iML1515.json") print('formula', model.metabolites.get_by_id('octapb_c').formula) print(compute_molecular_weight(model, 'octapb_c')) ``` -------------------------------- ### Configure and Run FBA Packages Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Flux Analysis/MetaboFBAExample.ipynb Sets the objective, initializes and builds Gapfilling, KBaseMedia, and MetaboFBA packages. Optimizes the model and saves the LP file. ```python FBAHelper.set_objective_from_target_reaction(model,"bio1") copy_model = cobra.io.json.from_json(cobra.io.json.to_json(model)) gfp = GapfillingPkg(copy_model) gfp.build_package({ "default_gapfill_models":[pickaxe_model] "default_gapfill_templates":[template], "gapfill_all_indecies_with_default_templates":1, "minimum_obj":0.01, "set_objective":0 }) kmp = KBaseMediaPkg(copy_model) kmp.build_package(media) mfp = MetaboFBanaPkg(copy_model) mfp.build_package({"peaks":metabolome.build_peaks_data(),"set_objective":1}) sol=model.optimize() with open('MetaboFBA.lp', 'w') as out: out.write(str(model.solver)) ``` -------------------------------- ### Initialize KBase API and Environment Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/MSCommunity_uptake.ipynb Sets up the KBase API connection and environment variables. Requires a KBase token for authentication. ```python # import kbase import os # local_cobrakbase_path = 'C:\Users\Andrew Freiburger\Dropbox\My PC (DESKTOP-M302P50)\Documents\UVic Civil Engineering\Internships\Agronne\cobrakbase' # os.environ["HOME"] = local_cobrakbase_path import cobrakbase token = 'JOSNYJGASTV5BGELWQTUSATE4TNHZ66U' kbase = cobrakbase.KBaseAPI(token) ftp_path = '../../../ModelSEEDDatabase' # import cFBA %run ../../modelseedpy/core/mscommunity.py %matplotlib inline ``` -------------------------------- ### Get exchange reactions from a test model Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/SteadyCom_Example.ipynb Attempts to retrieve exchange reactions from the created test model. This example shows that the textbook model might not have explicitly defined exchange reactions in this format. ```python test_model.get_exchange_reactions() ``` -------------------------------- ### Install pyeda wheel on Windows Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/index.md For Windows users, install the 'pyeda' module by downloading the appropriate wheel and installing it via pip. ```bash cd path/to/pyeda/wheel pip install pyeda_wheel_name.whl ``` -------------------------------- ### Setup KBase API and Load Model Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Flux Analysis/FullThermodynamicsExample.ipynb Initializes the KBase API with a token and loads a metabolic model from the KBase workspace. Sets the solver for the model. ```python # define the environment path import os local_cobrakbase_path = os.path.join('C:', 'Users', 'Andrew Freiburger','Documents','Argonne','cobrakbase') os.environ["HOME"] = local_cobrakbase_path # import the models import cobrakbase token = 'WE6CHYRDTJSGOHFIDGPE7WYFT6PRPXJL' kbase_api = cobrakbase.KBaseAPI(token) #Put the path to ModelSEEDpy on your machine here # import sys # sys.path.append("/Users/chenry/code/ModelSEEDpy") #import modelseedpy.fbapkg from modelseedpy import KBaseMediaPkg, FullThermoPkg from modelseedpy import FBAHelper model = kbase_api.get_from_ws("E_iAH991V2",40576) model.solver = 'glpk' kmp = KBaseMediaPkg(model) kmp.build_package(None) FBAHelper.set_objective_from_target_reaction(model,"bio1") sol=model.optimize() model.summary() ``` -------------------------------- ### Setting up ModelSEEDpy Packages and Model Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Flux Analysis/FlexibleBiomass.ipynb This snippet demonstrates the initialization of ModelSEEDpy packages and loading a model from KBase. It includes setting the solver and applying element uptake and media constraints before configuring the flexible biomass package. ```python import cobra from cobra import Model, Reaction, Metabolite import pandas as pd import cplex import optlang import math import json import sys from cobra.flux_analysis.parsimonious import pfba import cobrakbase sys.path.append("/Users/chenry/code/ModelSEEDpy") #import modelseedpy.fbapkg from modelseedpy import FlexibleBiomassPkg, ElementUptakePkg, KBaseMediaPkg kbase_api = cobrakbase.KBaseAPI(token = "5YAOMNFB7XOEKBKHRHJB4AIZSQ2EJGA5") model = kbase_api.get_from_ws("C4_Calvin_Zmays_Model",25427) #model = kbase_api.get_from_ws("E_iML1515.kb",40576) model.solver = 'optlang-cplex' #Applying uptake limit to total carbon uptake by model eup = ElementUptakePkg(model) eup.build_package({"C":60}) #Applying constraints based on KBase media #media = kbase_api.get_from_ws("Btheta_Ecoli_minimal_media",40576) kmp = KBaseMediaPkg(model) #kmp.build_package(media) kmp.build_package(None) #Applying flexible biomass constraints fbp = FlexibleBiomassPkg(model) fbp.build_package({"bio_rxn_id":"bio1","use_rna_class":[-0.75,0.75], "use_dna_class":[-0.75,0.75], "use_protein_class":[-0.1052,-0.1052], "use_energy_class":[-0.1,0.1]}) #Setting the objective to biomass biomass_objective = model.problem.Objective( 1 * model.reactions.bio1.flux_expression, direction='max') model.objective = biomass_objective #Printing LP file with open('FlexibleBiomass.lp', 'w') as out: out.write(str(model.solver)) #Solving sol=model.optimize() model.summary() ``` -------------------------------- ### Install ModelSEEDpy (Latest Stable) Source: https://github.com/modelseed/modelseedpy/blob/dev/README.rst Install the latest stable version of modelseedpy using pip. ```bash pip install modelseedpy ``` -------------------------------- ### Importing Libraries and Setting Up KBase API Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/MSCommunity_kinetics.ipynb Initializes the KBase API connection using a local path and token. Ensure the cobrakbase library is installed and a valid token is provided. ```python import os local_cobrakbase_path = 'C:\\Users\\Andrew Freiburger\\Dropbox\\My PC (DESKTOP-M302P50)\\Documents\\UVic Civil Engineering\\Internships\\Agronne\\cobrakbase' os.environ["HOME"] = local_cobrakbase_path import cobrakbase token = 'JOSNYJGASTV5BGELWQTUSATE4TNHZ66U' kbase = cobrakbase.KBaseAPI(token) import networkx from matplotlib import pyplot ftp_path = '../../../ModelSEEDDatabase' # import cFBA %run ../../modelseedpy/core/mscommunity.py %matplotlib inline ``` -------------------------------- ### Commented Out CommunityFBA Example Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/CommunityFBA3.ipynb This is a commented-out example of running the communityFBA function, likely for testing or demonstration purposes. It includes model and media information. ```python # modelInfo_7 = ["Hot_Lake_seven.mdl.v2",94153] # mediaInfo_7 = ["HotLakeMedia",94153] # communityFBA(modelInfo_7,mediaInfo_7,2100) ``` -------------------------------- ### Initialize SteadyCom with Environment Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/SteadyCom_Example.ipynb Creates a community solution using SteadyCom, incorporating an environment defined by `Environment.complete`. This allows for simulating community metabolism under specific environmental conditions. ```python env = Environment.complete(community.merged_model, inplace=False) communitySolution2 = SteadyCom(community,env) print(communitySolution2) ``` -------------------------------- ### Load model and media from KBase and set up FBA Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Flux Analysis/FBAExampleNotebook.ipynb Loads a model and media from the KBase workspace, builds the media package, sets the objective function, and optimizes the model. Requires a KBaseAPI client and valid workspace IDs. ```python kbase_api = cobrakbase.KBaseAPI() model = kbase_api.get_from_ws("E_iML1515.kb",40576) media = kbase_api.get_from_ws("Btheta_Ecoli_minimal_media",40576) pkgmgr = MSPackageManager.get_pkg_mgr(model) pkgmgr.getpkg("KBaseMediaPkg").build_package(media) FBAHelper.set_objective_from_target_reaction(model, "bio1") solution=model.optimize() model.summary() ``` -------------------------------- ### Running dFBA simulation with initial conditions Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Flux Analysis/dFBA.ipynb This example demonstrates how to execute a dFBA simulation using the dFBAPkg. It requires the model object, the path to the ModelSEED Database, initial metabolite concentrations, total simulation time, and the time step. The simulation results (concentrations and fluxes) are returned. ```python %run ../../modelseedpy/fbapkg/dfbapkg.py # define in the initial conditions modelseed_db_path = os.path.join('..', '..', '..', 'ModelSEEDDatabase') initial_concentrations_M = { "cpd00002":200, "cpd00008":100 } total_time = 5 timestep = 1 # execute the package dfba = dFBAPkg(model1, modelseed_db_path, verbose = False) conc, fluxes = dfba.simulate('model_kinetics.json', initial_concentrations_M, total_time, timestep, labeled_plots = False, export = False) ``` -------------------------------- ### Initialize MSCommunity, Gapfill, Run Simulation, and Compute Interactions Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/MSCommunity_thermo.ipynb Demonstrates the core workflow for community modeling: initializing MSCommunity, performing gapfilling with specified media, running a simulation, and computing inter-species interactions. Note that gapfilling may fail. ```python %%time # import the model # from modelseedpy.fbapkg import kbasemediapkg from pandas import set_option set_option('display.max_rows', None) %run ../../../modelseedpy/community/mscommunity.py # kmp = kbasemediapkg.KBaseMediaPkg(self.model) # kmp.build_package(media) # simulate and visualize the model mscom = MSCommunity(model) mscom.gapfill(media) %time solution = mscom.run(media) mscom.compute_interactions(solution, export_directory = '') ``` -------------------------------- ### Kinetics Data Structure Example Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/community/dfbapkg_api.md Example JSON structure for providing kinetics data to the simulate() method. It includes rate laws, initial concentrations, and metabolite IDs for specific reactions. ```json { "R_3OAS140": { "source_1": { "substituted_rate_law": "(68.0*A*B)/(50.0*0.34*C+360.0*B+0.34*A+A*B*C)", "initial_concentrations_M": { "A": 0.0200, "C": 0.022, "B": 0.0014 }, "met_id": { "A": "cpd11468", "B": "cpd00067", "C": "cpd11492" } } }, "rxn2": { "source_1": { "substituted_rate_law": "(A*B)/(50.0*0.34*C+3*B+0.34*A+C)", "initial_concentrations_M": { "A": 0.0200, "C": 0.022, "B": 0.0012 }, "met_id": { "A": "cpd11468", "B": "cpd00011", "C": "cpd11492" } } } } ``` -------------------------------- ### Initialize Model and Media Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/MSCommunity_uptake.ipynb Loads the community model and media from the KBase workspace. This is a prerequisite for running community flux balance analysis. ```python modelInfo = ["electro.community.edited.v2",93204] mediaInfo = ["CO2_minimal",93204] model = kbase.get_from_ws(modelInfo_2[0],modelInfo_2[1]) media = kbase.get_from_ws(mediaInfo_2[0],mediaInfo_2[1]) uptake = {} # evaluate the influence of kinetic constraints over a range of coefficients plots = [] for element in ['C', 'P']: uptake[element] = 60 banner = '\n{}\n{} uptake limit: {}'.format('='*50, element, uptake[element]) print(banner) model = kbase.get_from_ws(modelInfo_2[0],modelInfo_2[1]) media = kbase.get_from_ws(mediaInfo_2[0],mediaInfo_2[1]) cfba = MSCommunity(model) cfba.drain_fluxes(media) cfba.gapfill(media) cfba.constrain(media, element_uptake_limit = uptake) solution = cfba.run() cfba.compute_interactions(solution) graph, pos, labels = cfba.visualize() plots.append((graph, pos, labels, banner)) ``` -------------------------------- ### Get Compartment Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/mstemplate_api.md Retrieve the interesting compartment character for the reaction. ```python comptment = rxn_template.compartment() ``` -------------------------------- ### Initialize KBaseAPI and Environment Variables Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Flux Analysis/chemostat_dFBA.ipynb Sets up the environment by defining the KBase API token and the local COBRApy path. This is necessary for interacting with KBase services and loading models. ```python from pprint import pprint # define the environment path import os local_cobrakbase_path = os.path.join('C:', 'Users', 'Andrew Freiburger','Documents','Argonne','cobrakbase') os.environ["HOME"] = local_cobrakbase_path # import the models from cobrakbase import KBaseAPI, Metabolite, Reaction, Model token = 'WE6CHYRDTJSGOHFIDGPE7WYFT6PRPXJL' kbase_api = KBaseAPI(token) ``` -------------------------------- ### Get Gene Type Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Model Reconstruction/Genomes.ipynb Determine the type of the retrieved gene object. ```python type(gene) ``` -------------------------------- ### Initialize KBaseAPI and Load Model Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/CommunityFBA3.ipynb Initializes the KBaseAPI client with a token and loads a model from the KBase workspace. Sets the solver to 'optlang-cplex'. ```python import cobra from cobra import Model, Reaction, Metabolite import pandas as pd import cplex import optlang import math import json import sys import re import cProfile from optlang.symbolics import Zero, add import cobra.util.solver as sutil from cobra.flux_analysis.parsimonious import pfba from IPython.core.display import HTML import os os.environ["HOME"] = 'C:\\Users\\Andrew Freiburger\\Dropbox\\My PC (DESKTOP-M302P50)\\Documents\\UVic Civil Engineering\\Internships\\Agronne\\cobrakbase' import cobrakbase token = 'I6WL7MAW5Z4QO3OQ62YUR6HJM6RAUFHE' kbase = cobrakbase.KBaseAPI(token) sys.path.append("/Users/chandhanavoleti/Dropbox/My PC (DESKTOP-M302P50)/Documents/UVic Civil Engineering/Internships/Agronne/ModelSEEDpy/ModelSEEDpy") #import modelseedpy.fbapkg from modelseedpy import ElementUptakePkg, SimpleThermoPkg, ReactionUsePkg, BilevelPkg, CommKineticPkg, KBaseMediaPkg from collections import Counter from numpy import unique from itertools import combinations import networkx as nx import matplotlib.pyplot as plt import matplotlib.pyplot as pl2 ``` -------------------------------- ### Initialize KBase client Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/KBase/Workspace.ipynb Initialize the KBaseAPI client. You can use a default token or provide your own login token. ```python kbase = cobrakbase.KBaseAPI() # or kbase = cobrakbase.KBaseAPI(YOUR_LOGIN_TOKEN) ``` -------------------------------- ### Get media constraints Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/KBase/FBAModel.ipynb Retrieves the media constraints from a Media object. ```python media.get_media_constraints() ``` -------------------------------- ### Define and Execute Community Model Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity_1.ipynb This snippet shows the basic steps to load a model and media, then simulate and visualize the community. It requires importing MSCommunity and potentially KBaseMediaPkg. ```python # import the model %run ../../modelseedpy/core/mscommunity.py # from modelseedpy.fbapkg import kbasemediapkg modelInfo_2 = ["Hot_Lake_seven.mdl",93544] mediaInfo_2 = ["HotLakeMedia",93544] model = kbase.get_from_ws(modelInfo_2[0],modelInfo_2[1]) media = kbase.get_from_ws(mediaInfo_2[0],mediaInfo_2[1]) # kmp = kbasemediapkg.KBaseMediaPkg(self.model) # kmp.build_package(media) # simulate and visualize the model cfba = MSCommunity(model) cfba.drain_fluxes(media) cfba.gapfill(media) cfba.constrain(media) solution = cfba.run() cfba.compute_interactions(solution) cfba.visualize() ``` -------------------------------- ### Get NewModelTemplateComplex Data Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/mstemplate_api.md Retrieve the dictionary representation of the NewModelTemplateComplex content. ```python complex_data = complex_template.get_data() ``` -------------------------------- ### Initialize GapfillingHelper Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/gapfillinghelper_api.md Instantiate the GapfillingHelper with optional blacklisted reactions and auto-sink reactions for biomass growth. ```python gfhelper = GapfillingHelper(blacklist = [], auto_sink = ["cpd02701_c", "cpd11416_c0", "cpd15302_c"]) ``` -------------------------------- ### Get NewModelTemplateRole Data Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/mstemplate_api.md Retrieve the dictionary representation of the NewModelTemplateRole content. ```python role_template_dict = new_model_tmp.get_data() ``` -------------------------------- ### Get Stoichiometry Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/mstemplate_api.md Retrieve a dictionary of stoichiometric coefficients for each metabolite in the reaction. ```python rxn_stoichiometry = rxn_template.cstoichiometry() ``` -------------------------------- ### Get Elemental Masses Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/fbahelper_api.md Retrieves a dictionary containing the masses of all elements. ```python elementmasses = fbahelper.elemental_mass() ``` -------------------------------- ### Initialize Community and SteadyCom Solver Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/SteadyCom_Example.ipynb Sets up a community object with multiple models and initializes the SteadyCom solver for analyzing community metabolism. The output shows community growth and individual member contributions. ```python community = Community('electro.community',[model1, model2, model3]) merged_model = community.merged_model communitySolution = SteadyCom(community) print(communitySolution) ``` -------------------------------- ### Get media object from KBase Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/KBase/FBAModel.ipynb Retrieves a media object from the KBase workspace. ```python media = kbase.get_from_ws('Carbon-D-Glucose', ws) print(type(media)) ``` -------------------------------- ### Get Template Data Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/mstemplate_api.md Retrieve the entire template's data as a dictionary. ```python template_data = template.get_data() ``` -------------------------------- ### Get Roles Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/mstemplate_api.md Retrieve the set of all unique roles present in all complexes of the reaction. ```python roles = rxn_template.get_roles() ``` -------------------------------- ### Simulate and Visualize a Community Model Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/MSCommunity_uptake.ipynb This snippet demonstrates loading a community model and minimal media from KBase, then performing simulation and visualization. It includes drain flux calculation, gapfilling, constraining the model, running the simulation, computing interactions, and visualizing the results. Requires MSCommunity library and KBase access. ```python modelInfo = ["electro.community.edited.v2",93204] mediaInfo = ["CO2_minimal",93204] model = kbase.get_from_ws(modelInfo[0],modelInfo[1]) media = kbase.get_from_ws(mediaInfo[0],mediaInfo[1]) # simulate and visualize the model cfba = MSCommunity(model) cfba.drain_fluxes(media) cfba.gapfill(media) cfba.constrain(media) solution = cfba.run() cfba.compute_interactions(solution) cfba.visualize() ``` -------------------------------- ### Define and Execute Community Model (CO2 Minimal Media with Full Thermo) Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/MSCommunity_thermo.ipynb Loads a community model and minimal CO2 media from KBase, simulates its behavior, gap-fills, constrains it with media and full thermodynamic data, and visualizes the interactions. ```python # import the model # from modelseedpy.fbapkg import kbasemediapkg modelInfo_2 = ['electrosynth_comnty.mdl.gf.2021',93204] mediaInfo_2 = ["CO2_minimal",93204] model = kbase.get_from_ws(modelInfo_2[0],modelInfo_2[1]) media = kbase.get_from_ws(mediaInfo_2[0],mediaInfo_2[1]) # kmp = kbasemediapkg.KBaseMediaPkg(self.model) # kmp.build_package(media) # simulate and visualize the model mscom = MSCommunity(model) mscom.drain_fluxes(media) mscom.gapfill(media) mscom.constrain(media, msdb_path_for_fullthermo = ftp_path, verbose = False) solution = mscom.run() mscom.compute_interactions(solution) mscom.visualize() ``` -------------------------------- ### Get Default Media ID Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/fbahelper_api.md Returns the default media ID, which is 'Complete'. ```python media_id = fbahelper.medianame() ``` -------------------------------- ### Get Media from BiologPlate Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/biology_api.md Generate the media for a specific well ID from the BiologPlate. ```python bioplate.get_media(well_id) ``` -------------------------------- ### Define and Execute Community Model (Basic) Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/MSCommunity_thermo.ipynb Loads a community model and media from KBase, simulates its behavior, gap-fills, constrains it with media, and visualizes the interactions. This is a basic execution without full thermodynamic data. ```python # import the model # from modelseedpy.fbapkg import kbasemediapkg modelInfo_2 = ["CMM_iAH991V2_iML1515.kb",40576] mediaInfo_2 = ["Btheta_Ecoli_minimal_media",40576] model = kbase.get_from_ws(modelInfo_2[0],modelInfo_2[1]) media = kbase.get_from_ws(mediaInfo_2[0],mediaInfo_2[1]) # kmp = kbasemediapkg.KBaseMediaPkg(self.model) # kmp.build_package(media) # simulate and visualize the model mscom = MSCommunity(model) mscom.drain_fluxes(media) mscom.gapfill(media) mscom.constrain(media, msdb_path_for_fullthermo = ftp_path, verbose = False) solution = mscom.run() mscom.compute_interactions(solution) mscom.visualize() ``` -------------------------------- ### Example simulate() JSON Configuration Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/source/community/dfbapkg_api.md This JSON structure represents a configuration for the simulate() function, detailing kinetic parameters, initial concentrations, and metadata for a specific enzyme reaction. ```json { "2-Oxogluterate dehydrogenase": { "55199": { "RateLaw": "Vmax*S/(Km+S)", "initial_concentrations_M": { "S": 1.6e-08 }, "metadata": { "Buffer": "[50 mm Mops, 8 mm TCEP, 50 mm Mops, 8 mm TCEP]", "Enzyme Variant": "wildtype", "KineticMechanismType": "Michaelis-Menten", "Organism": "Pisum sativum", "Pathway": null, "Product": "NADH;H+;Oxidized N-alpha-(benzyloxycarbonyl)-N-omega-(D,L-1,2-dithiolane-3-pentanoyl)-L-lysine", "Publication": "Neuburger M, Polidori AM, Pi\u00e8tre E, Faure M, Jourdain A, Bourguignon J, Pucci B, Douce R: Interaction between the lipoamide-containing H-protein and the lipoamide dehydrogenase (L-protein) of the glycine decarboxylase multienzyme system. 1. Biochemical studies., Eur J Biochem 2000 (267) , 2882-9", "Temperature": "30.0", "annotations": { "ECNumber": "1.8.1.4", "KeggReactionID": null, "PubMedID": 10806385.0, "SabioReactionID": 13969 }, "pH": "7.5", "reaction_string": " <-> Nicotinamide adenine dinucleotide-reduced + H+" }, "substituted_parameters": { "Km": { "comment": "-", "deviat.": "10", "end val.": "-", "species": "N-alpha-(benzyloxycarbonyl)-N-omega-(D,L-1,2-dithiolane-3-pentanoyl)-L-lysine", "start val.": "170.0", "type": "Km", "unit": "\u00b5M" }, "Vmax": { "comment": "-", "deviat.": "7", "end val.": "-", "species": "-", "start val.": "90.0", "type": "Vmax", "unit": "nmol/min" } }, "substituted_rate_law": "1.5000000000000002e-09*S/(0.00016999999999999999+S)", "variables_molar": { "Km": "0.00016999999999999999", "Vmax": "1.5000000000000002e-09" }, "variables_name": { "Km": "N-alpha-(benzyloxycarbonyl)-N-omega-(D,L-1,2-dithiolane-3-pentanoyl)-L-lysine", "S": "N-alpha-(benzyloxycarbonyl)-N-omega-(D,L-1,2-dithiolane-3-pentanoyl)-L-lysine", "Vmax": "-" } } } } ``` -------------------------------- ### Get Seed Reaction Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/bigg.ipynb Retrieves a specific reaction from the ModelSEED database using its ID. ```python rxn = modelseed_local.get_seed_reaction('rxn05937') ``` -------------------------------- ### Load model and perform gapfilling Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Others/ATPSafeGapfillingTest.ipynb Loads a model from KBase, sets up media and objectives, performs gapfilling using MSBuilder, and compares the objective values before and after gapfilling. ```python kbase_api = cobrakbase.KBaseAPI() model = kbase_api.get_from_ws("",93541) MMMedia = model = kbase_api.get_from_ws("Carbon-D-Glucose","KBaseMedia") FBAHelper.set_objective_from_target_reaction(model, "bio2") pkgmgr = MSPackageManager.get_pkg_mgr(model) pkgmgr.getpkg("KBaseMediaPkg").build_package(MMMedia) solution=model.optimize() tests = [{"media":MMMedia,"is_max_threshold": True,"threshold":1.2*solution.objective_value}] template = kbase_api.get_from_ws("GramNegModelTemplateV3","NewKBaseModelTemplates") gfmodel = MSBuilder.gapfill_model(model,"bio1",template,MMMedia,tests) FBAHelper.set_objective_from_target_reaction(gfmodel, "bio2") gfpkgmgr = MSPackageManager.get_pkg_mgr(gfmodel) gfpkgmgr.getpkg("KBaseMediaPkg").build_package(MMMedia) gfsolution=gfmodel.optimize() print(str(solution.objective_value)+" vs "+str(gfsolution.objective_value)) ``` -------------------------------- ### Get Reaction Data Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/mstemplate_api.md Retrieve a dictionary containing all the data associated with the MSTemplateReaction object. ```python rxn_template_dict = rxn_template.get_data() ``` -------------------------------- ### Get Complex Roles Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/mstemplate_api.md Create a dictionary mapping each complex to its set of associated roles. ```python roles = rxn_template.get_complex_roles() ``` -------------------------------- ### Build KBaseMediaPkg Package Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/fbapkg/kbasemedia_api.md Build the package by specifying media or parameters to govern flux bounds of exchange reactions. Default uptake and excretion values can be overridden. ```python kbmedia.build_package(media_or_parameters, default_uptake=None, default_excretion=None) ``` -------------------------------- ### GapfillingHelper Initialization Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/source/core/gapfillinghelper_api.md Initializes the GapfillingHelper with optional blacklisted reactions and auto-sink reactions for biomass growth. ```APIDOC ## GapfillingHelper() ### Description Initializes the GapfillingHelper with optional blacklisted reactions and auto-sink reactions for biomass growth. ### Parameters - **blacklist** (list) - Optional - The collection of IDs for reactions that will not be examined during gapfilling. - **auto_sink** (list) - Optional - The collection of IDs for reactions that represent biomass growth. ``` -------------------------------- ### Importing ModelSeedPy helpers Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Model Reconstruction/genome_scale_build_model.ipynb Imports helper functions for getting classification and template data from ModelSeedPy. ```python from modelseedpy import MSBuilder from modelseedpy.helpers import get_template, get_classifier ``` -------------------------------- ### Simulate model growth with various media Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Others/TestATPMethod.ipynb Loads a list of media, builds packages for each media using the PackageManager, and optimizes the model to determine growth rates. This helps in understanding model behavior under different nutritional conditions. ```python media_names = [ "Glucose.aerobic", "Acetate.aerobic", "Ethanol.aerobic", "Pyruvate.aerobic", "Glycerol.aerobic", "Fumarate.aerobic", "Succinate.aerobic", "Oxoglutarate.aerobic", "L-Lactate.aerobic", "D-Lactate.aerobic", "Formate.aerobic", "Glucose.anaerobic", "Acetate.anaerobic", "Ethanol.anaerobic", "Pyruatve.anaerobic", "Glycerol.anaerobic", "Fumarate.anaerobic", "Succinate.anaerobic", "Oxoglutarate.anaerobic", "Formate-Nitrite", "Formate-Nitrate", "Glucose-DMSO", "Glucose-TMAO", "Pyruvate-DMSO", "Pyruvate-DMSO", "Pyruvate-Nitric.oxide", "Pyruvate-Nitrite", "Pyruvate-Nitrate", "Pyruvate-Sulfate", "Pyruvate-Sulfite"#, #"Hydrogenotrophic", #"control.media", #"Auxotrphic" ] media_list = [] for name in media_names: media_list.append(kbase_api.get_from_ws(name,94026)) pkgmgr = MSPackageManager.get_pkg_mgr(model) model.objective = "bio2" for media in media_list: pkgmgr.getpkg("KBaseMediaPkg").build_package(media) solution = model.optimize() print(media.id+簋str(solution.objective_value)) ``` -------------------------------- ### Simulate and Visualize a Microbial Community Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/MSCommunity_uptake.ipynb Loads a model and media from KBase, initializes MSCommunity, and runs a simulation. It then computes and visualizes the community interactions. ```python modelInfo_2 = ["CMM_iAH991V2_iML1515.kb",40576] mediaInfo_2 = ["Btheta_Ecoli_minimal_media",40576] model = kbase.get_from_ws(modelInfo_2[0],modelInfo_2[1]) media = kbase.get_from_ws(mediaInfo_2[0],mediaInfo_2[1]) # simulate and visualize the model cfba = MSCommunity(model) cfba.drain_fluxes(media) cfba.gapfill(media) cfba.constrain(media) solution = cfba.run() cfba.compute_interactions(solution) cfba.visualize() ``` -------------------------------- ### Import helper functions Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Others/download_templates.ipynb Import specific helper functions for getting classifiers, templates, and files. ```python from modelseedpy.helpers import get_classifier, get_template, get_file ``` -------------------------------- ### Define and Execute Community Model (CO2 Minimal Media) Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/MSCommunity/MSCommunity_thermo.ipynb Loads a community model and minimal CO2 media from KBase, simulates its behavior, gap-fills, constrains it with media, and visualizes the interactions. This is a basic execution without full thermodynamic data. ```python # import the model # from modelseedpy.fbapkg import kbasemediapkg modelInfo_2 = ['electrosynth_comnty.mdl.gf.2021',93204] mediaInfo_2 = ["CO2_minimal",93204] model = kbase.get_from_ws(modelInfo_2[0],modelInfo_2[1]) media = kbase.get_from_ws(mediaInfo_2[0],mediaInfo_2[1]) # kmp = kbasemediapkg.KBaseMediaPkg(self.model) # kmp.build_package(media) # simulate and visualize the model mscom = MSCommunity(model) mscom.drain_fluxes(media) mscom.gapfill(media) mscom.constrain(media) solution = mscom.run() mscom.compute_interactions(solution) mscom.visualize() ``` -------------------------------- ### Get HTML Representation of Template Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/mstemplate_api.md Generate an HTML string representation of the template's content. ```python template_html = template.__repr_html__() ``` -------------------------------- ### KBaseMediaPkg Initialization Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/fbapkg/kbasemedia_api.md Initializes the KBaseMediaPkg class with a CobraKBase model. This class is used to constrain exchange reactions and media compounds. ```APIDOC ## KBaseMediaPkg() ### Description Initializes the KBaseMediaPkg class with a CobraKBase model. This class is used to constrain exchange reactions and media compounds. ### Parameters * **model** (cobra.core.model.Model) - The CobraKBase model that will be edited. The conversion from standard COBRA models to CobraKBase models is facilitated by the cobrakbase package. ``` -------------------------------- ### Get Complex from Roles Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/mstemplate_api.md Generate a complex object based on a provided list of complex roles. ```python complex = template.get_complex_from_roles(roles) ``` -------------------------------- ### Build and initialize Gapfilling Package Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Model Reconstruction/Gapfilling.ipynb Initializes the GapfillingPkg with a COBRA model and builds the package using a specified template. ```python from modelseedpy import FBAHelper from modelseedpy import GapfillingPkg pkg_gf = GapfillingPkg(model_core) pkg_gf.build(template_gramneg) ``` -------------------------------- ### Add and Get Complexes Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/mstemplate_api.md Add a list of complexes to the reaction and retrieve the current list of complexes. ```python rxn_template.add_complexes(complex_list) complexes = rxn_template.get_complexes() ``` -------------------------------- ### Implement FullThermo Package with Constraints Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Flux Analysis/FBAPkg_tests.ipynb Initializes the FullThermoPkg with a model and builds the package with specified constraints. Exports the constrained LP file. ```python from modelseedpy.fbapkg import fullthermopkg # implement FullThermo with dgbin constraints ftp = fullthermopkg.FullThermoPkg(model) ftp.build_package({'modelseed_path':modelseed_db_path}) # export the constrained LP file with open('FullThermo.lp', 'w') as out: out.write(str(model.solver)) ``` -------------------------------- ### Get Template Compound Details Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/core/mstemplate_api.md Retrieve the compound object, name, or formula associated with the MSTemplateSpecies. ```python template_compound = met_template.compound() compound_name = met_template.name() compound_formula = met_template.formula() ``` -------------------------------- ### Set custom media and run FBA Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/KBase/FBAModel.ipynb Assigns a retrieved KBase Media object to the model's medium and runs FBA. ```python cobra_model.medium = media cobra_model.summary() ``` -------------------------------- ### Import necessary libraries Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Others/TestATPMethod.ipynb Imports required libraries for model building and manipulation. Ensure cobrakbase is installed. ```python import sys import time sys.path.append("/Users/chenry/code/ModelSEEDpy") import cobra import cobrakbase from modelseedpy import MSATPCorrection,MSEditorAPI,MSEquation,MSBuilder,MSPackageManager ``` -------------------------------- ### Loading KBase models and applying constraints Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Community Modeling/AimeeCommunityFBA2.ipynb Loads a community model and media from KBase, sets the solver, and uses MSBuilder to gapfill the model based on a template and media. ```python kbase_api = cobrakbase.KBaseAPI() model = kbase_api.get_from_ws("Cjaponicus_Ecoli_Community",92637) model.solver = 'optlang-cplex' #Applying constraints based on KBase media media = kbase_api.get_from_ws("ChitinM9Media",91858) template = kbase_api.get_from_ws("GramNegModelTemplateV3","NewKBaseModelTemplates") model = MSBuilder.gapfill_model(model,"bio1",template,media) ``` -------------------------------- ### Default Parameters for FlexibleBiomassPkg Source: https://github.com/modelseed/modelseedpy/blob/dev/docs/source/fbapkg/flexiblebiomass_api.md Example of default parameters that can be used to configure the FlexibleBiomassPkg. These can be customized in the 'parameters' argument. ```json { "flex_coefficient":0.75, "use_rna_class":[-0.75,0.75], "use_dna_class":[-0.75,0.75], "use_protein_class":[-0.75,0.75], "use_energy_class":[-0.1,0.1] } ``` -------------------------------- ### Count Genome Features Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Model Reconstruction/Genomes.ipynb Get the total number of features (genes) within the loaded genome object. ```python len(genome.features) ``` -------------------------------- ### Get the Classifier Model Source: https://github.com/modelseed/modelseedpy/blob/dev/examples/Model Reconstruction/Classifier.ipynb Import and retrieve the genome classifier model. This model is used to classify genomes. ```python from modelseedpy.helpers import get_classifier ``` ```python classifier = get_classifier('knn_filter') ```