JAL-1767 unit test for save and restore PCA
[jalview.git] / test / jalview / io / Jalview2xmlTests.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.io;
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.assertNull;
27 import static org.testng.Assert.assertSame;
28 import static org.testng.Assert.assertTrue;
29 import static org.testng.Assert.fail;
30
31 import jalview.analysis.PCA;
32 import jalview.api.AlignViewportI;
33 import jalview.api.AlignmentViewPanel;
34 import jalview.api.FeatureColourI;
35 import jalview.api.ViewStyleI;
36 import jalview.bin.Cache;
37 import jalview.datamodel.AlignmentAnnotation;
38 import jalview.datamodel.AlignmentI;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.PDBEntry;
41 import jalview.datamodel.PDBEntry.Type;
42 import jalview.datamodel.Point;
43 import jalview.datamodel.SequenceCollectionI;
44 import jalview.datamodel.SequenceFeature;
45 import jalview.datamodel.SequenceGroup;
46 import jalview.datamodel.SequenceI;
47 import jalview.datamodel.SequencePoint;
48 import jalview.datamodel.features.FeatureMatcher;
49 import jalview.datamodel.features.FeatureMatcherSet;
50 import jalview.datamodel.features.FeatureMatcherSetI;
51 import jalview.gui.AlignFrame;
52 import jalview.gui.AlignViewport;
53 import jalview.gui.AlignmentPanel;
54 import jalview.gui.CalculationChooser;
55 import jalview.gui.Desktop;
56 import jalview.gui.FeatureRenderer;
57 import jalview.gui.Jalview2XML;
58 import jalview.gui.JvOptionPane;
59 import jalview.gui.PCAPanel;
60 import jalview.gui.PopupMenu;
61 import jalview.gui.RotatableCanvas;
62 import jalview.gui.SliderPanel;
63 import jalview.math.MatrixTest;
64 import jalview.renderer.ResidueShaderI;
65 import jalview.schemes.AnnotationColourGradient;
66 import jalview.schemes.BuriedColourScheme;
67 import jalview.schemes.ColourSchemeI;
68 import jalview.schemes.ColourSchemeProperty;
69 import jalview.schemes.FeatureColour;
70 import jalview.schemes.JalviewColourScheme;
71 import jalview.schemes.RNAHelicesColour;
72 import jalview.schemes.StrandColourScheme;
73 import jalview.schemes.TCoffeeColourScheme;
74 import jalview.structure.StructureImportSettings;
75 import jalview.util.matcher.Condition;
76 import jalview.viewmodel.AlignmentViewport;
77 import jalview.viewmodel.PCAModel;
78
79 import java.awt.Color;
80 import java.io.File;
81 import java.io.IOException;
82 import java.util.ArrayList;
83 import java.util.HashMap;
84 import java.util.List;
85 import java.util.Map;
86
87 import javax.swing.JInternalFrame;
88 import javax.swing.JRadioButton;
89
90 import org.testng.Assert;
91 import org.testng.AssertJUnit;
92 import org.testng.annotations.BeforeClass;
93 import org.testng.annotations.BeforeMethod;
94 import org.testng.annotations.Test;
95
96 import junit.extensions.PA;
97
98 @Test(singleThreaded = true)
99 public class Jalview2xmlTests extends Jalview2xmlBase
100 {
101   @BeforeClass(alwaysRun = true)
102   public void setUp()
103   {
104     Cache.loadProperties("test/jalview/io/testProps.jvprops");
105   }
106
107   @BeforeMethod(alwaysRun = true)
108   public void setUpMethod()
109   {
110     Desktop.instance.closeAll_actionPerformed(null);
111   }
112
113   @Override
114   @BeforeClass(alwaysRun = true)
115   public void setUpJvOptionPane()
116   {
117     JvOptionPane.setInteractiveMode(false);
118     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
119   }
120
121   @Test(groups = { "Functional" })
122   public void testRNAStructureRecovery() throws Exception
123   {
124     String inFile = "examples/RF00031_folded.stk";
125     String tfile = File.createTempFile("JalviewTest", ".jvp")
126             .getAbsolutePath();
127     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
128             DataSourceType.FILE);
129     assertNotNull(af, "Didn't read input file " + inFile);
130     int olddsann = countDsAnn(af.getViewport());
131     assertTrue(olddsann > 0, "Didn't find any dataset annotations");
132     af.changeColour_actionPerformed(JalviewColourScheme.RNAHelices
133             .toString());
134     assertTrue(
135             af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
136             "Couldn't apply RNA helices colourscheme");
137     assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
138             "Failed to store as a project.");
139     af.closeMenuItem_actionPerformed(true);
140     af = null;
141     af = new FileLoader()
142             .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
143     assertNotNull(af, "Failed to import new project");
144     int newdsann = countDsAnn(af.getViewport());
145     assertEquals(olddsann, newdsann,
146             "Differing numbers of dataset sequence annotation\nOriginally "
147                     + olddsann + " and now " + newdsann);
148     System.out
149             .println("Read in same number of annotations as originally present ("
150                     + olddsann + ")");
151     assertTrue(
152
153     af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
154             "RNA helices colourscheme was not applied on import.");
155   }
156
157   @Test(groups = { "Functional" })
158   public void testTCoffeeScores() throws Exception
159   {
160     String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
161     String tfile = File.createTempFile("JalviewTest", ".jvp")
162             .getAbsolutePath();
163     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
164             DataSourceType.FILE);
165     assertNotNull(af, "Didn't read input file " + inFile);
166     af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
167     assertSame(af.getViewport().getGlobalColourScheme().getClass(),
168             TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
169     assertNotNull(ColourSchemeProperty.getColourScheme(af.getViewport()
170             .getAlignment(), af.getViewport().getGlobalColourScheme()
171             .getSchemeName()), "Recognise T-Coffee score from string");
172
173     assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
174             "Failed to store as a project.");
175     af.closeMenuItem_actionPerformed(true);
176     af = null;
177     af = new FileLoader()
178             .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
179     assertNotNull(af, "Failed to import new project");
180     assertSame(af.getViewport().getGlobalColourScheme().getClass(),
181             TCoffeeColourScheme.class,
182             "Didn't set T-coffee colourscheme for imported project.");
183     System.out
184             .println("T-Coffee score shading successfully recovered from project.");
185   }
186
187   @Test(groups = { "Functional" })
188   public void testColourByAnnotScores() throws Exception
189   {
190     String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
191     String tfile = File.createTempFile("JalviewTest", ".jvp")
192             .getAbsolutePath();
193     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
194             DataSourceType.FILE);
195     assertNotNull(af, "Didn't read input file " + inFile);
196     af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
197     AlignmentAnnotation[] aa = af.getViewport().getAlignment()
198             .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
199     assertTrue(
200
201     aa != null && aa.length > 0,
202             "Didn't find any IUPred annotation to use to shade alignment.");
203     AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
204             AnnotationColourGradient.ABOVE_THRESHOLD);
205     AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0],
206             null, AnnotationColourGradient.BELOW_THRESHOLD);
207     cs.setSeqAssociated(true);
208     gcs.setSeqAssociated(true);
209     af.changeColour(cs);
210     SequenceGroup sg = new SequenceGroup();
211     sg.setStartRes(57);
212     sg.setEndRes(92);
213     sg.cs.setColourScheme(gcs);
214     af.getViewport().getAlignment().addGroup(sg);
215     sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
216     sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
217     af.alignPanel.alignmentChanged();
218     assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
219             "Failed to store as a project.");
220     af.closeMenuItem_actionPerformed(true);
221     af = null;
222     af = new FileLoader()
223             .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
224     assertNotNull(af, "Failed to import new project");
225
226     // check for group and alignment colourschemes
227
228     ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
229     ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
230             .get(0).getColourScheme();
231     assertNotNull(_rcs, "Didn't recover global colourscheme");
232     assertTrue(_rcs instanceof AnnotationColourGradient,
233             "Didn't recover annotation colour global scheme");
234     AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
235     assertTrue(__rcs.isSeqAssociated(),
236             "Annotation colourscheme wasn't sequence associated");
237
238     boolean diffseqcols = false, diffgseqcols = false;
239     SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
240     for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
241             && (!diffseqcols || !diffgseqcols); p++)
242     {
243       if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
244               .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
245       {
246         diffseqcols = true;
247       }
248     }
249     assertTrue(diffseqcols, "Got Different sequence colours");
250     System.out
251             .println("Per sequence colourscheme (Background) successfully applied and recovered.");
252
253     assertNotNull(_rgcs, "Didn't recover group colourscheme");
254     assertTrue(_rgcs instanceof AnnotationColourGradient,
255             "Didn't recover annotation colour group colourscheme");
256     __rcs = (AnnotationColourGradient) _rgcs;
257     assertTrue(__rcs.isSeqAssociated(),
258             "Group Annotation colourscheme wasn't sequence associated");
259
260     for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
261             && (!diffseqcols || !diffgseqcols); p++)
262     {
263       if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null, 0f) != _rgcs
264               .findColour(sqs[2].getCharAt(p), p, sqs[2], null, 0f))
265       {
266         diffgseqcols = true;
267       }
268     }
269     assertTrue(diffgseqcols, "Got Different group sequence colours");
270     System.out
271             .println("Per sequence (Group) colourscheme successfully applied and recovered.");
272   }
273
274   @Test(groups = { "Functional" })
275   public void gatherViewsHere() throws Exception
276   {
277     int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
278             .getAlignFrames().length;
279     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
280             "examples/exampleFile_2_7.jar", DataSourceType.FILE);
281     assertNotNull(af, "Didn't read in the example file correctly.");
282     assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
283             "Didn't gather the views in the example file.");
284
285   }
286
287   @Test(groups = { "Functional" })
288   public void viewRefPdbAnnotation() throws Exception
289   {
290     StructureImportSettings.setProcessSecondaryStructure(true);
291     StructureImportSettings.setVisibleChainAnnotation(true);
292     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
293             "examples/exampleFile_2_7.jar", DataSourceType.FILE);
294     assertNotNull(af, "Didn't read in the example file correctly.");
295     AlignmentViewPanel sps = null;
296     for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
297     {
298       if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
299       {
300         sps = ap;
301         break;
302       }
303     }
304     assertNotNull(sps, "Couldn't find the structure view");
305     AlignmentAnnotation refan = null;
306     for (AlignmentAnnotation ra : sps.getAlignment()
307             .getAlignmentAnnotation())
308     {
309       if (ra.graph != 0)
310       {
311         refan = ra;
312         break;
313       }
314     }
315     assertNotNull(refan, "Annotation secondary structure not found.");
316     SequenceI sq = sps.getAlignment().findName("1A70|");
317     assertNotNull(sq, "Couldn't find 1a70 null chain");
318     // compare the manually added temperature factor annotation
319     // to the track automatically transferred from the pdb structure on load
320     assertNotNull(sq.getDatasetSequence().getAnnotation(),
321             "1a70 has no annotation");
322     for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
323     {
324       AlignmentAnnotation alaa;
325       sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
326       alaa.adjustForAlignment();
327       if (ala.graph == refan.graph)
328       {
329         for (int p = 0; p < ala.annotations.length; p++)
330         {
331           sq.findPosition(p);
332           try
333           {
334             assertTrue(
335                     (alaa.annotations[p] == null && refan.annotations[p] == null)
336                             || alaa.annotations[p].value == refan.annotations[p].value,
337                     "Mismatch at alignment position " + p);
338           } catch (NullPointerException q)
339           {
340             Assert.fail("Mismatch of alignment annotations at position "
341                     + p + " Ref seq ann: " + refan.annotations[p]
342                     + " alignment " + alaa.annotations[p]);
343           }
344         }
345       }
346     }
347
348   }
349
350   @Test(groups = { "Functional" })
351   public void testCopyViewSettings() throws Exception
352   {
353     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
354             "examples/exampleFile_2_7.jar", DataSourceType.FILE);
355     assertNotNull(af, "Didn't read in the example file correctly.");
356     AlignmentViewPanel sps = null, groups = null;
357     for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
358     {
359       if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
360       {
361         sps = ap;
362       }
363       if (ap.getViewName().contains("MAFFT"))
364       {
365         groups = ap;
366       }
367     }
368     assertNotNull(sps, "Couldn't find the structure view");
369     assertNotNull(groups, "Couldn't find the MAFFT view");
370
371     ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
372     ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
373     AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
374
375     groups.getAlignViewport().setViewStyle(structureStyle);
376     AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
377             .getViewStyle()));
378     Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
379             .getViewStyle()));
380
381   }
382
383   /**
384    * test store and recovery of expanded views
385    * 
386    * @throws Exception
387    */
388   @Test(groups = { "Functional" }, enabled = true)
389   public void testStoreAndRecoverExpandedviews() throws Exception
390   {
391     Desktop.instance.closeAll_actionPerformed(null);
392
393     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
394             "examples/exampleFile_2_7.jar", DataSourceType.FILE);
395     Assert.assertEquals(Desktop.getAlignFrames().length, 1);
396     String afid = af.getViewport().getSequenceSetId();
397
398     // check FileLoader returned a reference to the one alignFrame that is
399     // actually on the Desktop
400     assertSame(
401             af,
402             Desktop.getAlignFrameFor(af.getViewport()),
403             "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
404
405     Desktop.explodeViews(af);
406
407     int oldviews = Desktop.getAlignFrames().length;
408     Assert.assertEquals(Desktop.getAlignFrames().length,
409             Desktop.getAlignmentPanels(afid).length);
410     File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
411     try
412     {
413       new Jalview2XML(false).saveState(tfile);
414     } catch (Error e)
415     {
416       Assert.fail("Didn't save the expanded view state", e);
417     } catch (Exception e)
418     {
419       Assert.fail("Didn't save the expanded view state", e);
420     }
421     Desktop.instance.closeAll_actionPerformed(null);
422     if (Desktop.getAlignFrames() != null)
423     {
424       Assert.assertEquals(Desktop.getAlignFrames().length, 0);
425     }
426     af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
427             DataSourceType.FILE);
428     Assert.assertNotNull(af);
429     Assert.assertEquals(
430             Desktop.getAlignFrames().length,
431             Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
432     Assert.assertEquals(
433             Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
434             oldviews);
435   }
436
437   /**
438    * Test save and reload of a project with a different representative sequence
439    * in each view.
440    * 
441    * @throws Exception
442    */
443   @Test(groups = { "Functional" })
444   public void testStoreAndRecoverReferenceSeqSettings() throws Exception
445   {
446     Desktop.instance.closeAll_actionPerformed(null);
447     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
448             "examples/exampleFile_2_7.jar", DataSourceType.FILE);
449     assertNotNull(af, "Didn't read in the example file correctly.");
450     String afid = af.getViewport().getSequenceSetId();
451
452     // remember reference sequence for each panel
453     Map<String, SequenceI> refseqs = new HashMap<>();
454
455     /*
456      * mark sequence 2, 3, 4.. in panels 1, 2, 3...
457      * as reference sequence for itself and the preceding sequence
458      */
459     int n = 1;
460     for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
461     {
462       AlignViewportI av = ap.getAlignViewport();
463       AlignmentI alignment = ap.getAlignment();
464       int repIndex = n % alignment.getHeight();
465       SequenceI rep = alignment.getSequenceAt(repIndex);
466       refseqs.put(ap.getViewName(), rep);
467
468       // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
469       // todo refactor this to an alignment view controller
470       av.setDisplayReferenceSeq(true);
471       av.setColourByReferenceSeq(true);
472       av.getAlignment().setSeqrep(rep);
473
474       n++;
475     }
476     File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
477             ".jvp");
478     try
479     {
480       new Jalview2XML(false).saveState(tfile);
481     } catch (Throwable e)
482     {
483       Assert.fail("Didn't save the expanded view state", e);
484     }
485     Desktop.instance.closeAll_actionPerformed(null);
486     if (Desktop.getAlignFrames() != null)
487     {
488       Assert.assertEquals(Desktop.getAlignFrames().length, 0);
489     }
490
491     af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
492             DataSourceType.FILE);
493     afid = af.getViewport().getSequenceSetId();
494
495     for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
496     {
497       // check representative
498       AlignmentI alignment = ap.getAlignment();
499       SequenceI rep = alignment.getSeqrep();
500       Assert.assertNotNull(rep,
501               "Couldn't restore sequence representative from project");
502       // can't use a strong equals here, because by definition, the sequence IDs
503       // will be different.
504       // could set vamsas session save/restore flag to preserve IDs across
505       // load/saves.
506       Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
507               rep.toString(),
508               "Representative wasn't the same when recovered.");
509       Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
510               "Display reference sequence view setting not set.");
511       Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
512               "Colour By Reference Seq view setting not set.");
513     }
514   }
515
516   @Test(groups = { "Functional" })
517   public void testIsVersionStringLaterThan()
518   {
519     /*
520      * No version / development / test / autobuild is leniently assumed to be
521      * compatible
522      */
523     assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
524     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
525     assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
526     assertTrue(Jalview2XML.isVersionStringLaterThan(null,
527             "Development Build"));
528     assertTrue(Jalview2XML.isVersionStringLaterThan(null,
529             "DEVELOPMENT BUILD"));
530     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
531             "Development Build"));
532     assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
533     assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
534     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
535     assertTrue(Jalview2XML
536             .isVersionStringLaterThan(null, "Automated Build"));
537     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
538             "Automated Build"));
539     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
540             "AUTOMATED BUILD"));
541
542     /*
543      * same version returns true i.e. compatible
544      */
545     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
546     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
547     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
548     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
549     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
550
551     /*
552      * later version returns true
553      */
554     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
555     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
556     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
557     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
558     assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
559
560     /*
561      * earlier version returns false
562      */
563     assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
564     assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
565     assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
566     assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
567     assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
568   }
569
570   /**
571    * Test save and reload of a project with a different sequence group (and
572    * representative sequence) in each view.
573    * 
574    * @throws Exception
575    */
576   @Test(groups = { "Functional" })
577   public void testStoreAndRecoverGroupRepSeqs() throws Exception
578   {
579     Desktop.instance.closeAll_actionPerformed(null);
580     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
581             "examples/uniref50.fa", DataSourceType.FILE);
582     assertNotNull(af, "Didn't read in the example file correctly.");
583     String afid = af.getViewport().getSequenceSetId();
584     // make a second view of the alignment
585     af.newView_actionPerformed(null);
586
587     /*
588      * remember representative and hidden sequences marked 
589      * on each panel
590      */
591     Map<String, SequenceI> repSeqs = new HashMap<>();
592     Map<String, List<String>> hiddenSeqNames = new HashMap<>();
593
594     /*
595      * mark sequence 2, 3, 4.. in panels 1, 2, 3...
596      * as reference sequence for itself and the preceding sequence
597      */
598     int n = 1;
599     for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
600     {
601       AlignViewportI av = ap.getAlignViewport();
602       AlignmentI alignment = ap.getAlignment();
603       int repIndex = n % alignment.getHeight();
604       // ensure at least one preceding sequence i.e. index >= 1
605       repIndex = Math.max(repIndex, 1);
606       SequenceI repSeq = alignment.getSequenceAt(repIndex);
607       repSeqs.put(ap.getViewName(), repSeq);
608       List<String> hiddenNames = new ArrayList<>();
609       hiddenSeqNames.put(ap.getViewName(), hiddenNames);
610
611       /*
612        * have rep sequence represent itself and the one before it
613        * this hides the group (except for the rep seq)
614        */
615       SequenceGroup sg = new SequenceGroup();
616       sg.addSequence(repSeq, false);
617       SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
618       sg.addSequence(precedingSeq, false);
619       sg.setSeqrep(repSeq);
620       assertTrue(sg.getSequences().contains(repSeq));
621       assertTrue(sg.getSequences().contains(precedingSeq));
622       av.setSelectionGroup(sg);
623       assertSame(repSeq, sg.getSeqrep());
624
625       /*
626        * represent group with sequence adds to a map of hidden rep sequences
627        * (it does not create a group on the alignment) 
628        */
629       ((AlignmentViewport) av).hideSequences(repSeq, true);
630       assertSame(repSeq, sg.getSeqrep());
631       assertTrue(sg.getSequences().contains(repSeq));
632       assertTrue(sg.getSequences().contains(precedingSeq));
633       assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
634       Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
635               .getHiddenRepSequences();
636       assertNotNull(hiddenRepSeqsMap);
637       assertEquals(1, hiddenRepSeqsMap.size());
638       assertSame(sg, hiddenRepSeqsMap.get(repSeq));
639       assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
640       assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
641       hiddenNames.add(precedingSeq.getName());
642
643       n++;
644     }
645     File tfile = File
646             .createTempFile("testStoreAndRecoverGroupReps", ".jvp");
647     try
648     {
649       new Jalview2XML(false).saveState(tfile);
650     } catch (Throwable e)
651     {
652       Assert.fail("Didn't save the expanded view state", e);
653     }
654     Desktop.instance.closeAll_actionPerformed(null);
655     if (Desktop.getAlignFrames() != null)
656     {
657       Assert.assertEquals(Desktop.getAlignFrames().length, 0);
658     }
659
660     af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
661             DataSourceType.FILE);
662     afid = af.getViewport().getSequenceSetId();
663
664     for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
665     {
666       String viewName = ap.getViewName();
667       AlignViewportI av = ap.getAlignViewport();
668       AlignmentI alignment = ap.getAlignment();
669       List<SequenceGroup> groups = alignment.getGroups();
670       assertNotNull(groups);
671       assertTrue(groups.isEmpty(), "Alignment has groups");
672       Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
673               .getHiddenRepSequences();
674       assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
675       assertEquals(1, hiddenRepSeqsMap.size());
676       assertEquals(repSeqs.get(viewName).getDisplayId(true),
677               hiddenRepSeqsMap.keySet().iterator().next()
678                       .getDisplayId(true));
679
680       /*
681        * verify hidden sequences in restored panel
682        */
683       List<String> hidden = hiddenSeqNames.get(ap.getViewName());
684       HiddenSequences hs = alignment.getHiddenSequences();
685       assertEquals(
686               hidden.size(),
687               hs.getSize(),
688               "wrong number of restored hidden sequences in "
689                       + ap.getViewName());
690     }
691   }
692
693   /**
694    * Test save and reload of PDBEntry in Jalview project
695    * 
696    * @throws Exception
697    */
698   @Test(groups = { "Functional" })
699   public void testStoreAndRecoverPDBEntry() throws Exception
700   {
701     Desktop.instance.closeAll_actionPerformed(null);
702     String exampleFile = "examples/3W5V.pdb";
703     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
704             DataSourceType.FILE);
705     assertNotNull(af, "Didn't read in the example file correctly.");
706     String afid = af.getViewport().getSequenceSetId();
707
708     AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
709     System.out.println();
710     AlignmentViewPanel ap = alignPanels[0];
711     String tfileBase = new File(".").getAbsolutePath().replace(".", "");
712     String testFile = tfileBase + exampleFile;
713     AlignmentI alignment = ap.getAlignment();
714     System.out.println("blah");
715     SequenceI[] seqs = alignment.getSequencesArray();
716     Assert.assertNotNull(seqs[0]);
717     Assert.assertNotNull(seqs[1]);
718     Assert.assertNotNull(seqs[2]);
719     Assert.assertNotNull(seqs[3]);
720     Assert.assertNotNull(seqs[0].getDatasetSequence());
721     Assert.assertNotNull(seqs[1].getDatasetSequence());
722     Assert.assertNotNull(seqs[2].getDatasetSequence());
723     Assert.assertNotNull(seqs[3].getDatasetSequence());
724     PDBEntry[] pdbEntries = new PDBEntry[4];
725     pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
726     pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
727     pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
728     pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
729     Assert.assertEquals(seqs[0].getDatasetSequence().getAllPDBEntries()
730             .get(0), pdbEntries[0]);
731     Assert.assertEquals(seqs[1].getDatasetSequence().getAllPDBEntries()
732             .get(0), pdbEntries[1]);
733     Assert.assertEquals(seqs[2].getDatasetSequence().getAllPDBEntries()
734             .get(0), pdbEntries[2]);
735     Assert.assertEquals(seqs[3].getDatasetSequence().getAllPDBEntries()
736             .get(0), pdbEntries[3]);
737
738     File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
739     try
740     {
741       new Jalview2XML(false).saveState(tfile);
742     } catch (Throwable e)
743     {
744       Assert.fail("Didn't save the state", e);
745     }
746     Desktop.instance.closeAll_actionPerformed(null);
747     if (Desktop.getAlignFrames() != null)
748     {
749       Assert.assertEquals(Desktop.getAlignFrames().length, 0);
750     }
751
752     AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
753             tfile.getAbsolutePath(), DataSourceType.FILE);
754     String rfid = restoredFrame.getViewport().getSequenceSetId();
755     AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
756     AlignmentViewPanel rap = rAlignPanels[0];
757     AlignmentI rAlignment = rap.getAlignment();
758     System.out.println("blah");
759     SequenceI[] rseqs = rAlignment.getSequencesArray();
760     Assert.assertNotNull(rseqs[0]);
761     Assert.assertNotNull(rseqs[1]);
762     Assert.assertNotNull(rseqs[2]);
763     Assert.assertNotNull(rseqs[3]);
764     Assert.assertNotNull(rseqs[0].getDatasetSequence());
765     Assert.assertNotNull(rseqs[1].getDatasetSequence());
766     Assert.assertNotNull(rseqs[2].getDatasetSequence());
767     Assert.assertNotNull(rseqs[3].getDatasetSequence());
768
769     // The Asserts below are expected to fail until the PDB chainCode is
770     // recoverable from a Jalview projects
771     for (int chain = 0; chain < 4; chain++)
772     {
773       PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
774               .get(0);
775       PDBEntry expected = pdbEntries[chain];
776       Assert.assertEquals(recov.getId(), expected.getId(),
777               "Mismatch PDB ID");
778       Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
779               "Mismatch PDB ID");
780       Assert.assertEquals(recov.getType(), expected.getType(),
781               "Mismatch PDBEntry 'Type'");
782       Assert.assertNotNull(recov.getFile(),
783               "Recovered PDBEntry should have a non-null file entry");
784     }
785   }
786
787   /**
788    * Configure an alignment and a sub-group each with distinct colour schemes,
789    * Conservation and PID thresholds, and confirm these are restored from the
790    * saved project.
791    * 
792    * @throws IOException
793    */
794   @Test(groups = { "Functional" })
795   public void testStoreAndRecoverColourThresholds() throws IOException
796   {
797     Desktop.instance.closeAll_actionPerformed(null);
798     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
799             "examples/uniref50.fa", DataSourceType.FILE);
800
801     AlignViewport av = af.getViewport();
802     AlignmentI al = av.getAlignment();
803
804     /*
805      * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
806      */
807     af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
808     assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
809     af.abovePIDThreshold_actionPerformed(true);
810     SliderPanel sp = SliderPanel.getSliderPanel();
811     assertFalse(sp.isForConservation());
812     sp.valueChanged(10);
813     af.conservationMenuItem_actionPerformed(true);
814     sp = SliderPanel.getSliderPanel();
815     assertTrue(sp.isForConservation());
816     sp.valueChanged(20);
817     ResidueShaderI rs = av.getResidueShading();
818     assertEquals(rs.getThreshold(), 10);
819     assertTrue(rs.conservationApplied());
820     assertEquals(rs.getConservationInc(), 20);
821
822     /*
823      * create a group with Strand colouring, 30% Conservation
824      * and 40% PID threshold
825      */
826     SequenceGroup sg = new SequenceGroup();
827     sg.addSequence(al.getSequenceAt(0), false);
828     sg.setStartRes(15);
829     sg.setEndRes(25);
830     av.setSelectionGroup(sg);
831     PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
832     popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
833             .toString());
834     assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
835     assertEquals(al.getGroups().size(), 1);
836     assertSame(al.getGroups().get(0), sg);
837     popupMenu.conservationMenuItem_actionPerformed(true);
838     sp = SliderPanel.getSliderPanel();
839     assertTrue(sp.isForConservation());
840     sp.valueChanged(30);
841     popupMenu.abovePIDColour_actionPerformed(true);
842     sp = SliderPanel.getSliderPanel();
843     assertFalse(sp.isForConservation());
844     sp.valueChanged(40);
845     assertTrue(sg.getGroupColourScheme().conservationApplied());
846     assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
847     assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
848
849     /*
850      * save project, close windows, reload project, verify
851      */
852     File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
853             ".jvp");
854     tfile.deleteOnExit();
855     new Jalview2XML(false).saveState(tfile);
856     Desktop.instance.closeAll_actionPerformed(null);
857     af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
858             DataSourceType.FILE);
859     Assert.assertNotNull(af, "Failed to reload project");
860
861     /*
862      * verify alignment (background) colouring
863      */
864     rs = af.getViewport().getResidueShading();
865     assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
866     assertEquals(rs.getThreshold(), 10);
867     assertTrue(rs.conservationApplied());
868     assertEquals(rs.getConservationInc(), 20);
869
870     /*
871      * verify group colouring
872      */
873     assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
874     rs = af.getViewport().getAlignment().getGroups().get(0)
875             .getGroupColourScheme();
876     assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
877     assertEquals(rs.getThreshold(), 40);
878     assertTrue(rs.conservationApplied());
879     assertEquals(rs.getConservationInc(), 30);
880   }
881
882   /**
883    * Test save and reload of feature colour schemes and filter settings
884    * 
885    * @throws IOException
886    */
887   @Test(groups = { "Functional" })
888   public void testSaveLoadFeatureColoursAndFilters() throws IOException
889   {
890     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
891             ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
892     SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
893
894     /*
895      * add some features to the sequence
896      */
897     int score = 1;
898     addFeatures(seq1, "type1", score++);
899     addFeatures(seq1, "type2", score++);
900     addFeatures(seq1, "type3", score++);
901     addFeatures(seq1, "type4", score++);
902     addFeatures(seq1, "type5", score++);
903
904     /*
905      * set colour schemes for features
906      */
907     FeatureRenderer fr = af.getFeatureRenderer();
908     fr.findAllFeatures(true);
909
910     // type1: red
911     fr.setColour("type1", new FeatureColour(Color.red));
912
913     // type2: by label
914     FeatureColourI byLabel = new FeatureColour();
915     byLabel.setColourByLabel(true);
916     fr.setColour("type2", byLabel);
917
918     // type3: by score above threshold
919     FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1,
920             10);
921     byScore.setAboveThreshold(true);
922     byScore.setThreshold(2f);
923     fr.setColour("type3", byScore);
924
925     // type4: by attribute AF
926     FeatureColourI byAF = new FeatureColour();
927     byAF.setColourByLabel(true);
928     byAF.setAttributeName("AF");
929     fr.setColour("type4", byAF);
930
931     // type5: by attribute CSQ:PolyPhen below threshold
932     FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE,
933             1, 10);
934     byPolyPhen.setBelowThreshold(true);
935     byPolyPhen.setThreshold(3f);
936     byPolyPhen.setAttributeName("CSQ", "PolyPhen");
937     fr.setColour("type5", byPolyPhen);
938
939     /*
940      * set filters for feature types
941      */
942
943     // filter type1 features by (label contains "x")
944     FeatureMatcherSetI filterByX = new FeatureMatcherSet();
945     filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
946     fr.setFeatureFilter("type1", filterByX);
947
948     // filter type2 features by (score <= 2.4 and score > 1.1)
949     FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
950     filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
951     filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
952     fr.setFeatureFilter("type2", filterByScore);
953
954     // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
955     FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
956     filterByXY
957             .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
958     filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
959             "PolyPhen"));
960     fr.setFeatureFilter("type3", filterByXY);
961
962     /*
963      * save as Jalview project
964      */
965     File tfile = File.createTempFile("JalviewTest", ".jvp");
966     tfile.deleteOnExit();
967     String filePath = tfile.getAbsolutePath();
968     assertTrue(af.saveAlignment(filePath, FileFormat.Jalview),
969             "Failed to store as a project.");
970
971     /*
972      * close current alignment and load the saved project
973      */
974     af.closeMenuItem_actionPerformed(true);
975     af = null;
976     af = new FileLoader()
977             .LoadFileWaitTillLoaded(filePath, DataSourceType.FILE);
978     assertNotNull(af, "Failed to import new project");
979
980     /*
981      * verify restored feature colour schemes and filters
982      */
983     fr = af.getFeatureRenderer();
984     FeatureColourI fc = fr.getFeatureStyle("type1");
985     assertTrue(fc.isSimpleColour());
986     assertEquals(fc.getColour(), Color.red);
987     fc = fr.getFeatureStyle("type2");
988     assertTrue(fc.isColourByLabel());
989     fc = fr.getFeatureStyle("type3");
990     assertTrue(fc.isGraduatedColour());
991     assertNull(fc.getAttributeName());
992     assertTrue(fc.isAboveThreshold());
993     assertEquals(fc.getThreshold(), 2f);
994     fc = fr.getFeatureStyle("type4");
995     assertTrue(fc.isColourByLabel());
996     assertTrue(fc.isColourByAttribute());
997     assertEquals(fc.getAttributeName(), new String[] { "AF" });
998     fc = fr.getFeatureStyle("type5");
999     assertTrue(fc.isGraduatedColour());
1000     assertTrue(fc.isColourByAttribute());
1001     assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
1002     assertTrue(fc.isBelowThreshold());
1003     assertEquals(fc.getThreshold(), 3f);
1004
1005     assertEquals(fr.getFeatureFilter("type1").toStableString(),
1006             "Label Contains x");
1007     assertEquals(fr.getFeatureFilter("type2").toStableString(),
1008             "(Score LE 2.4) AND (Score GT 1.1)");
1009     assertEquals(fr.getFeatureFilter("type3").toStableString(),
1010             "(AF Contains X) OR (CSQ:PolyPhen NE 0.0)");
1011   }
1012
1013   private void addFeature(SequenceI seq, String featureType, int score)
1014   {
1015     SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
1016             score, "grp");
1017     sf.setValue("AF", score);
1018     sf.setValue("CSQ", new HashMap<String, String>()
1019     {
1020       {
1021         put("PolyPhen", Integer.toString(score));
1022       }
1023     });
1024     seq.addSequenceFeature(sf);
1025   }
1026
1027   /**
1028    * Adds two features of the given type to the given sequence, also setting the
1029    * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1030    * 
1031    * @param seq
1032    * @param featureType
1033    * @param score
1034    */
1035   private void addFeatures(SequenceI seq, String featureType, int score)
1036   {
1037     addFeature(seq, featureType, score++);
1038     addFeature(seq, featureType, score);
1039   }
1040
1041   /**
1042    * Test save and reload of a PCA viewer
1043    * 
1044    * @throws IOException
1045    */
1046   @Test(groups = { "Functional" })
1047   public void testSaveLoadPCA() throws IOException
1048   {
1049     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1050             "examples/uniref50.fa", DataSourceType.FILE);
1051     assertEquals(af.getViewport().getAlignment().getHeight(), 15);
1052
1053     /*
1054      * calculate and open PCA (calculates in a separate thread)
1055      */
1056     CalculationChooser chooser = new CalculationChooser(af);
1057     ((JRadioButton) PA.getValue(chooser, "pca")).setSelected(true);
1058     PA.invokeMethod(chooser, "calculate_actionPerformed()");
1059     PCAPanel pcaPanel = (PCAPanel) PA.getValue(chooser, "pcaPanel");
1060     assertNotNull(pcaPanel);
1061     waitFor(50); // let it get started!!
1062     while (pcaPanel.isWorking())
1063     {
1064       waitFor(50);
1065     }
1066     PA.invokeMethod(chooser, "close_actionPerformed()");
1067
1068     /*
1069      * rotate, zoom in, change background colour
1070      */
1071     RotatableCanvas rc = (RotatableCanvas) PA.getValue(pcaPanel, "rc");
1072     PA.setValue(rc, "bgColour", Color.PINK);
1073     rc.zoom(1.9f);
1074     rc.rotate(20, 40f);
1075
1076     /*
1077      * save as Jalview project
1078      */
1079     File tfile = File.createTempFile("JalviewTest", ".jvp");
1080     tfile.deleteOnExit();
1081     String filePath = tfile.getAbsolutePath();
1082     assertTrue(af.saveAlignment(filePath, FileFormat.Jalview),
1083             "Failed to store as a project.");
1084   
1085     /*
1086      * load the saved project and locate the restored PCA panel
1087      */
1088     new FileLoader().LoadFileWaitTillLoaded(filePath, DataSourceType.FILE);
1089     JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1090     PCAPanel pcaPanel2 = null;
1091     for (JInternalFrame frame : frames)
1092     {
1093       if (frame instanceof PCAPanel && frame != pcaPanel)
1094       {
1095         pcaPanel2 = (PCAPanel) frame;
1096       }
1097     }
1098     assertNotNull(pcaPanel2);
1099
1100     /*
1101      * compare restored and original PCA
1102      */
1103     PCAModel pcaModel = (PCAModel) PA.getValue(pcaPanel, "pcaModel");
1104     PCAModel pcaModel2 = (PCAModel) PA.getValue(pcaPanel2, "pcaModel");
1105     RotatableCanvas rc2 = (RotatableCanvas) PA.getValue(pcaPanel2, "rc");
1106     assertNotNull(pcaModel);
1107     assertNotNull(pcaModel2);
1108     assertNotNull(rc2);
1109     assertEquals(rc2.getBackgroundColour(), Color.PINK);
1110     assertEquals(PA.getValue(rc2, "scaleFactor"), 1.9f);
1111
1112     // original has input data
1113     assertNotNull(pcaModel.getInputData());
1114     // restored has no input data (JAL-2647 to do)
1115     assertNull(pcaModel2.getInputData());
1116
1117     // verify sequence points are at the same positions
1118     List<SequencePoint> seqPts = pcaModel.getSequencePoints();
1119     List<SequencePoint> seqPts2 = pcaModel2.getSequencePoints();
1120     assertEquals(seqPts.size(), seqPts2.size());
1121     for (int i = 0; i < seqPts.size(); i++)
1122     {
1123       SequencePoint sp = seqPts.get(i);
1124       SequencePoint sp2 = seqPts2.get(i);
1125       assertEquals(sp.getSequence().getName(), sp2.getSequence().getName());
1126       assertEquals(sp.coord, sp2.coord);
1127     }
1128
1129     // verify axis end points are at the same positions
1130     Point[] axes = (Point[]) PA.getValue(rc, "axisEndPoints");
1131     Point[] axes2 = (Point[]) PA.getValue(rc2, "axisEndPoints");
1132     assertEquals(axes.length, 3);
1133     assertEquals(axes2.length, 3);
1134     for (int i = 0; i < 3; i++)
1135     {
1136       assertEquals(axes[i], axes2[i]);
1137     }
1138
1139     // compare PCA data
1140     PCA pca = (PCA) PA.getValue(pcaModel, "pca");
1141     PCA pca2 = (PCA) PA.getValue(pcaModel2, "pca");
1142     assertNotNull(pca);
1143     assertNotNull(pca2);
1144     // same (BLOSUM62) score model (a singleton object)
1145     assertSame(PA.getValue(pca, "scoreModel"),
1146             PA.getValue(pca2, "scoreModel"));
1147     assertEquals(PA.getValue(pca, "similarityParams"),
1148             PA.getValue(pca2, "similarityParams"));
1149     MatrixTest.assertMatricesMatch(pca.getPairwiseScores(),
1150             pca2.getPairwiseScores());
1151     MatrixTest.assertMatricesMatch(pca.getTridiagonal(),
1152             pca2.getTridiagonal());
1153     MatrixTest.assertMatricesMatch(pca.getEigenmatrix(),
1154             pca2.getEigenmatrix());
1155   }
1156
1157   protected void waitFor(long t)
1158   {
1159     synchronized (this)
1160     {
1161       try
1162       {
1163         wait(t);
1164       } catch (InterruptedException e)
1165       {
1166         fail(e.getMessage());
1167       }
1168     }
1169   }
1170 }