### Install MICOM Package Source: https://github.com/micom-dev/micom/blob/main/README.rst Install the MICOM package using pip. Ensure you have Python and pip installed. ```bash pip install micom ``` -------------------------------- ### Register Gurobi Installation Source: https://github.com/micom-dev/micom/blob/main/docs/source/installing.ipynb Registers your Gurobi installation using your license key. Replace 'YOUR-LICENSE-KEY' with your actual Gurobi license key. ```bash grbgetkey YOUR-LICENSE-KEY ``` -------------------------------- ### Generate Example Data DataFrame Source: https://github.com/micom-dev/micom/blob/main/docs/source/high_level.ipynb Use this snippet to generate a sample DataFrame for understanding MICOM's input format requirements. This example data includes multiple E. coli species with varying abundances across different samples. ```python from micom.data import test_data data = test_data() data ``` -------------------------------- ### Define Initial Candidate Medium Source: https://github.com/micom-dev/micom/blob/main/docs/source/high_level.ipynb Create a pandas DataFrame to define the initial components and their import fluxes for a candidate growth medium. This is the starting point for the medium completion workflow. ```python import pandas as pd candidate_medium = pd.DataFrame({"reaction": ["EX_glc__D_m", "EX_o2_m"], "flux": [10, 20]}) candidate_medium ``` -------------------------------- ### Install Gurobi Solver with Conda Source: https://github.com/micom-dev/micom/blob/main/docs/source/installing.ipynb Installs the Gurobi solver using conda. This command adds the Gurobi package to your environment. ```bash conda install -c gurobi gurobi ``` -------------------------------- ### Install CPLEX Python Package Source: https://github.com/micom-dev/micom/blob/main/docs/source/installing.ipynb Installs the CPLEX Python package. Ensure to substitute '3.10' with your Python version and 'x86-64_linux' with your system's corresponding folder. ```bash pip install ibm/cplex/python/3.10/x86-64_linux ``` -------------------------------- ### MICOM Data Format Example Source: https://github.com/micom-dev/micom/blob/main/docs/source/_static/mes.html This snippet shows a sample of the data format used in MICOM, likely for metabolic compounds. It includes identifiers, quantities, and chemical information. ```text (8)5(10)4(9)2-7/h1,3-5,7-10H,2H2/t3-,4+,5+/m0/s1",C00181,,MNXM734573,135191.0,,SBO:0000247,cpd00154,CHEBI:53455,,EX_xyl_D(e)\nxyl_D[e],S_SRR5936020,15.74468085106383,aldehydo-D-xylose,150.12990000000002,5,0,xyl__D,XYLOSE,HMDB0000098,"InChI=1S/C5H10O5/c6-1-3(8)5(10)4(9)2-7/h1,3-5,7-10H,2H2/t3-,4+,5+/m0/s1",C00181,,MNXM734573,135191.0,,SBO:0000247,cpd00154,CHEBI:53455,,EX_xyl_D(e)\nzn2[e],S_SRR5935769,0.0,Zinc,65.409,0,0,zn2,ZN%2b2,HMDB0001303,InChI=1S/Zn/q+2,C00038,,MNXM729215,32051.0,,SBO:0000247,cpd00034,CHEBI:29105,,EX_zn2(e)\nzn2[e],S_SRR5935812,1.935483870967742,Zinc,65.409,0,0,zn2,ZN%2b2,HMDB0001303,InChI=1S/Zn/q+2,C00038,,MNXM729215,32051.0,,SBO:0000247,cpd00034,CHEBI:29105,,EX_zn2(e)\nzn2[e],S_SRR5935816,0.0,Zinc,65.409,0,0,zn2,ZN%2b2,HMDB0001303,InChI=1S/Zn/q+2,C00038,,MNXM729215,32051.0,,SBO:0000247,cpd00034,CHEBI:29105,,EX_zn2(e)\nnzn2[e],S_SRR5935843,3.7333333333333334,Zinc,65.409,0,0,zn2,ZN%2b2,HMDB0001303,InChI=1S/Zn/q+2,C00038,,MNXM729215,32051.0,,SBO:0000247,cpd00034,CHEBI:29105,,EX_zn2(e)\nnzn2[e],S_SRR5935924,0.0,Zinc,65.409,0,0,zn2,ZN%2b2,HMDB0001303,InChI=1S/Zn/q+2,C00038,,MNXM729215,32051.0,,SBO:0000247,cpd00034,CHEBI:29105,,EX_zn2(e)\nnzn2[e],S_SRR5935968,0.0,Zinc,65.409,0,0,zn2,ZN%2b2,HMDB0001303,InChI=1S/Zn/q+2,C00038,,MNXM729215,32051.0,,SBO:0000247,cpd00034,CHEBI:29105,,EX_zn2(e)\nnzn2[e],S_SRR5935971,0.0,Zinc,65.409,0,0,zn2,ZN%2b2,HMDB0001303,InChI=1S/Zn/q+2,C00038,,MNXM729215,32051.0,,SBO:0000247,cpd00034,CHEBI:29105,,EX_zn2(e)\nnzn2[e],S_SRR5935976,0.0,Zinc,65.409,0,0,zn2,ZN%2b2,HMDB0001303,InChI=1S/Zn/q+2,C00038,,MNXM729215,32051.0,,SBO:0000247,cpd00034,CHEBI:29105,,EX_zn2(e)\nnzn2[e],S_SRR5936000,0.0,Zinc,65.409,0,0,zn2,ZN%2b2,HMDB0001303,InChI=1S/Zn/q+2,C00038,,MNXM729215,32051.0,,SBO:0000247,cpd00034,CHEBI:29105,,EX_zn2(e)\nnzn2[e],S_SRR5936020,36.16438356164384,Zinc,65.409,0,0,zn2,ZN%2b2,HMDB0001303,InChI=1S/Zn/q+2,C00038,,MNXM729215,32051.0,,SBO:0000247,cpd00034,CHEBI:29105,,EX_zn2(e)\n ``` -------------------------------- ### Get Individual Taxa Growth Rates Source: https://github.com/micom-dev/micom/blob/main/docs/source/growth_fluxes.ipynb Optimizes the community model and retrieves individual growth rates and other information for each taxon in the community. ```python sol = com.optimize() sol.members ``` -------------------------------- ### Generate Example Taxonomy Source: https://github.com/micom-dev/micom/blob/main/docs/source/community.ipynb Generates a sample Pandas DataFrame representing a microbial taxonomy, which can be used as a specification for building a community model. This DataFrame includes organism IDs, genus, species, reaction and metabolite counts, and file paths to individual models. ```python from micom.data import test_taxonomy taxonomy = test_taxonomy() taxonomy ``` -------------------------------- ### Embedding Vega-Lite Visualizations with vegaEmbed Source: https://github.com/micom-dev/micom/blob/main/micom/data/templates/tests.html Embeds Vega-Lite specifications into HTML elements using the vegaEmbed library. This example shows how to embed both the association statistics chart and the flux analysis plots, ensuring they scale correctly. ```javascript // Embed the visualization in the container with id `vis` vegaEmbed("#stats", statSpec, {renderer: "svg"}).then(function(r) { svg = document.querySelector("#stats svg"); svg.setAttribute("width", "100%"); svg.setAttribute("height", "auto"); }); vegaEmbed("#vis", vlSpec, {renderer: "svg"}).then(function(r) { svg = document.querySelector("#vis svg"); svg.setAttribute("width", "100%"); svg.setAttribute("height", "auto"); }); ``` -------------------------------- ### Prepare AGORA Taxonomy with File Paths Source: https://github.com/micom-dev/micom/blob/main/docs/source/community.ipynb Loads a copy of the AGORA taxonomy and prepends a directory path to the 'file' column. This is useful when the AGORA models are downloaded to a specific folder, allowing `micom` to locate the individual model files. ```python from micom.data import agora tax = agora.copy() tax.file = "models/" + tax.file # assuming you have downloaded the AGORA models to the "models" folder tax.head() ``` -------------------------------- ### Apply Calculated Minimal Medium to Community Source: https://github.com/micom-dev/micom/blob/main/docs/source/media.ipynb Demonstrates how to use the output of `minimal_medium` to set the community's growth medium and then recalculate the cooperative tradeoff, showing the resulting growth rate. ```python med = minimal_medium(com, 0.8, min_growth=0.8) com.medium = med com.cooperative_tradeoff() ``` -------------------------------- ### Load Test Data Source: https://github.com/micom-dev/micom/blob/main/docs/source/viz.ipynb Loads test results and tradeoff data for visualization examples. This is a prerequisite for most visualization functions. ```python import micom.data as mmd results = mmd.test_results() tradeoff = mmd.test_tradeoff() ``` -------------------------------- ### Complete Community Medium with MICOM Source: https://github.com/micom-dev/micom/blob/main/docs/source/high_level.ipynb Use the `complete_community_medium` function to automatically add essential substrates to a candidate medium. This ensures all taxa in the community can grow at a specified minimum rate, by adding the smallest possible overall flux. ```python from micom.workflows import complete_community_medium medium = complete_community_medium(manifest, model_folder="models", medium=candidate_medium, community_growth=0.1, min_growth=0.01, max_import=10, threads=2) medium ``` -------------------------------- ### Construct a Micom Community Source: https://github.com/micom-dev/micom/blob/main/docs/source/community.ipynb This snippet shows how to initialize a new Micom Community object. It may take some time for large models. ```python %time com = Community(taxonomy) ``` -------------------------------- ### Run Growth Simulation with MICOM Source: https://github.com/micom-dev/micom/blob/main/docs/source/high_level.ipynb Simulates microbial community growth using the `grow` workflow. This function requires a manifest, model folder, growth medium, and a tradeoff parameter to balance community and individual growth rates. It also allows specifying the number of threads for computation. ```python from micom.workflows import grow res = grow(manifest, model_folder="models", medium=medium, tradeoff=0.5, threads=2) ``` -------------------------------- ### Get Relative Change in Growth Rates After Knockout Source: https://github.com/micom-dev/micom/blob/main/docs/source/taxa_knockouts.ipynb Calculates the relative change in growth rates ((new - old) / old) for each taxon after performing knockouts. This provides a normalized view of the impact of knockouts. ```python com.knockout_taxa(fraction=1.0, method="relative change") ``` -------------------------------- ### Build Community Models Source: https://github.com/micom-dev/micom/blob/main/docs/source/high_level.ipynb Use the `build` workflow to construct community models from an abundance table and a model database. Specify the output folder, database, abundance cutoff, and number of threads for parallel processing. ```python from micom.data import test_db from micom.workflows import build manifest = build(data, out_folder="models", model_db=test_db, cutoff=0.0001, threads=2) ``` -------------------------------- ### Get Raw Growth Rates After Knockout Source: https://github.com/micom-dev/micom/blob/main/docs/source/taxa_knockouts.ipynb Retrieves the absolute growth rates of all taxa after performing knockouts. This method is useful for observing the direct impact on growth without considering the initial growth rates. ```python com.knockout_taxa(fraction=1.0, method="raw") ``` -------------------------------- ### Load Micom Community from Pickle Source: https://github.com/micom-dev/micom/blob/main/docs/source/community.ipynb Loads a previously saved Micom Community object from a pickle file. This is significantly faster than constructing the community from scratch. ```python from micom import load_pickle %time com = load_pickle("community.pickle") ``` -------------------------------- ### Run Tradeoff Analysis Source: https://github.com/micom-dev/micom/blob/main/docs/source/high_level.ipynb Executes growth simulations with various tradeoff values to analyze their impact on microbial community growth rates. Requires manifest, model folder, and medium as inputs. ```python from micom.workflows import tradeoff tradeoff_rates = tradeoff(manifest, model_folder="models", medium=medium, threads=2) tradeoff_rates.head() ``` -------------------------------- ### Initialize Community and Load Test Data Source: https://github.com/micom-dev/micom/blob/main/docs/source/media.ipynb Loads test taxonomy data and initializes a MICOM Community object. This is a prerequisite for most media calculations. ```python from micom import Community, data tax = data.test_taxonomy() com = Community(tax) ``` -------------------------------- ### Model Manifest Structure Source: https://github.com/micom-dev/micom/blob/main/docs/source/high_level.ipynb The `build` workflow returns a model manifest DataFrame containing information about each built community model, including reaction and metabolite counts, file paths, and matching metrics. ```python manifest ``` -------------------------------- ### Access Workflow Results Source: https://github.com/micom-dev/micom/blob/main/docs/source/workflows.ipynb Demonstrates how to access the results of a specific sample from the list of results generated by the Micom workflow. Each entry in the results list corresponds to the analysis of one sample. ```python results[2] ``` -------------------------------- ### Load Qiime 2 Growth Medium Source: https://github.com/micom-dev/micom/blob/main/docs/source/high_level.ipynb Loads a growth medium from a Qiime 2 Artifact format into a pandas DataFrame. This DataFrame specifies available metabolites and their flux bounds for microbial consumption. ```python from micom.data import test_medium from micom.qiime_formats import load_qiime_medium medium = load_qiime_medium(test_medium) medium ``` -------------------------------- ### Calculate Minimal Medium Including Exports Source: https://github.com/micom-dev/micom/blob/main/docs/source/media.ipynb Calculates the minimal medium and also identifies the active exports (metabolites produced by the community) under minimal growth conditions. Exports are indicated by a negative sign. ```python med = minimal_medium(com, sol.growth_rate, min_growth=rates, exports=True) med ``` -------------------------------- ### Load Sample Data from File Source: https://github.com/micom-dev/micom/blob/main/docs/source/_static/niche.html Loads sample data from a CSV file, including sample IDs, taxa, and T-SNE coordinates. This data is intended for visualization or further analysis. ```python files = {'reduced': 'sample_id,taxon,TSNE 1,TSNE 2\nS_SRR5935769,s__Akkermansia_muciniphila,5.730705,-11.592141\nS_SRR5935769,s__Alistipes_finegoldii,-43.98386,3.6126847\nS_SRR5935769,s__Alistipes_onderdonkii,-56.89094,-2.7260766\nS_SRR5935769,s__Anaerobutyricum_hallii,-7.0742984,-23.116106\nS_SRR5935769,s__Anaerostipes_hadrus,21.849394,-33.667564\nS_SRR5935769,s__Anaerotruncus_colihominis,-57.00815,61.676617\nS_SRR5935769,s__'} ``` -------------------------------- ### Vega-Lite Specification for Growth Rates Source: https://github.com/micom-dev/micom/blob/main/docs/source/_static/growth_rates.html Defines the visualization specification for plotting growth rates. It includes data, width, height, and data mapping for taxa, sample IDs, abundance, and growth rates. ```javascript var vlSpec = { $schema: "https://vega.github.io/schema/vega-lite/v5.json", width: 300, height: 1386, data: { values: [{"taxon":"s__Bacteroides_eggerthii","sample_id":"S_SRR5935816","abundance":0.0003113611,"growth_rate":0.0007540915},{"taxon":"s__Bacteroides_fragilis","sample_id":"S_SRR5935816","abundance":0.0398182415,"growth_rate":0.0955593971},{"taxon":"s__Bacteroides_ovatus","sample_id":"S_SRR5935816","abundance":0.0950289465,"growth_rate":0.2286333443},{"taxon":"s__Bacteroides_sp__D2","sample_id":"S_SRR5935816","abundance":0.0022450836,"growth_rate":0.006430709},{"taxon":"s__Bacteroides_thetaiotaomicron","sample_id":"S_SRR5935816","abundance":0.0032087427,"growth_rate":0.0077894324},{"taxon":"s__Bacteroides_xylanisolvens","sample_id":"S_SRR5935816","abundance":0.0460614159,"growth_rate":0.1104574194},{"taxon":"s__Bifidobacterium_bifidum","sample_id":"S_SRR5935816","abundance":0.0002310174,"growth_rate":0.0003194578},{"taxon":"s__Bifidobacterium_longum","sample_id":"S_SRR5935816","abundance":0.0002839977,"growth_rate":0.0006938618},{"taxon":"s__Clostridium_sp__M62_1","sample_id":"S_SRR5935816","abundance":0.0001950373,"growth_rate":0.0005634066},{"taxon":"s__Collinsella_aerofaciens","sample_id":"S_SRR5935816","abundance":0.0001176046,"growth_rate":0.0001605042},{"taxon":"s__Coprococcus_comes","sample_id":"S_SRR5935816","abundance":0.0001832769,"growth_rate":0.000453079},{"taxon":"s__Dorea_formicigenerans","sample_id":"S_SRR5935816","abundance":0.0001455503,"growth_rate":0.0002462155},{"taxon":"s__Enterocloster_bolteae","sample_id":"S_SRR5935816","abundance":0.0001365844,"growth_rate":0.0000988244},{"taxon":"s__Escherichia_coli","sample_id":"S_SRR5935816","abundance":0.0002782921,"growth_rate":0.0006943899},{"taxon":"s__Eubacterium_ventriosum","sample_id":"S_SRR5935816","abundance":0.0003027445,"growth_rate":0.0012809917},{"taxon":"s__Haemophilus_parainfluenzae","sample_id":"S_SRR5935816","abundance":0.0007987798,"growth_rate":0.0011335148},{"taxon":"s__Parabacteroides_distasonis","sample_id":"S_SRR5935816","abundance":0.010659402,"growth_rate":0.0258553637},{"taxon":"s__Parabacteroides_merdae","sample_id":"S_SRR5935816","abundance":0.0025806642,"growth_rate":0.006259961},{"taxon":"s__Phocaeicola_coprophilus","sample_id":"S_SRR5935816","abundance":0.0005444744,"growth_rate":0.0035064815},{"taxon":"s__Phocaeicola_vulgatus","sample_id":"S_SRR5935816","abundance":0.3151953651,"growth_rate":0.7606023431},{"taxon":"s__Prevotella_intermedia","sample_id":"S_SRR5935816","abundance":0.0040670234,"growth_rate":0.0047182583},{"taxon":"s__Roseburia_intestinalis","sample_id":"S_SRR5935816","abundance":0.0577730881,"growth_rate":0.1377952636},{"taxon":"s___Ruminococcus___gnavus","sample_id":"S_SRR5935816","abundance":0.0003551426,"growth_rate":0.0014915829},{"taxon":"s___Ruminococcus___torques","sample_id":"S_SRR5935816","abundance":0.000226942,"growth_rate":0.0005509711},{"taxon":"s__Anaerobutyricum_hallii","sample_id":"S_SRR5935924","abundance":0.0017537138,"growth_rate":0.0602206031},{"taxon":"s__Bacteroides_eggerthii","sample_id":"S_SRR5935924","abundance":0.0068767033,"growth_rate":0.2361277484},{"taxon":"s__Bacteroides_fragilis","sample_id":"S_SRR5935924","abundance":0.0117412197,"growth_rate":0.4033517707},{"taxon":"s__Bacteroides_ovatus","sample_id":"S_SRR5935924","abundance":0.0697168267,"growth_rate":2.3952618607},{"taxon":"s__Bacteroides_sp__D2","sample_id":"S_SRR5935924","abundance":0.0018539581,"growth_rate":0.0636459875},{"taxon":"s__Bacteroides_thetaiotaomicron","sample_id":"S_SRR5935924","abundance":0.0047384389,"growth_rate":0.162810575},{"taxon":"s__Bacteroides_xylanisolvens","sample_id":"S_SRR5935924","abundance":0.0077414157,"growth_rate":0.2659428879},{"taxon":"s__Bifidobacterium_adolescentis","sample_id":"S_SRR5935924","abundance":0.000293713,"growth_rate":0.0100959787},{"taxon":"s__Bifidobacterium_dentium","sample_id":"S_SRR5935924","abundance":0.0003050853,"growth_rate":0.0005598202},{"taxon":"s__Bifidobacterium_longum","sample_id":"S_SRR5935924","abundance":0.0002880971,"growth_rate":0.0099024388},{"taxon":"s__Collinsella_aerofaciens","sample_id":"S_SRR5935924","abundance":0.0009659395,"growth_rate":0.0000000000}]} ``` -------------------------------- ### Load and Inspect a Community Model Source: https://github.com/micom-dev/micom/blob/main/docs/source/high_level.ipynb Load an individual community model from a pickle file using `load_pickle` and inspect its properties, such as the number of reactions. ```python from micom import load_pickle com = load_pickle("models/sample_1.pickle") print(len(com.reactions)) ``` -------------------------------- ### Minimal Medium with Cooperative Tradeoff Constraints Source: https://github.com/micom-dev/micom/blob/main/docs/source/media.ipynb Calculates the minimal medium by incorporating the growth rates derived from a cooperative tradeoff analysis as additional constraints. This ensures individual member growth rates are considered. ```python sol = com.cooperative_tradeoff() rates = sol.members.growth_rate.drop("medium") # extracellular medium has no growth rate med = minimal_medium(com, sol.growth_rate, min_growth=rates) med ``` -------------------------------- ### Plot Growth Rates Source: https://github.com/micom-dev/micom/blob/main/docs/source/viz.ipynb Creates an interactive HTML visualization of the predicted growth rates for taxa in the model. Use this to understand the overall growth potential of the community. ```python from micom.viz import plot_growth pl = plot_growth(results, filename="growth_rates.html") ``` -------------------------------- ### Vega-Lite Specification for Growth Rates Source: https://github.com/micom-dev/micom/blob/main/micom/data/templates/growth.html Defines the visualization for growth rates, including data mapping, scales, and interactive elements. It uses a logarithmic scale for growth rate and allows selection by sample ID. ```javascript var vlSpec = { $schema: "https://vega.github.io/schema/vega-lite/v5.json", width: 300, height: {{18 * n_taxa}}, data: { values: {{data | safe}} }, selection: { pts: {type: "single", fields: ["sample_id"]} }, transform: [{ calculate: "random()-0.5", as: "jitter" }], mark: { type: "point", filled: true, size: 40, tooltip: {content: "data"} }, encoding: { x: { field: "growth_rate", type: "quantitative", scale: {type: "log"}, axis: {title: "growth rate [1/h]", grid: false} }, y: { field: "taxon", type: "nominal", sort: {op: "median", field: "growth_rate", order: "descending"}, axis: {title: null, grid: true} }, yOffset: { field: "jitter", type: "quantitative", scale: {domain: [-1, 1]} }, color: { condition: { selection: "pts", field: "{{ color }}", type: "nominal", {% if color == "taxon" %}legend: null{% endif %} }, value: "lightgrey" }, opacity: { condition: { selection: "pts", value: 0.8 }, value: 0.2 } } }; ``` -------------------------------- ### Basic Cooperative Tradeoff Source: https://github.com/micom-dev/micom/blob/main/docs/source/growth_fluxes.ipynb Performs a cooperative tradeoff calculation, enforcing 100% of the maximum community growth rate. Requires a QP-capable solver. ```python sol = com.cooperative_tradeoff(fraction=1.0) sol ``` -------------------------------- ### Minimal Medium with Lowered Growth Rate Thresholds Source: https://github.com/micom-dev/micom/blob/main/docs/source/media.ipynb Calculates the minimal medium while requiring only 95% of the community and individual growth rates. This can prevent the inclusion of specific imports needed for marginal growth improvements. ```python med = minimal_medium(com, 0.95*sol.growth_rate, min_growth=0.95*rates) med ``` -------------------------------- ### Vega-Lite Specification for Summarized Interactions Source: https://github.com/micom-dev/micom/blob/main/micom/data/templates/focal_interactions.html Defines the visualization for summarized interactions. It uses a log scale for flux and allows single point selection for highlighting partners. ```javascript var summSpec = { $schema: "https://vega.github.io/schema/vega-lite/v5.json", width: 400, height: 200, data: { values: {{summary | safe}} }, selection: { pts: {type: "single", fields: ["partner"]} }, transform: [{ calculate: "random()-0.5", as: "jitter" }], mark: { type: "point", filled: true, size: 40, tooltip: {content: "data"} }, encoding: { x: { field: "flux", type: "quantitative", scale: {type: "log"}, axis: {title: "flux [{{unit}}]", grid: false} }, y: { field: "class", type: "nominal", axis: {title: null, grid: true} }, yOffset: { field: "jitter", type: "quantitative", scale: {domain: [-1, 1]} }, color: { condition: { selection: "pts", field: "class", type: "nominal", legend: null }, value: "lightgrey" }, opacity: { condition: { selection: "pts", value: 0.8 }, value: 0.2 } } }; ``` -------------------------------- ### Calculate Minimal Medium Minimizing Components Source: https://github.com/micom-dev/micom/blob/main/docs/source/media.ipynb Calculates the minimal medium for a specific growth rate (0.8) but prioritizes minimizing the *number* of different import fluxes used, rather than the total import flux. ```python minimal_medium(com, 0.8, minimize_components=True) ```