Mercurial > repos > padge > clipkit
comparison clipkit_repo/tests/unit/test_modes.py @ 0:49b058e85902 draft
"planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
author | padge |
---|---|
date | Fri, 25 Mar 2022 13:04:31 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:49b058e85902 |
---|---|
1 import pytest | |
2 from pathlib import Path | |
3 | |
4 import numpy as np | |
5 from Bio import AlignIO | |
6 from clipkit.modes import TrimmingMode, trim, shouldKeep | |
7 | |
8 here = Path(__file__) | |
9 | |
10 | |
11 class TestModes(object): | |
12 def test_shouldKeep_kpi_gappy_keep(self): | |
13 ## setup | |
14 mode = TrimmingMode.kpi_gappy | |
15 gappyness = 0.00 | |
16 gaps = 0.9 | |
17 parsimony_informative = True | |
18 constant_site = False | |
19 | |
20 assert True == shouldKeep( | |
21 mode, parsimony_informative, constant_site, gappyness, gaps | |
22 ) | |
23 | |
24 def test_shouldKeep_kpi_gappy_trim(self): | |
25 ## setup | |
26 mode = TrimmingMode.kpi_gappy | |
27 gappyness = 0.00 | |
28 gaps = 0.9 | |
29 parsimony_informative = False | |
30 constant_site = False | |
31 | |
32 assert False == shouldKeep( | |
33 mode, parsimony_informative, constant_site, gappyness, gaps | |
34 ) | |
35 | |
36 def test_shouldKeep_gappy_keep(self): | |
37 ## setup | |
38 mode = TrimmingMode.gappy | |
39 gappyness = 0.00 | |
40 gaps = 0.9 | |
41 parsimony_informative = True | |
42 constant_site = False | |
43 | |
44 assert True == shouldKeep( | |
45 mode, parsimony_informative, constant_site, gappyness, gaps | |
46 ) | |
47 | |
48 def test_shouldKeep_gappy_trim(self): | |
49 ## setup | |
50 mode = TrimmingMode.gappy | |
51 gappyness = 0.95 | |
52 gaps = 0.9 | |
53 parsimony_informative = True | |
54 constant_site = False | |
55 | |
56 assert False == shouldKeep( | |
57 mode, parsimony_informative, constant_site, gappyness, gaps | |
58 ) | |
59 | |
60 def test_shouldKeep_kpi_keep(self): | |
61 ## setup | |
62 mode = TrimmingMode.kpi | |
63 gappyness = 0.00 | |
64 gaps = 0.9 | |
65 parsimony_informative = True | |
66 constant_site = False | |
67 | |
68 assert True == shouldKeep( | |
69 mode, parsimony_informative, constant_site, gappyness, gaps | |
70 ) | |
71 | |
72 def test_shouldKeep_kpi_trim(self): | |
73 ## setup | |
74 mode = TrimmingMode.kpi | |
75 gappyness = 0.95 | |
76 gaps = 0.9 | |
77 parsimony_informative = False | |
78 constant_site = False | |
79 | |
80 assert False == shouldKeep( | |
81 mode, parsimony_informative, constant_site, gappyness, gaps | |
82 ) | |
83 | |
84 def test_shouldKeep_kpic_keep(self): | |
85 ## setup | |
86 mode = TrimmingMode.kpic | |
87 gappyness = 0.95 | |
88 gaps = 0.9 | |
89 parsimony_informative = False | |
90 constant_site = True | |
91 | |
92 assert True == shouldKeep( | |
93 mode, parsimony_informative, constant_site, gappyness, gaps | |
94 ) | |
95 | |
96 def test_shouldKeep_kpic_trim(self): | |
97 ## setup | |
98 mode = TrimmingMode.kpic | |
99 gappyness = 0.95 | |
100 gaps = 0.9 | |
101 parsimony_informative = False | |
102 constant_site = False | |
103 | |
104 assert False == shouldKeep( | |
105 mode, parsimony_informative, constant_site, gappyness, gaps | |
106 ) | |
107 | |
108 def test_shouldKeep_kpic_gappy_keep(self): | |
109 ## setup | |
110 mode = TrimmingMode.kpic_gappy | |
111 gappyness = 0.70 | |
112 gaps = 0.9 | |
113 parsimony_informative = False | |
114 constant_site = True | |
115 | |
116 assert True == shouldKeep( | |
117 mode, parsimony_informative, constant_site, gappyness, gaps | |
118 ) | |
119 | |
120 def test_shouldKeep_kpic_gappy_trim(self): | |
121 ## setup | |
122 mode = TrimmingMode.kpic_gappy | |
123 gappyness = 0.95 | |
124 gaps = 0.9 | |
125 parsimony_informative = False | |
126 constant_site = True | |
127 | |
128 assert False == shouldKeep( | |
129 mode, parsimony_informative, constant_site, gappyness, gaps | |
130 ) | |
131 | |
132 def test_gappy_mode(self): | |
133 ## setup | |
134 gappyness = 0.00 | |
135 parsimony_informative = True | |
136 keepD = {} | |
137 trimD = {} | |
138 i = 2 | |
139 gaps = 0.9 | |
140 alignment = AlignIO.read(f"{here.parent}/examples/simple.fa", "fasta") | |
141 use_log = False | |
142 constant_site = False | |
143 | |
144 for entry in alignment: | |
145 keepD[entry.description] = np.empty([6], dtype=str) | |
146 trimD = {} | |
147 for entry in alignment: | |
148 trimD[entry.description] = np.empty([6], dtype=str) | |
149 | |
150 ## execution | |
151 keepD, trimD = trim( | |
152 gappyness, | |
153 parsimony_informative, | |
154 constant_site, | |
155 keepD, | |
156 trimD, | |
157 i, | |
158 gaps, | |
159 alignment, | |
160 TrimmingMode.gappy, | |
161 use_log, | |
162 ) | |
163 | |
164 ## check results | |
165 expected_keepD = { | |
166 "1": np.array(["", "", "G", "", "", ""]), | |
167 "2": np.array(["", "", "G", "", "", ""]), | |
168 "3": np.array(["", "", "G", "", "", ""]), | |
169 "4": np.array(["", "", "A", "", "", ""]), | |
170 "5": np.array(["", "", "a", "", "", ""]), | |
171 } | |
172 expected_trimD = { | |
173 "1": np.array(["", "", "", "", "", ""]), | |
174 "2": np.array(["", "", "", "", "", ""]), | |
175 "3": np.array(["", "", "", "", "", ""]), | |
176 "4": np.array(["", "", "", "", "", ""]), | |
177 "5": np.array(["", "", "", "", "", ""]), | |
178 } | |
179 | |
180 assert expected_keepD.keys() == keepD.keys() | |
181 assert all( | |
182 np.array_equal(expected_keepD[key], keepD[key]) for key in expected_keepD | |
183 ) | |
184 assert expected_trimD.keys() == trimD.keys() | |
185 assert all( | |
186 np.array_equal(expected_trimD[key], trimD[key]) for key in expected_trimD | |
187 ) | |
188 | |
189 def test_kpi_gappy_mode(self): | |
190 ## setup | |
191 gappyness = 0.6 | |
192 parsimony_informative = False | |
193 constant_site = True | |
194 keepD = {} | |
195 trimD = {} | |
196 i = 1 | |
197 gaps = 0.9 | |
198 alignment = AlignIO.read(f"{here.parent}/examples/simple.fa", "fasta") | |
199 use_log = False | |
200 | |
201 for entry in alignment: | |
202 keepD[entry.description] = np.empty([6], dtype=str) | |
203 trimD = {} | |
204 for entry in alignment: | |
205 trimD[entry.description] = np.empty([6], dtype=str) | |
206 | |
207 ## execution | |
208 keepD, trimD = trim( | |
209 gappyness, | |
210 parsimony_informative, | |
211 constant_site, | |
212 keepD, | |
213 trimD, | |
214 i, | |
215 gaps, | |
216 alignment, | |
217 TrimmingMode.kpi_gappy, | |
218 use_log, | |
219 ) | |
220 | |
221 ## check results | |
222 expected_keepD = { | |
223 "1": np.array(["", "", "", "", "", ""]), | |
224 "2": np.array(["", "", "", "", "", ""]), | |
225 "3": np.array(["", "", "", "", "", ""]), | |
226 "4": np.array(["", "", "", "", "", ""]), | |
227 "5": np.array(["", "", "", "", "", ""]), | |
228 } | |
229 expected_trimD = { | |
230 "1": np.array(["", "-", "", "", "", ""]), | |
231 "2": np.array(["", "-", "", "", "", ""]), | |
232 "3": np.array(["", "-", "", "", "", ""]), | |
233 "4": np.array(["", "G", "", "", "", ""]), | |
234 "5": np.array(["", "C", "", "", "", ""]), | |
235 } | |
236 | |
237 assert expected_keepD.keys() == keepD.keys() | |
238 assert all( | |
239 np.array_equal(expected_keepD[key], keepD[key]) for key in expected_keepD | |
240 ) | |
241 assert expected_trimD.keys() == trimD.keys() | |
242 assert all( | |
243 np.array_equal(expected_trimD[key], trimD[key]) for key in expected_trimD | |
244 ) | |
245 | |
246 def test_kpi_mode(self): | |
247 ## setup | |
248 gappyness = 0.2 | |
249 parsimony_informative = True | |
250 constant_site = False | |
251 keepD = {} | |
252 trimD = {} | |
253 i = 5 | |
254 gaps = 0.9 | |
255 alignment = AlignIO.read(f"{here.parent}/examples/simple.fa", "fasta") | |
256 use_log = False | |
257 | |
258 for entry in alignment: | |
259 keepD[entry.description] = np.empty([6], dtype=str) | |
260 trimD = {} | |
261 for entry in alignment: | |
262 trimD[entry.description] = np.empty([6], dtype=str) | |
263 | |
264 ## execution | |
265 keepD, trimD = trim( | |
266 gappyness, | |
267 parsimony_informative, | |
268 constant_site, | |
269 keepD, | |
270 trimD, | |
271 i, | |
272 gaps, | |
273 alignment, | |
274 TrimmingMode.kpi, | |
275 use_log, | |
276 ) | |
277 | |
278 ## check results | |
279 expected_keepD = { | |
280 "1": np.array(["", "", "", "", "", "T"]), | |
281 "2": np.array(["", "", "", "", "", "T"]), | |
282 "3": np.array(["", "", "", "", "", "A"]), | |
283 "4": np.array(["", "", "", "", "", "A"]), | |
284 "5": np.array(["", "", "", "", "", "-"]), | |
285 } | |
286 expected_trimD = { | |
287 "1": np.array(["", "", "", "", "", ""]), | |
288 "2": np.array(["", "", "", "", "", ""]), | |
289 "3": np.array(["", "", "", "", "", ""]), | |
290 "4": np.array(["", "", "", "", "", ""]), | |
291 "5": np.array(["", "", "", "", "", ""]), | |
292 } | |
293 | |
294 assert expected_keepD.keys() == keepD.keys() | |
295 assert all( | |
296 np.array_equal(expected_keepD[key], keepD[key]) for key in expected_keepD | |
297 ) | |
298 assert expected_trimD.keys() == trimD.keys() | |
299 assert all( | |
300 np.array_equal(expected_trimD[key], trimD[key]) for key in expected_trimD | |
301 ) | |
302 | |
303 def test_kpic_mode(self): | |
304 ## setup | |
305 gappyness = 0.2 | |
306 parsimony_informative = False | |
307 constant_site = True | |
308 keepD = {} | |
309 trimD = {} | |
310 i = 0 | |
311 gaps = 0.9 | |
312 alignment = AlignIO.read(f"{here.parent}/examples/simple.fa", "fasta") | |
313 use_log = False | |
314 | |
315 for entry in alignment: | |
316 keepD[entry.description] = np.empty([6], dtype=str) | |
317 trimD = {} | |
318 for entry in alignment: | |
319 trimD[entry.description] = np.empty([6], dtype=str) | |
320 | |
321 ## execution | |
322 keepD, trimD = trim( | |
323 gappyness, | |
324 parsimony_informative, | |
325 constant_site, | |
326 keepD, | |
327 trimD, | |
328 i, | |
329 gaps, | |
330 alignment, | |
331 TrimmingMode.kpic, | |
332 use_log, | |
333 ) | |
334 | |
335 ## check results | |
336 expected_keepD = { | |
337 "1": np.array(["A", "", "", "", "", ""]), | |
338 "2": np.array(["A", "", "", "", "", ""]), | |
339 "3": np.array(["A", "", "", "", "", ""]), | |
340 "4": np.array(["A", "", "", "", "", ""]), | |
341 "5": np.array(["A", "", "", "", "", ""]), | |
342 } | |
343 expected_trimD = { | |
344 "1": np.array(["", "", "", "", "", ""]), | |
345 "2": np.array(["", "", "", "", "", ""]), | |
346 "3": np.array(["", "", "", "", "", ""]), | |
347 "4": np.array(["", "", "", "", "", ""]), | |
348 "5": np.array(["", "", "", "", "", ""]), | |
349 } | |
350 | |
351 assert expected_keepD.keys() == keepD.keys() | |
352 assert all( | |
353 np.array_equal(expected_keepD[key], keepD[key]) for key in expected_keepD | |
354 ) | |
355 assert expected_trimD.keys() == trimD.keys() | |
356 assert all( | |
357 np.array_equal(expected_trimD[key], trimD[key]) for key in expected_trimD | |
358 ) | |
359 | |
360 def test_kpic_gappy_mode(self): | |
361 ## setup | |
362 gappyness = 0.2 | |
363 parsimony_informative = False | |
364 constant_site = False | |
365 keepD = {} | |
366 trimD = {} | |
367 i = 3 | |
368 gaps = 0.9 | |
369 alignment = AlignIO.read(f"{here.parent}/examples/simple.fa", "fasta") | |
370 use_log = False | |
371 | |
372 for entry in alignment: | |
373 keepD[entry.description] = np.empty([6], dtype=str) | |
374 trimD = {} | |
375 for entry in alignment: | |
376 trimD[entry.description] = np.empty([6], dtype=str) | |
377 | |
378 ## execution | |
379 keepD, trimD = trim( | |
380 gappyness, | |
381 parsimony_informative, | |
382 constant_site, | |
383 keepD, | |
384 trimD, | |
385 i, | |
386 gaps, | |
387 alignment, | |
388 TrimmingMode.kpic_gappy, | |
389 use_log, | |
390 ) | |
391 | |
392 ## check results | |
393 expected_keepD = { | |
394 "1": np.array(["", "", "", "", "", ""]), | |
395 "2": np.array(["", "", "", "", "", ""]), | |
396 "3": np.array(["", "", "", "", "", ""]), | |
397 "4": np.array(["", "", "", "", "", ""]), | |
398 "5": np.array(["", "", "", "", "", ""]), | |
399 } | |
400 expected_trimD = { | |
401 "1": np.array(["", "", "", "T", "", ""]), | |
402 "2": np.array(["", "", "", "-", "", ""]), | |
403 "3": np.array(["", "", "", "-", "", ""]), | |
404 "4": np.array(["", "", "", "-", "", ""]), | |
405 "5": np.array(["", "", "", "-", "", ""]), | |
406 } | |
407 | |
408 assert expected_keepD.keys() == keepD.keys() | |
409 assert all( | |
410 np.array_equal(expected_keepD[key], keepD[key]) for key in expected_keepD | |
411 ) | |
412 assert expected_trimD.keys() == trimD.keys() | |
413 assert all( | |
414 np.array_equal(expected_trimD[key], trimD[key]) for key in expected_trimD | |
415 ) |