def test_metabolite_networks_neighbors(self): qc = {'$text': {'$search': 'glycerol'}} mn = qry.get_metabolite_network(qc, limit=1440) assert "Glycerol" in mn.nodes assert len(mn.edges) == 3219 assert len(mn.nodes) == 906 qc = {'$text': {'$search': 'glycerol'}, 'is_transport': True} mn = qry.get_metabolite_network(qc) assert "Glycerol" in mn.nodes assert len(mn.edges) == 228 assert len(mn.nodes) == 64 qc = {"_id": "rxn36327"} mn = qry.get_metabolite_network(qc) assert "(S)-Propane-1,2-diol" in mn.nodes qc = {"status": "OK", "reversibility": "<"} mn = qry.get_metabolite_network(qc) self.assertAlmostEqual(len(mn.edges), 2027, delta=100) self.assertAlmostEqual(len(mn.nodes), 961, delta=100) assert 'Phosphate' in mn.nodes r = neighbors_graph(mn, "Phosphate", beamwidth=8, maxnodes=100) assert r.number_of_nodes() == 95 r = neighbors_graph(mn, "Phosphate", beamwidth=6, maxnodes=20) assert r.number_of_nodes() == 20 r = neighbors_graph(mn, "Phosphate", beamwidth=4, maxnodes=20) assert r.number_of_nodes() == 20
def test_metabolite_network_bigg(self): qc = {"$or": [{"source.lib": 'bigg'}, {"xrefs.lib": 'bigg'}]} mn = qrymtntx.get_metabolite_network(qc, max_degree=1400) cmpnds = { 'carboxyacetyl-[acyl-carrier protein]', 'acetate', 'hexadecanoate', 'xylitol', "L-xylulose", "L-arabinitol" } assert len(cmpnds.intersection(mn.nodes())) == 6 assert mn.degree("L-arabinitol") >= 2 assert mn.degree("L-xylulose") >= 5 r = neighbors_graph(mn, "L-arabinitol", beamwidth=5, maxnodes=160) assert len(r) == 0 # L-arabinitol is product, not reactant paths = shortest_paths(mn, 'alpha-L-arabinan', 'L-arabinitol', 10) assert len(paths) == 10 assert paths[0][1] == 'aldehydo-L-arabinose' set_degree_as_weight(mn) paths = shortest_paths(mn, 'alpha-L-arabinan', 'L-arabinitol', 10, weight='weight') assert len(paths) == 1 assert paths[0][1] == 'aldehydo-L-arabinose' qc = {"source.lib": "bigg", "xrefs.lib": 'bigg', "balance": "true"} mn = qrymtntx.get_metabolite_network(qc) self.assertAlmostEqual(2815, len(mn.nodes()), delta=200) self.assertAlmostEqual(3741, len(mn.edges()), delta=200) assert 'L-xylulose' not in mn.nodes() assert "Zymosterol ester (yeast specific)" in mn.nodes() assert len(cmpnds.intersection(mn.nodes())) == 2 assert mn.degree("Zymosterol ester (yeast specific)") == 8 r = neighbors_graph(mn, "L-ascorbate", beamwidth=5, maxnodes=100) self.assertAlmostEqual(7, r.number_of_nodes(), delta=4)
def test_metabolite_network_rhea(self): qc = {"source.lib": "rhea", "balance": "true"} mn = qrymtntx.get_metabolite_network(qc, max_degree=660) paths = shortest_paths(mn, 'L-serine', 'acetyl-CoA', 1600, cutoff=5) assert 225 == len(paths) assert ['L-serine', 'phosphate', 'acetyl-CoA'] in paths set_degree_as_weight(mn) paths = shortest_paths(mn, 'L-serine', 'acetyl-CoA', 1600, cutoff=5, weight='weight') assert 2 == len(paths) assert [ 'L-serine', '3-(pyrazol-1-yl)-L-alanine', 'O-acetyl-L-serine', 'acetyl-CoA' ] in paths self.assertAlmostEqual(7806, len(mn.nodes()), delta=400) self.assertAlmostEqual(17698, len(mn.edges()), delta=1200) r = neighbors_graph(mn, "L-ascorbate", beamwidth=5, maxnodes=100) self.assertAlmostEqual(100, r.number_of_nodes(), delta=12) assert 5 == mn.in_degree('L-ascorbate') cofactors = [ 'FMNH2', 'L-ascorbate', 'Cu(+)', 'Cu(2+)', 'Fe(3+)', 'FMN', '5,10-methenyltetrahydrofolate', 'NH4(+)', 'Fe(2+)', 'Mn(2+)', "riboflavin", "heme b", "Zn(2+)", "Mg(2+)" ] for i in cofactors: assert i in mn.nodes(), i
def test_example_graph(self): qc = {'$text': {'$search': 'methicillin'}} g1 = self.qry.get_connections_graph(qc, "targets") self.assertAlmostEqual(82, g1.number_of_edges(), delta=10) self.assertAlmostEqual(73, g1.number_of_nodes(), delta=10) g2 = self.qry.get_connections_graph(qc, "enzymes") self.assertAlmostEqual(16, g2.number_of_edges(), delta=4) self.assertAlmostEqual(12, g2.number_of_nodes(), delta=4) g3 = self.qry.get_connections_graph(qc, "transporters") self.assertAlmostEqual(30, g3.number_of_edges(), delta=14) self.assertAlmostEqual(22, g3.number_of_nodes(), delta=4) g4 = self.qry.get_connections_graph(qc, "carriers") self.assertAlmostEqual(7, g4.number_of_edges(), delta=4) self.assertAlmostEqual(8, g4.number_of_nodes(), delta=4) r = nx.compose_all([g1, g2, g3, g4]) self.assertAlmostEqual(125, r.number_of_edges(), delta=20) self.assertAlmostEqual(94, r.number_of_nodes(), delta=14) remove_small_subgraphs(r) save_graph(r, EX_GRAPHS + 'drugbank-methicillin.json') r = neighbors_graph(r, "Ticarcillin", beamwidth=8, maxnodes=100) assert 2 == r.number_of_nodes()
def test_metabolite_network_reactome(self): qc = {"source.lib": "reactome", "balance": "true"} mn = qrymtntx.get_metabolite_network(qc, max_degree=400) self.assertAlmostEqual(430, len(mn.nodes()), delta=60) self.assertAlmostEqual(1157, len(mn.edges()), delta=120) assert "L-serine" in mn.nodes() r = neighbors_graph(mn, "acetyl-CoA", beamwidth=20, maxnodes=200) # number of nodes differ based on selected search branches self.assertAlmostEqual(143, r.number_of_nodes(), delta=30) paths = shortest_paths(mn, 'L-serine', 'acetyl-CoA', 30) assert 30 == len(paths) assert ['L-serine', 'glycine', 'CoA', 'acetyl-CoA'] in paths[:4] set_degree_as_weight(mn) paths = shortest_paths(mn, 'L-serine', 'acetyl-CoA', 30, weight='weight') assert 30 == len(paths) assert ['L-serine', 'glycine', 'CoA', 'acetyl-CoA'] == paths[0]
def test_drug_targets_graph(self): qc = {'$text': {'$search': '\"side effects\"'}} g = self.qry.get_connections_graph(qc, "targets") self.assertAlmostEqual(g.number_of_edges(), 580, delta=30) self.assertAlmostEqual(g.number_of_nodes(), 342, delta=20) assert "Olanzapine" in g.nodes assert "CCX915" in g.nodes r = neighbors_graph(g, "Olanzapine", max_iter=10, tol=1e-2) assert 5 == r.number_of_nodes() qc = {'$text': {'$search': 'defensin'}} gfile = "./docs/example-graphs/defensin-targets.json" g = self.qry.get_connections_graph(qc, "targets", gfile) assert g.number_of_edges() == 38 self.assertAlmostEqual(g.number_of_nodes(), 33, 10) g = self.qry.get_connections_graph(qc, "enzymes") assert g.number_of_edges() == 1 assert g.number_of_nodes() == 2 g = self.qry.get_connections_graph(qc, "transporters") assert g.number_of_edges() == 0 assert g.number_of_nodes() == 0 g = self.qry.get_connections_graph(qc, "carriers") assert g.number_of_edges() == 0 assert g.number_of_nodes() == 0