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.assertFalse;
25 import static org.testng.Assert.assertNotSame;
26 import static org.testng.Assert.assertSame;
27 import static org.testng.Assert.assertTrue;
29 import jalview.bin.Cache;
30 import jalview.bin.Jalview;
31 import jalview.datamodel.Alignment;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.Sequence;
34 import jalview.datamodel.SequenceFeature;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.io.DataSourceType;
38 import jalview.io.FileLoader;
39 import jalview.io.Jalview2xmlTests;
40 import jalview.renderer.ResidueShaderI;
41 import jalview.schemes.BuriedColourScheme;
42 import jalview.schemes.HelixColourScheme;
43 import jalview.schemes.JalviewColourScheme;
44 import jalview.schemes.StrandColourScheme;
45 import jalview.schemes.TurnColourScheme;
46 import jalview.util.MessageManager;
48 import java.awt.Color;
49 import java.util.List;
51 import org.testng.annotations.AfterMethod;
52 import org.testng.annotations.BeforeClass;
53 import org.testng.annotations.BeforeMethod;
54 import org.testng.annotations.Test;
56 public class AlignFrameTest
60 @BeforeClass(alwaysRun = true)
61 public void setUpJvOptionPane()
63 JvOptionPane.setInteractiveMode(false);
64 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
67 @Test(groups = "Functional")
68 public void testHideFeatureColumns()
70 SequenceI seq1 = new Sequence("Seq1", "ABCDEFGHIJ");
71 SequenceI seq2 = new Sequence("Seq2", "ABCDEFGHIJ");
72 seq1.addSequenceFeature(new SequenceFeature("Metal", "", 1, 5,
74 seq2.addSequenceFeature(new SequenceFeature("Metal", "", 6, 10,
76 seq1.addSequenceFeature(new SequenceFeature("Turn", "", 2, 4,
78 seq2.addSequenceFeature(new SequenceFeature("Turn", "", 7, 9,
80 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
81 AlignFrame alignFrame = new AlignFrame(al, al.getWidth(), al.getHeight());
84 * hiding a feature not present does nothing
86 assertFalse(alignFrame.hideFeatureColumns("exon", true));
87 assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
88 assertTrue(alignFrame.getViewport().getAlignment().getHiddenColumns()
91 assertFalse(alignFrame.hideFeatureColumns("exon", false));
92 assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
93 assertTrue(alignFrame.getViewport().getAlignment().getHiddenColumns()
98 * hiding a feature in all columns does nothing
100 assertFalse(alignFrame.hideFeatureColumns("Metal", true));
101 assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
102 List<int[]> hidden = alignFrame.getViewport().getAlignment()
105 assertTrue(hidden.isEmpty());
108 * hide a feature present in some columns
109 * sequence positions [2-4], [7-9] are column positions
110 * [1-3], [6-8] base zero
112 assertTrue(alignFrame.hideFeatureColumns("Turn", true));
113 hidden = alignFrame.getViewport().getAlignment().getHiddenColumns()
115 assertEquals(hidden.size(), 2);
116 assertEquals(hidden.get(0)[0], 1);
117 assertEquals(hidden.get(0)[1], 3);
118 assertEquals(hidden.get(1)[0], 6);
119 assertEquals(hidden.get(1)[1], 8);
122 @BeforeClass(alwaysRun = true)
123 public static void setUpBeforeClass() throws Exception
126 * use read-only test properties file
128 Cache.loadProperties("test/jalview/io/testProps.jvprops");
129 Jalview.main(new String[] { "-nonews" });
132 @AfterMethod(alwaysRun = true)
133 public void tearDown()
135 Desktop.instance.closeAll_actionPerformed(null);
139 * configure (read-only) properties for test to ensure Consensus is computed
140 * for colour Above PID testing
142 @BeforeMethod(alwaysRun = true)
145 Cache.loadProperties("test/jalview/io/testProps.jvprops");
146 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
147 Boolean.TRUE.toString());
148 af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
149 DataSourceType.FILE);
152 * wait for Consensus thread to complete
156 while (af.getViewport().getConsensusSeq() == null)
161 } catch (InterruptedException e)
169 * Test that changing background (alignment) colour scheme
171 * <li>with Apply Colour to All Groups not selected, does not change group
173 * <li>with Apply Colour to All Groups selected, does change group colours</li>
174 * <li>in neither case, changes alignment or group colour thresholds (PID or
178 @Test(groups = "Functional")
179 public void testChangeColour_background_groupsAndThresholds()
181 AlignViewport av = af.getViewport();
182 AlignmentI al = av.getAlignment();
185 * Colour alignment by Buried Index
187 af.applyToAllGroups_actionPerformed(false);
188 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
189 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
190 assertFalse(av.getResidueShading().conservationApplied());
191 assertEquals(av.getResidueShading().getThreshold(), 0);
194 * Apply Conservation 20%
196 af.conservationMenuItem_actionPerformed(true);
197 SliderPanel sp = SliderPanel.getSliderPanel();
198 assertEquals(sp.getTitle(), MessageManager.formatMessage(
199 "label.conservation_colour_increment",
200 new String[] { "Background" }));
201 assertTrue(sp.isForConservation());
203 assertTrue(av.getResidueShading().conservationApplied());
204 assertEquals(av.getResidueShading().getConservationInc(), 20);
207 * Apply PID threshold 10% (conservation still applies as well)
209 af.abovePIDThreshold_actionPerformed(true);
210 sp = SliderPanel.getSliderPanel();
211 assertFalse(sp.isForConservation());
212 assertEquals(sp.getTitle(), MessageManager.formatMessage(
213 "label.percentage_identity_threshold",
214 new String[] { "Background" }));
216 assertEquals(av.getResidueShading().getThreshold(), 10);
217 assertTrue(av.getResidueShading().conservationApplied());
218 assertEquals(av.getResidueShading().getConservationInc(), 20);
221 * create a group with Strand colouring, 30% Conservation
222 * and 40% PID threshold
224 SequenceGroup sg = new SequenceGroup();
225 sg.addSequence(al.getSequenceAt(0), false);
228 av.setSelectionGroup(sg);
231 * apply 30% Conservation to group
233 PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
234 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
236 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
237 assertEquals(al.getGroups().size(), 1);
238 assertSame(al.getGroups().get(0), sg);
239 popupMenu.conservationMenuItem_actionPerformed(true);
240 sp = SliderPanel.getSliderPanel();
241 assertTrue(sp.isForConservation());
242 assertEquals(sp.getTitle(), MessageManager.formatMessage(
243 "label.conservation_colour_increment",
244 new String[] { sg.getName() }));
246 assertTrue(sg.getGroupColourScheme().conservationApplied());
247 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
250 * apply 40% PID threshold to group
252 popupMenu.abovePIDColour_actionPerformed(true);
253 sp = SliderPanel.getSliderPanel();
254 assertFalse(sp.isForConservation());
255 assertEquals(sp.getTitle(), MessageManager.formatMessage(
256 "label.percentage_identity_threshold",
257 new String[] { sg.getName() }));
259 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
260 // conservation threshold is unchanged:
261 assertTrue(sg.getGroupColourScheme().conservationApplied());
262 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
265 * change alignment colour - group colour, and all thresholds,
266 * should be unaffected
268 af.changeColour_actionPerformed(JalviewColourScheme.Turn.toString());
269 assertTrue(av.getGlobalColourScheme() instanceof TurnColourScheme);
270 assertTrue(av.getResidueShading().conservationApplied());
271 assertEquals(av.getResidueShading().getConservationInc(), 20);
272 assertEquals(av.getResidueShading().getThreshold(), 10);
273 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
274 assertTrue(sg.getGroupColourScheme().conservationApplied());
275 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
276 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
279 * Now change alignment colour with Apply Colour To All Groups
280 * - group colour should change, but not colour thresholds
282 af.applyToAllGroups_actionPerformed(true);
283 af.changeColour_actionPerformed(JalviewColourScheme.Helix.toString());
284 assertTrue(av.getGlobalColourScheme() instanceof HelixColourScheme);
285 assertTrue(av.getResidueShading().conservationApplied());
286 assertEquals(av.getResidueShading().getConservationInc(), 20);
287 assertEquals(av.getResidueShading().getThreshold(), 10);
288 assertTrue(sg.getColourScheme() instanceof HelixColourScheme);
289 assertTrue(sg.getGroupColourScheme().conservationApplied());
290 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
291 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
295 * Test residue colouring with various options
297 * <li>no PID or Conservation threshold</li>
298 * <li>colour by Conservation applied</li>
299 * <li>colour by Conservation removed</li>
300 * <li>colour above PID - various values</li>
301 * <li>colour above PID removed</li>
302 * <li>Above PID plus By Conservation combined</li>
303 * <li>remove Above PID to leave just By Conservation</li>
304 * <li>re-add Above PID</li>
305 * <li>remove By Conservation to leave just Above PID</li>
306 * <li>remove Above PID to leave original colours</li>
309 @Test(groups = "Functional")
310 public void testColourThresholdActions()
312 AlignViewport av = af.getViewport();
313 AlignmentI al = av.getAlignment();
316 * Colour alignment by Helix Propensity, no thresholds
318 af.applyToAllGroups_actionPerformed(false);
319 af.changeColour_actionPerformed(JalviewColourScheme.Helix.toString());
320 assertTrue(av.getGlobalColourScheme() instanceof HelixColourScheme);
321 assertFalse(av.getResidueShading().conservationApplied());
322 assertEquals(av.getResidueShading().getThreshold(), 0);
325 * inspect the colour of
326 * FER_CAPAN.9(I), column 14 (14 base 0)
327 * FER_CAPAN.10(SER), column 16 (15 base 0)
329 SequenceI ferCapan = al.findName("FER_CAPAN");
330 ResidueShaderI rs = av.getResidueShading();
331 Color c = rs.findColour('I', 14, ferCapan);
332 Color i_original = new Color(138, 117, 138);
333 assertEquals(c, i_original);
334 c = rs.findColour('S', 15, ferCapan);
335 Color s_original = new Color(54, 201, 54);
336 assertEquals(c, s_original);
339 * colour by conservation with increment 10
341 af.conservationMenuItem_actionPerformed(true);
342 SliderPanel sp = SliderPanel.getSliderPanel();
343 assertTrue(sp.isForConservation());
344 assertEquals(sp.getValue(), 30); // initial slider setting
346 assertSame(rs, av.getResidueShading());
347 c = rs.findColour('I', 14, ferCapan);
348 Color i_faded = new Color(196, 186, 196);
349 assertEquals(c, i_faded);
350 c = rs.findColour('S', 15, ferCapan);
351 Color s_faded = new Color(144, 225, 144);
352 assertEquals(c, s_faded);
355 * deselect By Conservation - colour should revert
357 af.conservationMenuItem_actionPerformed(false);
358 c = rs.findColour('S', 15, ferCapan);
359 assertEquals(c, s_original);
362 * now Above PID, threshold = 0%
363 * should be no change
365 af.abovePIDThreshold_actionPerformed(true);
366 sp = SliderPanel.getSliderPanel();
367 assertFalse(sp.isForConservation());
368 assertEquals(sp.getValue(), 0); // initial slider setting
369 c = rs.findColour('I', 14, ferCapan);
370 assertEquals(c, i_original);
371 c = rs.findColour('S', 15, ferCapan);
372 assertEquals(c, s_original);
375 * Above PID, threshold = 1%
376 * 15.I becomes White because no match to consensus (V)
377 * 16.S remains coloured as matches 66.66% consensus
380 c = rs.findColour('I', 14, ferCapan);
381 assertEquals(c, Color.white);
382 c = rs.findColour('S', 15, ferCapan);
383 assertEquals(c, s_original);
386 * threshold 66% - no further change yet...
389 c = rs.findColour('I', 14, ferCapan);
390 assertEquals(c, Color.white);
391 c = rs.findColour('S', 15, ferCapan);
392 assertEquals(c, s_original);
395 * threshold 67% - now both residues are white
398 c = rs.findColour('I', 14, ferCapan);
399 assertEquals(c, Color.white);
400 c = rs.findColour('S', 15, ferCapan);
401 assertEquals(c, Color.white);
404 * deselect Above PID - colours should revert
406 af.abovePIDThreshold_actionPerformed(false);
407 c = rs.findColour('I', 14, ferCapan);
408 assertEquals(c, i_original);
409 c = rs.findColour('S', 15, ferCapan);
410 assertEquals(c, s_original);
413 * Now combine Above 50% PID and By Conservation 10%
414 * 15.I is White because no match to consensus (V)
415 * 16.S is coloured but faded
417 af.abovePIDThreshold_actionPerformed(true);
418 sp = SliderPanel.getSliderPanel();
419 assertFalse(sp.isForConservation());
421 af.conservationMenuItem_actionPerformed(true);
422 sp = SliderPanel.getSliderPanel();
423 assertTrue(sp.isForConservation());
425 c = rs.findColour('I', 14, ferCapan);
426 assertEquals(c, Color.white);
427 c = rs.findColour('S', 15, ferCapan);
428 assertEquals(c, s_faded);
431 * turn off Above PID - should just leave Conservation fading as before
433 af.abovePIDThreshold_actionPerformed(false);
434 c = rs.findColour('I', 14, ferCapan);
435 assertEquals(c, i_faded);
436 c = rs.findColour('S', 15, ferCapan);
437 assertEquals(c, s_faded);
440 * Now add Above 50% PID to conservation colouring
441 * - should give the same as PID followed by conservation (above)
443 af.abovePIDThreshold_actionPerformed(true);
444 SliderPanel.getSliderPanel().valueChanged(50);
445 c = rs.findColour('I', 14, ferCapan);
446 assertEquals(c, Color.white);
447 c = rs.findColour('S', 15, ferCapan);
448 assertEquals(c, s_faded);
451 * turn off By Conservation
452 * should leave I white, S original (unfaded) colour
454 af.conservationMenuItem_actionPerformed(false);
455 c = rs.findColour('I', 14, ferCapan);
456 assertEquals(c, Color.white);
457 c = rs.findColour('S', 15, ferCapan);
458 assertEquals(c, s_original);
461 * finally turn off Above PID to leave original colours
463 af.abovePIDThreshold_actionPerformed(false);
464 c = rs.findColour('I', 14, ferCapan);
465 assertEquals(c, i_original);
466 c = rs.findColour('S', 15, ferCapan);
467 assertEquals(c, s_original);
471 * Verify that making a New View transfers alignment and group colour schemes,
472 * including any thresholds, to the new view. Because New View is performed by
473 * saving and reloading a 'project' file, this is similar to verifying a
474 * project save and reload.
476 * @see Jalview2xmlTests#testStoreAndRecoverColourThresholds()
478 @Test(groups = "Functional")
479 public void testNewView_colourThresholds()
481 AlignViewport av = af.getViewport();
482 AlignmentI al = av.getAlignment();
485 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
487 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
488 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
489 af.abovePIDThreshold_actionPerformed(true);
490 SliderPanel sp = SliderPanel.getSliderPanel();
491 assertFalse(sp.isForConservation());
493 af.conservationMenuItem_actionPerformed(true);
494 sp = SliderPanel.getSliderPanel();
495 assertTrue(sp.isForConservation());
497 ResidueShaderI rs = av.getResidueShading();
498 assertEquals(rs.getThreshold(), 10);
499 assertTrue(rs.conservationApplied());
500 assertEquals(rs.getConservationInc(), 20);
503 * create a group with Strand colouring, 30% Conservation
504 * and 40% PID threshold
506 SequenceGroup sg = new SequenceGroup();
507 sg.addSequence(al.getSequenceAt(0), false);
510 av.setSelectionGroup(sg);
511 PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
512 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
514 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
515 assertEquals(al.getGroups().size(), 1);
516 assertSame(al.getGroups().get(0), sg);
517 popupMenu.conservationMenuItem_actionPerformed(true);
518 sp = SliderPanel.getSliderPanel();
519 assertTrue(sp.isForConservation());
521 popupMenu.abovePIDColour_actionPerformed(true);
522 sp = SliderPanel.getSliderPanel();
523 assertFalse(sp.isForConservation());
525 rs = sg.getGroupColourScheme();
526 assertTrue(rs.conservationApplied());
527 assertEquals(rs.getConservationInc(), 30);
528 assertEquals(rs.getThreshold(), 40);
531 * set slider panel focus to the background alignment
533 af.conservationMenuItem_actionPerformed(true);
534 sp = SliderPanel.getSliderPanel();
535 assertTrue(sp.isForConservation());
536 assertEquals(sp.getTitle(), MessageManager.formatMessage(
537 "label.conservation_colour_increment",
538 new String[] { "Background" }));
541 * make a new View, verify alignment and group colour schemes
543 af.newView_actionPerformed(null);
544 assertEquals(af.alignPanel.getViewName(), "View 1");
545 AlignViewport av2 = af.getViewport();
546 assertNotSame(av, av2);
547 rs = av2.getResidueShading();
548 assertNotSame(av.getResidueShading(), rs);
549 assertEquals(rs.getThreshold(), 10);
550 assertTrue(rs.conservationApplied());
551 assertEquals(rs.getConservationInc(), 20);
552 assertEquals(av2.getAlignment().getGroups().size(), 1);
553 sg = av2.getAlignment().getGroups().get(0);
554 rs = sg.getGroupColourScheme();
555 assertTrue(rs.conservationApplied());
556 assertEquals(rs.getConservationInc(), 30);
557 assertEquals(rs.getThreshold(), 40);
560 * check the Conservation SliderPanel (still open) is linked to
561 * and updates the new view (JAL-2385)
563 sp = SliderPanel.getSliderPanel();
564 assertTrue(sp.isForConservation());
565 assertEquals(sp.getTitle(), MessageManager.formatMessage(
566 "label.conservation_colour_increment",
567 new String[] { "View 1" }));
569 assertEquals(av2.getResidueShading().getConservationInc(), 22);