annotate manipulate/rename_kcf/test_rename_kcf.py @ 1:0a5e0df17054 draft default tip

Uploaded
author chrisb
date Fri, 06 May 2016 08:05:48 -0400
parents 89592faa2875
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
1 __license__ = "MIT"
89592faa2875 Uploaded
chrisb
parents:
diff changeset
2
89592faa2875 Uploaded
chrisb
parents:
diff changeset
3 import unittest
89592faa2875 Uploaded
chrisb
parents:
diff changeset
4 import rename_kcf as rk
89592faa2875 Uploaded
chrisb
parents:
diff changeset
5
89592faa2875 Uploaded
chrisb
parents:
diff changeset
6
89592faa2875 Uploaded
chrisb
parents:
diff changeset
7 class SimpleUnitTest(unittest.TestCase):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
8 def setUp(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
9 import os
89592faa2875 Uploaded
chrisb
parents:
diff changeset
10
89592faa2875 Uploaded
chrisb
parents:
diff changeset
11 os.environ["http_proxy"] = "" # work around for IOError: [Errno url error] invalid proxy for http:
89592faa2875 Uploaded
chrisb
parents:
diff changeset
12 pass
89592faa2875 Uploaded
chrisb
parents:
diff changeset
13
89592faa2875 Uploaded
chrisb
parents:
diff changeset
14 def tearDown(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
15 pass
89592faa2875 Uploaded
chrisb
parents:
diff changeset
16
89592faa2875 Uploaded
chrisb
parents:
diff changeset
17 def test_simple_kcf(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
18 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
19
89592faa2875 Uploaded
chrisb
parents:
diff changeset
20 kcinput = """ENTRY ((A??)AN) Glycan
89592faa2875 Uploaded
chrisb
parents:
diff changeset
21 NODE 2
89592faa2875 Uploaded
chrisb
parents:
diff changeset
22 1 galnac 0 0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
23 2 gal -8 0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
24 EDGE 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
25 1 2:1 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
26 ///
89592faa2875 Uploaded
chrisb
parents:
diff changeset
27 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
28
89592faa2875 Uploaded
chrisb
parents:
diff changeset
29 kchandle = StringIO.StringIO(''.join(kcinput))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
30 h = rk.read_meta_kcf(kchandle)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
31 i = rk.flatten_meta_kcf_list(h)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
32 self.assertIn("ENTRY GLY0 Glycan\n", i)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
33
89592faa2875 Uploaded
chrisb
parents:
diff changeset
34 def test_simple_kcf_rename_newcount(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
35 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
36
89592faa2875 Uploaded
chrisb
parents:
diff changeset
37 kcinput = """ENTRY ((A??)AN) Glycan
89592faa2875 Uploaded
chrisb
parents:
diff changeset
38 NODE 2
89592faa2875 Uploaded
chrisb
parents:
diff changeset
39 1 galnac 0 0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
40 2 gal -8 0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
41 EDGE 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
42 1 2:1 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
43 ///
89592faa2875 Uploaded
chrisb
parents:
diff changeset
44 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
45
89592faa2875 Uploaded
chrisb
parents:
diff changeset
46 kchandle = StringIO.StringIO(''.join(kcinput))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
47 h = rk.read_meta_kcf(kchandle, "FLY", 15)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
48 i = rk.flatten_meta_kcf_list(h)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
49 self.assertIn("ENTRY FLY15 Glycan\n", i)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
50
89592faa2875 Uploaded
chrisb
parents:
diff changeset
51 def test_initial_newline_simple_kcf(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
52 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
53
89592faa2875 Uploaded
chrisb
parents:
diff changeset
54 kcinput = """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
55 ENTRY ((A??)AN) Glycan
89592faa2875 Uploaded
chrisb
parents:
diff changeset
56 NODE 2
89592faa2875 Uploaded
chrisb
parents:
diff changeset
57 1 galnac 0 0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
58 2 gal -8 0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
59 EDGE 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
60 1 2:1 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
61 ///
89592faa2875 Uploaded
chrisb
parents:
diff changeset
62 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
63
89592faa2875 Uploaded
chrisb
parents:
diff changeset
64 kchandle = StringIO.StringIO(''.join(kcinput))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
65 h = rk.read_meta_kcf(kchandle)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
66 i = rk.flatten_meta_kcf_list(h)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
67 self.assertIn("ENTRY GLY0 Glycan\n", i)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
68
89592faa2875 Uploaded
chrisb
parents:
diff changeset
69 def test_multiple_kcf(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
70 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
71
89592faa2875 Uploaded
chrisb
parents:
diff changeset
72 kcinput = """ENTRY ((A??)AN) Glycan
89592faa2875 Uploaded
chrisb
parents:
diff changeset
73 NODE 2
89592faa2875 Uploaded
chrisb
parents:
diff changeset
74 1 galnac 0 0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
75 2 gal -8 0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
76 EDGE 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
77 1 2:1 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
78 ///
89592faa2875 Uploaded
chrisb
parents:
diff changeset
79 ENTRY ((A??)AN) Glycan
89592faa2875 Uploaded
chrisb
parents:
diff changeset
80 NODE 2
89592faa2875 Uploaded
chrisb
parents:
diff changeset
81 1 galnac 0 0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
82 2 gal -8 0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
83 EDGE 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
84 1 2:1 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
85 ///
89592faa2875 Uploaded
chrisb
parents:
diff changeset
86 ENTRY G00005 Glycan
89592faa2875 Uploaded
chrisb
parents:
diff changeset
87 NODE 6
89592faa2875 Uploaded
chrisb
parents:
diff changeset
88 1 PP-Dol 15 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
89 2 GlcNAc 8 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
90 3 GlcNAc 0 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
91 4 Man -9 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
92 5 Man -16 7
89592faa2875 Uploaded
chrisb
parents:
diff changeset
93 6 Man -16 -6
89592faa2875 Uploaded
chrisb
parents:
diff changeset
94 EDGE 5
89592faa2875 Uploaded
chrisb
parents:
diff changeset
95 1 2:a1 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
96 2 3:b1 2:4
89592faa2875 Uploaded
chrisb
parents:
diff changeset
97 3 4:b1 3:4
89592faa2875 Uploaded
chrisb
parents:
diff changeset
98 4 5:a1 4:6
89592faa2875 Uploaded
chrisb
parents:
diff changeset
99 5 6:a1 4:3
89592faa2875 Uploaded
chrisb
parents:
diff changeset
100 ///
89592faa2875 Uploaded
chrisb
parents:
diff changeset
101 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
102 kchandle = StringIO.StringIO(''.join(kcinput))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
103 h = rk.read_meta_kcf(kchandle)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
104 i = rk.flatten_meta_kcf_list(h)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
105 self.assertIn("ENTRY GLY0 Glycan\n", i)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
106 self.assertIn("ENTRY GLY1 Glycan\n", i)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
107 self.assertIn("ENTRY GLY2 Glycan\n", i)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
108
89592faa2875 Uploaded
chrisb
parents:
diff changeset
109 def test_empty_stream(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
110 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
111 m = rk.read_meta_kcf(None)
89592faa2875 Uploaded
chrisb
parents:
diff changeset
112 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
113 m = rk.read_meta_kcf([])
89592faa2875 Uploaded
chrisb
parents:
diff changeset
114 with self.assertRaises(IOError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
115 m = rk.read_meta_kcf("")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
116
89592faa2875 Uploaded
chrisb
parents:
diff changeset
117 def test_non_integer_counter(self):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
118 import StringIO
89592faa2875 Uploaded
chrisb
parents:
diff changeset
119
89592faa2875 Uploaded
chrisb
parents:
diff changeset
120 kcinput = """ENTRY ((A??)AN) Glycan
89592faa2875 Uploaded
chrisb
parents:
diff changeset
121 NODE 2
89592faa2875 Uploaded
chrisb
parents:
diff changeset
122 1 galnac 0 0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
123 2 gal -8 0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
124 EDGE 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
125 1 2:1 1
89592faa2875 Uploaded
chrisb
parents:
diff changeset
126 ///
89592faa2875 Uploaded
chrisb
parents:
diff changeset
127 """
89592faa2875 Uploaded
chrisb
parents:
diff changeset
128
89592faa2875 Uploaded
chrisb
parents:
diff changeset
129 kchandle = StringIO.StringIO(''.join(kcinput))
89592faa2875 Uploaded
chrisb
parents:
diff changeset
130 with self.assertRaises(TypeError):
89592faa2875 Uploaded
chrisb
parents:
diff changeset
131 h = rk.read_meta_kcf(kchandle, "FLY", "abc")
89592faa2875 Uploaded
chrisb
parents:
diff changeset
132
89592faa2875 Uploaded
chrisb
parents:
diff changeset
133
89592faa2875 Uploaded
chrisb
parents:
diff changeset
134 def run_tests():
89592faa2875 Uploaded
chrisb
parents:
diff changeset
135 unittest.main()
89592faa2875 Uploaded
chrisb
parents:
diff changeset
136
89592faa2875 Uploaded
chrisb
parents:
diff changeset
137
89592faa2875 Uploaded
chrisb
parents:
diff changeset
138 if __name__ == '__main__':
89592faa2875 Uploaded
chrisb
parents:
diff changeset
139 run_tests()
89592faa2875 Uploaded
chrisb
parents:
diff changeset
140
89592faa2875 Uploaded
chrisb
parents:
diff changeset
141