Reaction-based Metabolome-Microbiome Integration#
We first load some example data from github. This is data used also used in the manuscript. We simply load a .csv file with metabolite measurements and a group annotation file, together with a pre-computed metabolite-reaction graph. For more details on how to generate such a graph and what its structure, looks like see Network Generation and Using custom networks. The metabolite data should contain the samples in rows.
1import networkx as nx
2import matplotlib.pyplot as plt
3
4from pymantra.network import (
5 compute_reaction_estimates, add_reaction_estimates,
6 compute_multiomics_associations, add_microbiome_associations,
7 MultiOmicsLocalSearch
8)
9from pymantra.datasets import example_multiomics_enrichment_data
10
11
12# loading example data
13metabolite_data, microbiome_data, sample_groups, graph = \
14 example_multiomics_enrichment_data()
Once all data is loaded, we first compute the linear models and the difference
in residuals between samples groups by calling compute_reaction_estimates
and add them to the graph in the required way using add_reaction_estimates.
For how to use custom reaction models, see Custom Reaction Model Estimation.
17# compute and add reaction estimates
18residuals = compute_reaction_estimates(graph, metabolite_data, sample_groups)
19add_reaction_estimates(graph, sample_groups, residuals)
Next, the associations between the reaction values and the microbiome
measurements are computed by compute_microbiome_associations and add them
to the graph by add_microbiome_associations. The correlations and p-values
can also be analyzed seperately.
21# compute and add microbiome-reaction associations
22corr_associations, pvals = compute_multiomics_associations(
23 residuals, microbiome_data, sample_groups, comparison=("0", "1"))
24add_microbiome_associations(graph, sample_groups, corr_associations)
Finally, we can initialize a MultiOmicsLocalSearch object and run the
local search. Afterwards, the local search object contains a number of
functions to report and plot the results.
26# generate local search object and run
27# NOTE: these are randomly chose parameters
28mo_lso = MultiOmicsLocalSearch(graph, "organism", 10., 1e-4, 4, 10, 10, 2)
29mo_lso.run_local_search(n_threads=1, min_comp_size=4)
30
31# report the results
32print(f"Local Search solution: {mo_lso.solution}")
33# saving results
34mo_lso.solution[0].to_json("example_multiomics_solution.json")
35
36mo_lso.plot_score_progression()
37plt.show()
38
39mo_lso.plot_subnetwork(graph)
40plt.show()
41
42# option omitting metabolite nodes
43mo_lso.plot_subnetwork(node_types=nx.get_node_attributes(graph, "node_type"))
44plt.show()
Entire Example Code#
1import networkx as nx
2import matplotlib.pyplot as plt
3
4from pymantra.network import (
5 compute_reaction_estimates, add_reaction_estimates,
6 compute_multiomics_associations, add_microbiome_associations,
7 MultiOmicsLocalSearch
8)
9from pymantra.datasets import example_multiomics_enrichment_data
10
11
12# loading example data
13metabolite_data, microbiome_data, sample_groups, graph = \
14 example_multiomics_enrichment_data()
15
16
17# compute and add reaction estimates
18residuals = compute_reaction_estimates(graph, metabolite_data, sample_groups)
19add_reaction_estimates(graph, sample_groups, residuals)
20
21# compute and add microbiome-reaction associations
22corr_associations, pvals = compute_multiomics_associations(
23 residuals, microbiome_data, sample_groups, comparison=("0", "1"))
24add_microbiome_associations(graph, sample_groups, corr_associations)
25
26# generate local search object and run
27# NOTE: these are randomly chose parameters
28mo_lso = MultiOmicsLocalSearch(graph, "organism", 10., 1e-4, 4, 10, 10, 2)
29mo_lso.run_local_search(n_threads=1, min_comp_size=4)
30
31# report the results
32print(f"Local Search solution: {mo_lso.solution}")
33# saving results
34mo_lso.solution[0].to_json("example_multiomics_solution.json")
35
36mo_lso.plot_score_progression()
37plt.show()
38
39mo_lso.plot_subnetwork(graph)
40plt.show()
41
42# option omitting metabolite nodes
43mo_lso.plot_subnetwork(node_types=nx.get_node_attributes(graph, "node_type"))
44plt.show()