示例#1
0
def update_context(universe, graph):
    """Updates the context of a subgraph from the universe of all knowledge.

    :param pybel.BELGraph universe: The universe of knowledge
    :param pybel.BELGraph graph: A BEL graph
    """
    for namespace in get_namespaces(graph):
        if namespace in universe.namespace_url:
            graph.namespace_url[namespace] = universe.namespace_url[namespace]
        elif namespace in universe.namespace_owl:
            graph.namespace_owl[namespace] = universe.namespace_owl[namespace]
        elif namespace in universe.namespace_owl:
            graph.namespace_pattern[namespace] = universe.namespace_pattern[namespace]
        else:
            log.warning('namespace: %s missing from universe', namespace)

    for annotation in get_annotations(graph):
        if annotation in universe.annotation_url:
            graph.annotation_url[annotation] = universe.annotation_url[annotation]
        elif annotation in universe.annotation_owl:
            graph.annotation_owl[annotation] = universe.annotation_owl[annotation]
        elif annotation in universe.annotation_owl:
            graph.annotation_pattern[annotation] = universe.annotation_pattern[annotation]
        else:
            log.warning('annotation: %s missing from universe', annotation)
示例#2
0
    def test_namespaces_egf(self):
        result = {
            'HGNC': 10,
            'GOBP': 1,
        }

        self.assertEqual(set(result), get_namespaces(egf_graph))
        self.assertEqual(result, count_namespaces(egf_graph))
示例#3
0
def get_incorrect_names(graph: BELGraph) -> Mapping[str, Set[str]]:
    """Return the dict of the sets of all incorrect names from the given namespace in the graph.

    :return: The set of all incorrect names from the given namespace in the graph
    """
    return {
        namespace: get_incorrect_names_by_namespace(graph, namespace)
        for namespace in get_namespaces(graph)
    }
示例#4
0
    def test_namespaces_egf(self):
        """Test getting and counting namespaces' contents on the EGF graph."""
        result = {
            'HGNC': 10,
            'GO': 1,
        }

        self.assertEqual(set(result), get_namespaces(egf_graph))
        self.assertEqual(Counter(result), count_namespaces(egf_graph))
示例#5
0
    def test_namespaces_sialic(self):
        """Test getting and counting namespaces' contents on the sialic acid graph."""
        result = {
            'HGNC': 7,
            'CHEBI': 1,
        }

        self.assertEqual(set(result), get_namespaces(sialic_acid_graph))
        self.assertEqual(Counter(result), count_namespaces(sialic_acid_graph))
示例#6
0
    def test_namespaces_egf(self):
        """Test getting and counting namespaces' contents on the EGF graph."""
        result = {
            'hgnc': 15,
            'go': 3,
            'bel': 4,
        }

        self.assertEqual(set(result), get_namespaces(egf_graph))
        self.assertEqual(Counter(result), count_namespaces(egf_graph))
示例#7
0
def get_incorrect_names(graph):
    """Returns the dict of the sets of all incorrect names from the given namespace in the graph

    :param pybel.BELGraph graph: A BEL graph
    :return: The set of all incorrect names from the given namespace in the graph
    :rtype: dict[str,set[str]]
    """
    return {
        namespace: get_incorrect_names_by_namespace(graph, namespace)
        for namespace in get_namespaces(graph)
    }
示例#8
0
def get_names_including_errors(graph: BELGraph) -> Mapping[str, Set[str]]:
    """Get all names appearing in the graph, including erroneous names, and group in a dictionary by namespace.

    Takes the names from the graph in a given namespace and the erroneous names from the same namespace and returns
    them together as a unioned set

    :return: The dict of the sets of all correct and incorrect names from the given namespace in the graph
    """
    return {
        namespace: get_names_including_errors_by_namespace(graph, namespace)
        for namespace in get_namespaces(graph)
    }
示例#9
0
def get_names_including_errors(graph):
    """Takes the names from the graph in a given namespace and the erroneous names from the same namespace and returns
    them together as a unioned set

    :param pybel.BELGraph graph: A BEL graph
    :return: The dict of the sets of all correct and incorrect names from the given namespace in the graph
    :rtype: dict[str,set[str]]
    """
    return {
        namespace: get_names_including_errors_by_namespace(graph, namespace)
        for namespace in get_namespaces(graph)
    }
示例#10
0
    def test_summarize_sialic(self):
        """Test getting and counting namespaces' contents on the sialic acid graph."""
        namespace_result = {
            'hgnc': 8,
            'chebi': 2,
            'bel': 3,
        }
        self.assertEqual(set(namespace_result),
                         get_namespaces(sialic_acid_graph))
        self.assertEqual(Counter(namespace_result),
                         count_namespaces(sialic_acid_graph))

        hgnc_result = {
            'CD33':
            3,  # once as reference, once in complex, and once as variant
            'TYROBP': 1,
            'SYK': 1,
            'PTPN6': 1,
            'PTPN11': 1,
            'TREM2': 1,
        }
        chebi_result = {
            'sialic acid': 2,
        }
        names = get_names(sialic_acid_graph)
        self.assertEqual(set(namespace_result), set(names))
        self.assertEqual(set(hgnc_result), names['hgnc'])
        self.assertEqual(set(chebi_result), names['chebi'])
        self.assertEqual(set(hgnc_result),
                         get_names_by_namespace(sialic_acid_graph, 'hgnc'))
        self.assertEqual(set(chebi_result),
                         get_names_by_namespace(sialic_acid_graph, 'chebi'))
        self.assertEqual(
            hgnc_result,
            dict(count_names_by_namespace(sialic_acid_graph, 'hgnc')))
        self.assertEqual(
            chebi_result,
            dict(count_names_by_namespace(sialic_acid_graph, 'chebi')))
示例#11
0
    def test_namespaces_sialic(self):
        result = {'HGNC': 7, 'CHEBI': 1}

        self.assertEqual(set(result), get_namespaces(sialic_acid_graph))
        self.assertEqual(result, count_namespaces(sialic_acid_graph))