def test_to_networkx(self): g = terms_to_graph(self.terms_diam) na = g.to_networkx({"GO:0050896" : ["X1", "X2"]}) self.assertEqual(["GO:0030534", "GO:0045471"], na.successors("GO:0048149")) self.assertEqual(["GO:0050896"], na.successors("GO:0030534")) self.assertEqual(["GO:0050896"], na.successors("GO:0045471")) self.assertEqual(["X1", "X2"], na.node["GO:0050896"]["annotated_genes"])
def test_get_parents_cycle(self): g = terms_to_graph(self.terms_cycle) self.assertEqual(set(['GO:0030534', 'GO:0050896', 'GO:0005374', 'GO:0048149', 'GO:0045471']), g.get_ancestors("GO:0048149")) self.assertEqual([['GO:0048149', 'GO:0005374']], g.cycles)
def test_to_networkx(self): g = terms_to_graph(self.terms_diam) na = g.to_networkx({"GO:0050896": ["X1", "X2"]}) self.assertEqual(["GO:0030534", "GO:0045471"], na.successors("GO:0048149")) self.assertEqual(["GO:0050896"], na.successors("GO:0030534")) self.assertEqual(["GO:0050896"], na.successors("GO:0045471")) self.assertEqual(["X1", "X2"], na.node["GO:0050896"]["annotated_genes"])
def test_to_networkx(self): try: import networkx as nx except ImportError: print("Skipping test. To use this functionality you need to have networkx installed.", file=sys.stderr) else: g = terms_to_graph(self.terms_diam) na = g.to_networkx({"GO:0050896" : ["X1", "X2"]}) self.assertEqual(["GO:0030534", "GO:0045471"], na.successors("GO:0048149")) self.assertEqual(["GO:0050896"], na.successors("GO:0030534")) self.assertEqual(["GO:0050896"], na.successors("GO:0045471")) self.assertEqual(["X1", "X2"], na.node["GO:0050896"]["annotated_genes"])
def test_no_typedef(self): with self.assertRaises(ValueError): terms_to_graph(self.terms_cycle_no)
def test_bad_rel(self): with self.assertRaises(ValueError): terms_to_graph(self.terms_bad_rel)
def test_get_ancestors(self): g = terms_to_graph(self.terms_diam) self.assertEqual(set(["GO:0030534", "GO:0045471", "GO:0050896"]), g.get_ancestors("GO:0048149")) self.assertEqual(set(["GO:0050896"]), g.get_ancestors("GO:0030534"))
def test_get_term(self): g = terms_to_graph(self.terms_diam) self.assertEqual("GO:0045471", g.get_term("GO:0045471").id)