Exemplo n.º 1
0
def cyview(query,
           dataset='HMDB',
           connections='targets',
           name='',
           database=DATABASE):
    """ See HMDB/DrugBank graphs with Cytoscape runing on your local machine
`
     :param query: Query to select HMDB or DrugBank entries
     :param dataset: HMDB or DrugBank, not case sensitive
     :param connections: Connection type for DrugBank entries
     :param name: Name of the graph on Cytoscape, query is used as default value
     :param database: Name of the MongoDB database to connect
     """
    from py2cytoscape.data.cyrest_client import CyRestClient
    from py2cytoscape.data.style import Style
    qc = parseinputquery(query)
    print(qc)  # todo: tests with HMDB
    if dataset.upper() == 'HMDB':
        qry = QueryHMDB(index=database)
        pairs = qry.getconnectedmetabolites(qc)
        mn = qry.get_connections_graph(pairs, query)
    else:  # assume DrugBank
        qry = QueryDrugBank(db, database, 'drugbank')
        mn = qry.get_connections_graph(qc, connections)
    crcl = CyRestClient()
    mn.name = json.dumps(qc) if name == '' else name
    cyn = crcl.network.create_from_networkx(mn)
    crcl.layout.apply('kamada-kawai', network=cyn)
    crcl.style.apply(Style('default'), network=cyn)
Exemplo n.º 2
0
def cyview(query):
    """ See metabolite networks with Cytoscape runing on your local machine """
    from py2cytoscape.data.cyrest_client import CyRestClient
    qc = parseinputquery(query)
    qry = QueryModelSEED()
    mn = qry.get_metabolite_network(qc)
    client = CyRestClient()
    client.network.create_from_networkx(mn)
Exemplo n.º 3
0
def savegraph(query, graphfile, connections='targets'):
    """Save DrugBank interactions as graph files
    :param query: MongoDB query clause to select subsets of DrugBank entries
                  ex: \'{"carriers.name": "Serum albumin"}\'
    :param graphfile: File name for saving the output graph
                    ' in GraphML, GML, Cytoscape.js or d3js formats,'
                    ' see readme.md for details'
    :param connections: "targets", "enzymes", "transporters" or
                              "carriers
    """
    qry = QueryDrugBank(db, DATABASE, 'drugbank')
    qc = parseinputquery(query)
    g = qry.get_connections_graph(qc, connections, graphfile)
    print(nx.info(g))
Exemplo n.º 4
0
def cyview(query, name='', limit=4000):
    """ See IntEnz enzyme graphs with Cytoscape runing on your local machine

     :param query: Query to select IntEnz entries
     :param name: Name of the graph on Cytoscape, query is used as default value
     :param limit
     """
    from py2cytoscape.data.cyrest_client import CyRestClient
    from py2cytoscape.data.style import Style
    qc = parseinputquery(query)
    qry = QueryIntEnz()
    mn = qry.get_connections_graph(qc, limit)
    crcl = CyRestClient()
    mn.name = json.dumps(qc) if name == '' else name
    cyn = crcl.network.create_from_networkx(mn)
    crcl.layout.apply('kamada-kawai', network=cyn)
    crcl.style.apply(Style('default'), network=cyn)
Exemplo n.º 5
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)