JAL-3187 minor code change post merge (signature change)
[jalview.git] / test / jalview / gui / AlignFrameTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.gui;
22
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;
29
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;
51
52 import java.awt.Color;
53 import java.util.Iterator;
54
55 import org.testng.annotations.AfterMethod;
56 import org.testng.annotations.BeforeClass;
57 import org.testng.annotations.BeforeMethod;
58 import org.testng.annotations.Test;
59
60 public class AlignFrameTest
61 {
62   AlignFrame af;
63
64   @BeforeClass(alwaysRun = true)
65   public void setUpJvOptionPane()
66   {
67     JvOptionPane.setInteractiveMode(false);
68     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
69   }
70
71   @Test(groups = "Functional")
72   public void testHideFeatureColumns()
73   {
74     SequenceI seq1 = new Sequence("Seq1/01-10", "A---BCDEFG-HIJ");
75     SequenceI seq2 = new Sequence("Seq2/11-20", "-AB-CDEF--GHIJ");
76     String METAL = "Metal";
77     String TURN = "Turn";
78     seq1.addSequenceFeature(
79             new SequenceFeature(METAL, "", 1, 5, 0f, null));
80     seq2.addSequenceFeature(
81             new SequenceFeature(METAL, "", 16, 20, 10f, null));
82     seq1.addSequenceFeature(
83             new SequenceFeature(TURN, "", 2, 4, Float.NaN, null));
84     seq2.addSequenceFeature(
85             new SequenceFeature(TURN, "", 17, 19, Float.NaN, null));
86     AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
87     AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
88             al.getHeight());
89
90     /*
91      * make all features visible (select feature columns checks visibility)
92      */
93     alignFrame.getFeatureRenderer().findAllFeatures(true);
94
95     /*
96      * hiding a feature not present does nothing
97      */
98     assertFalse(alignFrame.hideFeatureColumns(true, "exon"));
99     assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
100     assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
101             .getNumberOfRegions(), 0);
102
103     assertFalse(alignFrame.hideFeatureColumns(false, "exon"));
104     assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
105     assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
106             .getNumberOfRegions(), 0);
107
108     /*
109      * hiding a feature in all columns does nothing
110      */
111     assertFalse(alignFrame.hideFeatureColumns(true, METAL));
112     assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
113     assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
114             .getNumberOfRegions(), 0);
115
116
117     /*
118      * threshold Metal to hide features where score < 5
119      * seq1 feature in columns 1-8 is hidden
120      * seq2 feature in columns 8-14 is shown
121      * result: columns 8-14 are hidden
122      * note this includes gapped columns spanned by the feature
123      */
124     FeatureColourI fc = new FeatureColour(null, Color.red, Color.blue, null,
125             0f, 10f);
126     fc.setAboveThreshold(true);
127     fc.setThreshold(5f);
128     alignFrame.getFeatureRenderer().setColour(METAL, fc);
129     assertTrue(alignFrame.hideFeatureColumns(true, METAL));
130     HiddenColumns hidden = alignFrame.getViewport().getAlignment().getHiddenColumns();
131     assertEquals(hidden.getNumberOfRegions(), 1);
132     Iterator<int[]> regions = hidden.iterator();
133     assertEquals(regions.next(), new int[] { 7, 13 }); // base 0
134     assertFalse(regions.hasNext());
135
136     /*
137      * hide a feature present in some columns
138      * seq1 positions [2-4] are column positions [4-6] base zero
139      * seq2 positions [17-19] are column positions [10-12] base zero
140      */
141     alignFrame.getViewport().showAllHiddenColumns();
142     assertTrue(alignFrame.hideFeatureColumns(true, TURN));
143     regions = alignFrame.getViewport().getAlignment()
144             .getHiddenColumns().iterator();
145     assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
146             .getNumberOfRegions(), 2);
147     assertEquals(regions.next(), new int[] { 4, 6 });
148     assertEquals(regions.next(), new int[] { 10, 12 });
149     assertFalse(regions.hasNext());
150     
151     /*
152      * hiding a contact feature should only hide start and end positions,
153      * not the intermediate columns
154      */
155     String DISULFIDE = "Disulfide Bond";
156     seq1.addSequenceFeature(
157             new SequenceFeature(DISULFIDE, "", 1, 5, 0f, null));
158     alignFrame.getViewport().showAllHiddenColumns();
159     assertTrue(alignFrame.hideFeatureColumns(true, DISULFIDE));
160     regions = alignFrame.getViewport().getAlignment().getHiddenColumns()
161             .iterator();
162     assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
163             .getNumberOfRegions(), 2);
164     assertEquals(regions.next(), new int[] { 0, 0 });
165     assertEquals(regions.next(), new int[] { 7, 7 });
166     assertFalse(regions.hasNext());
167
168     /*
169      * hide multiple feature types:
170      * TURN columns hides 4-6, 10-12
171      * DISULFIDE columns hides 0, 7
172      * combined is { 0-0, 4-7, 10-12 }
173      */
174     alignFrame.getViewport().showAllHiddenColumns();
175     assertTrue(alignFrame.hideFeatureColumns(true, TURN, DISULFIDE));
176     regions = alignFrame.getViewport().getAlignment().getHiddenColumns()
177             .iterator();
178     assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
179             .getNumberOfRegions(), 3);
180     assertEquals(regions.next(), new int[] { 0, 0 });
181     assertEquals(regions.next(), new int[] { 4, 7 });
182     assertEquals(regions.next(), new int[] { 10, 12 });
183     assertFalse(regions.hasNext());
184   }
185
186   @BeforeClass(alwaysRun = true)
187   public static void setUpBeforeClass() throws Exception
188   {
189     /*
190      * use read-only test properties file
191      */
192     Jalview.main(
193             new String[]
194             { "-nonews", "-props", "test/jalview/io/testProps.jvprops" });
195   }
196
197   @AfterMethod(alwaysRun = true)
198   public void tearDown()
199   {
200     Desktop.instance.closeAll_actionPerformed(null);
201   }
202
203   /**
204    * configure (read-only) properties for test to ensure Consensus is computed
205    * for colour Above PID testing
206    */
207   @BeforeMethod(alwaysRun = true)
208   public void setUp()
209   {
210     Cache.loadProperties("test/jalview/io/testProps.jvprops");
211     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
212             Boolean.TRUE.toString());
213     af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
214             DataSourceType.FILE);
215
216     /*
217      * wait for Consensus thread to complete
218      */
219     synchronized (this)
220     {
221       while (af.getViewport().getConsensusSeq() == null)
222       {
223         try
224         {
225           wait(50);
226         } catch (InterruptedException e)
227         {
228         }
229       }
230     }
231   }
232
233   /**
234    * Test that changing background (alignment) colour scheme
235    * <ul>
236    * <li>with Apply Colour to All Groups not selected, does not change group
237    * colours</li>
238    * <li>with Apply Colour to All Groups selected, does change group colours</li>
239    * <li>in neither case, changes alignment or group colour thresholds (PID or
240    * Conservation)</li>
241    * </ul>
242    */
243   @Test(groups = "Functional")
244   public void testChangeColour_background_groupsAndThresholds()
245   {
246     AlignViewport av = af.getViewport();
247     AlignmentI al = av.getAlignment();
248
249     /*
250      * Colour alignment by Buried Index
251      */
252     af.applyToAllGroups_actionPerformed(false);
253     af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
254     assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
255     assertFalse(av.getResidueShading().conservationApplied());
256     assertEquals(av.getResidueShading().getThreshold(), 0);
257
258     /*
259      * Apply Conservation 20%
260      */
261     af.conservationMenuItem_actionPerformed(true);
262     SliderPanel sp = SliderPanel.getSliderPanel();
263     assertEquals(sp.getTitle(), MessageManager.formatMessage(
264             "label.conservation_colour_increment",
265             new String[] { "Background" }));
266     assertTrue(sp.isForConservation());
267     sp.valueChanged(20);
268     assertTrue(av.getResidueShading().conservationApplied());
269     assertEquals(av.getResidueShading().getConservationInc(), 20);
270
271     /*
272      * Apply PID threshold 10% (conservation still applies as well)
273      */
274     af.abovePIDThreshold_actionPerformed(true);
275     sp = SliderPanel.getSliderPanel();
276     assertFalse(sp.isForConservation());
277     assertEquals(sp.getTitle(), MessageManager.formatMessage(
278             "label.percentage_identity_threshold",
279             new String[] { "Background" }));
280     sp.valueChanged(10);
281     assertEquals(av.getResidueShading().getThreshold(), 10);
282     assertTrue(av.getResidueShading().conservationApplied());
283     assertEquals(av.getResidueShading().getConservationInc(), 20);
284
285     /*
286      * create a group with Strand colouring, 30% Conservation
287      * and 40% PID threshold
288      */
289     SequenceGroup sg = new SequenceGroup();
290     sg.addSequence(al.getSequenceAt(0), false);
291     sg.setStartRes(15);
292     sg.setEndRes(25);
293     av.setSelectionGroup(sg);
294
295     /*
296      * apply 30% Conservation to group
297      */
298     PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
299     popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
300             .toString());
301     assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
302     assertEquals(al.getGroups().size(), 1);
303     assertSame(al.getGroups().get(0), sg);
304     popupMenu.conservationMenuItem_actionPerformed(true);
305     sp = SliderPanel.getSliderPanel();
306     assertTrue(sp.isForConservation());
307     assertEquals(sp.getTitle(), MessageManager.formatMessage(
308             "label.conservation_colour_increment",
309             new String[] { sg.getName() }));
310     sp.valueChanged(30);
311     assertTrue(sg.getGroupColourScheme().conservationApplied());
312     assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
313
314     /*
315      * apply 40% PID threshold to group
316      */
317     popupMenu.abovePIDColour_actionPerformed(true);
318     sp = SliderPanel.getSliderPanel();
319     assertFalse(sp.isForConservation());
320     assertEquals(sp.getTitle(), MessageManager.formatMessage(
321             "label.percentage_identity_threshold",
322             new String[] { sg.getName() }));
323     sp.valueChanged(40);
324     assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
325     // conservation threshold is unchanged:
326     assertTrue(sg.getGroupColourScheme().conservationApplied());
327     assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
328
329     /*
330      * change alignment colour - group colour, and all thresholds,
331      * should be unaffected
332      */
333     af.changeColour_actionPerformed(JalviewColourScheme.Turn.toString());
334     assertTrue(av.getGlobalColourScheme() instanceof TurnColourScheme);
335     assertTrue(av.getResidueShading().conservationApplied());
336     assertEquals(av.getResidueShading().getConservationInc(), 20);
337     assertEquals(av.getResidueShading().getThreshold(), 10);
338     assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
339     assertTrue(sg.getGroupColourScheme().conservationApplied());
340     assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
341     assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
342
343     /*
344      * Now change alignment colour with Apply Colour To All Groups
345      * - group colour should change, but not colour thresholds
346      */
347     af.applyToAllGroups_actionPerformed(true);
348     af.changeColour_actionPerformed(JalviewColourScheme.Helix.toString());
349     assertTrue(av.getGlobalColourScheme() instanceof HelixColourScheme);
350     assertTrue(av.getResidueShading().conservationApplied());
351     assertEquals(av.getResidueShading().getConservationInc(), 20);
352     assertEquals(av.getResidueShading().getThreshold(), 10);
353     assertTrue(sg.getColourScheme() instanceof HelixColourScheme);
354     assertTrue(sg.getGroupColourScheme().conservationApplied());
355     assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
356     assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
357   }
358
359   /**
360    * Test residue colouring with various options
361    * <ol>
362    * <li>no PID or Conservation threshold</li>
363    * <li>colour by Conservation applied</li>
364    * <li>colour by Conservation removed</li>
365    * <li>colour above PID - various values</li>
366    * <li>colour above PID removed</li>
367    * <li>Above PID plus By Conservation combined</li>
368    * <li>remove Above PID to leave just By Conservation</li>
369    * <li>re-add Above PID</li>
370    * <li>remove By Conservation to leave just Above PID</li>
371    * <li>remove Above PID to leave original colours</li>
372    * </ol>
373    */
374   @Test(groups = "Functional")
375   public void testColourThresholdActions()
376   {
377     AlignViewport av = af.getViewport();
378     AlignmentI al = av.getAlignment();
379
380     /*
381      * Colour alignment by Helix Propensity, no thresholds
382      */
383     af.applyToAllGroups_actionPerformed(false);
384     af.changeColour_actionPerformed(JalviewColourScheme.Helix.toString());
385     assertTrue(av.getGlobalColourScheme() instanceof HelixColourScheme);
386     assertFalse(av.getResidueShading().conservationApplied());
387     assertEquals(av.getResidueShading().getThreshold(), 0);
388
389     /*
390      * inspect the colour of 
391      * FER_CAPAN.9(I), column 14 (14 base 0)
392      * FER_CAPAN.10(SER), column 16 (15 base 0)
393      */
394     SequenceI ferCapan = al.findName("FER_CAPAN");
395     ResidueShaderI rs = av.getResidueShading();
396     Color c = rs.findColour('I', 14, ferCapan);
397     Color i_original = new Color(138, 117, 138);
398     assertEquals(c, i_original);
399     c = rs.findColour('S', 15, ferCapan);
400     Color s_original = new Color(54, 201, 54);
401     assertEquals(c, s_original);
402
403     /*
404      * colour by conservation with increment 10
405      */
406     af.conservationMenuItem_actionPerformed(true);
407     SliderPanel sp = SliderPanel.getSliderPanel();
408     assertTrue(sp.isForConservation());
409     assertEquals(sp.getValue(), 30); // initial slider setting
410     sp.valueChanged(10);
411     assertSame(rs, av.getResidueShading());
412     c = rs.findColour('I', 14, ferCapan);
413     Color i_faded = new Color(196, 186, 196);
414     assertEquals(c, i_faded);
415     c = rs.findColour('S', 15, ferCapan);
416     Color s_faded = new Color(144, 225, 144);
417     assertEquals(c, s_faded);
418
419     /*
420      * deselect By Conservation - colour should revert
421      */
422     af.conservationMenuItem_actionPerformed(false);
423     c = rs.findColour('S', 15, ferCapan);
424     assertEquals(c, s_original);
425
426     /*
427      * now Above PID, threshold = 0%
428      * should be no change
429      */
430     af.abovePIDThreshold_actionPerformed(true);
431     sp = SliderPanel.getSliderPanel();
432     assertFalse(sp.isForConservation());
433     assertEquals(sp.getValue(), 0); // initial slider setting
434     c = rs.findColour('I', 14, ferCapan);
435     assertEquals(c, i_original);
436     c = rs.findColour('S', 15, ferCapan);
437     assertEquals(c, s_original);
438
439     /*
440      * Above PID, threshold = 1%
441      * 15.I becomes White because no match to consensus (V)
442      * 16.S remains coloured as matches 66.66% consensus
443      */
444     sp.valueChanged(1);
445     c = rs.findColour('I', 14, ferCapan);
446     assertEquals(c, Color.white);
447     c = rs.findColour('S', 15, ferCapan);
448     assertEquals(c, s_original);
449
450     /*
451      * threshold 66% - no further change yet...
452      */
453     sp.valueChanged(66);
454     c = rs.findColour('I', 14, ferCapan);
455     assertEquals(c, Color.white);
456     c = rs.findColour('S', 15, ferCapan);
457     assertEquals(c, s_original);
458
459     /*
460      * threshold 67% - now both residues are white
461      */
462     sp.valueChanged(67);
463     c = rs.findColour('I', 14, ferCapan);
464     assertEquals(c, Color.white);
465     c = rs.findColour('S', 15, ferCapan);
466     assertEquals(c, Color.white);
467
468     /*
469      * deselect Above PID - colours should revert
470      */
471     af.abovePIDThreshold_actionPerformed(false);
472     c = rs.findColour('I', 14, ferCapan);
473     assertEquals(c, i_original);
474     c = rs.findColour('S', 15, ferCapan);
475     assertEquals(c, s_original);
476
477     /*
478      * Now combine Above 50% PID and By Conservation 10%
479      * 15.I is White because no match to consensus (V)
480      * 16.S is coloured but faded
481      */
482     af.abovePIDThreshold_actionPerformed(true);
483     sp = SliderPanel.getSliderPanel();
484     assertFalse(sp.isForConservation());
485     sp.valueChanged(50);
486     af.conservationMenuItem_actionPerformed(true);
487     sp = SliderPanel.getSliderPanel();
488     assertTrue(sp.isForConservation());
489     sp.valueChanged(10);
490     c = rs.findColour('I', 14, ferCapan);
491     assertEquals(c, Color.white);
492     c = rs.findColour('S', 15, ferCapan);
493     assertEquals(c, s_faded);
494
495     /*
496      * turn off Above PID - should just leave Conservation fading as before 
497      */
498     af.abovePIDThreshold_actionPerformed(false);
499     c = rs.findColour('I', 14, ferCapan);
500     assertEquals(c, i_faded);
501     c = rs.findColour('S', 15, ferCapan);
502     assertEquals(c, s_faded);
503
504     /*
505      * Now add Above 50% PID to conservation colouring
506      * - should give the same as PID followed by conservation (above)
507      */
508     af.abovePIDThreshold_actionPerformed(true);
509     SliderPanel.getSliderPanel().valueChanged(50);
510     c = rs.findColour('I', 14, ferCapan);
511     assertEquals(c, Color.white);
512     c = rs.findColour('S', 15, ferCapan);
513     assertEquals(c, s_faded);
514
515     /*
516      * turn off By Conservation
517      * should leave I white, S original (unfaded) colour
518      */
519     af.conservationMenuItem_actionPerformed(false);
520     c = rs.findColour('I', 14, ferCapan);
521     assertEquals(c, Color.white);
522     c = rs.findColour('S', 15, ferCapan);
523     assertEquals(c, s_original);
524
525     /*
526      * finally turn off Above PID to leave original colours
527      */
528     af.abovePIDThreshold_actionPerformed(false);
529     c = rs.findColour('I', 14, ferCapan);
530     assertEquals(c, i_original);
531     c = rs.findColour('S', 15, ferCapan);
532     assertEquals(c, s_original);
533   }
534
535   /**
536    * Verify that making a New View transfers alignment and group colour schemes,
537    * including any thresholds, to the new view. Because New View is performed by
538    * saving and reloading a 'project' file, this is similar to verifying a
539    * project save and reload.
540    * 
541    * @see Jalview2xmlTests#testStoreAndRecoverColourThresholds()
542    */
543   @Test(groups = "Functional")
544   public void testNewView_colourThresholds()
545   {
546     AlignViewport av = af.getViewport();
547     AlignmentI al = av.getAlignment();
548
549     /*
550      * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
551      */
552     af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
553     assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
554     af.abovePIDThreshold_actionPerformed(true);
555     SliderPanel sp = SliderPanel.getSliderPanel();
556     assertFalse(sp.isForConservation());
557     sp.valueChanged(10);
558     af.conservationMenuItem_actionPerformed(true);
559     sp = SliderPanel.getSliderPanel();
560     assertTrue(sp.isForConservation());
561     sp.valueChanged(20);
562     ResidueShaderI rs = av.getResidueShading();
563     assertEquals(rs.getThreshold(), 10);
564     assertTrue(rs.conservationApplied());
565     assertEquals(rs.getConservationInc(), 20);
566
567     /*
568      * create a group with Strand colouring, 30% Conservation
569      * and 40% PID threshold
570      */
571     SequenceGroup sg = new SequenceGroup();
572     sg.addSequence(al.getSequenceAt(0), false);
573     sg.setStartRes(15);
574     sg.setEndRes(25);
575     av.setSelectionGroup(sg);
576     PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
577     popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
578             .toString());
579     assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
580     assertEquals(al.getGroups().size(), 1);
581     assertSame(al.getGroups().get(0), sg);
582     popupMenu.conservationMenuItem_actionPerformed(true);
583     sp = SliderPanel.getSliderPanel();
584     assertTrue(sp.isForConservation());
585     sp.valueChanged(30);
586     popupMenu.abovePIDColour_actionPerformed(true);
587     sp = SliderPanel.getSliderPanel();
588     assertFalse(sp.isForConservation());
589     sp.valueChanged(40);
590     rs = sg.getGroupColourScheme();
591     assertTrue(rs.conservationApplied());
592     assertEquals(rs.getConservationInc(), 30);
593     assertEquals(rs.getThreshold(), 40);
594
595     /*
596      * set slider panel focus to the background alignment
597      */
598     af.conservationMenuItem_actionPerformed(true);
599     sp = SliderPanel.getSliderPanel();
600     assertTrue(sp.isForConservation());
601     assertEquals(sp.getTitle(), MessageManager.formatMessage(
602             "label.conservation_colour_increment",
603             new String[] { "Background" }));
604
605     /*
606      * make a new View, verify alignment and group colour schemes
607      */
608     af.newView_actionPerformed(null);
609     assertEquals(af.alignPanel.getViewName(), "View 1");
610     AlignViewport av2 = af.getViewport();
611     assertNotSame(av, av2);
612     assertSame(av2, af.alignPanel.av);
613     rs = av2.getResidueShading();
614     assertNotSame(av.getResidueShading(), rs);
615     assertEquals(rs.getThreshold(), 10);
616     assertTrue(rs.conservationApplied(), rs.toString());
617     assertEquals(rs.getConservationInc(), 20);
618     assertEquals(av2.getAlignment().getGroups().size(), 1);
619     sg = av2.getAlignment().getGroups().get(0);
620     rs = sg.getGroupColourScheme();
621     assertTrue(rs.conservationApplied());
622     assertEquals(rs.getConservationInc(), 30);
623     assertEquals(rs.getThreshold(), 40);
624
625     /*
626      * check the Conservation SliderPanel (still open) is linked to 
627      * and updates the new view (JAL-2385)
628      */
629     sp = SliderPanel.getSliderPanel();
630     assertTrue(sp.isForConservation());
631     assertEquals(sp.getTitle(), MessageManager.formatMessage(
632             "label.conservation_colour_increment",
633             new String[] { "View 1" }));
634     sp.valueChanged(22);
635     assertEquals(av2.getResidueShading().getConservationInc(), 22);
636   }
637
638   /**
639    * Verify that making a New View preserves the dataset reference for the
640    * alignment. Otherwise, see a 'duplicate jar entry' reference when trying to
641    * save alignments with multiple views, and codon mappings will not be shared
642    * across all panels in a split frame.
643    * 
644    * @see Jalview2xmlTests#testStoreAndRecoverColourThresholds()
645    */
646   @Test(groups = "Functional")
647   public void testNewView_dsRefPreserved()
648   {
649     AlignViewport av = af.getViewport();
650     AlignmentI al = av.getAlignment();
651     AlignmentI original_ds = al.getDataset();
652     af.newView_actionPerformed(null);
653     assertNotEquals("New view didn't select the a new panel", av,
654             af.getViewport());
655     org.testng.Assert.assertEquals(original_ds,
656             af.getViewport().getAlignment().getDataset(),
657             "Dataset was not preserved in new view");
658   }
659 }