def test_build_author_inclusion_filter(self): """Test getting a sub-graph by a single author.""" a, b, c, d = [protein(namespace='test', name=n()) for _ in range(4)] a1, a2, a3, a4, a5 = n(), n(), n(), n(), n() c1 = { CITATION_TYPE: CITATION_TYPE_PUBMED, CITATION_REFERENCE: n(), CITATION_AUTHORS: [a1, a2, a3] } c2 = { CITATION_TYPE: CITATION_TYPE_PUBMED, CITATION_REFERENCE: n(), CITATION_AUTHORS: [a1, a4] } graph = BELGraph() keyword, url = n(), n() graph.namespace_url[keyword] = url graph.add_increases(a, b, n(), citation=c1) graph.add_increases(a, b, n(), citation=c2) graph.add_increases(b, c, n(), citation=c1) graph.add_increases(c, d, n(), citation=c2) subgraph1 = get_subgraph_by_authors(graph, a1) self.assertIsInstance(subgraph1, BELGraph) self.assert_all_nodes_are_base_entities(subgraph1) self.assertIn(keyword, subgraph1.namespace_url) self.assertEqual(url, subgraph1.namespace_url[keyword]) self.assertIn(a, subgraph1) self.assertIn(b, subgraph1) self.assertIn(c, subgraph1) self.assertIn(d, subgraph1) subgraph2 = get_subgraph_by_authors(graph, a2) self.assertIsInstance(subgraph2, BELGraph) self.assert_all_nodes_are_base_entities(subgraph2) self.assertIn(keyword, subgraph2.namespace_url) self.assertEqual(url, subgraph2.namespace_url[keyword]) self.assertIn(a, subgraph2) self.assertIn(b, subgraph2) self.assertIn(c, subgraph2) self.assertNotIn(d, subgraph2) subgraph3 = get_subgraph_by_authors(graph, a5) self.assertIsInstance(subgraph3, BELGraph) self.assert_all_nodes_are_base_entities(subgraph3) self.assertIn(keyword, subgraph3.namespace_url) self.assertEqual(url, subgraph3.namespace_url[keyword]) self.assertEqual(0, subgraph3.number_of_nodes())
def test_build_author_set_inclusion_filter(self): """Test getting a sub-graph by a set of authors.""" a, b, c, d = [protein(namespace='test', name=n()) for _ in range(4)] a1, a2, a3, a4 = n(), n(), n(), n() c1 = { CITATION_TYPE: CITATION_TYPE_PUBMED, CITATION_REFERENCE: n(), CITATION_AUTHORS: [a1, a2, a3] } c2 = { CITATION_TYPE: CITATION_TYPE_PUBMED, CITATION_REFERENCE: n(), CITATION_AUTHORS: [a1, a4] } graph = BELGraph() keyword, url = n(), n() graph.namespace_url[keyword] = url graph.add_increases(a, b, n(), citation=c1) graph.add_increases(a, b, n(), citation=c2) graph.add_increases(b, c, n(), citation=c1) graph.add_increases(c, d, n(), citation=c2) subgraph1 = get_subgraph_by_authors(graph, [a1, a2]) self.assertIn(keyword, subgraph1.namespace_url) self.assertEqual(url, subgraph1.namespace_url[keyword]) self.assert_in_graph(a, subgraph1) self.assert_in_graph(b, subgraph1) self.assert_in_graph(c, subgraph1) self.assert_in_graph(d, subgraph1)
def test_build_author_set_inclusion_filter(self): """Test getting a sub-graph by a set of authors.""" a, b, c, d = [protein(namespace='test', name=n()) for _ in range(4)] a1, a2, a3, a4 = n(), n(), n(), n() c1 = { NAMESPACE: CITATION_TYPE_PUBMED, IDENTIFIER: n(), CITATION_AUTHORS: [a1, a2, a3] } c2 = { NAMESPACE: CITATION_TYPE_PUBMED, IDENTIFIER: n(), CITATION_AUTHORS: [a1, a4] } graph = BELGraph() keyword, url = n(), n() graph.namespace_url[keyword] = url graph.add_increases(a, b, evidence=n(), citation=c1) graph.add_increases(a, b, evidence=n(), citation=c2) graph.add_increases(b, c, evidence=n(), citation=c1) graph.add_increases(c, d, evidence=n(), citation=c2) subgraph1 = get_subgraph_by_authors(graph, [a1, a2]) self.assertIsInstance(subgraph1, BELGraph) self.assert_all_nodes_are_base_entities(subgraph1) self.assertIn(keyword, subgraph1.namespace_url) self.assertEqual(url, subgraph1.namespace_url[keyword]) self.assertIn(a, subgraph1) self.assertIn(b, subgraph1) self.assertIn(c, subgraph1) self.assertIn(d, subgraph1)