Пример #1
0
    def _run_helper(self, graph, protocol):
        """Helps run the protocol

        :param pybel.BELGraph graph: A BEL graph
        :param list[dict] protocol: The protocol to run, as JSON
        :rtype: pybel.BELGraph
        """
        result = graph

        for entry in protocol:
            meta_entry = entry.get('meta')

            if meta_entry is None:
                func = self.get_function(entry['function'])
                result = func(result, *(entry.get('args', [])),
                              **(entry.get('kwargs', {})))
            else:
                networks = (self._run_helper(graph, subprotocol)
                            for subprotocol in entry['pipeline'])

                if meta_entry == META_UNION:
                    result = union(networks)

                elif meta_entry == META_INTERSECTION:
                    result = node_intersection(networks)

                else:
                    raise ValueError(
                        'invalid meta-command: {}'.format(meta_entry))

        return result
Пример #2
0
 def test_intersection_trivial(self):
     res = node_intersection([self.g])
     self.assertEqual(self.g, res)
Пример #3
0
 def test_node_intersection(self):
     j = node_intersection([self.h, self.g], use_hash=True)
     self.help_check_join(j)
     self.help_check_initialize_h(self.h)
     self.help_check_initialize_g(self.g)
Пример #4
0
 def test_intersection_failure(self):
     with self.assertRaises(ValueError):
         node_intersection([])
Пример #5
0
 def test_node_intersection(self):
     j = node_intersection([self.h, self.g])
     self._help_check_join(j)
     self._help_check_initialize_h(self.h)
     self._help_check_initialize_g(self.g)