Clover icon

Coverage Report

  1. Project Clover database Mon Jan 6 2025 10:27:51 GMT
  2. Package jalview.project

File Jalview2xmlTests.java

 

Code metrics

80
861
33
1
1,918
1,444
100
0.12
26.09
33
3.03

Classes

Class Line # Actions
Jalview2xmlTests 119 861 100
0.919917992%
 

Contributing tests

This file is covered by 25 tests. .

Source view

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.project;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.Assert.assertFalse;
25    import static org.testng.Assert.assertNotNull;
26    import static org.testng.Assert.assertNotSame;
27    import static org.testng.Assert.assertNull;
28    import static org.testng.Assert.assertSame;
29    import static org.testng.Assert.assertTrue;
30   
31    import java.awt.Color;
32    import java.awt.Dimension;
33    import java.awt.Rectangle;
34    import java.io.File;
35    import java.io.IOException;
36    import java.util.ArrayList;
37    import java.util.BitSet;
38    import java.util.HashMap;
39    import java.util.List;
40    import java.util.Locale;
41    import java.util.Map;
42   
43    import javax.swing.JInternalFrame;
44   
45    import org.testng.Assert;
46    import org.testng.AssertJUnit;
47    import org.testng.annotations.BeforeClass;
48    import org.testng.annotations.Test;
49   
50    import jalview.analysis.AlignmentUtils;
51    import jalview.analysis.scoremodels.SimilarityParams;
52    import jalview.api.AlignViewportI;
53    import jalview.api.AlignmentViewPanel;
54    import jalview.api.FeatureColourI;
55    import jalview.api.ViewStyleI;
56    import jalview.api.structures.JalviewStructureDisplayI;
57    import jalview.bin.Cache;
58    import jalview.bin.Jalview;
59    import jalview.datamodel.AlignmentAnnotation;
60    import jalview.datamodel.AlignmentI;
61    import jalview.datamodel.Annotation;
62    import jalview.datamodel.ContactListI;
63    import jalview.datamodel.ContactMatrix;
64    import jalview.datamodel.ContactMatrixI;
65    import jalview.datamodel.DBRefEntry;
66    import jalview.datamodel.GeneLocus;
67    import jalview.datamodel.GroupSet;
68    import jalview.datamodel.HiddenSequences;
69    import jalview.datamodel.Mapping;
70    import jalview.datamodel.PDBEntry;
71    import jalview.datamodel.PDBEntry.Type;
72    import jalview.datamodel.Sequence;
73    import jalview.datamodel.Sequence.DBModList;
74    import jalview.datamodel.SequenceCollectionI;
75    import jalview.datamodel.SequenceFeature;
76    import jalview.datamodel.SequenceGroup;
77    import jalview.datamodel.SequenceI;
78    import jalview.datamodel.features.FeatureMatcher;
79    import jalview.datamodel.features.FeatureMatcherSet;
80    import jalview.datamodel.features.FeatureMatcherSetI;
81    import jalview.gui.AlignFrame;
82    import jalview.gui.AlignViewport;
83    import jalview.gui.AlignmentPanel;
84    import jalview.gui.AppJmol;
85    import jalview.gui.Desktop;
86    import jalview.gui.JvOptionPane;
87    import jalview.gui.OverviewPanel;
88    import jalview.gui.PCAPanel;
89    import jalview.gui.PopupMenu;
90    import jalview.gui.Preferences;
91    import jalview.gui.SliderPanel;
92    import jalview.gui.StructureChooser;
93    import jalview.gui.StructureViewer;
94    import jalview.gui.StructureViewer.ViewerType;
95    import jalview.io.DataSourceType;
96    import jalview.io.FileFormat;
97    import jalview.io.FileLoader;
98    import jalview.io.Jalview2xmlBase;
99    import jalview.renderer.ResidueShaderI;
100    import jalview.schemes.AnnotationColourGradient;
101    import jalview.schemes.BuriedColourScheme;
102    import jalview.schemes.ColourSchemeI;
103    import jalview.schemes.ColourSchemeProperty;
104    import jalview.schemes.FeatureColour;
105    import jalview.schemes.JalviewColourScheme;
106    import jalview.schemes.RNAHelicesColour;
107    import jalview.schemes.StrandColourScheme;
108    import jalview.schemes.TCoffeeColourScheme;
109    import jalview.structure.StructureImportSettings;
110    import jalview.structure.StructureSelectionManager;
111    import jalview.util.MapList;
112    import jalview.util.matcher.Condition;
113    import jalview.viewmodel.AlignmentViewport;
114    import jalview.viewmodel.seqfeatures.FeatureRendererModel;
115    import jalview.ws.datamodel.MappableContactMatrixI;
116    import jalview.ws.datamodel.alphafold.PAEContactMatrix;
117   
118    @Test(singleThreaded = true)
 
119    public class Jalview2xmlTests extends Jalview2xmlBase
120    {
121   
 
122  1 toggle @Override
123    @BeforeClass(alwaysRun = true)
124    public void setUpJvOptionPane()
125    {
126  1 if (Desktop.instance != null)
127  1 Desktop.instance.closeAll_actionPerformed(null);
128  1 JvOptionPane.setInteractiveMode(false);
129  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
130    }
131   
 
132  1 toggle @Test(groups = { "Functional" })
133    public void testRNAStructureRecovery() throws Exception
134    {
135  1 String inFile = "examples/RF00031_folded.stk";
136  1 String tfile = File.createTempFile("JalviewTest", ".jvp")
137    .getAbsolutePath();
138  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
139    DataSourceType.FILE);
140  1 assertNotNull(af, "Didn't read input file " + inFile);
141  1 int olddsann = countDsAnn(af.getViewport());
142  1 assertTrue(olddsann > 0, "Didn't find any dataset annotations");
143  1 af.changeColour_actionPerformed(
144    JalviewColourScheme.RNAHelices.toString());
145  1 assertTrue(
146    af.getViewport()
147    .getGlobalColourScheme() instanceof RNAHelicesColour,
148    "Couldn't apply RNA helices colourscheme");
149  1 af.saveAlignment(tfile, FileFormat.Jalview);
150  1 assertTrue(af.isSaveAlignmentSuccessful(),
151    "Failed to store as a project.");
152  1 af.closeMenuItem_actionPerformed(true);
153  1 af = null;
154  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
155    DataSourceType.FILE);
156  1 assertNotNull(af, "Failed to import new project");
157  1 int newdsann = countDsAnn(af.getViewport());
158  1 assertEquals(olddsann, newdsann,
159    "Differing numbers of dataset sequence annotation\nOriginally "
160    + olddsann + " and now " + newdsann);
161  1 System.out.println(
162    "Read in same number of annotations as originally present ("
163    + olddsann + ")");
164  1 assertTrue(
165   
166    af.getViewport()
167    .getGlobalColourScheme() instanceof RNAHelicesColour,
168    "RNA helices colourscheme was not applied on import.");
169    }
170   
 
171  1 toggle @Test(groups = { "Functional" })
172    public void testTCoffeeScores() throws Exception
173    {
174  1 String inFile = "examples/uniref50.fa",
175    inAnnot = "examples/uniref50.score_ascii";
176  1 String tfile = File.createTempFile("JalviewTest", ".jvp")
177    .getAbsolutePath();
178  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
179    DataSourceType.FILE);
180  1 assertNotNull(af, "Didn't read input file " + inFile);
181  1 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
182  1 AlignViewport viewport = af.getViewport();
183  1 assertSame(viewport.getGlobalColourScheme().getClass(),
184    TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
185  1 assertNotNull(
186    ColourSchemeProperty.getColourScheme(viewport,
187    viewport.getAlignment(),
188    viewport.getGlobalColourScheme().getSchemeName()),
189    "Recognise T-Coffee score from string");
190   
191  1 af.saveAlignment(tfile, FileFormat.Jalview);
192  1 assertTrue(af.isSaveAlignmentSuccessful(),
193    "Failed to store as a project.");
194  1 af.closeMenuItem_actionPerformed(true);
195  1 af = null;
196  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
197    DataSourceType.FILE);
198  1 assertNotNull(af, "Failed to import new project");
199  1 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
200    TCoffeeColourScheme.class,
201    "Didn't set T-coffee colourscheme for imported project.");
202  1 System.out.println(
203    "T-Coffee score shading successfully recovered from project.");
204    }
205   
 
206  1 toggle @Test(groups = { "Functional" })
207    public void testColourByAnnotScores() throws Exception
208    {
209  1 String inFile = "examples/uniref50.fa",
210    inAnnot = "examples/testdata/uniref50_iupred.jva";
211  1 String tfile = File.createTempFile("JalviewTest", ".jvp")
212    .getAbsolutePath();
213  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
214    DataSourceType.FILE);
215  1 assertNotNull(af, "Didn't read input file " + inFile);
216  1 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
217  1 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
218    .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
219  1 assertTrue(
220   
221    aa != null && aa.length > 0,
222    "Didn't find any IUPred annotation to use to shade alignment.");
223  1 AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
224    AnnotationColourGradient.ABOVE_THRESHOLD);
225  1 AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0], null,
226    AnnotationColourGradient.BELOW_THRESHOLD);
227  1 cs.setSeqAssociated(true);
228  1 gcs.setSeqAssociated(true);
229  1 af.changeColour(cs);
230  1 SequenceGroup sg = new SequenceGroup();
231  1 sg.setStartRes(57);
232  1 sg.setEndRes(92);
233  1 sg.cs.setColourScheme(gcs);
234  1 af.getViewport().getAlignment().addGroup(sg);
235  1 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
236  1 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
237  1 af.alignPanel.alignmentChanged();
238  1 af.saveAlignment(tfile, FileFormat.Jalview);
239  1 assertTrue(af.isSaveAlignmentSuccessful(),
240    "Failed to store as a project.");
241  1 af.closeMenuItem_actionPerformed(true);
242  1 af = null;
243  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
244    DataSourceType.FILE);
245  1 assertNotNull(af, "Failed to import new project");
246   
247    // check for group and alignment colourschemes
248   
249  1 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
250  1 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups().get(0)
251    .getColourScheme();
252  1 assertNotNull(_rcs, "Didn't recover global colourscheme");
253  1 assertTrue(_rcs instanceof AnnotationColourGradient,
254    "Didn't recover annotation colour global scheme");
255  1 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
256  1 assertTrue(__rcs.isSeqAssociated(),
257    "Annotation colourscheme wasn't sequence associated");
258   
259  1 boolean diffseqcols = false, diffgseqcols = false;
260  1 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
261  1 for (int p = 0, pSize = af.getViewport().getAlignment()
262  158 .getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++)
263    {
264  157 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
265    .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
266    {
267  20 diffseqcols = true;
268    }
269    }
270  1 assertTrue(diffseqcols, "Got Different sequence colours");
271  1 System.out.println(
272    "Per sequence colourscheme (Background) successfully applied and recovered.");
273   
274  1 assertNotNull(_rgcs, "Didn't recover group colourscheme");
275  1 assertTrue(_rgcs instanceof AnnotationColourGradient,
276    "Didn't recover annotation colour group colourscheme");
277  1 __rcs = (AnnotationColourGradient) _rgcs;
278  1 assertTrue(__rcs.isSeqAssociated(),
279    "Group Annotation colourscheme wasn't sequence associated");
280   
281  1 for (int p = 0, pSize = af.getViewport().getAlignment()
282  14 .getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++)
283    {
284  13 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null,
285    0f) != _rgcs.findColour(sqs[2].getCharAt(p), p, sqs[2], null,
286    0f))
287    {
288  1 diffgseqcols = true;
289    }
290    }
291  1 assertTrue(diffgseqcols, "Got Different group sequence colours");
292  1 System.out.println(
293    "Per sequence (Group) colourscheme successfully applied and recovered.");
294    }
295   
 
296  1 toggle @Test(groups = { "Functional" })
297    public void gatherViewsHere() throws Exception
298    {
299  1 int origCount = Desktop.getDesktopAlignFrames() == null ? 0
300    : Desktop.getDesktopAlignFrames().length;
301  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
302    "examples/exampleFile_2_7.jar", DataSourceType.FILE);
303  1 assertNotNull(af, "Didn't read in the example file correctly.");
304  1 assertTrue(Desktop.getDesktopAlignFrames().length == 1 + origCount,
305    "Didn't gather the views in the example file.");
306   
307    }
308   
309    /**
310    * Test for JAL-2223 - multiple mappings in View Mapping report
311    *
312    * @throws Exception
313    */
 
314  1 toggle @Test(groups = { "Functional" })
315    public void noDuplicatePdbMappingsMade() throws Exception
316    {
317  1 StructureImportSettings.setProcessSecondaryStructure(true);
318  1 StructureImportSettings.setVisibleChainAnnotation(true);
319  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
320    "examples/exampleFile_2_7.jar", DataSourceType.FILE);
321  1 assertNotNull(af, "Didn't read in the example file correctly.");
322   
323    // locate Jmol viewer
324    // count number of PDB mappings the structure selection manager holds -
325  1 String pdbFile = af.getCurrentView().getStructureSelectionManager()
326    .findFileForPDBId("1A70");
327  1 assertEquals(
328    af.getCurrentView().getStructureSelectionManager()
329    .getMapping(pdbFile).length,
330    2, "Expected only two mappings for 1A70");
331   
332    }
333   
 
334  1 toggle @Test(groups = { "Functional" })
335    public void viewRefPdbAnnotation() throws Exception
336    {
337  1 StructureImportSettings.setProcessSecondaryStructure(true);
338  1 StructureImportSettings.setVisibleChainAnnotation(true);
339  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
340    "examples/exampleFile_2_7.jar", DataSourceType.FILE);
341  1 assertNotNull(af, "Didn't read in the example file correctly.");
342  1 AlignmentViewPanel sps = null;
343  1 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
344    {
345  5 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
346    {
347  1 sps = ap;
348  1 break;
349    }
350    }
351  1 assertNotNull(sps, "Couldn't find the structure view");
352  1 AlignmentAnnotation refan = null;
353  1 for (AlignmentAnnotation ra : sps.getAlignment()
354    .getAlignmentAnnotation())
355    {
356  1 if (ra.graph != 0)
357    {
358  1 refan = ra;
359  1 break;
360    }
361    }
362  1 assertNotNull(refan, "Annotation secondary structure not found.");
363  1 SequenceI sq = sps.getAlignment().findName("1A70|");
364  1 assertNotNull(sq, "Couldn't find 1a70 null chain");
365    // compare the manually added temperature factor annotation
366    // to the track automatically transferred from the pdb structure on load
367  1 assertNotNull(sq.getDatasetSequence().getAnnotation(),
368    "1a70 has no annotation");
369  1 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
370    {
371  2 AlignmentAnnotation alaa;
372  2 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
373  2 alaa.adjustForAlignment();
374  2 if (ala.graph == refan.graph)
375    {
376  98 for (int p = 0; p < ala.annotations.length; p++)
377    {
378  97 sq.findPosition(p);
379  97 try
380    {
381  97 assertTrue((alaa.annotations[p] == null
382    && refan.annotations[p] == null)
383    || alaa.annotations[p].value == refan.annotations[p].value,
384    "Mismatch at alignment position " + p);
385    } catch (NullPointerException q)
386    {
387  0 Assert.fail("Mismatch of alignment annotations at position " + p
388    + " Ref seq ann: " + refan.annotations[p]
389    + " alignment " + alaa.annotations[p]);
390    }
391    }
392    }
393    }
394   
395    }
396   
 
397  1 toggle @Test(groups = { "Functional" })
398    public void testCopyViewSettings() throws Exception
399    {
400  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
401    "examples/exampleFile_2_7.jar", DataSourceType.FILE);
402  1 assertNotNull(af, "Didn't read in the example file correctly.");
403  1 AlignmentViewPanel sps = null, groups = null;
404  1 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
405    {
406  5 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
407    {
408  1 sps = ap;
409    }
410  5 if (ap.getViewName().contains("MAFFT"))
411    {
412  1 groups = ap;
413    }
414    }
415  1 assertNotNull(sps, "Couldn't find the structure view");
416  1 assertNotNull(groups, "Couldn't find the MAFFT view");
417   
418  1 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
419  1 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
420  1 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
421   
422  1 groups.getAlignViewport().setViewStyle(structureStyle);
423  1 AssertJUnit.assertFalse(
424    groupStyle.sameStyle(groups.getAlignViewport().getViewStyle()));
425  1 Assert.assertTrue(structureStyle
426    .sameStyle(groups.getAlignViewport().getViewStyle()));
427   
428    }
429   
430    /**
431    * test store and recovery of expanded views
432    *
433    * @throws Exception
434    */
 
435  1 toggle @Test(groups = { "Functional" }, enabled = true)
436    public void testStoreAndRecoverExpandedviews() throws Exception
437    {
438  1 Desktop.instance.closeAll_actionPerformed(null);
439   
440  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
441    "examples/exampleFile_2_7.jar", DataSourceType.FILE);
442  1 Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 1);
443  1 String afid = af.getViewport().getSequenceSetId();
444   
445    // check FileLoader returned a reference to the one alignFrame that is
446    // actually on the Desktop
447  1 assertSame(af, Desktop.getAlignFrameFor(af.getViewport()),
448    "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
449   
450  1 Desktop.explodeViews(af);
451   
452  1 int oldviews = Desktop.getDesktopAlignFrames().length;
453  1 Assert.assertEquals(Desktop.getDesktopAlignFrames().length,
454    Desktop.getAlignmentPanels(afid).length);
455  1 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
456  1 try
457    {
458  1 new Jalview2XML(false).saveState(tfile);
459    } catch (Error e)
460    {
461  0 Assert.fail("Didn't save the expanded view state", e);
462    } catch (Exception e)
463    {
464  0 Assert.fail("Didn't save the expanded view state", e);
465    }
466  1 Desktop.instance.closeAll_actionPerformed(null);
467  1 if (Desktop.getDesktopAlignFrames() != null)
468    {
469  0 Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
470    }
471  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
472    DataSourceType.FILE);
473  1 Assert.assertNotNull(af);
474  1 Assert.assertEquals(Desktop.getDesktopAlignFrames().length,
475    Desktop.getAlignmentPanels(
476    af.getViewport().getSequenceSetId()).length);
477  1 Assert.assertEquals(Desktop
478    .getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
479    oldviews);
480    }
481   
482    /**
483    * Test save and reload of a project with a different representative sequence
484    * in each view.
485    *
486    * @throws Exception
487    */
 
488  1 toggle @Test(groups = { "Functional" })
489    public void testStoreAndRecoverReferenceSeqSettings() throws Exception
490    {
491  1 Desktop.instance.closeAll_actionPerformed(null);
492  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
493    "examples/exampleFile_2_7.jar", DataSourceType.FILE);
494  1 assertNotNull(af, "Didn't read in the example file correctly.");
495  1 String afid = af.getViewport().getSequenceSetId();
496   
497    // remember reference sequence for each panel
498  1 Map<String, SequenceI> refseqs = new HashMap<>();
499   
500    /*
501    * mark sequence 2, 3, 4.. in panels 1, 2, 3...
502    * as reference sequence for itself and the preceding sequence
503    */
504  1 int n = 1;
505  1 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
506    {
507  5 AlignViewportI av = ap.getAlignViewport();
508  5 AlignmentI alignment = ap.getAlignment();
509  5 int repIndex = n % alignment.getHeight();
510  5 SequenceI rep = alignment.getSequenceAt(repIndex);
511  5 refseqs.put(ap.getViewName(), rep);
512   
513    // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
514    // todo refactor this to an alignment view controller
515  5 av.setDisplayReferenceSeq(true);
516  5 av.setColourByReferenceSeq(true);
517  5 av.getAlignment().setSeqrep(rep);
518   
519  5 n++;
520    }
521  1 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
522    ".jvp");
523  1 try
524    {
525  1 new Jalview2XML(false).saveState(tfile);
526    } catch (Throwable e)
527    {
528  0 Assert.fail("Didn't save the expanded view state", e);
529    }
530  1 Desktop.instance.closeAll_actionPerformed(null);
531  1 if (Desktop.getDesktopAlignFrames() != null)
532    {
533  0 Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
534    }
535   
536  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
537    DataSourceType.FILE);
538  1 afid = af.getViewport().getSequenceSetId();
539   
540  1 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
541    {
542    // check representative
543  5 AlignmentI alignment = ap.getAlignment();
544  5 SequenceI rep = alignment.getSeqrep();
545  5 Assert.assertNotNull(rep,
546    "Couldn't restore sequence representative from project");
547    // can't use a strong equals here, because by definition, the sequence IDs
548    // will be different.
549    // could set vamsas session save/restore flag to preserve IDs across
550    // load/saves.
551  5 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
552    rep.toString(),
553    "Representative wasn't the same when recovered.");
554  5 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
555    "Display reference sequence view setting not set.");
556  5 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
557    "Colour By Reference Seq view setting not set.");
558    }
559    }
560   
 
561  1 toggle @Test(groups = { "Functional" })
562    public void testIsVersionStringLaterThan()
563    {
564    /*
565    * No version / development / test / autobuild is leniently assumed to be
566    * compatible
567    */
568  1 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
569  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
570  1 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
571  1 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
572    "Development Build"));
573  1 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
574    "DEVELOPMENT BUILD"));
575  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
576    "Development Build"));
577  1 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
578  1 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
579  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
580  1 assertTrue(
581    Jalview2XML.isVersionStringLaterThan(null, "Automated Build"));
582  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
583    "Automated Build"));
584  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
585    "AUTOMATED BUILD"));
586   
587    /*
588    * same version returns true i.e. compatible
589    */
590  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
591  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
592  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
593  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
594  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
595   
596    /*
597    * later version returns true
598    */
599  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
600  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
601  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
602  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
603  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
604   
605    /*
606    * earlier version returns false
607    */
608  1 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
609  1 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
610  1 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
611  1 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
612  1 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
613    /*
614    * test for patch release versions
615    */
616  1 assertFalse(Jalview2XML.isVersionStringLaterThan("2.11.3.0", "2.11.2"));
617  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.11.3.0", "2.11.4"));
618  1 assertFalse(
619    Jalview2XML.isVersionStringLaterThan("2.12.2.0b1", "2.12.2.0"));
620  1 assertFalse(
621    Jalview2XML.isVersionStringLaterThan("2.12.2.3", "2.12.2.2"));
622   
623    }
624   
625    /**
626    * Test save and reload of a project with a different sequence group (and
627    * representative sequence) in each view.
628    *
629    * @throws Exception
630    */
 
631  1 toggle @Test(groups = { "Functional" })
632    public void testStoreAndRecoverGroupRepSeqs() throws Exception
633    {
634  1 Desktop.instance.closeAll_actionPerformed(null);
635  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
636    "examples/uniref50.fa", DataSourceType.FILE);
637  1 assertNotNull(af, "Didn't read in the example file correctly.");
638  1 String afid = af.getViewport().getSequenceSetId();
639    // make a second view of the alignment
640  1 af.newView_actionPerformed(null);
641   
642    /*
643    * remember representative and hidden sequences marked
644    * on each panel
645    */
646  1 Map<String, SequenceI> repSeqs = new HashMap<>();
647  1 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
648   
649    /*
650    * mark sequence 2, 3, 4.. in panels 1, 2, 3...
651    * as reference sequence for itself and the preceding sequence
652    */
653  1 int n = 1;
654  1 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
655    {
656  2 AlignViewportI av = ap.getAlignViewport();
657  2 AlignmentI alignment = ap.getAlignment();
658  2 int repIndex = n % alignment.getHeight();
659    // ensure at least one preceding sequence i.e. index >= 1
660  2 repIndex = Math.max(repIndex, 1);
661  2 SequenceI repSeq = alignment.getSequenceAt(repIndex);
662  2 repSeqs.put(ap.getViewName(), repSeq);
663  2 List<String> hiddenNames = new ArrayList<>();
664  2 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
665   
666    /*
667    * have rep sequence represent itself and the one before it
668    * this hides the group (except for the rep seq)
669    */
670  2 SequenceGroup sg = new SequenceGroup();
671  2 sg.addSequence(repSeq, false);
672  2 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
673  2 sg.addSequence(precedingSeq, false);
674  2 sg.setSeqrep(repSeq);
675  2 assertTrue(sg.getSequences().contains(repSeq));
676  2 assertTrue(sg.getSequences().contains(precedingSeq));
677  2 av.setSelectionGroup(sg);
678  2 assertSame(repSeq, sg.getSeqrep());
679   
680    /*
681    * represent group with sequence adds to a map of hidden rep sequences
682    * (it does not create a group on the alignment)
683    */
684  2 ((AlignmentViewport) av).hideSequences(repSeq, true);
685  2 assertSame(repSeq, sg.getSeqrep());
686  2 assertTrue(sg.getSequences().contains(repSeq));
687  2 assertTrue(sg.getSequences().contains(precedingSeq));
688  2 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
689  2 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
690    .getHiddenRepSequences();
691  2 assertNotNull(hiddenRepSeqsMap);
692  2 assertEquals(1, hiddenRepSeqsMap.size());
693  2 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
694  2 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
695  2 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
696  2 hiddenNames.add(precedingSeq.getName());
697   
698  2 n++;
699    }
700  1 File tfile = File.createTempFile("testStoreAndRecoverGroupReps",
701    ".jvp");
702  1 try
703    {
704  1 new Jalview2XML(false).saveState(tfile);
705    } catch (Throwable e)
706    {
707  0 Assert.fail("Didn't save the expanded view state", e);
708    }
709  1 Desktop.instance.closeAll_actionPerformed(null);
710  1 if (Desktop.getDesktopAlignFrames() != null)
711    {
712  0 Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
713    }
714   
715  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
716    DataSourceType.FILE);
717  1 afid = af.getViewport().getSequenceSetId();
718   
719  1 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
720    {
721  2 String viewName = ap.getViewName();
722  2 AlignViewportI av = ap.getAlignViewport();
723  2 AlignmentI alignment = ap.getAlignment();
724  2 List<SequenceGroup> groups = alignment.getGroups();
725  2 assertNotNull(groups);
726  2 assertTrue(groups.isEmpty(), "Alignment has groups");
727  2 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
728    .getHiddenRepSequences();
729  2 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
730  2 assertEquals(1, hiddenRepSeqsMap.size());
731  2 assertEquals(repSeqs.get(viewName).getDisplayId(true),
732    hiddenRepSeqsMap.keySet().iterator().next()
733    .getDisplayId(true));
734   
735    /*
736    * verify hidden sequences in restored panel
737    */
738  2 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
739  2 HiddenSequences hs = alignment.getHiddenSequences();
740  2 assertEquals(hidden.size(), hs.getSize(),
741    "wrong number of restored hidden sequences in "
742    + ap.getViewName());
743    }
744    }
745   
746    /**
747    * Test save and reload of PDBEntry in Jalview project
748    *
749    * @throws Exception
750    */
 
751  1 toggle @Test(groups = { "Functional" })
752    public void testStoreAndRecoverPDBEntry() throws Exception
753    {
754  1 Desktop.instance.closeAll_actionPerformed(null);
755  1 String exampleFile = "examples/3W5V.pdb";
756  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
757    DataSourceType.FILE);
758  1 assertNotNull(af, "Didn't read in the example file correctly.");
759  1 String afid = af.getViewport().getSequenceSetId();
760   
761  1 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
762  1 System.out.println();
763  1 AlignmentViewPanel ap = alignPanels[0];
764  1 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
765  1 String testFile = tfileBase + exampleFile;
766  1 AlignmentI alignment = ap.getAlignment();
767  1 System.out.println("blah");
768  1 SequenceI[] seqs = alignment.getSequencesArray();
769  1 Assert.assertNotNull(seqs[0]);
770  1 Assert.assertNotNull(seqs[1]);
771  1 Assert.assertNotNull(seqs[2]);
772  1 Assert.assertNotNull(seqs[3]);
773  1 Assert.assertNotNull(seqs[0].getDatasetSequence());
774  1 Assert.assertNotNull(seqs[1].getDatasetSequence());
775  1 Assert.assertNotNull(seqs[2].getDatasetSequence());
776  1 Assert.assertNotNull(seqs[3].getDatasetSequence());
777  1 PDBEntry[] pdbEntries = new PDBEntry[4];
778  1 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
779  1 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
780  1 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
781  1 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
782  1 Assert.assertEquals(
783    seqs[0].getDatasetSequence().getAllPDBEntries().get(0),
784    pdbEntries[0]);
785  1 Assert.assertEquals(
786    seqs[1].getDatasetSequence().getAllPDBEntries().get(0),
787    pdbEntries[1]);
788  1 Assert.assertEquals(
789    seqs[2].getDatasetSequence().getAllPDBEntries().get(0),
790    pdbEntries[2]);
791  1 Assert.assertEquals(
792    seqs[3].getDatasetSequence().getAllPDBEntries().get(0),
793    pdbEntries[3]);
794   
795  1 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
796  1 try
797    {
798  1 new Jalview2XML(false).saveState(tfile);
799    } catch (Throwable e)
800    {
801  0 Assert.fail("Didn't save the state", e);
802    }
803  1 Desktop.instance.closeAll_actionPerformed(null);
804  1 if (Desktop.getDesktopAlignFrames() != null)
805    {
806  0 Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
807    }
808   
809  1 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
810    tfile.getAbsolutePath(), DataSourceType.FILE);
811  1 String rfid = restoredFrame.getViewport().getSequenceSetId();
812  1 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
813  1 AlignmentViewPanel rap = rAlignPanels[0];
814  1 AlignmentI rAlignment = rap.getAlignment();
815  1 System.out.println("blah");
816  1 SequenceI[] rseqs = rAlignment.getSequencesArray();
817  1 Assert.assertNotNull(rseqs[0]);
818  1 Assert.assertNotNull(rseqs[1]);
819  1 Assert.assertNotNull(rseqs[2]);
820  1 Assert.assertNotNull(rseqs[3]);
821  1 Assert.assertNotNull(rseqs[0].getDatasetSequence());
822  1 Assert.assertNotNull(rseqs[1].getDatasetSequence());
823  1 Assert.assertNotNull(rseqs[2].getDatasetSequence());
824  1 Assert.assertNotNull(rseqs[3].getDatasetSequence());
825   
826    // The Asserts below are expected to fail until the PDB chainCode is
827    // recoverable from a Jalview projects
828  5 for (int chain = 0; chain < 4; chain++)
829    {
830  4 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
831    .get(0);
832  4 PDBEntry expected = pdbEntries[chain];
833  4 Assert.assertEquals(recov.getId(), expected.getId(),
834    "Mismatch PDB ID");
835  4 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
836    "Mismatch PDB ID");
837  4 Assert.assertEquals(recov.getType(), expected.getType(),
838    "Mismatch PDBEntry 'Type'");
839  4 Assert.assertNotNull(recov.getFile(),
840    "Recovered PDBEntry should have a non-null file entry");
841  4 Assert.assertEquals(
842    recov.getFile().toLowerCase(Locale.ENGLISH)
843    .lastIndexOf("pdb"),
844    recov.getFile().length() - 3,
845    "Recovered PDBEntry file should have PDB suffix");
846    }
847    }
848   
849    /**
850    * Test save and reload of Jmol view in Jalview project is restored to same location/etc
851    * Currently fails (2.11.4.2 onwards and 2.12)
852    *
853    * @throws Exception
854    */
 
855  0 toggle @Test(groups = { "Functional" },enabled=false)
856    public void testStoreAndRecoverStructView() throws Exception
857    {
858  0 Desktop.instance.closeAll_actionPerformed(null);
859  0 String exampleFile = "examples/3W5V.pdb";
860  0 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
861    DataSourceType.FILE);
862  0 assertNotNull(af, "Didn't read in the example file correctly.");
863  0 StructureViewer sv[]=new StructureViewer[] {null};
864  0 Thread t = new Thread(new Runnable() {
 
865  0 toggle @Override
866    public void run()
867    {
868  0 sv[0] = StructureChooser.openStructureFileForSequence(af.alignPanel.getStructureSelectionManager(), null, af.alignPanel,
869   
870    af.getViewport().getAlignment().getSequenceAt(0), false, exampleFile, null, null, false, false, false, ViewerType.JMOL);
871    }
872    });
873  0 t.start();
874  0 int n=1;
875  0 do
876    {
877  0 try {
878  0 Thread.sleep(50*n);
879  0 } catch (InterruptedException x) {};
880  0 } while (!(sv[0] != null && sv[0].getJalviewStructureDisplay() != null
881    && sv[0].getJalviewStructureDisplay().getWidth() > 0) && t.isAlive()
882    && n++ < 10);
883  0 Assert.assertNotNull(sv[0]);
884  0 ((AppJmol)sv[0].getJalviewStructureDisplay()).setLocation(65, 75);
885  0 int x=sv[0].getJalviewStructureDisplay().getX(),y=sv[0].getJalviewStructureDisplay().getY();
886    // shouldn't be square!
887  0 Assert.assertTrue(x!=y);
888   
889  0 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
890  0 try
891    {
892  0 new Jalview2XML(false).saveState(tfile);
893    } catch (Throwable e)
894    {
895  0 Assert.fail("Didn't save the state", e);
896    }
897  0 Desktop.instance.closeAll_actionPerformed(null);
898  0 if (Desktop.getDesktopAlignFrames() != null)
899    {
900  0 Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
901    }
902   
903  0 JalviewStructureDisplayI newDisplay=null;
904  0 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
905    tfile.getAbsolutePath(), DataSourceType.FILE);
906  0 for (JInternalFrame f:Desktop.getDesktop().getAllFrames()) {
907  0 if (f instanceof JalviewStructureDisplayI)
908    {
909  0 Assert.assertNull(newDisplay,"More than one structure viewer was created in test. Unexpected fail.");
910  0 newDisplay=(JalviewStructureDisplayI) f;
911    }
912    }
913    // wait around again
914  0 n=1;
915  0 do
916    {
917  0 try {
918  0 Thread.sleep(50*n);
919  0 } catch (InterruptedException iex) {};
920  0 } while (!(newDisplay.getWidth() > 0));
921   
922  0 Assert.assertEquals(restoredFrame.getX(),x);
923  0 Assert.assertEquals(restoredFrame.getY(),y);
924    }
925   
926    /**
927    * Configure an alignment and a sub-group each with distinct colour schemes,
928    * Conservation and PID thresholds, and confirm these are restored from the
929    * saved project.
930    *
931    * @throws IOException
932    */
 
933  1 toggle @Test(groups = { "Functional" })
934    public void testStoreAndRecoverAnnotationRowElementColours()
935    throws IOException
936    {
937  1 Desktop.instance.closeAll_actionPerformed(null);
938  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded("SEQ\tMNQ",
939    DataSourceType.PASTE);
940   
941  1 AlignViewport av = af.getViewport();
942  1 AlignmentI al = av.getAlignment();
943  1 SequenceI fsq;
944  1 fsq = al.getSequenceAt(0);
945  1 Annotation annots[] = new Annotation[fsq.getLength()];
946  1 AlignmentAnnotation ala = new AlignmentAnnotation("Colour", "Annots",
947    annots);
948  1 annots[0] = new Annotation(1.0f);
949  1 annots[1] = new Annotation(2.0f);
950  1 annots[2] = new Annotation(3.0f);
951  1 annots[0].colour = Color.RED;
952  1 annots[1].colour = Color.GREEN;
953  1 annots[2].colour = Color.BLUE;
954  1 ala.validateRangeAndDisplay();
955  1 al.getSequenceAt(0).addAlignmentAnnotation(ala);
956  1 al.addAnnotation(ala);
957    /*
958    * and colour by annotation
959    */
960  1 AnnotationColourGradient acg = new AnnotationColourGradient(ala,
961    af.alignPanel.av.getGlobalColourScheme(), 0);
962  1 acg.setSeqAssociated(true);
963  1 acg.setPredefinedColours(true);
964  1 af.changeColour(acg);
965  1 Color seqcol[] = new Color[3];
966  4 for (int iStart = fsq.findIndex(fsq.getStart()), i = 0; i < 3; i++)
967    {
968  3 seqcol[i] = af.alignPanel.getSeqPanel().seqCanvas
969    .getSequenceRenderer()
970    .getResidueColour(fsq, iStart + i, null);
971    }
972    /*
973    * save project, close windows, reload project, verify
974    */
975  1 File tfile = File.createTempFile(
976    "testStoreAndRecoverAnnotRowElemColors", ".jvp");
977  1 tfile.deleteOnExit();
978  1 new Jalview2XML(false).saveState(tfile);
979    // Desktop.instance.closeAll_actionPerformed(null);
980  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
981    DataSourceType.FILE);
982  1 Assert.assertNotNull(af, "Failed to reload project");
983    /*
984    * verify alignment annotation has colors
985    */
986  1 av = af.getViewport();
987   
988  1 ColourSchemeI loadedCscheme = av.getGlobalColourScheme();
989  1 Assert.assertTrue(loadedCscheme instanceof AnnotationColourGradient,
990    "Didn't apply Annotation colour gradient");
991  1 acg = (AnnotationColourGradient) loadedCscheme;
992  1 assertTrue(acg.isSeqAssociated());
993  1 assertTrue(acg.isPredefinedColours());
994   
995  1 al = av.getAlignment();
996  1 fsq = al.getSequenceAt(0);
997  1 ala = fsq.getAnnotation()[0];
998  1 Assert.assertNotNull(ala, "No annotation row recovered");
999  1 Assert.assertNotNull(ala.annotations);
1000  1 for (int iStart = al.getSequenceAt(0)
1001  4 .findIndex(al.getSequenceAt(0).getStart()), i = 0; i < 3; i++)
1002    {
1003  3 Assert.assertTrue(ala.annotations[i].colour != null);
1004  3 Assert.assertTrue(ala.annotations[i].colour.equals(annots[i].colour));
1005  3 Color newseqcol = af.alignPanel.getSeqPanel().seqCanvas
1006    .getSequenceRenderer()
1007    .getResidueColour(fsq, iStart + i, null);
1008  3 Assert.assertTrue(seqcol[i].equals(newseqcol),
1009    "Sequence shading is different");
1010   
1011    }
1012   
1013    }
1014   
1015    /**
1016    * Configure an alignment and a sub-group each with distinct colour schemes,
1017    * Conservation and PID thresholds, and confirm these are restored from the
1018    * saved project.
1019    *
1020    * @throws IOException
1021    */
 
1022  1 toggle @Test(groups = { "Functional" })
1023    public void testStoreAndRecoverColourThresholds() throws IOException
1024    {
1025  1 Desktop.instance.closeAll_actionPerformed(null);
1026  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1027    "examples/uniref50.fa", DataSourceType.FILE);
1028   
1029  1 AlignViewport av = af.getViewport();
1030  1 AlignmentI al = av.getAlignment();
1031   
1032    /*
1033    * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
1034    */
1035  1 av.setColourAppliesToAllGroups(false);
1036  1 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
1037  1 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
1038  1 af.abovePIDThreshold_actionPerformed(true);
1039  1 SliderPanel sp = SliderPanel.getSliderPanel();
1040  1 assertFalse(sp.isForConservation());
1041  1 sp.valueChanged(10);
1042  1 af.conservationMenuItem_actionPerformed(true);
1043  1 sp = SliderPanel.getSliderPanel();
1044  1 assertTrue(sp.isForConservation());
1045  1 sp.valueChanged(20);
1046  1 ResidueShaderI rs = av.getResidueShading();
1047  1 assertEquals(rs.getThreshold(), 10);
1048  1 assertTrue(rs.conservationApplied());
1049  1 assertEquals(rs.getConservationInc(), 20);
1050   
1051    /*
1052    * create a group with Strand colouring, 30% Conservation
1053    * and 40% PID threshold
1054    * (notice menu action applies to selection group even if mouse click
1055    * is at a sequence not in the group)
1056    */
1057  1 SequenceGroup sg = new SequenceGroup();
1058  1 sg.addSequence(al.getSequenceAt(0), false);
1059  1 sg.setStartRes(15);
1060  1 sg.setEndRes(25);
1061  1 av.setSelectionGroup(sg);
1062  1 PopupMenu popupMenu = new PopupMenu(af.alignPanel, al.getSequenceAt(2),
1063    null);
1064  1 popupMenu.changeColour_actionPerformed(
1065    JalviewColourScheme.Strand.toString());
1066  1 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
1067  1 assertEquals(al.getGroups().size(), 1);
1068  1 assertSame(al.getGroups().get(0), sg);
1069  1 popupMenu.conservationMenuItem_actionPerformed(true);
1070  1 sp = SliderPanel.getSliderPanel();
1071  1 assertTrue(sp.isForConservation());
1072  1 sp.valueChanged(30);
1073  1 popupMenu.abovePIDColour_actionPerformed(true);
1074  1 sp = SliderPanel.getSliderPanel();
1075  1 assertFalse(sp.isForConservation());
1076  1 sp.valueChanged(40);
1077  1 assertTrue(sg.getGroupColourScheme().conservationApplied());
1078  1 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
1079  1 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
1080   
1081    /*
1082    * save project, close windows, reload project, verify
1083    */
1084  1 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
1085    ".jvp");
1086  1 tfile.deleteOnExit();
1087  1 new Jalview2XML(false).saveState(tfile);
1088  1 Desktop.instance.closeAll_actionPerformed(null);
1089  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1090    DataSourceType.FILE);
1091  1 Assert.assertNotNull(af, "Failed to reload project");
1092   
1093    /*
1094    * verify alignment (background) colouring
1095    */
1096  1 rs = af.getViewport().getResidueShading();
1097  1 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
1098  1 assertEquals(rs.getThreshold(), 10);
1099  1 assertTrue(rs.conservationApplied());
1100  1 assertEquals(rs.getConservationInc(), 20);
1101   
1102    /*
1103    * verify group colouring
1104    */
1105  1 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
1106  1 rs = af.getViewport().getAlignment().getGroups().get(0)
1107    .getGroupColourScheme();
1108  1 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
1109  1 assertEquals(rs.getThreshold(), 40);
1110  1 assertTrue(rs.conservationApplied());
1111  1 assertEquals(rs.getConservationInc(), 30);
1112    }
1113   
1114    /**
1115    * Test save and reload of feature colour schemes and filter settings
1116    *
1117    * @throws IOException
1118    */
 
1119  1 toggle @Test(groups = { "Functional" })
1120    public void testSaveLoadFeatureColoursAndFilters() throws IOException
1121    {
1122  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1123    ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
1124  1 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
1125   
1126    /*
1127    * add some features to the sequence
1128    */
1129  1 int score = 1;
1130  1 addFeatures(seq1, "type1", score++);
1131  1 addFeatures(seq1, "type2", score++);
1132  1 addFeatures(seq1, "type3", score++);
1133  1 addFeatures(seq1, "type4", score++);
1134  1 addFeatures(seq1, "type5", score++);
1135   
1136    /*
1137    * set colour schemes for features
1138    */
1139  1 FeatureRendererModel fr = af.getFeatureRenderer();
1140  1 fr.findAllFeatures(true);
1141   
1142    // type1: red
1143  1 fr.setColour("type1", new FeatureColour(Color.red));
1144   
1145    // type2: by label
1146  1 FeatureColourI byLabel = new FeatureColour();
1147  1 byLabel.setColourByLabel(true);
1148  1 fr.setColour("type2", byLabel);
1149   
1150    // type3: by score above threshold
1151  1 FeatureColourI byScore = new FeatureColour(null, Color.BLACK,
1152    Color.BLUE, null, 1, 10);
1153  1 byScore.setAboveThreshold(true);
1154  1 byScore.setThreshold(2f);
1155  1 fr.setColour("type3", byScore);
1156   
1157    // type4: by attribute AF
1158  1 FeatureColourI byAF = new FeatureColour();
1159  1 byAF.setColourByLabel(true);
1160  1 byAF.setAttributeName("AF");
1161  1 fr.setColour("type4", byAF);
1162   
1163    // type5: by attribute CSQ:PolyPhen below threshold
1164  1 FeatureColourI byPolyPhen = new FeatureColour(null, Color.BLACK,
1165    Color.BLUE, null, 1, 10);
1166  1 byPolyPhen.setBelowThreshold(true);
1167  1 byPolyPhen.setThreshold(3f);
1168  1 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
1169  1 fr.setColour("type5", byPolyPhen);
1170   
1171    /*
1172    * set filters for feature types
1173    */
1174   
1175    // filter type1 features by (label contains "x")
1176  1 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
1177  1 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
1178  1 fr.setFeatureFilter("type1", filterByX);
1179   
1180    // filter type2 features by (score <= 2.4 and score > 1.1)
1181  1 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
1182  1 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
1183  1 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
1184  1 fr.setFeatureFilter("type2", filterByScore);
1185   
1186    // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
1187  1 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
1188  1 filterByXY
1189    .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
1190  1 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
1191    "PolyPhen"));
1192  1 fr.setFeatureFilter("type3", filterByXY);
1193   
1194    /*
1195    * save as Jalview project
1196    */
1197  1 File tfile = File.createTempFile("JalviewTest", ".jvp");
1198  1 tfile.deleteOnExit();
1199  1 String filePath = tfile.getAbsolutePath();
1200  1 af.saveAlignment(filePath, FileFormat.Jalview);
1201  1 assertTrue(af.isSaveAlignmentSuccessful(),
1202    "Failed to store as a project.");
1203   
1204    /*
1205    * close current alignment and load the saved project
1206    */
1207  1 af.closeMenuItem_actionPerformed(true);
1208  1 af = null;
1209  1 af = new FileLoader().LoadFileWaitTillLoaded(filePath,
1210    DataSourceType.FILE);
1211  1 assertNotNull(af, "Failed to import new project");
1212   
1213    /*
1214    * verify restored feature colour schemes and filters
1215    */
1216  1 fr = af.getFeatureRenderer();
1217  1 FeatureColourI fc = fr.getFeatureStyle("type1");
1218  1 assertTrue(fc.isSimpleColour());
1219  1 assertEquals(fc.getColour(), Color.red);
1220  1 fc = fr.getFeatureStyle("type2");
1221  1 assertTrue(fc.isColourByLabel());
1222  1 fc = fr.getFeatureStyle("type3");
1223  1 assertTrue(fc.isGraduatedColour());
1224  1 assertNull(fc.getAttributeName());
1225  1 assertTrue(fc.isAboveThreshold());
1226  1 assertEquals(fc.getThreshold(), 2f);
1227  1 fc = fr.getFeatureStyle("type4");
1228  1 assertTrue(fc.isColourByLabel());
1229  1 assertTrue(fc.isColourByAttribute());
1230  1 assertEquals(fc.getAttributeName(), new String[] { "AF" });
1231  1 fc = fr.getFeatureStyle("type5");
1232  1 assertTrue(fc.isGraduatedColour());
1233  1 assertTrue(fc.isColourByAttribute());
1234  1 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
1235  1 assertTrue(fc.isBelowThreshold());
1236  1 assertEquals(fc.getThreshold(), 3f);
1237   
1238  1 assertEquals(fr.getFeatureFilter("type1").toStableString(),
1239    "Label Contains x");
1240  1 assertEquals(fr.getFeatureFilter("type2").toStableString(),
1241    "(Score LE 2.4) AND (Score GT 1.1)");
1242  1 assertEquals(fr.getFeatureFilter("type3").toStableString(),
1243    "(AF Contains X) OR (CSQ:PolyPhen NE 0)");
1244    }
1245   
 
1246  10 toggle private void addFeature(SequenceI seq, String featureType, int score)
1247    {
1248  10 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
1249    score, "grp");
1250  10 sf.setValue("AF", score);
1251  10 sf.setValue("CSQ", new HashMap<String, String>()
1252    {
 
1253  10 toggle {
1254  10 put("PolyPhen", Integer.toString(score));
1255    }
1256    });
1257  10 seq.addSequenceFeature(sf);
1258    }
1259   
1260    /**
1261    * Adds two features of the given type to the given sequence, also setting the
1262    * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1263    *
1264    * @param seq
1265    * @param featureType
1266    * @param score
1267    */
 
1268  5 toggle private void addFeatures(SequenceI seq, String featureType, int score)
1269    {
1270  5 addFeature(seq, featureType, score++);
1271  5 addFeature(seq, featureType, score);
1272    }
1273   
1274    /**
1275    * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
1276    * view (JAL-3171) this test ensures we can import and merge those views
1277    */
 
1278  1 toggle @Test(groups = { "Functional" })
1279    public void testMergeDatasetsforViews() throws IOException
1280    {
1281    // simple project - two views on one alignment
1282  1 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
1283    "examples/testdata/projects/twoViews.jvp", DataSourceType.FILE);
1284  1 assertNotNull(af);
1285  1 assertTrue(af.getAlignPanels().size() > 1);
1286  1 verifyDs(af);
1287    }
1288   
1289    /**
1290    * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
1291    * view (JAL-3171) this test ensures we can import and merge those views This
1292    * is a more complex project
1293    */
 
1294  1 toggle @Test(groups = { "Functional" })
1295    public void testMergeDatasetsforManyViews() throws IOException
1296    {
1297  1 Desktop.instance.closeAll_actionPerformed(null);
1298   
1299    // complex project - one dataset, several views on several alignments
1300  1 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
1301    "examples/testdata/projects/manyViews.jvp",
1302    DataSourceType.FILE);
1303  1 assertNotNull(af);
1304   
1305  1 AlignmentI ds = null;
1306  1 for (AlignFrame alignFrame : Desktop.getDesktopAlignFrames())
1307    {
1308  3 if (ds == null)
1309    {
1310  1 ds = verifyDs(alignFrame);
1311    }
1312    else
1313    {
1314    // check that this frame's dataset matches the last
1315  2 assertTrue(ds == verifyDs(alignFrame));
1316    }
1317    }
1318    }
1319   
 
1320  4 toggle private AlignmentI verifyDs(AlignFrame af)
1321    {
1322  4 AlignmentI ds = null;
1323  4 for (AlignmentViewPanel ap : af.getAlignPanels())
1324    {
1325  10 if (ds == null)
1326    {
1327  4 ds = ap.getAlignment().getDataset();
1328    }
1329    else
1330    {
1331  6 assertTrue(ap.getAlignment().getDataset() == ds,
1332    "Dataset was not the same for imported 2.10.5 project with several alignment views");
1333    }
1334    }
1335  4 return ds;
1336    }
1337   
 
1338  1 toggle @Test(groups = "Functional")
1339    public void testPcaViewAssociation() throws IOException
1340    {
1341  1 Desktop.instance.closeAll_actionPerformed(null);
1342  1 final String PCAVIEWNAME = "With PCA";
1343    // create a new tempfile
1344  1 File tempfile = File.createTempFile("jvPCAviewAssoc", "jvp");
1345   
1346    {
1347  1 String exampleFile = "examples/uniref50.fa";
1348  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
1349    DataSourceType.FILE);
1350  1 assertNotNull(af, "Didn't read in the example file correctly.");
1351  1 AlignmentPanel origView = (AlignmentPanel) af.getAlignPanels().get(0);
1352  1 AlignmentPanel newview = af.newView(PCAVIEWNAME, true);
1353    // create another for good measure
1354  1 af.newView("Not the PCA View", true);
1355  1 PCAPanel pcaPanel = new PCAPanel(origView, "BLOSUM62",
1356    new SimilarityParams(true, true, true, false));
1357    // we're in the test exec thread, so we can just run synchronously here
1358  1 pcaPanel.run();
1359   
1360    // now switch the linked view
1361  1 pcaPanel.selectAssociatedView(newview);
1362   
1363  1 assertTrue(pcaPanel.getAlignViewport() == newview.getAlignViewport(),
1364    "PCA should be associated with 'With PCA' view: test is broken");
1365   
1366    // now save and reload project
1367  1 Jalview2XML jv2xml = new jalview.project.Jalview2XML(false);
1368  1 tempfile.delete();
1369  1 jv2xml.saveState(tempfile);
1370  1 assertTrue(jv2xml.errorMessage == null,
1371    "Failed to save dummy project with PCA: test broken");
1372    }
1373   
1374    // load again.
1375  1 Desktop.instance.closeAll_actionPerformed(null);
1376  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1377    tempfile.getCanonicalPath(), DataSourceType.FILE);
1378  1 JInternalFrame[] frames = Desktop.instance.getAllFrames();
1379    // PCA and the tabbed alignment view should be the only two windows on the
1380    // desktop
1381  1 assertEquals(frames.length, 2,
1382    "PCA and the tabbed alignment view should be the only two windows on the desktop");
1383  1 PCAPanel pcaPanel = (PCAPanel) frames[frames[0] == af ? 1 : 0];
1384   
1385  1 AlignmentViewPanel restoredNewView = null;
1386  1 for (AlignmentViewPanel alignpanel : Desktop.getAlignmentPanels(null))
1387    {
1388  3 if (alignpanel.getAlignViewport() == pcaPanel.getAlignViewport())
1389    {
1390  1 restoredNewView = alignpanel;
1391    }
1392    }
1393  1 assertEquals(restoredNewView.getViewName(), PCAVIEWNAME);
1394  1 assertTrue(
1395    restoredNewView.getAlignViewport() == pcaPanel
1396    .getAlignViewport(),
1397    "Didn't restore correct view association for the PCA view");
1398    }
1399   
1400    /**
1401    * Test save and reload of DBRefEntry including GeneLocus in project
1402    *
1403    * @throws Exception
1404    */
 
1405  1 toggle @Test(groups = { "Functional" })
1406    public void testStoreAndRecoverGeneLocus() throws Exception
1407    {
1408  1 Desktop.instance.closeAll_actionPerformed(null);
1409  1 String seqData = ">P30419\nACDE\n>X1235\nGCCTGTGACGAA";
1410  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqData,
1411    DataSourceType.PASTE);
1412  1 assertNotNull(af, "Didn't read in the example file correctly.");
1413   
1414  1 AlignmentViewPanel ap = Desktop.getAlignmentPanels(null)[0];
1415  1 SequenceI pep = ap.getAlignment().getSequenceAt(0);
1416  1 SequenceI cds = ap.getAlignment().getSequenceAt(1);
1417   
1418    /*
1419    * give 'protein' a dbref to self, a dbref with map to CDS,
1420    * and a dbref with map to gene 'locus'
1421    */
1422  1 DBRefEntry dbref1 = new DBRefEntry("Uniprot", "1", "P30419", null);
1423  1 pep.addDBRef(dbref1);
1424  1 Mapping cdsmap = new Mapping(cds,
1425    new MapList(new int[]
1426    { 1, 4 }, new int[] { 1, 12 }, 1, 3));
1427  1 DBRefEntry dbref2 = new DBRefEntry("EMBLCDS", "2", "X1235", cdsmap);
1428  1 pep.addDBRef(dbref2);
1429  1 Mapping locusmap = new Mapping(null,
1430    new MapList(new int[]
1431    { 1, 4 }, new int[] { 2674123, 2674135 }, 1, 3));
1432  1 DBRefEntry dbref3 = new GeneLocus("human", "GRCh38", "5", locusmap);
1433  1 pep.addDBRef(dbref3);
1434   
1435  1 File tfile = File.createTempFile("testStoreAndRecoverGeneLocus",
1436    ".jvp");
1437  1 try
1438    {
1439  1 new Jalview2XML(false).saveState(tfile);
1440    } catch (Throwable e)
1441    {
1442  0 Assert.fail("Didn't save the state", e);
1443    }
1444  1 Desktop.instance.closeAll_actionPerformed(null);
1445   
1446  1 new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1447    DataSourceType.FILE);
1448  1 AlignmentViewPanel rap = Desktop.getAlignmentPanels(null)[0];
1449  1 SequenceI rpep = rap.getAlignment().getSequenceAt(0);
1450  1 DBModList<DBRefEntry> dbrefs = rpep.getDBRefs();
1451  1 assertEquals(rpep.getName(), "P30419");
1452  1 assertEquals(dbrefs.size(), 3);
1453  1 DBRefEntry dbRef = dbrefs.get(0);
1454  1 assertFalse(dbRef instanceof GeneLocus);
1455  1 assertNull(dbRef.getMap());
1456  1 assertEquals(dbRef, dbref1);
1457   
1458    /*
1459    * restored dbrefs with mapping have a different 'map to'
1460    * sequence but otherwise match the original dbrefs
1461    */
1462  1 dbRef = dbrefs.get(1);
1463  1 assertFalse(dbRef instanceof GeneLocus);
1464  1 assertTrue(dbRef.equalRef(dbref2));
1465  1 assertNotNull(dbRef.getMap());
1466  1 SequenceI rcds = rap.getAlignment().getSequenceAt(1);
1467  1 assertSame(dbRef.getMap().getTo(), rcds);
1468    // compare MapList but not map.to
1469  1 assertEquals(dbRef.getMap().getMap(), dbref2.getMap().getMap());
1470   
1471    /*
1472    * GeneLocus map.to is null so can compare Mapping objects
1473    */
1474  1 dbRef = dbrefs.get(2);
1475  1 assertTrue(dbRef instanceof GeneLocus);
1476  1 assertEquals(dbRef, dbref3);
1477    }
1478   
1479    /**
1480    * test store and recovery of Overview windows
1481    *
1482    * @throws Exception
1483    */
 
1484  1 toggle @Test(groups = { "Functional" }, enabled = true)
1485    public void testStoreAndRecoverOverview() throws Exception
1486    {
1487  1 Desktop.instance.closeAll_actionPerformed(null);
1488   
1489  1 Cache.setProperty("SHOW_OVERVIEW", "false");
1490  1 Cache.setProperty(Preferences.USE_LEGACY_GAP, "false");
1491  1 Cache.setColourProperty(Preferences.GAP_COLOUR, Color.green);
1492  1 Cache.setColourProperty(Preferences.HIDDEN_COLOUR, Color.yellow);
1493  1 Cache.setProperty(Preferences.SHOW_OV_HIDDEN_AT_START, "true");
1494   
1495  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1496    "examples/uniref50.fa", DataSourceType.FILE);
1497   
1498    /*
1499    * open and resize / reposition overview
1500    */
1501  1 af.overviewMenuItem_actionPerformed(null);
1502  1 OverviewPanel ov1 = af.alignPanel.getOverviewPanel();
1503  1 assertNotNull(ov1);
1504  1 ov1.setFrameBounds(20, 30, 200, 400);
1505  1 assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa");
1506  1 assertTrue(ov1.isShowHiddenRegions());
1507   
1508    /*
1509    * open a New View and its Overview and reposition it
1510    */
1511  1 af.newView_actionPerformed(null);
1512  1 af.overviewMenuItem_actionPerformed(null);
1513  1 OverviewPanel ov2 = af.alignPanel.getOverviewPanel();
1514  1 assertNotNull(ov2);
1515  1 assertNotSame(ov1, ov2);
1516  1 ov2.setFrameBounds(25, 35, 205, 405);
1517  1 assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa Original");
1518  1 assertEquals(ov2.getTitle(), "Overview examples/uniref50.fa View 1");
1519   
1520  1 File tfile = File.createTempFile("testStoreAndRecoverOverview", ".jvp");
1521  1 new Jalview2XML(false).saveState(tfile);
1522  1 Desktop.instance.closeAll_actionPerformed(null);
1523   
1524    /*
1525    * change preferences (should _not_ affect reloaded Overviews)
1526    */
1527  1 Cache.setProperty("SHOW_OVERVIEW", "true");
1528  1 Cache.setProperty(Preferences.USE_LEGACY_GAP, "true");
1529  1 Cache.setColourProperty(Preferences.GAP_COLOUR, Color.blue);
1530  1 Cache.setColourProperty(Preferences.HIDDEN_COLOUR, Color.orange);
1531  1 Cache.setProperty(Preferences.SHOW_OV_HIDDEN_AT_START, "false");
1532   
1533  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1534    DataSourceType.FILE);
1535   
1536    /*
1537    * workaround: explicitly select View 1 (not in focus after restore)
1538    */
1539  1 af.tabSelectionChanged(1);
1540   
1541    /*
1542    * verify restored overview for View 1
1543    */
1544  1 ov2 = af.alignPanel.getOverviewPanel();
1545  1 assertEquals(ov2.getCanvas().getGapColour(), Color.green);
1546    // 'non-legacy' colouring uses white for non-gapped residues
1547  1 assertEquals(ov2.getCanvas().getResidueColour(), Color.white);
1548  1 assertEquals(ov2.getCanvas().getHiddenColour(), Color.yellow);
1549  1 assertEquals(ov2.getTitle(), "Overview examples/uniref50.fa View 1");
1550  1 assertEquals(ov2.getFrameBounds(), new Rectangle(25, 35, 205, 405));
1551  1 assertTrue(ov2.isShowHiddenRegions());
1552   
1553    /*
1554    * verify restored overview for Original view
1555    */
1556  1 af.tabSelectionChanged(0);
1557  1 ov1 = af.alignPanel.getOverviewPanel();
1558  1 assertEquals(ov1.getCanvas().getGapColour(), Color.green);
1559    // 'non-legacy' colouring uses white for non-gapped residues
1560  1 assertEquals(ov1.getCanvas().getResidueColour(), Color.white);
1561  1 assertEquals(ov1.getCanvas().getHiddenColour(), Color.yellow);
1562  1 assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa Original");
1563   
1564  1 double scaling = jalview.gui.JvSwingUtilsTest.getScaling(ov1);
1565    // int width = scaling == 1.0 ? 225 : 200;
1566    // int width = scaling == 1.0 ? 225 : 200;
1567  1 Rectangle ov1Rectangle = ov1.getFrameBounds();
1568  1 assertEquals(ov1Rectangle,
1569    new Rectangle(20, 30, ov1Rectangle.width, 400));
1570  1 int width = ov1Rectangle.width;
1571  1 assertTrue(width >= 200 && width <= 225,
1572    "Rectangle width was not in the range expected (200<=width<=225; width="
1573    + width + ")");
1574  1 assertTrue(ov1.isShowHiddenRegions());
1575    }
1576   
1577    /**
1578    * Test that a view with no Overview is restored with no Overview, even if
1579    * 'Open Overview' is selected in Preferences
1580    *
1581    * @throws Exception
1582    */
 
1583  1 toggle @Test(groups = { "Functional" }, enabled = true)
1584    public void testStoreAndRecoverNoOverview() throws Exception
1585    {
1586  1 Cache.setProperty("SHOW_OVERVIEW", "false");
1587  1 Desktop.instance.closeAll_actionPerformed(null);
1588  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1589    ">seq1\nMATRSQFLVNF\n", DataSourceType.PASTE);
1590   
1591  1 File tfile = File.createTempFile("testStoreAndRecoverOverview", ".jvp");
1592  1 new Jalview2XML(false).saveState(tfile);
1593  1 Desktop.instance.closeAll_actionPerformed(null);
1594   
1595  1 Cache.setProperty("SHOW_OVERVIEW", "true");
1596  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1597    DataSourceType.FILE);
1598   
1599  1 assertNull(af.alignPanel.getOverviewPanel());
1600    }
1601   
1602    /**
1603    * Test that a view from an older version of Jalview is restored with Overview
1604    * automatically shown when the preference is set
1605    *
1606    * @throws Exception
1607    */
 
1608  1 toggle @Test(groups = { "Functional" }, enabled = true)
1609    public void testAutoShowOverviewForLegacyProjects() throws Exception
1610    {
1611  1 Desktop.instance.closeAll_actionPerformed(null);
1612  1 Cache.setProperty("SHOW_OVERVIEW", "true");
1613  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1614    "examples/exampleFile.jvp", DataSourceType.FILE);
1615   
1616  1 Cache.setProperty("SHOW_OVERVIEW", "false");
1617  1 assertNotNull(af.alignPanel.getOverviewPanel());
1618    }
1619   
1620    /**
1621    * Test that loading example.jvp, doing some stuff, then hitting reload
1622    * doesn't leave the modified window still open
1623    *
1624    * See JAL-4127 - interactively performing the same actions and reloading
1625    * works fine, but programmatically they do not
1626    *
1627    * @throws Exception
1628    */
 
1629  0 toggle @Test(groups = { "Functional" }, enabled = false)
1630    public void testReloadActuallyReloads() throws Exception
1631    {
1632  0 Desktop.instance.closeAll_actionPerformed(null);
1633  0 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1634    "examples/exampleFile.jvp", DataSourceType.FILE);
1635  0 af.getViewport().getColumnSelection().addElement(3);
1636  0 af.hideSelColumns_actionPerformed(null);
1637  0 af.newView("new", true);
1638  0 af.reload_actionPerformed(null);
1639  0 Thread.sleep(30);
1640    // af exists still but isn't shown
1641  0 assertTrue(af.isClosed());
1642    }
1643   
 
1644  1 toggle @Test(groups = { "Functional" })
1645    public void testMatrixToFloatsAndBack()
1646    {
1647  1 int imax = 2000;
1648  1 int i = imax;
1649  1 SequenceI sq = new Sequence("dummy", "SEQ");
1650  1998 while (sq.getLength() < i)
1651    {
1652  1997 sq.setSequence(sq.getSequenceAsString() + 'Q');
1653    }
1654  1 float[][] paevals = new float[i][i];
1655  2001 for (i = imax - 1; i >= 0; i--)
1656    {
1657  2003000 for (int j = 0; j <= i; j++)
1658    {
1659  2001000 paevals[i][j] = ((i - j < 2)
1660    || ((i > 1 && i < 5) && (j > 1 && i < 5))) ? 1 : 0f;
1661  2001000 paevals[j][i] = -paevals[i][j];
1662    }
1663    }
1664  1 PAEContactMatrix dummyMat = new PAEContactMatrix(sq, paevals);
1665  1 String content = ContactMatrix.contactToFloatString(dummyMat);
1666  1 Assert.assertTrue(content.contains("\t1.")); // at least one element must be
1667    // 1
1668  1 float[][] vals = ContactMatrix.fromFloatStringToContacts(content,
1669    sq.getLength(), sq.getLength());
1670  1 assertEquals(vals[3][4], paevals[3][4]);
1671  1 assertEquals(vals[4][3], paevals[4][3]);
1672   
1673    // test recovery
1674  2001 for (i = 0; i < imax; i++)
1675    {
1676  4002000 for (int j = 0; j < imax; j++)
1677    {
1678  4000000 assertEquals(vals[i][j], paevals[i][j]);
1679    }
1680    }
1681    }
1682   
 
1683  1 toggle @Test(groups = { "Functional" })
1684    public void testPAEsaveRestore() throws Exception
1685    {
1686  1 Desktop.instance.closeAll_actionPerformed(null);
1687  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1688    ">seq1\nMATRSQFLVNF\n", DataSourceType.PASTE);
1689  1 AlignmentI al = af.getViewport().getAlignment();
1690    // PAE matrices are added as reference annotation to the dataset sequence
1691    // at least for now.
1692  1 SequenceI sq = al.getSequenceAt(0).getDatasetSequence();
1693  1 int i = sq.getLength();
1694  1 float[][] paevals = new float[i][i];
1695  12 for (i = i - 1; i >= 0; i--)
1696    {
1697  77 for (int j = 0; j <= i; j++)
1698    {
1699  66 paevals[i][j] = ((i - j < 2)
1700    || ((i > 1 && i < 5) && (j > 1 && i < 5))) ? 1 : 0f;
1701  66 paevals[j][i] = -paevals[i][j];
1702    }
1703    }
1704  1 PAEContactMatrix dummyMat = new PAEContactMatrix(sq, paevals);
1705  1 String content = ContactMatrix.contactToFloatString(dummyMat);
1706  1 Assert.assertTrue(content.contains("\t1.")); // at least one element must be
1707    // 1
1708  1 float[][] vals = ContactMatrix.fromFloatStringToContacts(content,
1709    sq.getLength(), sq.getLength());
1710  1 assertEquals(vals[3][4], paevals[3][4]);
1711  1 assertEquals(vals[4][3], paevals[4][3]);
1712  1 dummyMat.setGroupSet(GroupSet.makeGroups(dummyMat, false, 0.5f, false));
1713  1 Assert.assertNotSame(dummyMat.getNewick(), "");
1714  1 AlignmentAnnotation paeCm = sq.addContactList(dummyMat);
1715  1 al.addAnnotation(paeCm);
1716    // verify store/restore of group bitsets
1717  1 for (BitSet gp : dummyMat.getGroups())
1718    {
1719  3 StringBuilder sb = new StringBuilder();
1720  3 for (long val : gp.toLongArray())
1721    {
1722  3 if (sb.length() > 0)
1723    {
1724  0 sb.append(",");
1725    }
1726  3 sb.append(val);
1727    }
1728  3 String[] longvals = sb.toString().split(",");
1729  3 long[] newlongvals = new long[longvals.length];
1730  6 for (int lv = 0; lv < longvals.length; lv++)
1731    {
1732  3 try
1733    {
1734  3 newlongvals[lv] = Long.valueOf(longvals[lv]);
1735    } catch (Exception x)
1736    {
1737  0 Assert.fail("failed to deserialise bitset element ");
1738    }
1739    }
1740  3 BitSet newGp = BitSet.valueOf(newlongvals);
1741  3 assertTrue(gp.equals(newGp));
1742    }
1743  1 File tfile = File.createTempFile("testStoreAndRecoverPAEmatrix",
1744    ".jvp");
1745  1 new Jalview2XML(false).saveState(tfile);
1746  1 Desktop.instance.closeAll_actionPerformed(null);
1747   
1748  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1749    DataSourceType.FILE);
1750  1 AlignmentI newAl = af.getViewport().getAlignment();
1751  1 SequenceI newSeq = newAl.getSequenceAt(0).getDatasetSequence();
1752    // check annotation of the expected type exists
1753  1 Assert.assertEquals(newSeq.getAnnotation().length, 1);
1754  1 Assert.assertEquals(newSeq.getAnnotation()[0].graph, paeCm.graph);
1755   
1756    // check a contact matrix was recovered
1757  1 Assert.assertEquals(newSeq.getContactMaps().size(), 1);
1758    // and can be found for the annotation on the sequence
1759  1 ContactMatrixI restoredMat = newSeq
1760    .getContactMatrixFor(newSeq.getAnnotation()[0]);
1761  1 Assert.assertNotNull(restoredMat);
1762  1 MapList oldMap = ((MappableContactMatrixI) dummyMat).getMapFor(sq);
1763  1 MapList newMap = ((MappableContactMatrixI) restoredMat)
1764    .getMapFor(newSeq);
1765  1 Assert.assertEquals(oldMap.getFromRanges(), newMap.getFromRanges());
1766  1 Assert.assertEquals(oldMap.getToRanges(), newMap.getToRanges());
1767  1 Assert.assertEquals(oldMap.getFromRatio(), newMap.getFromRatio());
1768  1 Assert.assertEquals(oldMap.getToRatio(), newMap.getToRatio());
1769  12 for (i = sq.getLength() - 1; i >= 0; i--)
1770    {
1771  11 ContactListI oldCM = dummyMat.getContactList(i),
1772    newCM = restoredMat.getContactList(i);
1773  132 for (int j = oldCM.getContactHeight(); j >= 0; j--)
1774    {
1775  121 double old_j = oldCM.getContactAt(j);
1776  121 double new_j = newCM.getContactAt(j);
1777  121 Assert.assertEquals(old_j, new_j);
1778    }
1779    }
1780  1 Assert.assertEquals(restoredMat.hasGroups(), dummyMat.hasGroups());
1781  1 Assert.assertEquals(restoredMat.getGroups(), dummyMat.getGroups());
1782  1 Assert.assertEquals(restoredMat.hasTree(), dummyMat.hasTree());
1783  1 Assert.assertEquals(restoredMat.getNewick(), dummyMat.getNewick());
1784   
1785    // verify no duplicate PAE matrix data when new view created and saved
1786   
1787    // add reference annotations to view first, then copy
1788  1 AlignmentUtils.addReferenceAnnotationTo(newAl, newAl.getSequenceAt(0),
1789    newSeq.getAnnotation()[0], null);
1790   
1791  1 AlignmentViewPanel newview = af.newView("copy of PAE", true);
1792   
1793    // redundant asserts here check all is good with the new view firest...
1794  1 AlignmentI newviewAl = newview.getAlignment();
1795  1 SequenceI newviewSeq = newviewAl.getSequenceAt(0);
1796    // check annotation of the expected type exists
1797  1 Assert.assertEquals(newviewSeq.getAnnotation().length, 1);
1798  1 Assert.assertEquals(newviewSeq.getAnnotation()[0].graph, paeCm.graph);
1799    // check we have just one contact matrix mapping
1800  1 Assert.assertEquals(newviewSeq.getContactMaps().size(), 1);
1801   
1802    // and can be found for the annotation on the sequence
1803  1 ContactMatrixI newviewMat = newviewSeq
1804    .getContactMatrixFor(newviewSeq.getAnnotation()[0]);
1805  1 Assert.assertNotNull(newviewMat);
1806   
1807  1 Assert.assertTrue(newviewMat == restoredMat);
1808   
1809    // save the two views and restore. Now look at visible annotation to check
1810    // all views have shared refs.
1811   
1812  1 tfile = File.createTempFile("testStoreAndRecoverPAEmatrixTwoViews",
1813    ".jvp");
1814  1 new Jalview2XML(false).saveState(tfile);
1815  1 Desktop.instance.closeAll_actionPerformed(null);
1816   
1817  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1818    DataSourceType.FILE);
1819  1 newAl = af.getAlignPanels().get(0).getAlignment();
1820  1 AlignmentAnnotation view1aa = newAl.getSequenceAt(0).getAnnotation()[0];
1821   
1822  1 newviewAl = af.getAlignPanels().get(1).getAlignment();
1823  1 AlignmentAnnotation view2aa = newviewAl.getSequenceAt(0)
1824    .getAnnotation()[0];
1825   
1826    // annotations are shared across alignment views - so should still have an
1827    // identical pair of annotations.
1828  1 Assert.assertTrue(view1aa == view2aa);
1829    // identical annotations means identical contact matrix mappings
1830  1 Assert.assertEquals(
1831    newAl.getDataset().getSequenceAt(0).getContactMaps().size(), 1);
1832   
1833    // TODO Verify when distinct mappable PAEs are created, only one PAE dataset
1834    // is actually held.
1835    // Assert.assertTrue(view1aa!=view2aa);
1836    // restoredMat = newAl.getContactMatrixFor(view1aa);
1837    // newviewMat = newviewAl.getContactMatrixFor(view2aa);
1838    // Assert.assertTrue(restoredMat!=newviewMat);
1839   
1840    }
1841   
 
1842  1 toggle @Test(groups = "Functional")
1843    public void testStoreAndRestoreIDwidthAndAnnotationHeight()
1844    throws IOException
1845    {
1846  1 Desktop.instance.closeAll_actionPerformed(null);
1847  1 final String SECONDVIEW = "With Diffferent IDwidth";
1848    // create a new tempfile
1849  1 File tempfile = File.createTempFile("jvIdWidthStoreRestore", "jvp");
1850   
1851  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1852    "examples/exampleFile.jvp", DataSourceType.FILE);
1853  1 assertNotNull(af, "Didn't read in the example file correctly.");
1854    // FIXME JAL-4281 test made platform dependent to pass, but probably
1855    // shouldn't be platform dependent
1856  1 int idWidth = af.alignPanel.getAlignViewport().getIdWidth();
1857  1 double scaling = jalview.gui.JvSwingUtilsTest.getScaling(af.alignPanel);
1858    // int expectedWidth = Platform.isMac() ? 144 : Platform.isLinux() ? scaling
1859    // == 1.0 ? 131 : 128 : 138;
1860  1 int minExpectedWidth = 128;
1861  1 int maxExpectedWidth = 144;
1862  1 assertTrue(minExpectedWidth <= idWidth && maxExpectedWidth >= idWidth,
1863    "Legacy project import should have fixed ID width. Not within the expected range ("
1864    + minExpectedWidth + "-" + maxExpectedWidth + ")");
1865  1 assertTrue(
1866    af.alignPanel.getIdPanel().getIdCanvas().isManuallyAdjusted());
1867   
1868  1 af.alignPanel.getAlignViewport().setIdWidth(100);
1869  1 af.alignPanel.updateLayout();
1870  1 assertTrue(
1871    af.alignPanel.getIdPanel().getIdCanvas().isManuallyAdjusted());
1872   
1873  1 Jalview2XML jv2xml = new jalview.project.Jalview2XML(false);
1874  1 tempfile.delete();
1875  1 jv2xml.saveState(tempfile);
1876  1 assertTrue(jv2xml.errorMessage == null,
1877    "Failed to save dummy project with PCA: test broken");
1878  1 af = null;
1879    // load again.
1880  1 Desktop.instance.closeAll_actionPerformed(null);
1881  1 af = new FileLoader().LoadFileWaitTillLoaded(
1882    tempfile.getCanonicalPath(), DataSourceType.FILE);
1883  1 assertTrue(
1884    af.alignPanel.getIdPanel().getIdCanvas().isManuallyAdjusted());
1885  1 assertEquals(af.alignPanel.getAlignViewport().getIdWidth(), 100,
1886    "New project exported and import should have adjusted ID width");
1887   
1888  1 af.alignPanel.getAlignViewport().setIdWidth(100);
1889  1 af.alignPanel.updateLayout();
1890  1 assertTrue(
1891    af.alignPanel.getIdPanel().getIdCanvas().isManuallyAdjusted());
1892   
1893    // now make it autoadjusted
1894  1 af.alignPanel.getAlignViewport().setIdWidth(-1);
1895  1 af.alignPanel.getIdPanel().getIdCanvas().setManuallyAdjusted(false);
1896  1 af.alignPanel.updateLayout();
1897  1 assertFalse(
1898    af.alignPanel.getIdPanel().getIdCanvas().isManuallyAdjusted());
1899  1 assertTrue(af.alignPanel.getAlignViewport().getIdWidth() > -1,
1900    "New project exported and import should have adjusted ID width");
1901   
1902  1 jv2xml = new jalview.project.Jalview2XML(false);
1903  1 tempfile.delete();
1904  1 jv2xml.saveState(tempfile);
1905  1 assertTrue(jv2xml.errorMessage == null,
1906    "Failed to save dummy project with PCA: test broken");
1907  1 af = null;
1908    // load again.
1909  1 Desktop.instance.closeAll_actionPerformed(null);
1910  1 af = new FileLoader().LoadFileWaitTillLoaded(
1911    tempfile.getCanonicalPath(), DataSourceType.FILE);
1912  1 assertFalse(
1913    af.alignPanel.getIdPanel().getIdCanvas().isManuallyAdjusted());
1914  1 assertTrue(af.alignPanel.getAlignViewport().getIdWidth() > -1,
1915    "New project exported and import should have adjusted ID width");
1916    }
1917   
1918    }