Clover icon

Coverage Report

  1. Project Clover database Thu Nov 27 2025 16:51:35 GMT
  2. Package jalview.project

File Jalview2xmlTests.java

 

Code metrics

92
938
36
1
2,099
1,557
109
0.12
26.06
36
3.03

Classes

Class Line # Actions
Jalview2xmlTests 129 938 109
0.924953192.5%
 

Contributing tests

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