Network Generation#

We start by defining a set of metabolites and microbial species, for which we want to extract the metabolic network.

Please note that all names need to be given as internal names/IDs. For more information on how to map them see Name Mapping.

 1from pymantra.database import NetworkGenerator, reduce_reaction_nodes
 2
 3species = {
 4    "Acidipropionibacterium virtanenii", "Acidothermus cellulolyticus",
 5    "Azoarcus sp.", "Candidatus Pantoea", "Intestinibaculum porci",
 6    "Microbacterium wangchenii", "Permianibacter aggregans",
 7    "Plasmodium falciparum 3D7", "Pseudolysobacter antarcticus",
 8    "Pseudomonas viridiflava"
 9}
10metabolites = {
11    "6pgc", "6pgl", "coF420", "coF420h", "g6p", "h", "h2o", "nad", "nadp",
12    "nadph"
13}

To generate a valid network from a local neo4j database, we use the NetworkGenerator class. This requires neo4j to be installed (we recommend using docker for this) and the mantra.dump file to be moved in the correct place (see the installation manual for more details). To initialize the NetworkGenerator object you only need to pass the URI and (optionally) a user and password for authentication.

15generator = NetworkGenerator("bolt://127.0.0.1:7687", ("<user>", "<password>"))

Subsequently, we extract all edges for the given metabolites and microbial species from the database. The edges are returned by edge type. All reactions extracted with the given reaction_organism are either human-catalysed reactions or catalysed by one of the microbial species passed.

17edges = generator.get_reaction_subgraph(
18    species, set(), metabolites, reaction_organism=("Abbreviation_KEGG", "hsa")
19)

Finally, we can use the extracted edges to generate a networkx.DiGraph object, which automatically contains the correct node- and edge-type annotation required for downstream analyses.

Additionaly, we call reduce_reaction_nodes on the resulting graph to avoid having multiple reaction nodes with the same substrates and products, as there is no way to distinguish them in the downstream computations.

21network = generator.as_networkx(
22    edges=edges, reaction_subgraph=True)
23network = reduce_reaction_nodes(network)

Full Example Code#

 1from pymantra.database import NetworkGenerator, reduce_reaction_nodes
 2
 3species = {
 4    "Acidipropionibacterium virtanenii", "Acidothermus cellulolyticus",
 5    "Azoarcus sp.", "Candidatus Pantoea", "Intestinibaculum porci",
 6    "Microbacterium wangchenii", "Permianibacter aggregans",
 7    "Plasmodium falciparum 3D7", "Pseudolysobacter antarcticus",
 8    "Pseudomonas viridiflava"
 9}
10metabolites = {
11    "6pgc", "6pgl", "coF420", "coF420h", "g6p", "h", "h2o", "nad", "nadp",
12    "nadph"
13}
14
15generator = NetworkGenerator("bolt://127.0.0.1:7687", ("<user>", "<password>"))
16
17edges = generator.get_reaction_subgraph(
18    species, set(), metabolites, reaction_organism=("Abbreviation_KEGG", "hsa")
19)
20
21network = generator.as_networkx(
22    edges=edges, reaction_subgraph=True)
23network = reduce_reaction_nodes(network)