source: orange-bioinformatics/tests/test_kegg.py @ 1533:8543e989a290

Revision 1533:8543e989a290, 3.6 KB checked in by ales_erjavec, 2 years ago (diff)

Added tests dir with unittests for obiKEGG2

Line 
1import unittest
2import obiKEGG2 as kegg
3
4#from obiKEGGservices import
5#from
6
7#class TestServices(unittest.TestCase):
8#    def test_services(self):
9#        service = kegg.web_service()
10#        service.binfo("gb")
11#        service.bfind("gb E-cadherin human")
12#        service.bget("eco:b0002 hin:tRNA-Cys-1")
13       
14       
15class TestGenome(unittest.TestCase):
16    def test_genome(self):
17        genome = kegg.KEGGGenome()
18        org_codes = genome.keys()
19       
20        for code in org_codes[:10]:
21            self.assertTrue(code in genome)
22            self.assertTrue(genome.has_key(code))
23            entry = genome[code]
24            self.assertEqual(entry.entry_key, code)
25            self.assertIsInstance(entry, genome.ENTRY_TYPE)
26            self.assertIsInstance(entry.name, str)
27            self.assertIsInstance(entry.taxid, str)
28           
29           
30        self.assertTrue(genome.get_entry("No such name --,,;;';p[[]&&&") is None)
31        self.assertRaises(KeyError, genome.__getitem__, ("No such name --,,;;';p[[]&&&"))
32       
33        self.assertTrue(genome.search("homo sapiens")[0] == "hsa")
34        entry = genome['hsa']
35        self.assertEqual(entry.taxid, "9606")
36       
37       
38class TestGenes(unittest.TestCase):
39    def _tester(self, org):
40        genes = kegg.KEGGGenes(org)
41        keys = genes.keys()
42        for gene in keys[:10]:
43            self.assertTrue(gene in genes)
44            self.assertTrue(genes.has_key(gene))
45            entry = genes[gene]
46            self.assertTrue(gene.endswith(entry.entry_key))
47            self.assertIsInstance(entry, genes.ENTRY_TYPE)
48            self.assertIsInstance(entry.aliases(), list)
49            self.assertTrue(all(isinstance(a, basestring) for a in entry.aliases()))
50           
51    def test_hsa(self):
52        self._tester("hsa")
53       
54    def test_sce(self):
55        self._tester("sce") 
56       
57   
58class TestPathways(unittest.TestCase):
59    def _tester(self, id):
60        pathways = kegg.KEGGPathways()
61       
62        self.assertRaises(KeyError, pathways.__getitem__, ("--invalid--"))
63        pathway = pathways[id]
64        self.assertTrue(id.endswith(pathway.entry_key))
65        self.assertIsInstance(pathway, pathways.ENTRY_TYPE)
66       
67        path = kegg.KEGGPathway(id)
68       
69    def test_1(self):
70        self._tester("ec00190")
71           
72    def test_2(self):
73        self._tester("hsa00190")
74       
75       
76class TestOrganism(unittest.TestCase):
77    def _tester(self, org):
78        self.organism = org = kegg.KEGGOrganism(org)
79        genes = org.genes
80        self.assertTrue(all(g.startswith(org.org_code) for g in genes))
81        pathways = org.pathways()
82        pathways_for_genes = org.pathways(with_ids=list(genes)[:5])
83        self.assertTrue(all(p.startswith("path:" + org.org_code) \
84                            for p in pathways + pathways_for_genes))
85       
86    def test_hsa(self):
87        self._tester("hsa")
88        # Test search
89        self.assertEqual(self.organism.org_code,
90                         kegg.KEGGOrganism("Homo sapiens").org_code)
91       
92    def test_sce(self):
93        self._tester("sce")
94       
95class TestOld(unittest.TestCase):
96    def test(self):
97        p = kegg.KEGGPathway("sce00010")
98        print p.genes
99        print p.reactions
100        print p.compounds
101        print p.image
102        g = kegg.KEGGGenome()
103        org = kegg.KEGGOrganism("Homo sapiens")
104        print list(org.genes)[:10]
105#        org.gene_aliases
106        print org.pathways(with_ids=org.genes.keys()[:5])
107#        print org.enzymes()
108        print org.get_enriched_pathways(org.genes.keys()[:10])
109        print org.genematcher
Note: See TracBrowser for help on using the repository browser.