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.junit.Assert.assertNotEquals;
24 import static org.testng.Assert.assertEquals;
25 import static org.testng.Assert.assertFalse;
26 import static org.testng.Assert.assertNotSame;
27 import static org.testng.Assert.assertSame;
28 import static org.testng.Assert.assertTrue;
30 import jalview.api.FeatureColourI;
31 import jalview.bin.Cache;
32 import jalview.bin.Jalview;
33 import jalview.datamodel.Alignment;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.HiddenColumns;
36 import jalview.datamodel.Sequence;
37 import jalview.datamodel.SequenceFeature;
38 import jalview.datamodel.SequenceGroup;
39 import jalview.datamodel.SequenceI;
40 import jalview.io.DataSourceType;
41 import jalview.io.FileLoader;
42 import jalview.project.Jalview2xmlTests;
43 import jalview.renderer.ResidueShaderI;
44 import jalview.schemes.BuriedColourScheme;
45 import jalview.schemes.FeatureColour;
46 import jalview.schemes.HelixColourScheme;
47 import jalview.schemes.JalviewColourScheme;
48 import jalview.schemes.StrandColourScheme;
49 import jalview.schemes.TurnColourScheme;
50 import jalview.util.MessageManager;
52 import java.awt.Color;
53 import java.util.Iterator;
55 import org.testng.annotations.AfterMethod;
56 import org.testng.annotations.BeforeClass;
57 import org.testng.annotations.BeforeMethod;
58 import org.testng.annotations.Test;
60 public class AlignFrameTest
64 @BeforeClass(alwaysRun = true)
65 public static void setUpBeforeClass() throws Exception
69 * use read-only test properties file
71 Cache.loadProperties("test/jalview/io/testProps.jvprops");
72 Jalview.main(new String[] { "-nonews" });
75 @AfterMethod(alwaysRun = true)
76 public void tearDown()
78 Desktop.instance.closeAll_actionPerformed(null);
82 * configure (read-only) properties for test to ensure Consensus is computed for
83 * colour Above PID testing
85 @BeforeMethod(alwaysRun = true)
88 Cache.loadProperties("test/jalview/io/testProps.jvprops");
89 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
90 Boolean.TRUE.toString());
91 af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
95 * wait for Consensus thread to complete
99 while (af.getViewport().getConsensusSeq() == null)
104 } catch (InterruptedException e)
111 public static void setUpJvOptionPane()
113 JvOptionPane.setInteractiveMode(false);
114 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
117 @Test(groups = "Functional")
118 public void testHideFeatureColumns()
120 SequenceI seq1 = new Sequence("Seq1", "ABCDEFGHIJ");
121 SequenceI seq2 = new Sequence("Seq2", "ABCDEFGHIJ");
122 seq1.addSequenceFeature(new SequenceFeature("Metal", "", 1, 5, 0f, null));
123 seq2.addSequenceFeature(new SequenceFeature("Metal", "", 6, 10, 10f,
125 seq1.addSequenceFeature(new SequenceFeature("Turn", "", 2, 4,
127 seq2.addSequenceFeature(new SequenceFeature("Turn", "", 7, 9,
129 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
130 AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
134 * make all features visible (select feature columns checks visibility)
136 alignFrame.getFeatureRenderer().findAllFeatures(true);
139 * hiding a feature not present does nothing
141 assertFalse(alignFrame.hideFeatureColumns("exon", true));
142 assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
144 assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
145 .getNumberOfRegions(), 0);
147 assertFalse(alignFrame.hideFeatureColumns("exon", false));
148 assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
150 assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
151 .getNumberOfRegions(), 0);
154 * hiding a feature in all columns does nothing
156 assertFalse(alignFrame.hideFeatureColumns("Metal", true));
157 assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
159 assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
160 .getNumberOfRegions(), 0);
164 * threshold Metal to hide features where score < 5
165 * seq1 feature in columns 1-5 is hidden
166 * seq2 feature in columns 6-10 is shown
168 FeatureColourI fc = new FeatureColour(null, Color.red, Color.blue, null,
170 fc.setAboveThreshold(true);
172 alignFrame.getFeatureRenderer().setColour("Metal", fc);
173 assertTrue(alignFrame.hideFeatureColumns("Metal", true));
174 HiddenColumns hidden = alignFrame.getViewport().getAlignment().getHiddenColumns();
175 assertEquals(hidden.getNumberOfRegions(), 1);
176 Iterator<int[]> regions = hidden.iterator();
177 int[] next = regions.next();
178 assertEquals(next[0], 5);
179 assertEquals(next[1], 9);
182 * hide a feature present in some columns
183 * sequence positions [2-4], [7-9] are column positions
184 * [1-3], [6-8] base zero
186 alignFrame.getViewport().showAllHiddenColumns();
187 assertTrue(alignFrame.hideFeatureColumns("Turn", true));
188 regions = alignFrame.getViewport().getAlignment()
189 .getHiddenColumns().iterator();
190 assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
191 .getNumberOfRegions(), 2);
192 next = regions.next();
193 assertEquals(next[0], 1);
194 assertEquals(next[1], 3);
195 next = regions.next();
196 assertEquals(next[0], 6);
197 assertEquals(next[1], 8);
201 * Test that changing background (alignment) colour scheme
203 * <li>with Apply Colour to All Groups not selected, does not change group
205 * <li>with Apply Colour to All Groups selected, does change group colours</li>
206 * <li>in neither case, changes alignment or group colour thresholds (PID or
210 @Test(groups = "Functional")
211 public void testChangeColour_background_groupsAndThresholds()
213 AlignViewport av = af.getViewport();
214 AlignmentI al = av.getAlignment();
217 * Colour alignment by Buried Index
219 af.applyToAllGroups_actionPerformed(false);
220 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
221 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
222 assertFalse(av.getResidueShading().conservationApplied());
223 assertEquals(av.getResidueShading().getThreshold(), 0);
226 * Apply Conservation 20%
228 af.conservationMenuItem_actionPerformed(true);
229 SliderPanel sp = SliderPanel.getSliderPanel();
230 assertEquals(sp.getTitle(), MessageManager.formatMessage(
231 "label.conservation_colour_increment",
232 new String[] { "Background" }));
233 assertTrue(sp.isForConservation());
235 assertTrue(av.getResidueShading().conservationApplied());
236 assertEquals(av.getResidueShading().getConservationInc(), 20);
239 * Apply PID threshold 10% (conservation still applies as well)
241 af.abovePIDThreshold_actionPerformed(true);
242 sp = SliderPanel.getSliderPanel();
243 assertFalse(sp.isForConservation());
244 assertEquals(sp.getTitle(), MessageManager.formatMessage(
245 "label.percentage_identity_threshold",
246 new String[] { "Background" }));
248 assertEquals(av.getResidueShading().getThreshold(), 10);
249 assertTrue(av.getResidueShading().conservationApplied());
250 assertEquals(av.getResidueShading().getConservationInc(), 20);
253 * create a group with Strand colouring, 30% Conservation
254 * and 40% PID threshold
256 SequenceGroup sg = new SequenceGroup();
257 sg.addSequence(al.getSequenceAt(0), false);
260 av.setSelectionGroup(sg);
263 * apply 30% Conservation to group
264 * (notice menu action applies to selection group even if mouse click
265 * is at a sequence not in the group)
267 PopupMenu popupMenu = new PopupMenu(af.alignPanel, al.getSequenceAt(2),
269 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
271 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
272 assertEquals(al.getGroups().size(), 1);
273 assertSame(al.getGroups().get(0), sg);
274 popupMenu.conservationMenuItem_actionPerformed(true);
275 sp = SliderPanel.getSliderPanel();
276 assertTrue(sp.isForConservation());
277 assertEquals(sp.getTitle(), MessageManager.formatMessage(
278 "label.conservation_colour_increment",
279 new String[] { sg.getName() }));
281 assertTrue(sg.getGroupColourScheme().conservationApplied());
282 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
285 * apply 40% PID threshold to group
287 popupMenu.abovePIDColour_actionPerformed(true);
288 sp = SliderPanel.getSliderPanel();
289 assertFalse(sp.isForConservation());
290 assertEquals(sp.getTitle(), MessageManager.formatMessage(
291 "label.percentage_identity_threshold",
292 new String[] { sg.getName() }));
294 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
295 // conservation threshold is unchanged:
296 assertTrue(sg.getGroupColourScheme().conservationApplied());
297 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
300 * change alignment colour - group colour, and all thresholds,
301 * should be unaffected
303 af.changeColour_actionPerformed(JalviewColourScheme.Turn.toString());
304 assertTrue(av.getGlobalColourScheme() instanceof TurnColourScheme);
305 assertTrue(av.getResidueShading().conservationApplied());
306 assertEquals(av.getResidueShading().getConservationInc(), 20);
307 assertEquals(av.getResidueShading().getThreshold(), 10);
308 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
309 assertTrue(sg.getGroupColourScheme().conservationApplied());
310 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
311 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
314 * Now change alignment colour with Apply Colour To All Groups
315 * - group colour should change, but not colour thresholds
317 af.applyToAllGroups_actionPerformed(true);
318 af.changeColour_actionPerformed(JalviewColourScheme.Helix.toString());
319 assertTrue(av.getGlobalColourScheme() instanceof HelixColourScheme);
320 assertTrue(av.getResidueShading().conservationApplied());
321 assertEquals(av.getResidueShading().getConservationInc(), 20);
322 assertEquals(av.getResidueShading().getThreshold(), 10);
323 assertTrue(sg.getColourScheme() instanceof HelixColourScheme);
324 assertTrue(sg.getGroupColourScheme().conservationApplied());
325 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
326 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
330 * Test residue colouring with various options
332 * <li>no PID or Conservation threshold</li>
333 * <li>colour by Conservation applied</li>
334 * <li>colour by Conservation removed</li>
335 * <li>colour above PID - various values</li>
336 * <li>colour above PID removed</li>
337 * <li>Above PID plus By Conservation combined</li>
338 * <li>remove Above PID to leave just By Conservation</li>
339 * <li>re-add Above PID</li>
340 * <li>remove By Conservation to leave just Above PID</li>
341 * <li>remove Above PID to leave original colours</li>
344 @Test(groups = "Functional")
345 public void testColourThresholdActions()
347 AlignViewport av = af.getViewport();
348 AlignmentI al = av.getAlignment();
351 * Colour alignment by Helix Propensity, no thresholds
353 af.applyToAllGroups_actionPerformed(false);
354 af.changeColour_actionPerformed(JalviewColourScheme.Helix.toString());
355 assertTrue(av.getGlobalColourScheme() instanceof HelixColourScheme);
356 assertFalse(av.getResidueShading().conservationApplied());
357 assertEquals(av.getResidueShading().getThreshold(), 0);
360 * inspect the colour of
361 * FER_CAPAN.9(I), column 14 (14 base 0)
362 * FER_CAPAN.10(SER), column 16 (15 base 0)
364 SequenceI ferCapan = al.findName("FER_CAPAN");
365 ResidueShaderI rs = av.getResidueShading();
366 Color c = rs.findColour('I', 14, ferCapan);
367 Color i_original = new Color(138, 117, 138);
368 assertEquals(c, i_original);
369 c = rs.findColour('S', 15, ferCapan);
370 Color s_original = new Color(54, 201, 54);
371 assertEquals(c, s_original);
374 * colour by conservation with increment 10
376 af.conservationMenuItem_actionPerformed(true);
377 SliderPanel sp = SliderPanel.getSliderPanel();
378 assertTrue(sp.isForConservation());
379 assertEquals(sp.getValue(), 30); // initial slider setting
381 assertSame(rs, av.getResidueShading());
382 c = rs.findColour('I', 14, ferCapan);
383 Color i_faded = new Color(196, 186, 196);
384 assertEquals(c, i_faded);
385 c = rs.findColour('S', 15, ferCapan);
386 Color s_faded = new Color(144, 225, 144);
387 assertEquals(c, s_faded);
390 * deselect By Conservation - colour should revert
392 af.conservationMenuItem_actionPerformed(false);
393 c = rs.findColour('S', 15, ferCapan);
394 assertEquals(c, s_original);
397 * now Above PID, threshold = 0%
398 * should be no change
400 af.abovePIDThreshold_actionPerformed(true);
401 sp = SliderPanel.getSliderPanel();
402 assertFalse(sp.isForConservation());
403 assertEquals(sp.getValue(), 0); // initial slider setting
404 c = rs.findColour('I', 14, ferCapan);
405 assertEquals(c, i_original);
406 c = rs.findColour('S', 15, ferCapan);
407 assertEquals(c, s_original);
410 * Above PID, threshold = 1%
411 * 15.I becomes White because no match to consensus (V)
412 * 16.S remains coloured as matches 66.66% consensus
415 c = rs.findColour('I', 14, ferCapan);
416 assertEquals(c, Color.white);
417 c = rs.findColour('S', 15, ferCapan);
418 assertEquals(c, s_original);
421 * threshold 66% - no further change yet...
424 c = rs.findColour('I', 14, ferCapan);
425 assertEquals(c, Color.white);
426 c = rs.findColour('S', 15, ferCapan);
427 assertEquals(c, s_original);
430 * threshold 67% - now both residues are white
433 c = rs.findColour('I', 14, ferCapan);
434 assertEquals(c, Color.white);
435 c = rs.findColour('S', 15, ferCapan);
436 assertEquals(c, Color.white);
439 * deselect Above PID - colours should revert
441 af.abovePIDThreshold_actionPerformed(false);
442 c = rs.findColour('I', 14, ferCapan);
443 assertEquals(c, i_original);
444 c = rs.findColour('S', 15, ferCapan);
445 assertEquals(c, s_original);
448 * Now combine Above 50% PID and By Conservation 10%
449 * 15.I is White because no match to consensus (V)
450 * 16.S is coloured but faded
452 af.abovePIDThreshold_actionPerformed(true);
453 sp = SliderPanel.getSliderPanel();
454 assertFalse(sp.isForConservation());
456 af.conservationMenuItem_actionPerformed(true);
457 sp = SliderPanel.getSliderPanel();
458 assertTrue(sp.isForConservation());
460 c = rs.findColour('I', 14, ferCapan);
461 assertEquals(c, Color.white);
462 c = rs.findColour('S', 15, ferCapan);
463 assertEquals(c, s_faded);
466 * turn off Above PID - should just leave Conservation fading as before
468 af.abovePIDThreshold_actionPerformed(false);
469 c = rs.findColour('I', 14, ferCapan);
470 assertEquals(c, i_faded);
471 c = rs.findColour('S', 15, ferCapan);
472 assertEquals(c, s_faded);
475 * Now add Above 50% PID to conservation colouring
476 * - should give the same as PID followed by conservation (above)
478 af.abovePIDThreshold_actionPerformed(true);
479 SliderPanel.getSliderPanel().valueChanged(50);
480 c = rs.findColour('I', 14, ferCapan);
481 assertEquals(c, Color.white);
482 c = rs.findColour('S', 15, ferCapan);
483 assertEquals(c, s_faded);
486 * turn off By Conservation
487 * should leave I white, S original (unfaded) colour
489 af.conservationMenuItem_actionPerformed(false);
490 c = rs.findColour('I', 14, ferCapan);
491 assertEquals(c, Color.white);
492 c = rs.findColour('S', 15, ferCapan);
493 assertEquals(c, s_original);
496 * finally turn off Above PID to leave original colours
498 af.abovePIDThreshold_actionPerformed(false);
499 c = rs.findColour('I', 14, ferCapan);
500 assertEquals(c, i_original);
501 c = rs.findColour('S', 15, ferCapan);
502 assertEquals(c, s_original);
506 * Verify that making a New View transfers alignment and group colour schemes,
507 * including any thresholds, to the new view. Because New View is performed by
508 * saving and reloading a 'project' file, this is similar to verifying a
509 * project save and reload.
511 * @see Jalview2xmlTests#testStoreAndRecoverColourThresholds()
513 @Test(groups = "Functional")
514 public void testNewView_colourThresholds()
516 AlignViewport av = af.getViewport();
517 AlignmentI al = av.getAlignment();
520 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
522 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
523 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
524 af.abovePIDThreshold_actionPerformed(true);
525 SliderPanel sp = SliderPanel.getSliderPanel();
526 assertFalse(sp.isForConservation());
528 af.conservationMenuItem_actionPerformed(true);
529 sp = SliderPanel.getSliderPanel();
530 assertTrue(sp.isForConservation());
532 ResidueShaderI rs = av.getResidueShading();
533 assertEquals(rs.getThreshold(), 10);
534 assertTrue(rs.conservationApplied());
535 assertEquals(rs.getConservationInc(), 20);
538 * create a group with Strand colouring, 30% Conservation
539 * and 40% PID threshold
541 SequenceGroup sg = new SequenceGroup();
542 sg.addSequence(al.getSequenceAt(0), false);
545 av.setSelectionGroup(sg);
546 PopupMenu popupMenu = new PopupMenu(af.alignPanel, al.getSequenceAt(0),
548 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
550 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
551 assertEquals(al.getGroups().size(), 1);
552 assertSame(al.getGroups().get(0), sg);
553 popupMenu.conservationMenuItem_actionPerformed(true);
554 sp = SliderPanel.getSliderPanel();
555 assertTrue(sp.isForConservation());
557 popupMenu.abovePIDColour_actionPerformed(true);
558 sp = SliderPanel.getSliderPanel();
559 assertFalse(sp.isForConservation());
561 rs = sg.getGroupColourScheme();
562 assertTrue(rs.conservationApplied());
563 assertEquals(rs.getConservationInc(), 30);
564 assertEquals(rs.getThreshold(), 40);
567 * set slider panel focus to the background alignment
569 af.conservationMenuItem_actionPerformed(true);
570 sp = SliderPanel.getSliderPanel();
571 assertTrue(sp.isForConservation());
572 assertEquals(sp.getTitle(), MessageManager.formatMessage(
573 "label.conservation_colour_increment",
574 new String[] { "Background" }));
577 * make a new View, verify alignment and group colour schemes
579 af.newView_actionPerformed(null);
580 assertEquals(af.alignPanel.getViewName(), "View 1");
581 AlignViewport av2 = af.getViewport();
582 assertNotSame(av, av2);
583 assertSame(av2, af.alignPanel.av);
584 rs = av2.getResidueShading();
585 assertNotSame(av.getResidueShading(), rs);
586 assertEquals(rs.getThreshold(), 10);
587 assertTrue(rs.conservationApplied(), rs.toString());
588 assertEquals(rs.getConservationInc(), 20);
589 assertEquals(av2.getAlignment().getGroups().size(), 1);
590 sg = av2.getAlignment().getGroups().get(0);
591 rs = sg.getGroupColourScheme();
592 assertTrue(rs.conservationApplied());
593 assertEquals(rs.getConservationInc(), 30);
594 assertEquals(rs.getThreshold(), 40);
597 * check the Conservation SliderPanel (still open) is linked to
598 * and updates the new view (JAL-2385)
600 sp = SliderPanel.getSliderPanel();
601 assertTrue(sp.isForConservation());
602 assertEquals(sp.getTitle(), MessageManager.formatMessage(
603 "label.conservation_colour_increment",
604 new String[] { "View 1" }));
606 assertEquals(av2.getResidueShading().getConservationInc(), 22);
610 * Verify that making a New View preserves the dataset reference for the
611 * alignment. Otherwise, see a 'duplicate jar entry' reference when trying to
612 * save alignments with multiple views, and codon mappings will not be shared
613 * across all panels in a split frame.
615 * @see Jalview2xmlTests#testStoreAndRecoverColourThresholds()
617 @Test(groups = "Functional")
618 public void testNewView_dsRefPreserved()
620 AlignViewport av = af.getViewport();
621 AlignmentI al = av.getAlignment();
622 AlignmentI original_ds = al.getDataset();
623 af.newView_actionPerformed(null);
624 assertNotEquals("New view didn't select the a new panel", av,
626 org.testng.Assert.assertEquals(original_ds,
627 af.getViewport().getAlignment().getDataset(),
628 "Dataset was not preserved in new view");