Ejemplo n.º 1
0
 def test_connected_metabolites__example_graph(self):
     qc = {'$text': {'$search': 'albumin'}}
     connections = self.qry.getconnectedmetabolites(qc, max_associations=10)
     r = self.qry.get_connections_graph(connections, json.dumps(qc))
     print(nx.info(r))
     from nosqlbiosets.graphutils import save_graph
     save_graph(r, EXAMPLES + 'hmdb-ex-graph.json')
     assert 49 == len(r)
Ejemplo n.º 2
0
def savegraph(query, outfile, limit=4000):
    """Save IntEnz reaction connections as graph files

    param: qc: MongoDB query clause to select subsets of IntEnz entries,
               e.g.: \'{"reactions.label.value": ' '"Chemically balanced"}\'
    param: outfile: File name for saving the output graph
                    Format is selected based on the file extension
                    of the given output file;
                             .xml for GraphML, .gml for GML,
                             .json for Cytoscape.js
    param: --limit: Maximum number of enzyme-metabolite connections
    """
    qry = QueryIntEnz()
    qc = parseinputquery(query)
    cgraph = qry.get_connections_graph(qc, int(limit / 2))
    print(nx.info(cgraph))
    save_graph(cgraph, outfile)
Ejemplo n.º 3
0
 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()