def test_1(self):
        graph = BELGraph()
        u = protein('HGNC', name='U')
        v = protein('HGNC', name='V')
        w = protein('HGNC', name='W')

        graph.add_qualified_edge(u,
                                 v,
                                 relation=INCREASES,
                                 evidence='',
                                 citation='',
                                 annotations={
                                     'A': {'1', '2'},
                                     'B': {'X'}
                                 })

        graph.add_qualified_edge(u,
                                 w,
                                 relation=INCREASES,
                                 evidence='',
                                 citation='',
                                 annotations={
                                     'A': {'1', '3'},
                                     'C': {'a'}
                                 })

        graph.add_qualified_edge(
            w,
            v,
            relation=INCREASES,
            evidence='',
            citation='',
        )

        x = dict(Counter(iter_annotation_value_pairs(graph)))

        self.assertEqual(
            {
                ('A', '1'): 2,
                ('A', '2'): 1,
                ('A', '3'): 1,
                ('B', 'X'): 1,
                ('C', 'a'): 1,
            }, x)

        y = Counter(iter_annotation_values(graph, 'A'))
        self.assertEqual(x['A', '1'] + x['A', '2'] + x['A', '3'],
                         sum(y.values()))

        y = Counter(iter_annotation_values(graph, 'B'))
        self.assertEqual(x['B', 'X'], sum(y.values()))

        y = Counter(iter_annotation_values(graph, 'C'))
        self.assertEqual(x['C', 'a'], sum(y.values()))
    def test_1(self):
        """Test iterating over annotation/value pairs."""
        graph = BELGraph()
        u = protein('HGNC', name='U')
        v = protein('HGNC', name='V')
        w = protein('HGNC', name='W')

        graph.add_increases(u,
                            v,
                            evidence=n(),
                            citation=n(),
                            annotations={
                                'A': {'1', '2'},
                                'B': {'X'}
                            })

        graph.add_increases(u,
                            w,
                            evidence=n(),
                            citation=n(),
                            annotations={
                                'A': {'1', '3'},
                                'C': {'a'}
                            })

        graph.add_increases(
            w,
            v,
            evidence=n(),
            citation=n(),
        )

        x = dict(Counter(iter_annotation_value_pairs(graph)))

        self.assertEqual(
            {
                ('A', '1'): 2,
                ('A', '2'): 1,
                ('A', '3'): 1,
                ('B', 'X'): 1,
                ('C', 'a'): 1,
            }, x)

        y = Counter(iter_annotation_values(graph, 'A'))
        self.assertEqual(x['A', '1'] + x['A', '2'] + x['A', '3'],
                         sum(y.values()))

        y = Counter(iter_annotation_values(graph, 'B'))
        self.assertEqual(x['B', 'X'], sum(y.values()))

        y = Counter(iter_annotation_values(graph, 'C'))
        self.assertEqual(x['C', 'a'], sum(y.values()))
def get_annotation_values(graph, annotation):
    """Get all values for the given annotation

    :param pybel.BELGraph graph: A BEL graph
    :param str annotation: The annotation to summarize
    :return: A set of all annotation values
    :rtype: set[str]
    """
    return set(iter_annotation_values(graph, annotation))
def count_annotation_values(graph, annotation):
    """Counts in how many edges each annotation appears in a graph

    :param pybel.BELGraph graph: A BEL graph
    :param str annotation: The annotation to count
    :return: A Counter from {annotation value: frequency}
    :rtype: collections.Counter
    """
    return Counter(iter_annotation_values(graph, annotation))