def test_append_sample(self): seeding = Seeding() seeding.append_sample() self.assertEqual(1, len(seeding)) s = seeding.dumps() self.assertIsInstance(s, str)
def test_no_seeding(self): graph = egf_graph.copy() seeding = Seeding() result = seeding.run(graph) self.assertEqual(graph.number_of_nodes(), result.number_of_nodes()) self.assertEqual(graph.number_of_edges(), result.number_of_edges())
def test_random_sample(self): graph = generate_random_graph(50, 1000) seeding = Seeding() seeding.append_sample(number_edges=10) seeding.append_sample(number_edges=10) result = seeding.run(graph) # TODO this will fail randomly some times lol, so make allowed to be sort of wrong self.assertIn(result.number_of_edges(), {18, 19, 20})
def add_seed_neighbors( self, nodes: Union[BaseEntity, Iterable[BaseEntity]]) -> Query: """Add a seed by neighbors and return a new query.""" seeding = self.get_seeding() or Seeding() seeding.append_neighbors(nodes) return Query( parent_id=self.id, assembly=self.assembly, seeding=seeding.dumps(), pipeline=self.pipeline, )
def test_seed_by_neighbor(self): graph = BELGraph() a, b, c, d = (Protein(namespace=n(), name=str(i)) for i in range(4)) graph.add_increases(a, b, n(), n()) graph.add_increases(b, c, n(), n()) graph.add_increases(c, d, n(), n()) seeding = Seeding() seeding.append_neighbors(b) result = seeding.run(graph) self.assertIsInstance(result, BELGraph) # test nodes self.assertIn(a, result) self.assertIn(b, result) self.assertIn(c, result) self.assertNotIn(d, result) # test edges self.assertIn(b, result[a]) self.assertIn(c, result[b]) self.assertNotIn(d, result[c])
def get_seeding(self) -> Optional[Seeding]: """Get the seeding container, if it has any entries.""" if self.seeding: seeding_json = [({ SEED_METHOD: entry[SEED_METHOD], SEED_DATA: [ parse_result_to_dsl(node_dict) for node_dict in entry[SEED_DATA] ], } if entry[SEED_METHOD] in NODE_SEED_TYPES else entry) for entry in json.loads(self.seeding)] return Seeding.from_json(seeding_json)
def test_seeding(self): query = Query(seeding=Seeding()) self.assertEqual(0, len(query.seeding))
def test_none(self): """Test construction of a seeding container.""" seeding = Seeding() self.assertEqual(0, len(seeding)) self.assertEqual('[]', seeding.dumps())
def test_none(self): seeding = Seeding() self.assertEqual(0, len(seeding)) self.assertEqual('[]', seeding.dumps())