Exemplo n.º 1
0
def get_mutations(gene_names, cell_types):
    """Return the mutation status of genes in cell types.

    Parameters
    ----------
    gene_names : list
        HGNC gene symbols for which mutations are queried.
    cell_types : list
        List of cell type names in which mutations are queried.
        The cell type names follow the CCLE database conventions.

        Example: LOXIMVI_SKIN, BT20_BREAST

    Returns
    -------
    res : str
        A json string containing the mutation status of
        the given proteins in the given cell types as returned by the
        NDEx web service.
    """
    url = ndex_context + 'mutation/cell_line'
    if isinstance(gene_names, basestring):
        gene_names = [gene_names]
    if isinstance(cell_types, basestring):
        cell_types = [cell_types]
    params = {g: cell_types for g in gene_names}
    res = ndex_client.send_request(url, params, is_json=True)
    return res
Exemplo n.º 2
0
def get_mutations(gene_names, cell_types):
    """Return the mutation status of genes in cell types.

    Parameters
    ----------
    gene_names : list
        HGNC gene symbols for which mutations are queried.
    cell_types : list
        List of cell type names in which mutations are queried.
        The cell type names follow the CCLE database conventions.

        Example: LOXIMVI_SKIN, BT20_BREAST

    Returns
    -------
    res : str
        A json string containing the mutation status of
        the given proteins in the given cell types as returned by the
        NDEx web service.
    """
    url = ndex_context + 'mutation/cell_line'
    if isinstance(gene_names, basestring):
        gene_names = [gene_names]
    if isinstance(cell_types, basestring):
        cell_types = [cell_types]
    params = {g: cell_types for g in gene_names}
    res = ndex_client.send_request(url, params, is_json=True)
    return res
Exemplo n.º 3
0
def get_relevant_nodes(network_id, query_nodes):
    """Return a set of network nodes relevant to a given query set.

    A heat diffusion algorithm is used on a pre-computed heat kernel for the
    given network which starts from the given query nodes. The nodes
    in the network are ranked according to heat score which is a measure
    of relevance with respect to the query nodes.

    Parameters
    ----------
    network_id : str
        The UUID of the network in NDEx.
    query_nodes : list[str]
        A list of node names with respect to which relevance is queried.

    Returns
    -------
    ranked_entities : list[(str, float)]
        A list containing pairs of node names and their relevance scores.
    """
    url = ndex_relevance + '/rank_entities'
    kernel_id = get_heat_kernel(network_id)
    if kernel_id is None:
        return None
    if isinstance(query_nodes, basestring):
        query_nodes = [query_nodes]
    params = {'identifier_set': query_nodes,
              'kernel_id': kernel_id}
    res = ndex_client.send_request(url, params, is_json=True)
    ranked_entities = res.get('ranked_entities')
    if ranked_entities is None:
        logger.error('Could not get ranked entities.')
        return None
    return ranked_entities
Exemplo n.º 4
0
def get_relevant_nodes(network_id, query_nodes):
    """Return a set of network nodes relevant to a given query set.

    A heat diffusion algorithm is used on a pre-computed heat kernel for the
    given network which starts from the given query nodes. The nodes
    in the network are ranked according to heat score which is a measure
    of relevance with respect to the query nodes.

    Parameters
    ----------
    network_id : str
        The UUID of the network in NDEx.
    query_nodes : list[str]
        A list of node names with respect to which relevance is queried.

    Returns
    -------
    ranked_entities : list[(str, float)]
        A list containing pairs of node names and their relevance scores.
    """
    url = ndex_relevance + '/rank_entities'
    kernel_id = get_heat_kernel(network_id)
    if kernel_id is None:
        return None
    if isinstance(query_nodes, basestring):
        query_nodes = [query_nodes]
    params = {'identifier_set': query_nodes, 'kernel_id': kernel_id}
    res = ndex_client.send_request(url, params, is_json=True)
    ranked_entities = res.get('ranked_entities')
    if ranked_entities is None:
        logger.error('Could not get ranked entities.')
        return None
    return ranked_entities
Exemplo n.º 5
0
def process_ndex_neighborhood(gene_names,
                              network_id=None,
                              rdf_out='bel_output.rdf',
                              print_output=True):
    """Return a BelRdfProcessor for an NDEx network neighborhood.

    Parameters
    ----------
    gene_names : list
        A list of HGNC gene symbols to search the neighborhood of.
        Example: ['BRAF', 'MAP2K1']
    network_id : Optional[str]
        The UUID of the network in NDEx. By default, the BEL Large Corpus
        network is used.
    rdf_out : Optional[str]
        Name of the output file to save the RDF returned by the web service.
        This is useful for debugging purposes or to repeat the same query
        on an offline RDF file later. Default: bel_output.rdf

    Returns
    -------
    bp : BelRdfProcessor
        A BelRdfProcessor object which contains INDRA Statements in bp.statements.

    Notes
    -----
    This function calls process_belrdf to the returned RDF string from the
    webservice.
    """
    logger.warning('This method is deprecated and the results are not '
                   'guaranteed to be correct. Please use '
                   'process_pybel_neighborhood instead.')
    if network_id is None:
        network_id = '9ea3c170-01ad-11e5-ac0f-000c29cb28fb'
    url = ndex_bel2rdf + '/network/%s/asBELRDF/query' % network_id
    params = {'searchString': ' '.join(gene_names)}
    # The ndex_client returns the rdf as the content of a json dict
    res_json = ndex_client.send_request(url, params, is_json=True)
    if not res_json:
        logger.error('No response for NDEx neighborhood query.')
        return None
    if res_json.get('error'):
        error_msg = res_json.get('message')
        logger.error('BEL/RDF response contains error: %s' % error_msg)
        return None
    rdf = res_json.get('content')
    if not rdf:
        logger.error('BEL/RDF response is empty.')
        return None

    with open(rdf_out, 'wb') as fh:
        fh.write(rdf.encode('utf-8'))
    bp = process_belrdf(rdf, print_output=print_output)
    return bp
Exemplo n.º 6
0
def process_ndex_neighborhood(gene_names, network_id=None,
                              rdf_out='bel_output.rdf', print_output=True):
    """Return a BelRdfProcessor for an NDEx network neighborhood.

    Parameters
    ----------
    gene_names : list
        A list of HGNC gene symbols to search the neighborhood of.
        Example: ['BRAF', 'MAP2K1']
    network_id : Optional[str]
        The UUID of the network in NDEx. By default, the BEL Large Corpus
        network is used.
    rdf_out : Optional[str]
        Name of the output file to save the RDF returned by the web service.
        This is useful for debugging purposes or to repeat the same query
        on an offline RDF file later. Default: bel_output.rdf

    Returns
    -------
    bp : BelRdfProcessor
        A BelRdfProcessor object which contains INDRA Statements in bp.statements.

    Notes
    -----
    This function calls process_belrdf to the returned RDF string from the
    webservice.
    """
    logger.warning('This method is deprecated and the results are not '
                   'guaranteed to be correct. Please use '
                   'process_pybel_neighborhood instead.')
    if network_id is None:
        network_id = '9ea3c170-01ad-11e5-ac0f-000c29cb28fb'
    url = ndex_bel2rdf + '/network/%s/asBELRDF/query' % network_id
    params = {'searchString': ' '.join(gene_names)}
    # The ndex_client returns the rdf as the content of a json dict
    res_json = ndex_client.send_request(url, params, is_json=True)
    if not res_json:
        logger.error('No response for NDEx neighborhood query.')
        return None
    if res_json.get('error'):
        error_msg = res_json.get('message')
        logger.error('BEL/RDF response contains error: %s' % error_msg)
        return None
    rdf = res_json.get('content')
    if not rdf:
        logger.error('BEL/RDF response is empty.')
        return None

    with open(rdf_out, 'wb') as fh:
        fh.write(rdf.encode('utf-8'))
    bp = process_belrdf(rdf, print_output=print_output)
    return bp
Exemplo n.º 7
0
def get_heat_kernel(network_id):
    """Return the identifier of a heat kernel calculated for a given network.

    Parameters
    ----------
    network_id : str
        The UUID of the network in NDEx.

    Returns
    -------
    kernel_id : str
        The identifier of the heat kernel calculated for the given network.
    """
    url = ndex_relevance + '/%s/generate_ndex_heat_kernel' % network_id
    res = ndex_client.send_request(url, {}, is_json=True, use_get=True)
    kernel_id = res.get('kernel_id')
    if kernel_id is None:
        logging.error('Could not get heat kernel for network.')
        return None
    return kernel_id
Exemplo n.º 8
0
def process_ndex_neighborhood(gene_names, network_id=None, rdf_out="bel_output.rdf"):
    """Return a BelProcessor for an NDEx network neighborhood.

    Parameters
    ----------
    gene_names : list
        A list of HGNC gene symbols to search the neighborhood of.
        Example: ['BRAF', 'MAP2K1']
    network_id : Optional[str]
        The UUID of the network in NDEx. By default, the BEL Large Corpus
        network is used.
    rdf_out : Optional[str]
        Name of the output file to save the RDF returned by the web service.
        This is useful for debugging purposes or to repeat the same query
        on an offline RDF file later. Default: bel_output.rdf

    Returns
    -------
    bp : BelProcessor
        A BelProcessor object which contains INDRA Statements in bp.statements.

    Notes
    -----
    This function calls process_belrdf to the returned RDF string from the
    webservice.
    """
    if network_id is None:
        network_id = "9ea3c170-01ad-11e5-ac0f-000c29cb28fb"
    url = ndex_bel2rdf + "/network/%s/asBELRDF/query" % network_id
    params = {"searchString": " ".join(gene_names)}
    rdf = ndex_client.send_request(url, params, is_json=False)
    if rdf is None:
        logger.info("No response for NDEx neighborhood query.")
        return None
    with open(rdf_out, "wt") as fh:
        fh.write(rdf.encode("utf-8"))
    bp = process_belrdf(rdf)
    return bp
Exemplo n.º 9
0
def get_heat_kernel(network_id):
    """Return the identifier of a heat kernel calculated for a given network.

    Parameters
    ----------
    network_id : str
        The UUID of the network in NDEx.

    Returns
    -------
    kernel_id : str
        The identifier of the heat kernel calculated for the given network.
    """
    url = ndex_relevance + '/%s/generate_ndex_heat_kernel' % network_id
    res = ndex_client.send_request(url, {}, is_json=True, use_get=True)
    if res is None:
        logger.error('Could not get heat kernel for network %s.' % network_id)
        return None

    kernel_id = res.get('kernel_id')
    if kernel_id is None:
        logger.error('Could not get heat kernel for network %s.' % network_id)
        return None
    return kernel_id