1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.analysis.scoremodels; |
22 |
|
|
23 |
|
import static org.testng.Assert.assertEquals; |
24 |
|
import static org.testng.Assert.assertTrue; |
25 |
|
|
26 |
|
import jalview.api.analysis.ScoreModelI; |
27 |
|
import jalview.api.analysis.SimilarityParamsI; |
28 |
|
import jalview.datamodel.Alignment; |
29 |
|
import jalview.datamodel.AlignmentI; |
30 |
|
import jalview.datamodel.AlignmentView; |
31 |
|
import jalview.datamodel.Sequence; |
32 |
|
import jalview.datamodel.SequenceFeature; |
33 |
|
import jalview.datamodel.SequenceI; |
34 |
|
import jalview.gui.AlignFrame; |
35 |
|
import jalview.gui.AlignViewport; |
36 |
|
import jalview.gui.JvOptionPane; |
37 |
|
import jalview.io.DataSourceType; |
38 |
|
import jalview.io.FileLoader; |
39 |
|
import jalview.math.MatrixI; |
40 |
|
|
41 |
|
import java.util.Arrays; |
42 |
|
|
43 |
|
import org.testng.Assert; |
44 |
|
import org.testng.annotations.BeforeClass; |
45 |
|
import org.testng.annotations.Test; |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (132) |
Complexity: 14 |
Complexity Density: 0.12 |
|
47 |
|
public class FeatureDistanceModelTest |
48 |
|
{ |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
50 |
1 |
@BeforeClass(alwaysRun = true)... |
51 |
|
public void setUpJvOptionPane() |
52 |
|
{ |
53 |
1 |
JvOptionPane.setInteractiveMode(false); |
54 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
55 |
|
} |
56 |
|
|
57 |
|
public static String alntestFile = "FER1_MESCR/72-76 DVYIL\nFER1_SPIOL/71-75 DVYIL\nFER3_RAPSA/21-25 DVYVL\nFER1_MAIZE/73-77 DVYIL\n"; |
58 |
|
|
59 |
|
int[] sf1 = new int[] { 74, 74, 73, 73, 23, 23, -1, -1 }; |
60 |
|
|
61 |
|
int[] sf2 = new int[] { -1, -1, 74, 75, -1, -1, 76, 77 }; |
62 |
|
|
63 |
|
int[] sf3 = new int[] { -1, -1, -1, -1, -1, -1, 76, 77 }; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
@return |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 5 |
Complexity Density: 0.25 |
|
76 |
3 |
public AlignFrame getTestAlignmentFrame()... |
77 |
|
{ |
78 |
3 |
AlignFrame alf = new FileLoader(false) |
79 |
|
.LoadFileWaitTillLoaded(alntestFile, DataSourceType.PASTE); |
80 |
3 |
AlignmentI al = alf.getViewport().getAlignment(); |
81 |
3 |
Assert.assertEquals(al.getHeight(), 4); |
82 |
3 |
Assert.assertEquals(al.getWidth(), 5); |
83 |
15 |
for (int i = 0; i < 4; i++) |
84 |
|
{ |
85 |
12 |
SequenceI ds = al.getSequenceAt(i).getDatasetSequence(); |
86 |
12 |
if (sf1[i * 2] > 0) |
87 |
|
{ |
88 |
9 |
ds.addSequenceFeature(new SequenceFeature("sf1", "sf1", sf1[i * 2], |
89 |
|
sf1[i * 2 + 1], "sf1")); |
90 |
|
} |
91 |
12 |
if (sf2[i * 2] > 0) |
92 |
|
{ |
93 |
6 |
ds.addSequenceFeature(new SequenceFeature("sf2", "sf2", sf2[i * 2], |
94 |
|
sf2[i * 2 + 1], "sf2")); |
95 |
|
} |
96 |
12 |
if (sf3[i * 2] > 0) |
97 |
|
{ |
98 |
3 |
ds.addSequenceFeature(new SequenceFeature("sf3", "sf3", sf3[i * 2], |
99 |
|
sf3[i * 2 + 1], "sf3")); |
100 |
|
} |
101 |
|
} |
102 |
3 |
alf.setShowSeqFeatures(true); |
103 |
3 |
alf.getFeatureRenderer().setVisible("sf1"); |
104 |
3 |
alf.getFeatureRenderer().setVisible("sf2"); |
105 |
3 |
alf.getFeatureRenderer().setVisible("sf3"); |
106 |
3 |
alf.getFeatureRenderer().findAllFeatures(true); |
107 |
3 |
Assert.assertEquals( |
108 |
|
alf.getFeatureRenderer().getDisplayedFeatureTypes().size(), 3, |
109 |
|
"Number of feature types"); |
110 |
3 |
assertTrue(alf.getCurrentView().areFeaturesDisplayed()); |
111 |
3 |
return alf; |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
114 |
1 |
@Test(groups = { "Functional" })... |
115 |
|
public void testFeatureScoreModel() throws Exception |
116 |
|
{ |
117 |
1 |
AlignFrame alf = getTestAlignmentFrame(); |
118 |
1 |
ScoreModelI sm = new FeatureDistanceModel(); |
119 |
1 |
sm = ScoreModels.getInstance().getScoreModel(sm.getName(), |
120 |
|
alf.getCurrentView().getAlignPanel()); |
121 |
1 |
alf.selectAllSequenceMenuItem_actionPerformed(null); |
122 |
|
|
123 |
1 |
MatrixI dm = sm.findDistances(alf.getViewport().getAlignmentView(true), |
124 |
|
SimilarityParams.Jalview); |
125 |
1 |
assertEquals(dm.getValue(0, 2), 0d, |
126 |
|
"FER1_MESCR (0) should be identical with RAPSA (2)"); |
127 |
1 |
assertTrue(dm.getValue(0, 1) > dm.getValue(0, 2), |
128 |
|
"FER1_MESCR (0) should be further from SPIOL (1) than it is from RAPSA (2)"); |
129 |
|
} |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
131 |
1 |
@Test(groups = { "Functional" })... |
132 |
|
public void testFeatureScoreModel_hiddenFirstColumn() throws Exception |
133 |
|
{ |
134 |
1 |
AlignFrame alf = getTestAlignmentFrame(); |
135 |
|
|
136 |
1 |
alf.getViewport().hideColumns(0, 1); |
137 |
1 |
ScoreModelI sm = new FeatureDistanceModel(); |
138 |
1 |
sm = ScoreModels.getInstance().getScoreModel(sm.getName(), |
139 |
|
alf.getCurrentView().getAlignPanel()); |
140 |
1 |
alf.selectAllSequenceMenuItem_actionPerformed(null); |
141 |
1 |
MatrixI dm = sm.findDistances(alf.getViewport().getAlignmentView(true), |
142 |
|
SimilarityParams.Jalview); |
143 |
1 |
assertEquals(dm.getValue(0, 2), 0d, |
144 |
|
"FER1_MESCR (0) should be identical with RAPSA (2)"); |
145 |
1 |
assertTrue(dm.getValue(0, 1) > dm.getValue(0, 2), |
146 |
|
"FER1_MESCR (0) should be further from SPIOL (1) than it is from RAPSA (2)"); |
147 |
|
} |
148 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
1PASS
|
|
149 |
1 |
@Test(groups = { "Functional" })... |
150 |
|
public void testFeatureScoreModel_HiddenColumns() throws Exception |
151 |
|
{ |
152 |
1 |
AlignFrame alf = getTestAlignmentFrame(); |
153 |
|
|
154 |
1 |
alf.getViewport().hideColumns(3, 4); |
155 |
1 |
alf.getViewport().hideColumns(0, 1); |
156 |
|
|
157 |
1 |
ScoreModelI sm = new FeatureDistanceModel(); |
158 |
1 |
sm = ScoreModels.getInstance().getScoreModel(sm.getName(), |
159 |
|
alf.getCurrentView().getAlignPanel()); |
160 |
1 |
alf.selectAllSequenceMenuItem_actionPerformed(null); |
161 |
1 |
MatrixI dm = sm.findDistances(alf.getViewport().getAlignmentView(true), |
162 |
|
SimilarityParams.Jalview); |
163 |
1 |
assertEquals(dm.getValue(0, 2), 0d, |
164 |
|
"After hiding last two columns FER1_MESCR (0) should still be identical with RAPSA (2)"); |
165 |
1 |
assertEquals(dm.getValue(0, 1), 0d, |
166 |
|
"After hiding last two columns FER1_MESCR (0) should now also be identical with SPIOL (1)"); |
167 |
4 |
for (int s = 0; s < 3; s++) |
168 |
|
{ |
169 |
3 |
assertTrue(dm.getValue(s, 3) > 0d, |
170 |
|
"After hiding last two columns " |
171 |
|
+ alf.getViewport().getAlignment().getSequenceAt(s) |
172 |
|
.getName() |
173 |
|
+ "(" + s |
174 |
|
+ ") should still be distinct from FER1_MAIZE (3)"); |
175 |
|
} |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
182 |
1 |
@Test(groups = { "Functional" })... |
183 |
|
public void testFindFeatureAt_PointFeature() throws Exception |
184 |
|
{ |
185 |
1 |
String alignment = "a CCCCCCGGGGGGCCCCCC\n" + "b CCCCCCGGGGGGCCCCCC\n" |
186 |
|
+ "c CCCCCCGGGGGGCCCCCC\n"; |
187 |
1 |
AlignFrame af = new jalview.io.FileLoader(false) |
188 |
|
.LoadFileWaitTillLoaded(alignment, DataSourceType.PASTE); |
189 |
1 |
SequenceI aseq = af.getViewport().getAlignment().getSequenceAt(0); |
190 |
1 |
SequenceFeature sf = null; |
191 |
1 |
sf = new SequenceFeature("disulphide bond", "", 2, 5, Float.NaN, ""); |
192 |
1 |
aseq.addSequenceFeature(sf); |
193 |
1 |
assertTrue(sf.isContactFeature()); |
194 |
1 |
af.refreshFeatureUI(true); |
195 |
1 |
af.getFeatureRenderer().setAllVisible(Arrays.asList("disulphide bond")); |
196 |
1 |
Assert.assertEquals( |
197 |
|
af.getFeatureRenderer().getDisplayedFeatureTypes().size(), 1, |
198 |
|
"Should be just one feature type displayed"); |
199 |
|
|
200 |
1 |
Assert.assertEquals( |
201 |
|
af.getFeatureRenderer().findFeaturesAtColumn(aseq, 1).size(), |
202 |
|
0); |
203 |
|
|
204 |
1 |
Assert.assertEquals( |
205 |
|
af.getFeatureRenderer().findFeaturesAtColumn(aseq, 2).size(), |
206 |
|
1); |
207 |
|
|
208 |
1 |
Assert.assertEquals( |
209 |
|
af.getFeatureRenderer().findFeaturesAtColumn(aseq, 3).size(), |
210 |
|
0); |
211 |
|
|
212 |
1 |
Assert.assertEquals( |
213 |
|
af.getFeatureRenderer().findFeaturesAtColumn(aseq, 4).size(), |
214 |
|
0); |
215 |
|
|
216 |
1 |
Assert.assertEquals( |
217 |
|
af.getFeatureRenderer().findFeaturesAtColumn(aseq, 5).size(), |
218 |
|
1); |
219 |
|
|
220 |
1 |
Assert.assertEquals( |
221 |
|
af.getFeatureRenderer().findFeaturesAtColumn(aseq, 6).size(), |
222 |
|
0); |
223 |
|
} |
224 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
225 |
1 |
@Test(groups = { "Functional" })... |
226 |
|
public void testFindDistances() throws Exception |
227 |
|
{ |
228 |
1 |
String seqs = ">s1\nABCDE\n>seq2\nABCDE\n"; |
229 |
1 |
AlignFrame alf = new FileLoader().LoadFileWaitTillLoaded(seqs, |
230 |
|
DataSourceType.PASTE); |
231 |
1 |
SequenceI s1 = alf.getViewport().getAlignment().getSequenceAt(0); |
232 |
1 |
SequenceI s2 = alf.getViewport().getAlignment().getSequenceAt(1); |
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
1 |
s1.addSequenceFeature( |
247 |
|
new SequenceFeature("domain", null, 1, 3, 0f, null)); |
248 |
1 |
s1.addSequenceFeature( |
249 |
|
new SequenceFeature("variant", null, 2, 4, 0f, null)); |
250 |
1 |
s1.addSequenceFeature( |
251 |
|
new SequenceFeature("variant", null, 3, 5, 0f, null)); |
252 |
1 |
s2.addSequenceFeature( |
253 |
|
new SequenceFeature("domain", null, 2, 4, 0f, null)); |
254 |
1 |
s2.addSequenceFeature( |
255 |
|
new SequenceFeature("variant", null, 1, 2, 0f, null)); |
256 |
1 |
s2.addSequenceFeature( |
257 |
|
new SequenceFeature("variant", null, 5, 5, 0f, null)); |
258 |
1 |
alf.setShowSeqFeatures(true); |
259 |
1 |
alf.getFeatureRenderer().findAllFeatures(true); |
260 |
|
|
261 |
1 |
ScoreModelI sm = new FeatureDistanceModel(); |
262 |
1 |
sm = ScoreModels.getInstance().getScoreModel(sm.getName(), |
263 |
|
alf.getCurrentView().getAlignPanel()); |
264 |
1 |
alf.selectAllSequenceMenuItem_actionPerformed(null); |
265 |
|
|
266 |
1 |
AlignmentView alignmentView = alf.getViewport().getAlignmentView(true); |
267 |
1 |
MatrixI distances = sm.findDistances(alignmentView, |
268 |
|
SimilarityParams.Jalview); |
269 |
1 |
assertEquals(distances.width(), 2); |
270 |
1 |
assertEquals(distances.height(), 2); |
271 |
1 |
assertEquals(distances.getValue(0, 0), 0d); |
272 |
1 |
assertEquals(distances.getValue(1, 1), 0d); |
273 |
|
|
274 |
1 |
assertEquals(distances.getValue(0, 1), 1d, |
275 |
|
"expected identical pairs. (check normalisation for similarity score)"); |
276 |
1 |
assertEquals(distances.getValue(1, 0), 1d); |
277 |
|
} |
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
282 |
1 |
@Test(groups = "Functional")... |
283 |
|
public void testFindDistances_withParams() |
284 |
|
{ |
285 |
1 |
AlignFrame af = setupAlignmentView(); |
286 |
1 |
AlignViewport viewport = af.getViewport(); |
287 |
1 |
AlignmentView view = viewport.getAlignmentView(false); |
288 |
|
|
289 |
1 |
ScoreModelI sm = new FeatureDistanceModel(); |
290 |
1 |
sm = ScoreModels.getInstance().getScoreModel(sm.getName(), |
291 |
|
af.alignPanel); |
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
1 |
SimilarityParamsI params = new SimilarityParams(true, true, true, true); |
304 |
1 |
MatrixI distances = sm.findDistances(view, params); |
305 |
1 |
assertEquals(distances.getValue(0, 0), 0d); |
306 |
1 |
assertEquals(distances.getValue(1, 1), 0d); |
307 |
1 |
assertEquals(distances.getValue(0, 1), 13d / 6); |
308 |
1 |
assertEquals(distances.getValue(1, 0), 13d / 6); |
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
1 |
params = new SimilarityParams(true, true, false, true); |
315 |
1 |
distances = sm.findDistances(view, params); |
316 |
1 |
assertEquals(distances.getValue(0, 1), 6d / 6); |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
@return |
334 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
335 |
1 |
protected AlignFrame setupAlignmentView()... |
336 |
|
{ |
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
1 |
SequenceI s1 = new Sequence("s1", "FR K S"); |
343 |
1 |
SequenceI s2 = new Sequence("s2", "FS L"); |
344 |
|
|
345 |
1 |
s1.addSequenceFeature( |
346 |
|
new SequenceFeature("chain", null, 1, 4, 0f, null)); |
347 |
1 |
s1.addSequenceFeature( |
348 |
|
new SequenceFeature("domain", null, 1, 4, 0f, null)); |
349 |
1 |
s2.addSequenceFeature( |
350 |
|
new SequenceFeature("chain", null, 1, 3, 0f, null)); |
351 |
1 |
s2.addSequenceFeature( |
352 |
|
new SequenceFeature("metal", null, 1, 3, 0f, null)); |
353 |
1 |
s2.addSequenceFeature( |
354 |
|
new SequenceFeature("Pfam", null, 1, 3, 0f, null)); |
355 |
1 |
AlignmentI al = new Alignment(new SequenceI[] { s1, s2 }); |
356 |
1 |
AlignFrame af = new AlignFrame(al, 300, 300); |
357 |
1 |
af.setShowSeqFeatures(true); |
358 |
1 |
af.getFeatureRenderer().findAllFeatures(true); |
359 |
1 |
return af; |
360 |
|
} |
361 |
|
|
362 |
|
} |