comparison clipkit_repo/tests/unit/test_smart_gap_helper.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 import pytest_mock
3 from pathlib import Path
4
5
6 import numpy as np
7 from Bio import AlignIO
8 from Bio import SeqIO
9 from Bio.Seq import Seq
10 from Bio.SeqRecord import SeqRecord
11 from Bio.Align import MultipleSeqAlignment
12
13 from clipkit.smart_gap_helper import (
14 smart_gap_threshold_determination,
15 greatest_diff_in_slopes,
16 gap_to_gap_slope,
17 get_gaps_distribution,
18 count_and_sort_gaps
19 )
20 from clipkit.files import FileFormat
21
22 here = Path(__file__)
23
24 class TestSmartGapsHelper(object):
25 def test_smart_gap_threshold_simple_case(self):
26 ## set up
27 alignment = AlignIO.read(f"{here.parent}/examples/simple.fa", "fasta")
28 expected_gaps = 0.8
29
30 ## execution
31 gaps = smart_gap_threshold_determination(alignment)
32
33 ## check results
34 assert expected_gaps == gaps
35
36 def test_smart_gap_threshold_standard_case(self):
37 ## set up
38 alignment = AlignIO.read(f"{here.parent}/examples/EOG091N44M8_aa.fa", "fasta")
39
40 ## execution
41 gaps = smart_gap_threshold_determination(alignment)
42 expected_gaps = 0.8803
43
44 ## check results
45 assert expected_gaps == gaps
46
47 def test_greatest_diff_in_slopes_simple_case(self):
48 ## set up
49 slopes = [0.833333333333333]
50 gaps_arr = [[0.8, 1.0], [0.6, 1.0], [0.2, 1.0], [0.0, 3.0]]
51 expected_return = 0.8
52
53 ## execution
54 greatest_diff = greatest_diff_in_slopes(slopes, gaps_arr)
55
56 ## check results
57 assert greatest_diff == expected_return
58
59 def test_greatest_diff_in_slopes_standard_case(self):
60 ## set up
61 slopes = [
62 0.453329706695677,
63 0.1903630604288502,
64 2.153316106804466,
65 0.11466574934067258,
66 2.4933133868262236,
67 0.6879944960440355,
68 0.037924469626292194,
69 2.1786492374727793,
70 2.4933133868262236,
71 4.12796697626421,
72 1.6999864001087854,
73 1.0319917440660464,
74 0.7933269867174482,
75 0.11399518940300717,
76 0.8026602453847114
77 ]
78 gaps_arr = [
79 [0.9915, 136.0],
80 [0.9829, 4.0],
81 [0.9573, 5.0],
82 [0.9487, 19.0],
83 [0.9402, 1.0],
84 [0.9316, 22.0],
85 [0.9231, 6.0],
86 [0.8974, 1.0],
87 [0.8889, 19.0],
88 [0.8803, 22.0],
89 [0.8718, 36.0],
90 [0.8632, 15.0],
91 [0.8462, 18.0],
92 [0.8376, 7.0],
93 [0.8205, 2.0],
94 [0.812, 7.0],
95 [0.8034, 19.0],
96 [0.7949, 1.0],
97 [0.7692, 288.0],
98 [0.7607, 279.0],
99 [0.7521, 6.0],
100 [0.6667, 5.0],
101 [0.1197, 1.0],
102 [0.1026, 2.0],
103 [0.0855, 1.0],
104 [0.0769, 1.0],
105 [0.0598, 2.0],
106 [0.0342, 1.0],
107 [0.0256, 3.0],
108 [0.0171, 1.0],
109 [0.0085, 1.0],
110 [0.0, 95.0]
111 ]
112 expected_return = 0.8803
113
114 ## execution
115 greatest_diff = greatest_diff_in_slopes(slopes, gaps_arr)
116
117 ## check results
118 assert greatest_diff == expected_return
119
120 def test_gap_to_gap_slope_simple_case(self):
121 ## set up
122 gaps_arr = [[0.8, 1.0], [0.6, 1.0], [0.2, 1.0], [0.0, 3.0]]
123 alignment_length = 6
124
125 ## execution
126 slopes = gap_to_gap_slope(gaps_arr, alignment_length)
127 expected_slopes = [0.833333333333333]
128
129 ## check results
130 assert expected_slopes == slopes
131
132 def test_get_gaps_distribution(self):
133 ## set up
134 alignment = AlignIO.read(f"{here.parent}/examples/simple.fa", "fasta")
135 alignment_length = 6
136
137 ## execution
138 gaps_arr = get_gaps_distribution(alignment, alignment_length)
139 expected_gaps_arr = [0.0, 0.6, 0.0, 0.8, 0.0, 0.2]
140
141 ## check results
142 assert expected_gaps_arr == gaps_arr
143
144 def test_count_and_sort_gaps(self):
145 ## set up
146 gaps_dist = [0.0, 0.6, 0.0, 0.8, 0.0, 0.2]
147
148 ## execution
149 gaps_arr = count_and_sort_gaps(gaps_dist)
150 expected_gaps_arr = [[0.8, 1.0], [0.6, 1.0], [0.2, 1.0], [0.0, 3.0]]
151
152 ## check results
153 assert expected_gaps_arr == gaps_arr
154
155
156
157
158