Esempio n. 1
0
    def test_all_filter(self):
        graph = BELGraph()
        graph.add_increases(Protein(n(), n()),
                            Protein(n(), n()),
                            citation=n(),
                            evidence=n(),
                            annotations={'A': {'1', '2', '3'}})

        self.assertEqual(
            1,
            count_passed_edge_filter(
                graph, build_annotation_dict_all_filter({'A': {'1'}})))
        self.assertEqual(
            1,
            count_passed_edge_filter(
                graph, build_annotation_dict_all_filter({'A': {'1', '2'}})))
        self.assertEqual(
            1,
            count_passed_edge_filter(
                graph, build_annotation_dict_all_filter({'A': {'1', '2',
                                                               '3'}})))
        self.assertEqual(
            0,
            count_passed_edge_filter(
                graph,
                build_annotation_dict_all_filter({'A': {'1', '2', '3', '4'}})))
        self.assertEqual(
            0,
            count_passed_edge_filter(
                graph, build_annotation_dict_all_filter({'A': {'4'}})))
Esempio n. 2
0
    def test_all_filter(self):
        graph = BELGraph()
        graph.add_edge(1, 2, annotations={'A': {'1', '2', '3'}})

        self.assertEqual(
            1,
            count_passed_edge_filter(
                graph, build_annotation_dict_all_filter({'A': {'1'}})))
        self.assertEqual(
            1,
            count_passed_edge_filter(
                graph, build_annotation_dict_all_filter({'A': {'1', '2'}})))
        self.assertEqual(
            1,
            count_passed_edge_filter(
                graph, build_annotation_dict_all_filter({'A': {'1', '2',
                                                               '3'}})))
        self.assertEqual(
            0,
            count_passed_edge_filter(
                graph,
                build_annotation_dict_all_filter({'A': {'1', '2', '3', '4'}})))
        self.assertEqual(
            0,
            count_passed_edge_filter(
                graph, build_annotation_dict_all_filter({'A': {'4'}})))
Esempio n. 3
0
    def test_any_filter(self):
        graph = BELGraph()
        graph.annotation_list['A'] = set('12345')
        graph.add_increases(Protein(n(), n()), Protein(n(), n()), citation=n(), evidence=n(), annotations={
            'A': {'1', '2', '3'}
        })

        self.assertEqual(1, count_passed_edge_filter(graph, build_annotation_dict_any_filter(graph._clean_annotations({'A': {'1'}}))))
        self.assertEqual(1, count_passed_edge_filter(graph, build_annotation_dict_any_filter(graph._clean_annotations({'A': {'1', '2'}}))))
        self.assertEqual(1, count_passed_edge_filter(graph, build_annotation_dict_any_filter(graph._clean_annotations({'A': {'1', '2', '3'}}))))
Esempio n. 4
0
 def test_all_filter_no_annotations(self):
     graph = BELGraph()
     graph.add_increases(protein(n(), n()), protein(n(), n()), n(), n())
     self.assertEqual(
         0,
         count_passed_edge_filter(
             graph, build_annotation_dict_all_filter({'A': {'1'}})))
Esempio n. 5
0
def summarize_edge_filter(graph: BELGraph,
                          edge_predicates: EdgePredicates) -> None:
    """Print a summary of the number of edges passing a given set of filters."""
    passed = count_passed_edge_filter(graph, edge_predicates)
    e = (', '.join(edge_filter.__name__ for edge_filter in edge_predicates) if
         isinstance(edge_predicates, Iterable) else edge_predicates.__name__)
    print(f'{passed}/{graph.number_of_edges()} edges passed {e}')
Esempio n. 6
0
 def test_all_filter_no_query(self):
     """Test that the all filter returns true when there's no argument"""
     graph = BELGraph()
     graph.add_increases(protein(n(), n()), protein(n(), n()), n(), n())
     self.assertEqual(
         1,
         count_passed_edge_filter(graph,
                                  build_annotation_dict_all_filter({})))
Esempio n. 7
0
    def test_any_filter(self):
        graph = BELGraph()
        graph.add_increases(protein(n(), n()),
                            protein(n(), n()),
                            n(),
                            n(),
                            annotations={'A': {'1', '2', '3'}})

        self.assertEqual(
            1,
            count_passed_edge_filter(
                graph, build_annotation_dict_any_filter({'A': {'1'}})))
        self.assertEqual(
            1,
            count_passed_edge_filter(
                graph, build_annotation_dict_any_filter({'A': {'1', '2'}})))
        self.assertEqual(
            1,
            count_passed_edge_filter(
                graph, build_annotation_dict_any_filter({'A': {'1', '2',
                                                               '3'}})))
Esempio n. 8
0
    def test_all_filter_dict(self):
        graph = BELGraph()
        graph.annotation_list['A'] = set('12345')
        a, b = Protein(namespace='hgnc', identifier='1', name='A'), Protein(namespace='hgnc', identifier='2', name='B')
        graph.add_increases(a, b, citation=n(), evidence=n(), annotations={
            'A': {'1', '2', '3'},
        })

        self.assertEqual(1, count_passed_edge_filter(graph, build_annotation_dict_all_filter(graph._clean_annotations({'A': {'1': True}}))))
        self.assertEqual(1, count_passed_edge_filter(graph, build_annotation_dict_all_filter(graph._clean_annotations({
            'A': {'1': True, '2': True}
        }))))
        self.assertEqual(1, count_passed_edge_filter(graph, build_annotation_dict_all_filter(graph._clean_annotations({
            'A': {'1': True, '2': True, '3': True}
        }))))
        self.assertEqual(0, count_passed_edge_filter(graph, build_annotation_dict_all_filter(graph._clean_annotations({
            'A': {'1': True, '2': True, '3': True, '4': True}
        }))))
        self.assertEqual(0, count_passed_edge_filter(graph, build_annotation_dict_all_filter(graph._clean_annotations({
            'A': {'4': True}
        }))))
Esempio n. 9
0
def summarize_edge_filter(graph, edge_filters):
    """Prints a summary of the number of edges passing a given set of filters

    :param pybel.BELGraph graph: A BEL graph
    :param edge_filters: A filter or list of filters
    :type edge_filters: (pybel.BELGraph, tuple, tuple, int) -> bool or iter[(pybel.BELGraph, tuple, tuple, int) -> bool]
    """
    passed = count_passed_edge_filter(graph, edge_filters)
    print('{}/{} edges passed {}'.format(
        passed, graph.number_of_edges(),
        (', '.join(edge_filter.__name__ for edge_filter in edge_filters)
         if isinstance(edge_filters, Iterable) else edge_filters.__name__)))
Esempio n. 10
0
    def test_concatenate_multiple_edge_filter(self):
        def has_odd_source(graph, u, v, k):
            return u % 2 != 0

        def has_even_target(graph, u, v, k):
            return v % 2 == 0

        edges = make_edge_iterator_set(filter_edges(self.universe, [has_odd_source, has_even_target]))
        self.assertEqual({(1, 2), (1, 4), (5, 6)}, edges)

        self.assertEqual(3, count_passed_edge_filter(self.universe, [has_odd_source, has_even_target]))

        has_even_source = invert_edge_predicate(has_odd_source)
        edges = make_edge_iterator_set(filter_edges(self.universe, has_even_source))
        self.assertEqual({(2, 3), (8, 2)}, edges)