1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.renderer; |
22 |
|
|
23 |
|
import static org.testng.Assert.assertEquals; |
24 |
|
import static org.testng.Assert.assertFalse; |
25 |
|
import static org.testng.Assert.assertNotEquals; |
26 |
|
import static org.testng.Assert.assertNotNull; |
27 |
|
import static org.testng.Assert.assertTrue; |
28 |
|
|
29 |
|
import org.testng.annotations.Test; |
30 |
|
|
31 |
|
import jalview.datamodel.AlignmentAnnotation; |
32 |
|
import jalview.datamodel.ColumnSelection; |
33 |
|
import jalview.datamodel.ContactListI; |
34 |
|
import jalview.datamodel.ContactRange; |
35 |
|
import jalview.datamodel.Mapping; |
36 |
|
import jalview.datamodel.SeqDistanceContactMatrix; |
37 |
|
import jalview.datamodel.Sequence; |
38 |
|
import jalview.datamodel.SequenceI; |
39 |
|
import jalview.util.MapList; |
40 |
|
import jalview.util.StringUtils; |
41 |
|
import jalview.ws.datamodel.MappableContactMatrixI; |
42 |
|
|
|
|
| 98.9% |
Uncovered Elements: 1 (90) |
Complexity: 8 |
Complexity Density: 0.1 |
|
43 |
|
public class ContactGeometryTest |
44 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
1PASS
|
|
45 |
1 |
@Test(groups = "Functional")... |
46 |
|
public void testCoverageofRange() |
47 |
|
{ |
48 |
|
|
49 |
|
|
50 |
58 |
for (int range = 12; range < 2000; range += 35) |
51 |
|
{ |
52 |
57 |
StringBuilder sb = new StringBuilder(); |
53 |
56601 |
while (sb.length() < range) |
54 |
|
{ |
55 |
56544 |
sb.append("c"); |
56 |
|
} |
57 |
57 |
SequenceI sq = new Sequence("a", sb.toString()); |
58 |
57 |
MappableContactMatrixI cm = new SeqDistanceContactMatrix(range); |
59 |
57 |
AlignmentAnnotation cm_aan = sq.addContactList(cm); |
60 |
57 |
ContactListI cl = sq.getContactListFor(cm_aan, 10); |
61 |
57 |
assertNotNull(cl); |
62 |
141431 |
for (int ht = range / 2; ht < range * 3; ht++) |
63 |
|
{ |
64 |
141374 |
ContactGeometry clgeom = new ContactGeometry(cl, ht); |
65 |
141374 |
assertNotNull(clgeom.allSteps()); |
66 |
|
} |
67 |
|
} |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
70 |
1 |
@Test(groups = "Functional")... |
71 |
|
public void testContactGeometry() |
72 |
|
{ |
73 |
1 |
SequenceI sq = new Sequence("a", "SSSQ"); |
74 |
1 |
MappableContactMatrixI cm = new SeqDistanceContactMatrix(4); |
75 |
1 |
AlignmentAnnotation cm_aan = sq.addContactList(cm); |
76 |
1 |
checkConsistencyFor(sq, cm_aan); |
77 |
|
|
78 |
1 |
MappableContactMatrixI newcm = cm.liftOver(sq, |
79 |
|
new Mapping(sq, new MapList(new int[] |
80 |
|
{ 1, 4 }, new int[] { 1, 4 }, 1, 1))); |
81 |
1 |
AlignmentAnnotation mapped_cm = sq.addContactList(newcm); |
82 |
1 |
checkConsistencyFor(sq, mapped_cm); |
83 |
|
} |
84 |
|
|
85 |
|
|
|
|
| 98.4% |
Uncovered Elements: 1 (62) |
Complexity: 3 |
Complexity Density: 0.05 |
|
86 |
2 |
private void checkConsistencyFor(SequenceI sq, AlignmentAnnotation cm_aan)... |
87 |
|
{ |
88 |
2 |
int col = 1; |
89 |
2 |
ContactListI cl = sq.getContactListFor(cm_aan, col); |
90 |
2 |
assertNotNull(cl); |
91 |
2 |
assertEquals(cl.getContactHeight(), 4); |
92 |
|
|
93 |
|
|
94 |
2 |
ContactGeometry testee = new ContactGeometry(cl, 2); |
95 |
2 |
assertEquals(testee.contacts_per_pixel, 2d); |
96 |
2 |
ContactGeometry.contactInterval lastInterval = testee.mapFor(1); |
97 |
2 |
assertEquals(lastInterval.cStart, 2); |
98 |
2 |
assertEquals(lastInterval.cEnd, 3); |
99 |
2 |
assertEquals(lastInterval.pStart, 1); |
100 |
2 |
assertEquals(lastInterval.pEnd, 1); |
101 |
2 |
ContactGeometry.contactInterval another = testee.mapFor(1, 2); |
102 |
2 |
assertEquals(lastInterval, another); |
103 |
|
|
104 |
2 |
testee = new ContactGeometry(cl, 395); |
105 |
2 |
lastInterval = testee.mapFor(390, 395); |
106 |
2 |
assertNotNull(lastInterval); |
107 |
2 |
assertEquals(lastInterval.cEnd, 3); |
108 |
2 |
assertEquals(lastInterval.pEnd, 394); |
109 |
|
|
110 |
2 |
testee = new ContactGeometry(cl, 40); |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
82 |
for (int p = 0; p < 40; p++) |
117 |
|
{ |
118 |
80 |
int expectC = (p / 10); |
119 |
80 |
int expectP = (expectC) * 10; |
120 |
80 |
ContactGeometry.contactInterval ci_at = testee.mapFor(p), |
121 |
|
ci_from = testee.mapFor(p, p); |
122 |
80 |
assertNotNull(ci_at); |
123 |
|
|
124 |
80 |
assertEquals(ci_at.cStart, expectC, |
125 |
|
"Different cStart at position " + p); |
126 |
80 |
assertEquals(ci_at.cEnd, expectC, "Different cEnd at position " + p); |
127 |
80 |
assertEquals(ci_at.pStart, expectP, |
128 |
|
"Different pStart at position " + p); |
129 |
80 |
assertEquals(ci_at.pEnd, expectP + 9, |
130 |
|
"Different pEnd at position " + p); |
131 |
|
|
132 |
80 |
assertEquals(ci_from, ci_at, |
133 |
|
"Different contactIntervals at position " + p); |
134 |
|
|
135 |
80 |
ContactRange cr = cl.getRangeFor(ci_at.cStart, ci_at.cEnd); |
136 |
80 |
assertEquals(cr.getFrom_column(), cr.getTo_column()); |
137 |
80 |
assertEquals((double) cr.getMean(), |
138 |
|
(double) Math.abs(col - cr.getFrom_column()), |
139 |
|
"Didn't resolve expected value at position " + p); |
140 |
|
} |
141 |
|
|
142 |
2 |
ContactGeometry.contactInterval ci_at0 = testee.mapFor(0); |
143 |
2 |
ContactGeometry.contactInterval ci_at9 = testee.mapFor(9); |
144 |
2 |
assertNotNull(ci_at9); |
145 |
|
|
146 |
2 |
assertEquals(ci_at0, ci_at9); |
147 |
|
|
148 |
|
|
149 |
2 |
ContactGeometry.contactInterval ci_at10 = testee.mapFor(10); |
150 |
2 |
assertNotNull(ci_at10); |
151 |
2 |
ContactGeometry.contactInterval ci_at11 = testee.mapFor(11); |
152 |
2 |
assertNotNull(ci_at11); |
153 |
|
|
154 |
2 |
assertEquals(ci_at11, ci_at10, |
155 |
|
"Off-by-one in ContactGeometry mapping."); |
156 |
|
|
157 |
2 |
assertNotEquals(ci_at0, ci_at10, |
158 |
|
"Expected adjacent cells to be not equal."); |
159 |
|
|
160 |
|
|
161 |
2 |
assertEquals(ci_at11.cStart, ci_at9.cStart + 1); |
162 |
|
|
163 |
2 |
assertEquals(ci_at9.cEnd + 1, ci_at11.cStart); |
164 |
2 |
assertEquals(ci_at9.cEnd + 1, ci_at11.cEnd); |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
2 |
ColumnSelection cs = new ColumnSelection(); |
169 |
2 |
cs.addElement(2); |
170 |
|
|
171 |
2 |
boolean mask = false; |
172 |
2 |
do |
173 |
|
{ |
174 |
2 |
assertFalse(testee.intersects(ci_at0, cs, null, mask)); |
175 |
2 |
assertFalse(testee.intersects(ci_at11, cs, null, mask)); |
176 |
2 |
assertTrue(testee.intersects(testee.mapFor(21), cs, null, mask)); |
177 |
2 |
assertFalse(testee.intersects(testee.mapFor(31), cs, null, mask)); |
178 |
2 |
cs.addElement(3); |
179 |
2 |
assertTrue(testee.intersects(testee.mapFor(31), cs, null, mask)); |
180 |
2 |
cs.removeElement(2); |
181 |
2 |
assertFalse(testee.intersects(testee.mapFor(21), cs, null, mask)); |
182 |
2 |
mask = !mask; |
183 |
2 |
} while (!mask); |
184 |
|
|
185 |
|
} |
186 |
|
} |