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.AlignViewportI;
31 import jalview.api.FeatureColourI;
32 import jalview.bin.Cache;
33 import jalview.bin.Jalview;
34 import jalview.datamodel.Alignment;
35 import jalview.datamodel.AlignmentI;
36 import jalview.datamodel.HiddenColumns;
37 import jalview.datamodel.Sequence;
38 import jalview.datamodel.SequenceFeature;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.io.DataSourceType;
42 import jalview.io.FileLoader;
43 import jalview.project.Jalview2xmlTests;
44 import jalview.renderer.ResidueShaderI;
45 import jalview.schemes.BuriedColourScheme;
46 import jalview.schemes.FeatureColour;
47 import jalview.schemes.HelixColourScheme;
48 import jalview.schemes.JalviewColourScheme;
49 import jalview.schemes.StrandColourScheme;
50 import jalview.schemes.TurnColourScheme;
51 import jalview.util.MessageManager;
52 import jalview.viewmodel.AlignmentViewport;
54 import java.awt.Color;
55 import java.util.Iterator;
57 import org.testng.annotations.AfterMethod;
58 import org.testng.annotations.BeforeClass;
59 import org.testng.annotations.BeforeMethod;
60 import org.testng.annotations.Test;
62 public class AlignFrameTest
66 @BeforeClass(alwaysRun = true)
67 public static void setUpBeforeClass() throws Exception
71 * use read-only test properties file
73 Cache.loadProperties("test/jalview/io/testProps.jvprops");
74 Jalview.main(new String[] { "-nonews" });
77 @AfterMethod(alwaysRun = true)
78 public void tearDown()
80 Desktop.instance.closeAll_actionPerformed(null);
84 * configure (read-only) properties for test to ensure Consensus is computed for
85 * colour Above PID testing
87 @BeforeMethod(alwaysRun = true)
90 Cache.loadProperties("test/jalview/io/testProps.jvprops");
91 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
92 Boolean.TRUE.toString());
93 af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
97 * wait for Consensus thread to complete
101 while (af.getViewport().getConsensusSeq() == null)
106 } catch (InterruptedException e)
113 public static void setUpJvOptionPane()
115 JvOptionPane.setInteractiveMode(false);
116 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
119 @Test(groups = "Functional")
120 public void testHideFeatureColumns()
122 SequenceI seq1 = new Sequence("Seq1", "ABCDEFGHIJ");
123 SequenceI seq2 = new Sequence("Seq2", "ABCDEFGHIJ");
124 seq1.addSequenceFeature(new SequenceFeature("Metal", "", 1, 5, 0f, null));
125 seq2.addSequenceFeature(new SequenceFeature("Metal", "", 6, 10, 10f,
127 seq1.addSequenceFeature(new SequenceFeature("Turn", "", 2, 4,
129 seq2.addSequenceFeature(new SequenceFeature("Turn", "", 7, 9,
131 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
132 AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
136 * make all features visible (select feature columns checks visibility)
138 alignFrame.getFeatureRenderer().findAllFeatures(true);
141 * hiding a feature not present does nothing
143 assertFalse(alignFrame.hideFeatureColumns("exon", true));
144 assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
146 assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
147 .getNumberOfRegions(), 0);
149 assertFalse(alignFrame.hideFeatureColumns("exon", false));
150 assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
152 assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
153 .getNumberOfRegions(), 0);
156 * hiding a feature in all columns does nothing
158 assertFalse(alignFrame.hideFeatureColumns("Metal", true));
159 assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
161 assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
162 .getNumberOfRegions(), 0);
166 * threshold Metal to hide features where score < 5
167 * seq1 feature in columns 1-5 is hidden
168 * seq2 feature in columns 6-10 is shown
170 FeatureColourI fc = new FeatureColour(null, Color.red, Color.blue, null,
172 fc.setAboveThreshold(true);
174 alignFrame.getFeatureRenderer().setColour("Metal", fc);
175 assertTrue(alignFrame.hideFeatureColumns("Metal", true));
176 HiddenColumns hidden = alignFrame.getViewport().getAlignment().getHiddenColumns();
177 assertEquals(hidden.getNumberOfRegions(), 1);
178 Iterator<int[]> regions = hidden.iterator();
179 int[] next = regions.next();
180 assertEquals(next[0], 5);
181 assertEquals(next[1], 9);
184 * hide a feature present in some columns
185 * sequence positions [2-4], [7-9] are column positions
186 * [1-3], [6-8] base zero
188 alignFrame.getViewport().showAllHiddenColumns();
189 assertTrue(alignFrame.hideFeatureColumns("Turn", true));
190 regions = alignFrame.getViewport().getAlignment()
191 .getHiddenColumns().iterator();
192 assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
193 .getNumberOfRegions(), 2);
194 next = regions.next();
195 assertEquals(next[0], 1);
196 assertEquals(next[1], 3);
197 next = regions.next();
198 assertEquals(next[0], 6);
199 assertEquals(next[1], 8);
203 * Test that changing background (alignment) colour scheme
205 * <li>with Apply Colour to All Groups not selected, does not change group
207 * <li>with Apply Colour to All Groups selected, does change group colours</li>
208 * <li>in neither case, changes alignment or group colour thresholds (PID or
212 @Test(groups = "Functional")
213 public void testChangeColour_background_groupsAndThresholds()
215 AlignViewportI av = af.getViewport();
216 AlignmentI al = av.getAlignment();
219 * Colour alignment by Buried Index
221 af.applyToAllGroups_actionPerformed(false);
222 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
223 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
224 assertFalse(av.getResidueShading().conservationApplied());
225 assertEquals(av.getResidueShading().getThreshold(), 0);
228 * Apply Conservation 20%
230 af.conservationMenuItem_actionPerformed(true);
231 SliderPanel sp = SliderPanel.getSliderPanel();
232 assertEquals(sp.getTitle(), MessageManager.formatMessage(
233 "label.conservation_colour_increment",
234 new String[] { "Background" }));
235 assertTrue(sp.isForConservation());
237 assertTrue(av.getResidueShading().conservationApplied());
238 assertEquals(av.getResidueShading().getConservationInc(), 20);
241 * Apply PID threshold 10% (conservation still applies as well)
243 af.abovePIDThreshold_actionPerformed(true);
244 sp = SliderPanel.getSliderPanel();
245 assertFalse(sp.isForConservation());
246 assertEquals(sp.getTitle(), MessageManager.formatMessage(
247 "label.percentage_identity_threshold",
248 new String[] { "Background" }));
250 assertEquals(av.getResidueShading().getThreshold(), 10);
251 assertTrue(av.getResidueShading().conservationApplied());
252 assertEquals(av.getResidueShading().getConservationInc(), 20);
255 * create a group with Strand colouring, 30% Conservation
256 * and 40% PID threshold
258 SequenceGroup sg = new SequenceGroup();
259 sg.addSequence(al.getSequenceAt(0), false);
262 av.setSelectionGroup(sg);
265 * apply 30% Conservation to group
266 * (notice menu action applies to selection group even if mouse click
267 * is at a sequence not in the group)
269 PopupMenu popupMenu = new PopupMenu(af.alignPanel, al.getSequenceAt(2),
271 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
273 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
274 assertEquals(al.getGroups().size(), 1);
275 assertSame(al.getGroups().get(0), sg);
276 popupMenu.conservationMenuItem_actionPerformed(true);
277 sp = SliderPanel.getSliderPanel();
278 assertTrue(sp.isForConservation());
279 assertEquals(sp.getTitle(), MessageManager.formatMessage(
280 "label.conservation_colour_increment",
281 new String[] { sg.getName() }));
283 assertTrue(sg.getGroupColourScheme().conservationApplied());
284 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
287 * apply 40% PID threshold to group
289 popupMenu.abovePIDColour_actionPerformed(true);
290 sp = SliderPanel.getSliderPanel();
291 assertFalse(sp.isForConservation());
292 assertEquals(sp.getTitle(), MessageManager.formatMessage(
293 "label.percentage_identity_threshold",
294 new String[] { sg.getName() }));
296 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
297 // conservation threshold is unchanged:
298 assertTrue(sg.getGroupColourScheme().conservationApplied());
299 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
302 * change alignment colour - group colour, and all thresholds,
303 * should be unaffected
305 af.changeColour_actionPerformed(JalviewColourScheme.Turn.toString());
306 assertTrue(av.getGlobalColourScheme() instanceof TurnColourScheme);
307 assertTrue(av.getResidueShading().conservationApplied());
308 assertEquals(av.getResidueShading().getConservationInc(), 20);
309 assertEquals(av.getResidueShading().getThreshold(), 10);
310 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
311 assertTrue(sg.getGroupColourScheme().conservationApplied());
312 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
313 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
316 * Now change alignment colour with Apply Colour To All Groups
317 * - group colour should change, but not colour thresholds
319 af.applyToAllGroups_actionPerformed(true);
320 af.changeColour_actionPerformed(JalviewColourScheme.Helix.toString());
321 assertTrue(av.getGlobalColourScheme() instanceof HelixColourScheme);
322 assertTrue(av.getResidueShading().conservationApplied());
323 assertEquals(av.getResidueShading().getConservationInc(), 20);
324 assertEquals(av.getResidueShading().getThreshold(), 10);
325 assertTrue(sg.getColourScheme() instanceof HelixColourScheme);
326 assertTrue(sg.getGroupColourScheme().conservationApplied());
327 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
328 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
332 * Test residue colouring with various options
334 * <li>no PID or Conservation threshold</li>
335 * <li>colour by Conservation applied</li>
336 * <li>colour by Conservation removed</li>
337 * <li>colour above PID - various values</li>
338 * <li>colour above PID removed</li>
339 * <li>Above PID plus By Conservation combined</li>
340 * <li>remove Above PID to leave just By Conservation</li>
341 * <li>re-add Above PID</li>
342 * <li>remove By Conservation to leave just Above PID</li>
343 * <li>remove Above PID to leave original colours</li>
346 @Test(groups = "Functional")
347 public void testColourThresholdActions()
349 AlignViewportI av = af.getViewport();
350 AlignmentI al = av.getAlignment();
353 * Colour alignment by Helix Propensity, no thresholds
355 af.applyToAllGroups_actionPerformed(false);
356 af.changeColour_actionPerformed(JalviewColourScheme.Helix.toString());
357 assertTrue(av.getGlobalColourScheme() instanceof HelixColourScheme);
358 assertFalse(av.getResidueShading().conservationApplied());
359 assertEquals(av.getResidueShading().getThreshold(), 0);
362 * inspect the colour of
363 * FER_CAPAN.9(I), column 14 (14 base 0)
364 * FER_CAPAN.10(SER), column 16 (15 base 0)
366 SequenceI ferCapan = al.findName("FER_CAPAN");
367 ResidueShaderI rs = av.getResidueShading();
368 Color c = rs.findColour('I', 14, ferCapan);
369 Color i_original = new Color(138, 117, 138);
370 assertEquals(c, i_original);
371 c = rs.findColour('S', 15, ferCapan);
372 Color s_original = new Color(54, 201, 54);
373 assertEquals(c, s_original);
376 * colour by conservation with increment 10
378 af.conservationMenuItem_actionPerformed(true);
379 SliderPanel sp = SliderPanel.getSliderPanel();
380 assertTrue(sp.isForConservation());
381 assertEquals(sp.getValue(), 30); // initial slider setting
383 assertSame(rs, av.getResidueShading());
384 c = rs.findColour('I', 14, ferCapan);
385 Color i_faded = new Color(196, 186, 196);
386 assertEquals(c, i_faded);
387 c = rs.findColour('S', 15, ferCapan);
388 Color s_faded = new Color(144, 225, 144);
389 assertEquals(c, s_faded);
392 * deselect By Conservation - colour should revert
394 af.conservationMenuItem_actionPerformed(false);
395 c = rs.findColour('S', 15, ferCapan);
396 assertEquals(c, s_original);
399 * now Above PID, threshold = 0%
400 * should be no change
402 af.abovePIDThreshold_actionPerformed(true);
403 sp = SliderPanel.getSliderPanel();
404 assertFalse(sp.isForConservation());
405 assertEquals(sp.getValue(), 0); // initial slider setting
406 c = rs.findColour('I', 14, ferCapan);
407 assertEquals(c, i_original);
408 c = rs.findColour('S', 15, ferCapan);
409 assertEquals(c, s_original);
412 * Above PID, threshold = 1%
413 * 15.I becomes White because no match to consensus (V)
414 * 16.S remains coloured as matches 66.66% consensus
417 c = rs.findColour('I', 14, ferCapan);
418 assertEquals(c, Color.white);
419 c = rs.findColour('S', 15, ferCapan);
420 assertEquals(c, s_original);
423 * threshold 66% - no further change yet...
426 c = rs.findColour('I', 14, ferCapan);
427 assertEquals(c, Color.white);
428 c = rs.findColour('S', 15, ferCapan);
429 assertEquals(c, s_original);
432 * threshold 67% - now both residues are white
435 c = rs.findColour('I', 14, ferCapan);
436 assertEquals(c, Color.white);
437 c = rs.findColour('S', 15, ferCapan);
438 assertEquals(c, Color.white);
441 * deselect Above PID - colours should revert
443 af.abovePIDThreshold_actionPerformed(false);
444 c = rs.findColour('I', 14, ferCapan);
445 assertEquals(c, i_original);
446 c = rs.findColour('S', 15, ferCapan);
447 assertEquals(c, s_original);
450 * Now combine Above 50% PID and By Conservation 10%
451 * 15.I is White because no match to consensus (V)
452 * 16.S is coloured but faded
454 af.abovePIDThreshold_actionPerformed(true);
455 sp = SliderPanel.getSliderPanel();
456 assertFalse(sp.isForConservation());
458 af.conservationMenuItem_actionPerformed(true);
459 sp = SliderPanel.getSliderPanel();
460 assertTrue(sp.isForConservation());
462 c = rs.findColour('I', 14, ferCapan);
463 assertEquals(c, Color.white);
464 c = rs.findColour('S', 15, ferCapan);
465 assertEquals(c, s_faded);
468 * turn off Above PID - should just leave Conservation fading as before
470 af.abovePIDThreshold_actionPerformed(false);
471 c = rs.findColour('I', 14, ferCapan);
472 assertEquals(c, i_faded);
473 c = rs.findColour('S', 15, ferCapan);
474 assertEquals(c, s_faded);
477 * Now add Above 50% PID to conservation colouring
478 * - should give the same as PID followed by conservation (above)
480 af.abovePIDThreshold_actionPerformed(true);
481 SliderPanel.getSliderPanel().valueChanged(50);
482 c = rs.findColour('I', 14, ferCapan);
483 assertEquals(c, Color.white);
484 c = rs.findColour('S', 15, ferCapan);
485 assertEquals(c, s_faded);
488 * turn off By Conservation
489 * should leave I white, S original (unfaded) colour
491 af.conservationMenuItem_actionPerformed(false);
492 c = rs.findColour('I', 14, ferCapan);
493 assertEquals(c, Color.white);
494 c = rs.findColour('S', 15, ferCapan);
495 assertEquals(c, s_original);
498 * finally turn off Above PID to leave original colours
500 af.abovePIDThreshold_actionPerformed(false);
501 c = rs.findColour('I', 14, ferCapan);
502 assertEquals(c, i_original);
503 c = rs.findColour('S', 15, ferCapan);
504 assertEquals(c, s_original);
508 * Verify that making a New View transfers alignment and group colour schemes,
509 * including any thresholds, to the new view. Because New View is performed by
510 * saving and reloading a 'project' file, this is similar to verifying a
511 * project save and reload.
513 * @see Jalview2xmlTests#testStoreAndRecoverColourThresholds()
515 @Test(groups = "Functional")
516 public void testNewView_colourThresholds()
518 AlignViewportI av = af.getViewport();
519 AlignmentI al = av.getAlignment();
522 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
524 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
525 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
526 af.abovePIDThreshold_actionPerformed(true);
527 SliderPanel sp = SliderPanel.getSliderPanel();
528 assertFalse(sp.isForConservation());
530 af.conservationMenuItem_actionPerformed(true);
531 sp = SliderPanel.getSliderPanel();
532 assertTrue(sp.isForConservation());
534 ResidueShaderI rs = av.getResidueShading();
535 assertEquals(rs.getThreshold(), 10);
536 assertTrue(rs.conservationApplied());
537 assertEquals(rs.getConservationInc(), 20);
540 * create a group with Strand colouring, 30% Conservation
541 * and 40% PID threshold
543 SequenceGroup sg = new SequenceGroup();
544 sg.addSequence(al.getSequenceAt(0), false);
547 av.setSelectionGroup(sg);
548 PopupMenu popupMenu = new PopupMenu(af.alignPanel, al.getSequenceAt(0),
550 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
552 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
553 assertEquals(al.getGroups().size(), 1);
554 assertSame(al.getGroups().get(0), sg);
555 popupMenu.conservationMenuItem_actionPerformed(true);
556 sp = SliderPanel.getSliderPanel();
557 assertTrue(sp.isForConservation());
559 popupMenu.abovePIDColour_actionPerformed(true);
560 sp = SliderPanel.getSliderPanel();
561 assertFalse(sp.isForConservation());
563 rs = sg.getGroupColourScheme();
564 assertTrue(rs.conservationApplied());
565 assertEquals(rs.getConservationInc(), 30);
566 assertEquals(rs.getThreshold(), 40);
569 * set slider panel focus to the background alignment
571 af.conservationMenuItem_actionPerformed(true);
572 sp = SliderPanel.getSliderPanel();
573 assertTrue(sp.isForConservation());
574 assertEquals(sp.getTitle(), MessageManager.formatMessage(
575 "label.conservation_colour_increment",
576 new String[] { "Background" }));
579 * make a new View, verify alignment and group colour schemes
581 af.newView_actionPerformed(null);
582 assertEquals(af.alignPanel.getViewName(), "View 1");
583 AlignmentViewport av2 = af.getViewport();
584 assertNotSame(av, av2);
585 assertSame(av2, af.alignPanel.av);
586 rs = av2.getResidueShading();
587 assertNotSame(av.getResidueShading(), rs);
588 assertEquals(rs.getThreshold(), 10);
589 assertTrue(rs.conservationApplied(), rs.toString());
590 assertEquals(rs.getConservationInc(), 20);
591 assertEquals(av2.getAlignment().getGroups().size(), 1);
592 sg = av2.getAlignment().getGroups().get(0);
593 rs = sg.getGroupColourScheme();
594 assertTrue(rs.conservationApplied());
595 assertEquals(rs.getConservationInc(), 30);
596 assertEquals(rs.getThreshold(), 40);
599 * check the Conservation SliderPanel (still open) is linked to
600 * and updates the new view (JAL-2385)
602 sp = SliderPanel.getSliderPanel();
603 assertTrue(sp.isForConservation());
604 assertEquals(sp.getTitle(), MessageManager.formatMessage(
605 "label.conservation_colour_increment",
606 new String[] { "View 1" }));
608 assertEquals(av2.getResidueShading().getConservationInc(), 22);
612 * Verify that making a New View preserves the dataset reference for the
613 * alignment. Otherwise, see a 'duplicate jar entry' reference when trying to
614 * save alignments with multiple views, and codon mappings will not be shared
615 * across all panels in a split frame.
617 * @see Jalview2xmlTests#testStoreAndRecoverColourThresholds()
619 @Test(groups = "Functional")
620 public void testNewView_dsRefPreserved()
622 AlignViewport av = af.getViewport();
623 AlignmentI al = av.getAlignment();
624 AlignmentI original_ds = al.getDataset();
625 af.newView_actionPerformed(null);
626 assertNotEquals("New view didn't select the a new panel", av,
628 org.testng.Assert.assertEquals(original_ds,
629 af.getViewport().getAlignment().getDataset(),
630 "Dataset was not preserved in new view");