Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.project

File Jalview2xmlTests.java

 

Code metrics

92
964
38
1
2,219
1,653
112
0.12
25.37
38
2.95

Classes

Class Line # Actions
Jalview2xmlTests 127 964 112
0.9268738692.7%
 

Contributing tests

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