2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertTrue;
26 import jalview.api.AlignViewportI;
27 import jalview.bin.Cache;
28 import jalview.bin.Jalview;
29 import jalview.datamodel.Alignment;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.Sequence;
32 import jalview.datamodel.SequenceI;
33 import jalview.gui.SeqPanel.MousePos;
34 import jalview.io.DataSourceType;
35 import jalview.io.FileLoader;
37 import java.awt.Event;
38 import java.awt.event.MouseEvent;
40 import org.testng.annotations.AfterMethod;
41 import org.testng.annotations.BeforeClass;
42 import org.testng.annotations.Test;
44 public class SeqPanelTest
48 @BeforeClass(alwaysRun = true)
49 public void setUpJvOptionPane()
51 JvOptionPane.setInteractiveMode(false);
52 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
54 @Test(groups = "Functional")
55 public void testSetStatusReturnsNearestResiduePosition()
57 SequenceI seq1 = new Sequence("Seq1", "AACDE");
58 SequenceI seq2 = new Sequence("Seq2", "AA--E");
59 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
60 AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
62 AlignmentI visAl = alignFrame.getViewport().getAlignment();
64 // Test either side of gap
66 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
67 visAl.getSequenceAt(1), 1, 1), 2);
68 assertEquals(alignFrame.statusBar.getText(),
69 "Sequence 2 ID: Seq2 Residue: ALA (2)");
71 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
72 visAl.getSequenceAt(1), 4, 1), 3);
73 assertEquals(alignFrame.statusBar.getText(),
74 "Sequence 2 ID: Seq2 Residue: GLU (3)");
75 // no status message at a gap, returns next residue position to the right
77 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
78 visAl.getSequenceAt(1), 2, 1), 3);
79 assertEquals(alignFrame.statusBar.getText(), "Sequence 2 ID: Seq2");
81 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
82 visAl.getSequenceAt(1), 3, 1), 3);
83 assertEquals(alignFrame.statusBar.getText(), "Sequence 2 ID: Seq2");
86 @Test(groups = "Functional")
87 public void testAmbiguousAminoAcidGetsStatusMessage()
89 SequenceI seq1 = new Sequence("Seq1", "ABCDE");
90 SequenceI seq2 = new Sequence("Seq2", "AB--E");
91 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
92 AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
94 AlignmentI visAl = alignFrame.getViewport().getAlignment();
97 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
98 visAl.getSequenceAt(1), 1, 1), 2);
99 assertEquals(alignFrame.statusBar.getText(),
100 "Sequence 2 ID: Seq2 Residue: B (2)");
103 @Test(groups = "Functional")
104 public void testFindMousePosition_unwrapped()
106 String seqData = ">Seq1\nAACDE\n>Seq2\nAA--E\n";
107 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(seqData,
108 DataSourceType.PASTE);
109 AlignViewportI av = alignFrame.getViewport();
110 av.setShowAnnotation(true);
111 av.setWrapAlignment(false);
112 final int charHeight = av.getCharHeight();
113 final int charWidth = av.getCharWidth();
115 assertTrue(charHeight > 0);
116 assertTrue(charWidth > 0);
117 assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
119 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
124 * mouse at top left of unwrapped panel
126 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
128 MousePos pos = testee.findMousePosition(evt);
129 assertEquals(pos.column, 0);
130 assertEquals(pos.seqIndex, 0);
131 assertEquals(pos.annotationIndex, -1);
134 @AfterMethod(alwaysRun = true)
135 public void tearDown()
137 Desktop.instance.closeAll_actionPerformed(null);
140 @Test(groups = "Functional")
141 public void testFindMousePosition_wrapped()
143 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true");
144 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
145 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
146 "examples/uniref50.fa", DataSourceType.FILE);
147 AlignViewportI av = alignFrame.getViewport();
148 av.setScaleAboveWrapped(false);
149 av.setScaleLeftWrapped(false);
150 av.setScaleRightWrapped(false);
151 alignFrame.alignPanel.paintAlignment(false, false);
153 final int charHeight = av.getCharHeight();
154 final int charWidth = av.getCharWidth();
155 final int alignmentHeight = av.getAlignment().getHeight();
158 assertTrue(charHeight > 0);
159 assertTrue(charWidth > 0);
160 assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
162 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
167 * mouse at top left of wrapped panel; there is a gap of charHeight
168 * above the alignment
170 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
172 MousePos pos = testee.findMousePosition(evt);
173 assertEquals(pos.column, 0);
174 assertEquals(pos.seqIndex, -1); // above sequences
175 assertEquals(pos.annotationIndex, -1);
178 * cursor at bottom of gap above
181 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
183 pos = testee.findMousePosition(evt);
184 assertEquals(pos.seqIndex, -1);
185 assertEquals(pos.annotationIndex, -1);
188 * cursor over top of first sequence
191 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
193 pos = testee.findMousePosition(evt);
194 assertEquals(pos.seqIndex, 0);
195 assertEquals(pos.annotationIndex, -1);
198 * cursor at bottom of first sequence
200 y = 2 * charHeight - 1;
201 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
203 pos = testee.findMousePosition(evt);
204 assertEquals(pos.seqIndex, 0);
205 assertEquals(pos.annotationIndex, -1);
208 * cursor at top of second sequence
211 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
213 pos = testee.findMousePosition(evt);
214 assertEquals(pos.seqIndex, 1);
215 assertEquals(pos.annotationIndex, -1);
218 * cursor at bottom of second sequence
220 y = 3 * charHeight - 1;
221 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
223 pos = testee.findMousePosition(evt);
224 assertEquals(pos.seqIndex, 1);
225 assertEquals(pos.annotationIndex, -1);
228 * cursor at bottom of last sequence
230 y = charHeight * (1 + alignmentHeight) - 1;
231 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
233 pos = testee.findMousePosition(evt);
234 assertEquals(pos.seqIndex, alignmentHeight - 1);
235 assertEquals(pos.annotationIndex, -1);
238 * cursor below sequences, in 3-pixel gap above annotations
241 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
243 pos = testee.findMousePosition(evt);
244 assertEquals(pos.seqIndex, alignmentHeight - 1);
245 assertEquals(pos.annotationIndex, -1);
248 * cursor still in the gap above annotations, now at the bottom of it
249 * method reports index of nearest sequence above
251 y += SeqCanvas.SEQS_ANNOTATION_GAP - 1; // 3-1 = 2
252 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
254 pos = testee.findMousePosition(evt);
255 assertEquals(pos.seqIndex, alignmentHeight - 1);
256 assertEquals(pos.annotationIndex, -1);
259 * cursor at the top of the first annotation
262 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
264 pos = testee.findMousePosition(evt);
265 assertEquals(pos.seqIndex, alignmentHeight - 1);
266 assertEquals(pos.annotationIndex, 0); // over first annotation
269 * cursor at the bottom of the first annotation
271 y += av.getAlignment().getAlignmentAnnotation()[0].height - 1;
272 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
274 pos = testee.findMousePosition(evt);
275 assertEquals(pos.seqIndex, alignmentHeight - 1);
276 assertEquals(pos.annotationIndex, 0);
279 * cursor at the top of the second annotation
282 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
284 pos = testee.findMousePosition(evt);
285 assertEquals(pos.seqIndex, alignmentHeight - 1);
286 assertEquals(pos.annotationIndex, 1);
289 * cursor at the bottom of the second annotation
291 y += av.getAlignment().getAlignmentAnnotation()[1].height - 1;
292 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
294 pos = testee.findMousePosition(evt);
295 assertEquals(pos.seqIndex, alignmentHeight - 1);
296 assertEquals(pos.annotationIndex, 1);
299 * cursor at the top of the third annotation
302 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
304 pos = testee.findMousePosition(evt);
305 assertEquals(pos.seqIndex, alignmentHeight - 1);
306 assertEquals(pos.annotationIndex, 2);
309 * cursor at the bottom of the third annotation
311 y += av.getAlignment().getAlignmentAnnotation()[2].height - 1;
312 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
314 pos = testee.findMousePosition(evt);
315 assertEquals(pos.seqIndex, alignmentHeight - 1);
316 assertEquals(pos.annotationIndex, 2);
319 * cursor in gap between wrapped widths
322 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
324 pos = testee.findMousePosition(evt);
325 assertEquals(pos.seqIndex, -1);
326 assertEquals(pos.annotationIndex, -1);
329 * cursor at bottom of gap between wrapped widths
332 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
334 pos = testee.findMousePosition(evt);
335 assertEquals(pos.seqIndex, -1);
336 assertEquals(pos.annotationIndex, -1);
339 * cursor at top of first sequence, second wrapped width
342 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
344 pos = testee.findMousePosition(evt);
345 assertEquals(pos.seqIndex, 0);
346 assertEquals(pos.annotationIndex, -1);
349 @Test(groups = "Functional")
350 public void testFindMousePosition_wrapped_scaleAbove()
352 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true");
353 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
354 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
355 "examples/uniref50.fa", DataSourceType.FILE);
356 AlignViewportI av = alignFrame.getViewport();
357 av.setScaleAboveWrapped(true);
358 av.setScaleLeftWrapped(false);
359 av.setScaleRightWrapped(false);
360 alignFrame.alignPanel.paintAlignment(false, false);
362 final int charHeight = av.getCharHeight();
363 final int charWidth = av.getCharWidth();
364 final int alignmentHeight = av.getAlignment().getHeight();
367 assertTrue(charHeight > 0);
368 assertTrue(charWidth > 0);
369 assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
371 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
376 * mouse at top left of wrapped panel; there is a gap of charHeight
377 * above the alignment
379 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
381 MousePos pos = testee.findMousePosition(evt);
382 assertEquals(pos.column, 0);
383 assertEquals(pos.seqIndex, -1); // above sequences
384 assertEquals(pos.annotationIndex, -1);
387 * cursor at bottom of gap above
388 * two charHeights including scale panel
390 y = 2 * charHeight - 1;
391 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
393 pos = testee.findMousePosition(evt);
394 assertEquals(pos.seqIndex, -1);
395 assertEquals(pos.annotationIndex, -1);
398 * cursor over top of first sequence
401 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
403 pos = testee.findMousePosition(evt);
404 assertEquals(pos.seqIndex, 0);
405 assertEquals(pos.annotationIndex, -1);
408 * cursor at bottom of first sequence
411 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
413 pos = testee.findMousePosition(evt);
414 assertEquals(pos.seqIndex, 0);
415 assertEquals(pos.annotationIndex, -1);
418 * cursor at top of second sequence
421 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
423 pos = testee.findMousePosition(evt);
424 assertEquals(pos.seqIndex, 1);
425 assertEquals(pos.annotationIndex, -1);
428 * cursor at bottom of second sequence
431 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
433 pos = testee.findMousePosition(evt);
434 assertEquals(pos.seqIndex, 1);
435 assertEquals(pos.annotationIndex, -1);
438 * cursor at bottom of last sequence
439 * (scale + gap + sequences)
441 y = charHeight * (2 + alignmentHeight) - 1;
442 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
444 pos = testee.findMousePosition(evt);
445 assertEquals(pos.seqIndex, alignmentHeight - 1);
446 assertEquals(pos.annotationIndex, -1);
449 * cursor below sequences, in 3-pixel gap above annotations
452 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
454 pos = testee.findMousePosition(evt);
455 assertEquals(pos.seqIndex, alignmentHeight - 1);
456 assertEquals(pos.annotationIndex, -1);
459 * cursor still in the gap above annotations, now at the bottom of it
460 * method reports index of nearest sequence above
462 y += SeqCanvas.SEQS_ANNOTATION_GAP - 1; // 3-1 = 2
463 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
465 pos = testee.findMousePosition(evt);
466 assertEquals(pos.seqIndex, alignmentHeight - 1);
467 assertEquals(pos.annotationIndex, -1);
470 * cursor at the top of the first annotation
473 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
475 pos = testee.findMousePosition(evt);
476 assertEquals(pos.seqIndex, alignmentHeight - 1);
477 assertEquals(pos.annotationIndex, 0); // over first annotation
480 * cursor at the bottom of the first annotation
482 y += av.getAlignment().getAlignmentAnnotation()[0].height - 1;
483 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
485 pos = testee.findMousePosition(evt);
486 assertEquals(pos.seqIndex, alignmentHeight - 1);
487 assertEquals(pos.annotationIndex, 0);
490 * cursor at the top of the second annotation
493 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
495 pos = testee.findMousePosition(evt);
496 assertEquals(pos.seqIndex, alignmentHeight - 1);
497 assertEquals(pos.annotationIndex, 1);
500 * cursor at the bottom of the second annotation
502 y += av.getAlignment().getAlignmentAnnotation()[1].height - 1;
503 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
505 pos = testee.findMousePosition(evt);
506 assertEquals(pos.seqIndex, alignmentHeight - 1);
507 assertEquals(pos.annotationIndex, 1);
510 * cursor at the top of the third annotation
513 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
515 pos = testee.findMousePosition(evt);
516 assertEquals(pos.seqIndex, alignmentHeight - 1);
517 assertEquals(pos.annotationIndex, 2);
520 * cursor at the bottom of the third annotation
522 y += av.getAlignment().getAlignmentAnnotation()[2].height - 1;
523 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
525 pos = testee.findMousePosition(evt);
526 assertEquals(pos.seqIndex, alignmentHeight - 1);
527 assertEquals(pos.annotationIndex, 2);
530 * cursor in gap between wrapped widths
533 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
535 pos = testee.findMousePosition(evt);
536 assertEquals(pos.seqIndex, -1);
537 assertEquals(pos.annotationIndex, -1);
540 * cursor at bottom of gap between wrapped widths
543 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
545 pos = testee.findMousePosition(evt);
546 assertEquals(pos.seqIndex, -1);
547 assertEquals(pos.annotationIndex, -1);
550 * cursor at top of scale, second wrapped width
553 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
555 pos = testee.findMousePosition(evt);
556 assertEquals(pos.seqIndex, -1);
557 assertEquals(pos.annotationIndex, -1);
560 * cursor at bottom of scale, second wrapped width
563 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
565 pos = testee.findMousePosition(evt);
566 assertEquals(pos.seqIndex, -1);
567 assertEquals(pos.annotationIndex, -1);
570 * cursor at top of first sequence, second wrapped width
573 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
575 pos = testee.findMousePosition(evt);
576 assertEquals(pos.seqIndex, 0);
577 assertEquals(pos.annotationIndex, -1);
579 @BeforeClass(alwaysRun = true)
580 public static void setUpBeforeClass() throws Exception
583 * use read-only test properties file
585 Cache.loadProperties("test/jalview/io/testProps.jvprops");
586 Jalview.main(new String[] { "-nonews" });