2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.project;
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;
31 import java.awt.Color;
32 import java.awt.Rectangle;
34 import java.io.IOException;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Locale;
41 import javax.swing.JInternalFrame;
43 import org.testng.Assert;
44 import org.testng.AssertJUnit;
45 import org.testng.annotations.BeforeClass;
46 import org.testng.annotations.Test;
48 import jalview.analysis.scoremodels.SimilarityParams;
49 import jalview.api.AlignViewportI;
50 import jalview.api.AlignmentViewPanel;
51 import jalview.api.FeatureColourI;
52 import jalview.api.ViewStyleI;
53 import jalview.bin.Cache;
54 import jalview.datamodel.AlignmentAnnotation;
55 import jalview.datamodel.AlignmentI;
56 import jalview.datamodel.Annotation;
57 import jalview.datamodel.DBRefEntry;
58 import jalview.datamodel.GeneLocus;
59 import jalview.datamodel.HiddenSequences;
60 import jalview.datamodel.Mapping;
61 import jalview.datamodel.PDBEntry;
62 import jalview.datamodel.PDBEntry.Type;
63 import jalview.datamodel.Sequence.DBModList;
64 import jalview.datamodel.SequenceCollectionI;
65 import jalview.datamodel.SequenceFeature;
66 import jalview.datamodel.SequenceGroup;
67 import jalview.datamodel.SequenceI;
68 import jalview.datamodel.features.FeatureMatcher;
69 import jalview.datamodel.features.FeatureMatcherSet;
70 import jalview.datamodel.features.FeatureMatcherSetI;
71 import jalview.gui.AlignFrame;
72 import jalview.gui.AlignViewport;
73 import jalview.gui.AlignmentPanel;
74 import jalview.gui.Desktop;
75 import jalview.gui.JvOptionPane;
76 import jalview.gui.OverviewPanel;
77 import jalview.gui.PCAPanel;
78 import jalview.gui.PopupMenu;
79 import jalview.gui.Preferences;
80 import jalview.gui.SliderPanel;
81 import jalview.io.DataSourceType;
82 import jalview.io.FileFormat;
83 import jalview.io.FileLoader;
84 import jalview.io.Jalview2xmlBase;
85 import jalview.renderer.ResidueShaderI;
86 import jalview.schemes.AnnotationColourGradient;
87 import jalview.schemes.BuriedColourScheme;
88 import jalview.schemes.ColourSchemeI;
89 import jalview.schemes.ColourSchemeProperty;
90 import jalview.schemes.FeatureColour;
91 import jalview.schemes.JalviewColourScheme;
92 import jalview.schemes.RNAHelicesColour;
93 import jalview.schemes.StrandColourScheme;
94 import jalview.schemes.TCoffeeColourScheme;
95 import jalview.structure.StructureImportSettings;
96 import jalview.util.MapList;
97 import jalview.util.matcher.Condition;
98 import jalview.viewmodel.AlignmentViewport;
99 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
101 @Test(singleThreaded = true)
102 public class Jalview2xmlTests extends Jalview2xmlBase
106 @BeforeClass(alwaysRun = true)
107 public void setUpJvOptionPane()
109 JvOptionPane.setInteractiveMode(false);
110 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
113 @Test(groups = { "Functional" })
114 public void testRNAStructureRecovery() throws Exception
116 String inFile = "examples/RF00031_folded.stk";
117 String tfile = File.createTempFile("JalviewTest", ".jvp")
119 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
120 DataSourceType.FILE);
121 assertNotNull(af, "Didn't read input file " + inFile);
122 int olddsann = countDsAnn(af.getViewport());
123 assertTrue(olddsann > 0, "Didn't find any dataset annotations");
124 af.changeColour_actionPerformed(
125 JalviewColourScheme.RNAHelices.toString());
128 .getGlobalColourScheme() instanceof RNAHelicesColour,
129 "Couldn't apply RNA helices colourscheme");
130 af.saveAlignment(tfile, FileFormat.Jalview);
131 assertTrue(af.isSaveAlignmentSuccessful(),
132 "Failed to store as a project.");
133 af.closeMenuItem_actionPerformed(true);
135 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
136 DataSourceType.FILE);
137 assertNotNull(af, "Failed to import new project");
138 int newdsann = countDsAnn(af.getViewport());
139 assertEquals(olddsann, newdsann,
140 "Differing numbers of dataset sequence annotation\nOriginally "
141 + olddsann + " and now " + newdsann);
143 "Read in same number of annotations as originally present ("
148 .getGlobalColourScheme() instanceof RNAHelicesColour,
149 "RNA helices colourscheme was not applied on import.");
152 @Test(groups = { "Functional" })
153 public void testTCoffeeScores() throws Exception
155 String inFile = "examples/uniref50.fa",
156 inAnnot = "examples/uniref50.score_ascii";
157 String tfile = File.createTempFile("JalviewTest", ".jvp")
159 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
160 DataSourceType.FILE);
161 assertNotNull(af, "Didn't read input file " + inFile);
162 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
163 AlignViewport viewport = af.getViewport();
164 assertSame(viewport.getGlobalColourScheme().getClass(),
165 TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
167 ColourSchemeProperty.getColourScheme(viewport,
168 viewport.getAlignment(),
169 viewport.getGlobalColourScheme().getSchemeName()),
170 "Recognise T-Coffee score from string");
172 af.saveAlignment(tfile, FileFormat.Jalview);
173 assertTrue(af.isSaveAlignmentSuccessful(),
174 "Failed to store as a project.");
175 af.closeMenuItem_actionPerformed(true);
177 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
178 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.");
184 "T-Coffee score shading successfully recovered from project.");
187 @Test(groups = { "Functional" })
188 public void testColourByAnnotScores() throws Exception
190 String inFile = "examples/uniref50.fa",
191 inAnnot = "examples/testdata/uniref50_iupred.jva";
192 String tfile = File.createTempFile("JalviewTest", ".jvp")
194 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
195 DataSourceType.FILE);
196 assertNotNull(af, "Didn't read input file " + inFile);
197 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
198 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
199 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
202 aa != null && aa.length > 0,
203 "Didn't find any IUPred annotation to use to shade alignment.");
204 AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
205 AnnotationColourGradient.ABOVE_THRESHOLD);
206 AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0], null,
207 AnnotationColourGradient.BELOW_THRESHOLD);
208 cs.setSeqAssociated(true);
209 gcs.setSeqAssociated(true);
211 SequenceGroup sg = new SequenceGroup();
214 sg.cs.setColourScheme(gcs);
215 af.getViewport().getAlignment().addGroup(sg);
216 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
217 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
218 af.alignPanel.alignmentChanged();
219 af.saveAlignment(tfile, FileFormat.Jalview);
220 assertTrue(af.isSaveAlignmentSuccessful(),
221 "Failed to store as a project.");
222 af.closeMenuItem_actionPerformed(true);
224 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
225 DataSourceType.FILE);
226 assertNotNull(af, "Failed to import new project");
228 // check for group and alignment colourschemes
230 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
231 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups().get(0)
233 assertNotNull(_rcs, "Didn't recover global colourscheme");
234 assertTrue(_rcs instanceof AnnotationColourGradient,
235 "Didn't recover annotation colour global scheme");
236 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
237 assertTrue(__rcs.isSeqAssociated(),
238 "Annotation colourscheme wasn't sequence associated");
240 boolean diffseqcols = false, diffgseqcols = false;
241 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
243 pSize = af.getViewport().getAlignment().getWidth(); p < pSize
244 && (!diffseqcols || !diffgseqcols); p++)
246 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
247 .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
252 assertTrue(diffseqcols, "Got Different sequence colours");
254 "Per sequence colourscheme (Background) successfully applied and recovered.");
256 assertNotNull(_rgcs, "Didn't recover group colourscheme");
257 assertTrue(_rgcs instanceof AnnotationColourGradient,
258 "Didn't recover annotation colour group colourscheme");
259 __rcs = (AnnotationColourGradient) _rgcs;
260 assertTrue(__rcs.isSeqAssociated(),
261 "Group Annotation colourscheme wasn't sequence associated");
264 pSize = af.getViewport().getAlignment().getWidth(); p < pSize
265 && (!diffseqcols || !diffgseqcols); p++)
267 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null,
268 0f) != _rgcs.findColour(sqs[2].getCharAt(p), p, sqs[2], null,
274 assertTrue(diffgseqcols, "Got Different group sequence colours");
276 "Per sequence (Group) colourscheme successfully applied and recovered.");
279 @Test(groups = { "Functional" })
280 public void gatherViewsHere() throws Exception
282 int origCount = Desktop.getAlignFrames() == null ? 0
283 : Desktop.getAlignFrames().length;
284 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
285 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
286 assertNotNull(af, "Didn't read in the example file correctly.");
287 assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
288 "Didn't gather the views in the example file.");
293 * Test for JAL-2223 - multiple mappings in View Mapping report
297 @Test(groups = { "Functional" })
298 public void noDuplicatePdbMappingsMade() throws Exception
300 StructureImportSettings.setProcessSecondaryStructure(true);
301 StructureImportSettings.setVisibleChainAnnotation(true);
302 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
303 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
304 assertNotNull(af, "Didn't read in the example file correctly.");
306 // locate Jmol viewer
307 // count number of PDB mappings the structure selection manager holds -
308 String pdbFile = af.getCurrentView().getStructureSelectionManager()
309 .findFileForPDBId("1A70");
311 af.getCurrentView().getStructureSelectionManager()
312 .getMapping(pdbFile).length,
313 2, "Expected only two mappings for 1A70");
317 @Test(groups = { "Functional" })
318 public void viewRefPdbAnnotation() throws Exception
320 StructureImportSettings.setProcessSecondaryStructure(true);
321 StructureImportSettings.setVisibleChainAnnotation(true);
322 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
323 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
324 assertNotNull(af, "Didn't read in the example file correctly.");
325 AlignmentViewPanel sps = null;
326 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
328 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
334 assertNotNull(sps, "Couldn't find the structure view");
335 AlignmentAnnotation refan = null;
336 for (AlignmentAnnotation ra : sps.getAlignment()
337 .getAlignmentAnnotation())
345 assertNotNull(refan, "Annotation secondary structure not found.");
346 SequenceI sq = sps.getAlignment().findName("1A70|");
347 assertNotNull(sq, "Couldn't find 1a70 null chain");
348 // compare the manually added temperature factor annotation
349 // to the track automatically transferred from the pdb structure on load
350 assertNotNull(sq.getDatasetSequence().getAnnotation(),
351 "1a70 has no annotation");
352 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
354 AlignmentAnnotation alaa;
355 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
356 alaa.adjustForAlignment();
357 if (ala.graph == refan.graph)
359 for (int p = 0; p < ala.annotations.length; p++)
364 assertTrue((alaa.annotations[p] == null
365 && refan.annotations[p] == null)
366 || alaa.annotations[p].value == refan.annotations[p].value,
367 "Mismatch at alignment position " + p);
368 } catch (NullPointerException q)
370 Assert.fail("Mismatch of alignment annotations at position " + p
371 + " Ref seq ann: " + refan.annotations[p]
372 + " alignment " + alaa.annotations[p]);
380 @Test(groups = { "Functional" })
381 public void testCopyViewSettings() throws Exception
383 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
384 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
385 assertNotNull(af, "Didn't read in the example file correctly.");
386 AlignmentViewPanel sps = null, groups = null;
387 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
389 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
393 if (ap.getViewName().contains("MAFFT"))
398 assertNotNull(sps, "Couldn't find the structure view");
399 assertNotNull(groups, "Couldn't find the MAFFT view");
401 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
402 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
403 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
405 groups.getAlignViewport().setViewStyle(structureStyle);
406 AssertJUnit.assertFalse(
407 groupStyle.sameStyle(groups.getAlignViewport().getViewStyle()));
408 Assert.assertTrue(structureStyle
409 .sameStyle(groups.getAlignViewport().getViewStyle()));
414 * test store and recovery of expanded views
418 @Test(groups = { "Functional" }, enabled = true)
419 public void testStoreAndRecoverExpandedviews() throws Exception
421 Desktop.instance.closeAll_actionPerformed(null);
423 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
424 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
425 Assert.assertEquals(Desktop.getAlignFrames().length, 1);
426 String afid = af.getViewport().getSequenceSetId();
428 // check FileLoader returned a reference to the one alignFrame that is
429 // actually on the Desktop
430 assertSame(af, Desktop.getAlignFrameFor(af.getViewport()),
431 "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
433 Desktop.explodeViews(af);
435 int oldviews = Desktop.getAlignFrames().length;
436 Assert.assertEquals(Desktop.getAlignFrames().length,
437 Desktop.getAlignmentPanels(afid).length);
438 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
441 new Jalview2XML(false).saveState(tfile);
444 Assert.fail("Didn't save the expanded view state", e);
445 } catch (Exception e)
447 Assert.fail("Didn't save the expanded view state", e);
449 Desktop.instance.closeAll_actionPerformed(null);
450 if (Desktop.getAlignFrames() != null)
452 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
454 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
455 DataSourceType.FILE);
456 Assert.assertNotNull(af);
457 Assert.assertEquals(Desktop.getAlignFrames().length,
458 Desktop.getAlignmentPanels(
459 af.getViewport().getSequenceSetId()).length);
460 Assert.assertEquals(Desktop
461 .getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
466 * Test save and reload of a project with a different representative sequence
471 @Test(groups = { "Functional" })
472 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
474 Desktop.instance.closeAll_actionPerformed(null);
475 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
476 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
477 assertNotNull(af, "Didn't read in the example file correctly.");
478 String afid = af.getViewport().getSequenceSetId();
480 // remember reference sequence for each panel
481 Map<String, SequenceI> refseqs = new HashMap<>();
484 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
485 * as reference sequence for itself and the preceding sequence
488 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
490 AlignViewportI av = ap.getAlignViewport();
491 AlignmentI alignment = ap.getAlignment();
492 int repIndex = n % alignment.getHeight();
493 SequenceI rep = alignment.getSequenceAt(repIndex);
494 refseqs.put(ap.getViewName(), rep);
496 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
497 // todo refactor this to an alignment view controller
498 av.setDisplayReferenceSeq(true);
499 av.setColourByReferenceSeq(true);
500 av.getAlignment().setSeqrep(rep);
504 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
508 new Jalview2XML(false).saveState(tfile);
509 } catch (Throwable e)
511 Assert.fail("Didn't save the expanded view state", e);
513 Desktop.instance.closeAll_actionPerformed(null);
514 if (Desktop.getAlignFrames() != null)
516 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
519 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
520 DataSourceType.FILE);
521 afid = af.getViewport().getSequenceSetId();
523 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
525 // check representative
526 AlignmentI alignment = ap.getAlignment();
527 SequenceI rep = alignment.getSeqrep();
528 Assert.assertNotNull(rep,
529 "Couldn't restore sequence representative from project");
530 // can't use a strong equals here, because by definition, the sequence IDs
531 // will be different.
532 // could set vamsas session save/restore flag to preserve IDs across
534 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
536 "Representative wasn't the same when recovered.");
537 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
538 "Display reference sequence view setting not set.");
539 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
540 "Colour By Reference Seq view setting not set.");
544 @Test(groups = { "Functional" })
545 public void testIsVersionStringLaterThan()
548 * No version / development / test / autobuild is leniently assumed to be
551 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
552 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
553 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
554 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
555 "Development Build"));
556 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
557 "DEVELOPMENT BUILD"));
558 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
559 "Development Build"));
560 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
561 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
562 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
564 Jalview2XML.isVersionStringLaterThan(null, "Automated Build"));
565 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
567 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
571 * same version returns true i.e. compatible
573 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
574 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
575 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
576 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
577 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
580 * later version returns true
582 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
583 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
584 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
585 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
586 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
589 * earlier version returns false
591 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
592 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
593 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
594 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
595 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
597 * test for patch release versions
599 assertFalse(Jalview2XML.isVersionStringLaterThan("2.11.3.0", "2.11.2"));
600 assertTrue(Jalview2XML.isVersionStringLaterThan("2.11.3.0","2.11.4"));
601 assertFalse(Jalview2XML.isVersionStringLaterThan("2.12.2.0b1","2.12.2.0"));
602 assertFalse(Jalview2XML.isVersionStringLaterThan("2.12.2.3","2.12.2.2"));
607 * Test save and reload of a project with a different sequence group (and
608 * representative sequence) in each view.
612 @Test(groups = { "Functional" })
613 public void testStoreAndRecoverGroupRepSeqs() throws Exception
615 Desktop.instance.closeAll_actionPerformed(null);
616 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
617 "examples/uniref50.fa", DataSourceType.FILE);
618 assertNotNull(af, "Didn't read in the example file correctly.");
619 String afid = af.getViewport().getSequenceSetId();
620 // make a second view of the alignment
621 af.newView_actionPerformed(null);
624 * remember representative and hidden sequences marked
627 Map<String, SequenceI> repSeqs = new HashMap<>();
628 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
631 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
632 * as reference sequence for itself and the preceding sequence
635 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
637 AlignViewportI av = ap.getAlignViewport();
638 AlignmentI alignment = ap.getAlignment();
639 int repIndex = n % alignment.getHeight();
640 // ensure at least one preceding sequence i.e. index >= 1
641 repIndex = Math.max(repIndex, 1);
642 SequenceI repSeq = alignment.getSequenceAt(repIndex);
643 repSeqs.put(ap.getViewName(), repSeq);
644 List<String> hiddenNames = new ArrayList<>();
645 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
648 * have rep sequence represent itself and the one before it
649 * this hides the group (except for the rep seq)
651 SequenceGroup sg = new SequenceGroup();
652 sg.addSequence(repSeq, false);
653 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
654 sg.addSequence(precedingSeq, false);
655 sg.setSeqrep(repSeq);
656 assertTrue(sg.getSequences().contains(repSeq));
657 assertTrue(sg.getSequences().contains(precedingSeq));
658 av.setSelectionGroup(sg);
659 assertSame(repSeq, sg.getSeqrep());
662 * represent group with sequence adds to a map of hidden rep sequences
663 * (it does not create a group on the alignment)
665 ((AlignmentViewport) av).hideSequences(repSeq, true);
666 assertSame(repSeq, sg.getSeqrep());
667 assertTrue(sg.getSequences().contains(repSeq));
668 assertTrue(sg.getSequences().contains(precedingSeq));
669 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
670 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
671 .getHiddenRepSequences();
672 assertNotNull(hiddenRepSeqsMap);
673 assertEquals(1, hiddenRepSeqsMap.size());
674 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
675 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
676 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
677 hiddenNames.add(precedingSeq.getName());
681 File tfile = File.createTempFile("testStoreAndRecoverGroupReps",
685 new Jalview2XML(false).saveState(tfile);
686 } catch (Throwable e)
688 Assert.fail("Didn't save the expanded view state", e);
690 Desktop.instance.closeAll_actionPerformed(null);
691 if (Desktop.getAlignFrames() != null)
693 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
696 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
697 DataSourceType.FILE);
698 afid = af.getViewport().getSequenceSetId();
700 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
702 String viewName = ap.getViewName();
703 AlignViewportI av = ap.getAlignViewport();
704 AlignmentI alignment = ap.getAlignment();
705 List<SequenceGroup> groups = alignment.getGroups();
706 assertNotNull(groups);
707 assertTrue(groups.isEmpty(), "Alignment has groups");
708 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
709 .getHiddenRepSequences();
710 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
711 assertEquals(1, hiddenRepSeqsMap.size());
712 assertEquals(repSeqs.get(viewName).getDisplayId(true),
713 hiddenRepSeqsMap.keySet().iterator().next()
714 .getDisplayId(true));
717 * verify hidden sequences in restored panel
719 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
720 HiddenSequences hs = alignment.getHiddenSequences();
721 assertEquals(hidden.size(), hs.getSize(),
722 "wrong number of restored hidden sequences in "
728 * Test save and reload of PDBEntry in Jalview project
732 @Test(groups = { "Functional" })
733 public void testStoreAndRecoverPDBEntry() throws Exception
735 Desktop.instance.closeAll_actionPerformed(null);
736 String exampleFile = "examples/3W5V.pdb";
737 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
738 DataSourceType.FILE);
739 assertNotNull(af, "Didn't read in the example file correctly.");
740 String afid = af.getViewport().getSequenceSetId();
742 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
743 System.out.println();
744 AlignmentViewPanel ap = alignPanels[0];
745 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
746 String testFile = tfileBase + exampleFile;
747 AlignmentI alignment = ap.getAlignment();
748 System.out.println("blah");
749 SequenceI[] seqs = alignment.getSequencesArray();
750 Assert.assertNotNull(seqs[0]);
751 Assert.assertNotNull(seqs[1]);
752 Assert.assertNotNull(seqs[2]);
753 Assert.assertNotNull(seqs[3]);
754 Assert.assertNotNull(seqs[0].getDatasetSequence());
755 Assert.assertNotNull(seqs[1].getDatasetSequence());
756 Assert.assertNotNull(seqs[2].getDatasetSequence());
757 Assert.assertNotNull(seqs[3].getDatasetSequence());
758 PDBEntry[] pdbEntries = new PDBEntry[4];
759 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
760 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
761 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
762 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
764 seqs[0].getDatasetSequence().getAllPDBEntries().get(0),
767 seqs[1].getDatasetSequence().getAllPDBEntries().get(0),
770 seqs[2].getDatasetSequence().getAllPDBEntries().get(0),
773 seqs[3].getDatasetSequence().getAllPDBEntries().get(0),
776 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
779 new Jalview2XML(false).saveState(tfile);
780 } catch (Throwable e)
782 Assert.fail("Didn't save the state", e);
784 Desktop.instance.closeAll_actionPerformed(null);
785 if (Desktop.getAlignFrames() != null)
787 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
790 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
791 tfile.getAbsolutePath(), DataSourceType.FILE);
792 String rfid = restoredFrame.getViewport().getSequenceSetId();
793 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
794 AlignmentViewPanel rap = rAlignPanels[0];
795 AlignmentI rAlignment = rap.getAlignment();
796 System.out.println("blah");
797 SequenceI[] rseqs = rAlignment.getSequencesArray();
798 Assert.assertNotNull(rseqs[0]);
799 Assert.assertNotNull(rseqs[1]);
800 Assert.assertNotNull(rseqs[2]);
801 Assert.assertNotNull(rseqs[3]);
802 Assert.assertNotNull(rseqs[0].getDatasetSequence());
803 Assert.assertNotNull(rseqs[1].getDatasetSequence());
804 Assert.assertNotNull(rseqs[2].getDatasetSequence());
805 Assert.assertNotNull(rseqs[3].getDatasetSequence());
807 // The Asserts below are expected to fail until the PDB chainCode is
808 // recoverable from a Jalview projects
809 for (int chain = 0; chain < 4; chain++)
811 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
813 PDBEntry expected = pdbEntries[chain];
814 Assert.assertEquals(recov.getId(), expected.getId(),
816 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
818 Assert.assertEquals(recov.getType(), expected.getType(),
819 "Mismatch PDBEntry 'Type'");
820 Assert.assertNotNull(recov.getFile(),
821 "Recovered PDBEntry should have a non-null file entry");
823 recov.getFile().toLowerCase(Locale.ENGLISH)
825 recov.getFile().length() - 3,
826 "Recovered PDBEntry file should have PDB suffix");
831 * Configure an alignment and a sub-group each with distinct colour schemes,
832 * Conservation and PID thresholds, and confirm these are restored from the
835 * @throws IOException
837 @Test(groups = { "Functional" })
838 public void testStoreAndRecoverAnnotationRowElementColours()
841 Desktop.instance.closeAll_actionPerformed(null);
842 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded("SEQ\tMNQ",
843 DataSourceType.PASTE);
845 AlignViewport av = af.getViewport();
846 AlignmentI al = av.getAlignment();
848 fsq = al.getSequenceAt(0);
849 Annotation annots[] = new Annotation[fsq.getLength()];
850 AlignmentAnnotation ala = new AlignmentAnnotation("Colour", "Annots",
852 annots[0] = new Annotation(1.0f);
853 annots[1] = new Annotation(2.0f);
854 annots[2] = new Annotation(3.0f);
855 annots[0].colour = Color.RED;
856 annots[1].colour = Color.GREEN;
857 annots[2].colour = Color.BLUE;
858 ala.validateRangeAndDisplay();
859 al.getSequenceAt(0).addAlignmentAnnotation(ala);
860 al.addAnnotation(ala);
862 * and colour by annotation
864 AnnotationColourGradient acg = new AnnotationColourGradient(ala,
865 af.alignPanel.av.getGlobalColourScheme(), 0);
866 acg.setSeqAssociated(true);
867 acg.setPredefinedColours(true);
868 af.changeColour(acg);
869 Color seqcol[] = new Color[3];
870 for (int iStart=fsq.findIndex(fsq.getStart()),i=0;i<3;i++) {
871 seqcol[i] = af.alignPanel.getSeqPanel().seqCanvas.getSequenceRenderer().getResidueColour(fsq, iStart+i, null);
874 * save project, close windows, reload project, verify
876 File tfile = File.createTempFile(
877 "testStoreAndRecoverAnnotRowElemColors", ".jvp");
878 tfile.deleteOnExit();
879 new Jalview2XML(false).saveState(tfile);
880 //Desktop.instance.closeAll_actionPerformed(null);
881 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
882 DataSourceType.FILE);
883 Assert.assertNotNull(af, "Failed to reload project");
885 * verify alignment annotation has colors
887 av = af.getViewport();
889 ColourSchemeI loadedCscheme = av.getGlobalColourScheme();
890 Assert.assertTrue(loadedCscheme instanceof AnnotationColourGradient,"Didn't apply Annotation colour gradient");
891 acg = (AnnotationColourGradient) loadedCscheme;
892 assertTrue(acg.isSeqAssociated());
893 assertTrue(acg.isPredefinedColours());
895 al = av.getAlignment();
896 fsq = al.getSequenceAt(0);
897 ala = fsq.getAnnotation()[0];
898 Assert.assertNotNull(ala, "No annotation row recovered");
899 Assert.assertNotNull(ala.annotations);
900 for (int iStart = al.getSequenceAt(0)
901 .findIndex(al.getSequenceAt(0).getStart()), i = 0; i < 3; i++)
903 Assert.assertTrue(ala.annotations[i].colour!=null);
904 Assert.assertTrue(ala.annotations[i].colour.equals(annots[i].colour));
905 Color newseqcol = af.alignPanel.getSeqPanel().seqCanvas.getSequenceRenderer().getResidueColour(fsq, iStart+i, null);
906 Assert.assertTrue(seqcol[i].equals(newseqcol),"Sequence shading is different");
913 * Configure an alignment and a sub-group each with distinct colour schemes,
914 * Conservation and PID thresholds, and confirm these are restored from the
917 * @throws IOException
919 @Test(groups = { "Functional" })
920 public void testStoreAndRecoverColourThresholds() throws IOException
922 Desktop.instance.closeAll_actionPerformed(null);
923 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
924 "examples/uniref50.fa", DataSourceType.FILE);
926 AlignViewport av = af.getViewport();
927 AlignmentI al = av.getAlignment();
930 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
932 av.setColourAppliesToAllGroups(false);
933 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
934 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
935 af.abovePIDThreshold_actionPerformed(true);
936 SliderPanel sp = SliderPanel.getSliderPanel();
937 assertFalse(sp.isForConservation());
939 af.conservationMenuItem_actionPerformed(true);
940 sp = SliderPanel.getSliderPanel();
941 assertTrue(sp.isForConservation());
943 ResidueShaderI rs = av.getResidueShading();
944 assertEquals(rs.getThreshold(), 10);
945 assertTrue(rs.conservationApplied());
946 assertEquals(rs.getConservationInc(), 20);
949 * create a group with Strand colouring, 30% Conservation
950 * and 40% PID threshold
951 * (notice menu action applies to selection group even if mouse click
952 * is at a sequence not in the group)
954 SequenceGroup sg = new SequenceGroup();
955 sg.addSequence(al.getSequenceAt(0), false);
958 av.setSelectionGroup(sg);
959 PopupMenu popupMenu = new PopupMenu(af.alignPanel, al.getSequenceAt(2),
961 popupMenu.changeColour_actionPerformed(
962 JalviewColourScheme.Strand.toString());
963 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
964 assertEquals(al.getGroups().size(), 1);
965 assertSame(al.getGroups().get(0), sg);
966 popupMenu.conservationMenuItem_actionPerformed(true);
967 sp = SliderPanel.getSliderPanel();
968 assertTrue(sp.isForConservation());
970 popupMenu.abovePIDColour_actionPerformed(true);
971 sp = SliderPanel.getSliderPanel();
972 assertFalse(sp.isForConservation());
974 assertTrue(sg.getGroupColourScheme().conservationApplied());
975 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
976 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
979 * save project, close windows, reload project, verify
981 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
983 tfile.deleteOnExit();
984 new Jalview2XML(false).saveState(tfile);
985 Desktop.instance.closeAll_actionPerformed(null);
986 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
987 DataSourceType.FILE);
988 Assert.assertNotNull(af, "Failed to reload project");
991 * verify alignment (background) colouring
993 rs = af.getViewport().getResidueShading();
994 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
995 assertEquals(rs.getThreshold(), 10);
996 assertTrue(rs.conservationApplied());
997 assertEquals(rs.getConservationInc(), 20);
1000 * verify group colouring
1002 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
1003 rs = af.getViewport().getAlignment().getGroups().get(0)
1004 .getGroupColourScheme();
1005 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
1006 assertEquals(rs.getThreshold(), 40);
1007 assertTrue(rs.conservationApplied());
1008 assertEquals(rs.getConservationInc(), 30);
1012 * Test save and reload of feature colour schemes and filter settings
1014 * @throws IOException
1016 @Test(groups = { "Functional" })
1017 public void testSaveLoadFeatureColoursAndFilters() throws IOException
1019 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1020 ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
1021 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
1024 * add some features to the sequence
1027 addFeatures(seq1, "type1", score++);
1028 addFeatures(seq1, "type2", score++);
1029 addFeatures(seq1, "type3", score++);
1030 addFeatures(seq1, "type4", score++);
1031 addFeatures(seq1, "type5", score++);
1034 * set colour schemes for features
1036 FeatureRendererModel fr = af.getFeatureRenderer();
1037 fr.findAllFeatures(true);
1040 fr.setColour("type1", new FeatureColour(Color.red));
1043 FeatureColourI byLabel = new FeatureColour();
1044 byLabel.setColourByLabel(true);
1045 fr.setColour("type2", byLabel);
1047 // type3: by score above threshold
1048 FeatureColourI byScore = new FeatureColour(null, Color.BLACK,
1049 Color.BLUE, null, 1, 10);
1050 byScore.setAboveThreshold(true);
1051 byScore.setThreshold(2f);
1052 fr.setColour("type3", byScore);
1054 // type4: by attribute AF
1055 FeatureColourI byAF = new FeatureColour();
1056 byAF.setColourByLabel(true);
1057 byAF.setAttributeName("AF");
1058 fr.setColour("type4", byAF);
1060 // type5: by attribute CSQ:PolyPhen below threshold
1061 FeatureColourI byPolyPhen = new FeatureColour(null, Color.BLACK,
1062 Color.BLUE, null, 1, 10);
1063 byPolyPhen.setBelowThreshold(true);
1064 byPolyPhen.setThreshold(3f);
1065 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
1066 fr.setColour("type5", byPolyPhen);
1069 * set filters for feature types
1072 // filter type1 features by (label contains "x")
1073 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
1074 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
1075 fr.setFeatureFilter("type1", filterByX);
1077 // filter type2 features by (score <= 2.4 and score > 1.1)
1078 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
1079 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
1080 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
1081 fr.setFeatureFilter("type2", filterByScore);
1083 // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
1084 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
1086 .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
1087 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
1089 fr.setFeatureFilter("type3", filterByXY);
1092 * save as Jalview project
1094 File tfile = File.createTempFile("JalviewTest", ".jvp");
1095 tfile.deleteOnExit();
1096 String filePath = tfile.getAbsolutePath();
1097 af.saveAlignment(filePath, FileFormat.Jalview);
1098 assertTrue(af.isSaveAlignmentSuccessful(),
1099 "Failed to store as a project.");
1102 * close current alignment and load the saved project
1104 af.closeMenuItem_actionPerformed(true);
1106 af = new FileLoader().LoadFileWaitTillLoaded(filePath,
1107 DataSourceType.FILE);
1108 assertNotNull(af, "Failed to import new project");
1111 * verify restored feature colour schemes and filters
1113 fr = af.getFeatureRenderer();
1114 FeatureColourI fc = fr.getFeatureStyle("type1");
1115 assertTrue(fc.isSimpleColour());
1116 assertEquals(fc.getColour(), Color.red);
1117 fc = fr.getFeatureStyle("type2");
1118 assertTrue(fc.isColourByLabel());
1119 fc = fr.getFeatureStyle("type3");
1120 assertTrue(fc.isGraduatedColour());
1121 assertNull(fc.getAttributeName());
1122 assertTrue(fc.isAboveThreshold());
1123 assertEquals(fc.getThreshold(), 2f);
1124 fc = fr.getFeatureStyle("type4");
1125 assertTrue(fc.isColourByLabel());
1126 assertTrue(fc.isColourByAttribute());
1127 assertEquals(fc.getAttributeName(), new String[] { "AF" });
1128 fc = fr.getFeatureStyle("type5");
1129 assertTrue(fc.isGraduatedColour());
1130 assertTrue(fc.isColourByAttribute());
1131 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
1132 assertTrue(fc.isBelowThreshold());
1133 assertEquals(fc.getThreshold(), 3f);
1135 assertEquals(fr.getFeatureFilter("type1").toStableString(),
1136 "Label Contains x");
1137 assertEquals(fr.getFeatureFilter("type2").toStableString(),
1138 "(Score LE 2.4) AND (Score GT 1.1)");
1139 assertEquals(fr.getFeatureFilter("type3").toStableString(),
1140 "(AF Contains X) OR (CSQ:PolyPhen NE 0)");
1143 private void addFeature(SequenceI seq, String featureType, int score)
1145 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
1147 sf.setValue("AF", score);
1148 sf.setValue("CSQ", new HashMap<String, String>()
1151 put("PolyPhen", Integer.toString(score));
1154 seq.addSequenceFeature(sf);
1158 * Adds two features of the given type to the given sequence, also setting the
1159 * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1162 * @param featureType
1165 private void addFeatures(SequenceI seq, String featureType, int score)
1167 addFeature(seq, featureType, score++);
1168 addFeature(seq, featureType, score);
1172 * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
1173 * view (JAL-3171) this test ensures we can import and merge those views
1175 @Test(groups = { "Functional" })
1176 public void testMergeDatasetsforViews() throws IOException
1178 // simple project - two views on one alignment
1179 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
1180 "examples/testdata/projects/twoViews.jvp", DataSourceType.FILE);
1182 assertTrue(af.getAlignPanels().size() > 1);
1187 * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
1188 * view (JAL-3171) this test ensures we can import and merge those views This
1189 * is a more complex project
1191 @Test(groups = { "Functional" })
1192 public void testMergeDatasetsforManyViews() throws IOException
1194 Desktop.instance.closeAll_actionPerformed(null);
1196 // complex project - one dataset, several views on several alignments
1197 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
1198 "examples/testdata/projects/manyViews.jvp",
1199 DataSourceType.FILE);
1202 AlignmentI ds = null;
1203 for (AlignFrame alignFrame : Desktop.getAlignFrames())
1207 ds = verifyDs(alignFrame);
1211 // check that this frame's dataset matches the last
1212 assertTrue(ds == verifyDs(alignFrame));
1217 private AlignmentI verifyDs(AlignFrame af)
1219 AlignmentI ds = null;
1220 for (AlignmentViewPanel ap : af.getAlignPanels())
1224 ds = ap.getAlignment().getDataset();
1228 assertTrue(ap.getAlignment().getDataset() == ds,
1229 "Dataset was not the same for imported 2.10.5 project with several alignment views");
1235 @Test(groups = "Functional")
1236 public void testPcaViewAssociation() throws IOException
1238 Desktop.instance.closeAll_actionPerformed(null);
1239 final String PCAVIEWNAME = "With PCA";
1240 // create a new tempfile
1241 File tempfile = File.createTempFile("jvPCAviewAssoc", "jvp");
1244 String exampleFile = "examples/uniref50.fa";
1245 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
1246 DataSourceType.FILE);
1247 assertNotNull(af, "Didn't read in the example file correctly.");
1248 AlignmentPanel origView = (AlignmentPanel) af.getAlignPanels().get(0);
1249 AlignmentPanel newview = af.newView(PCAVIEWNAME, true);
1250 // create another for good measure
1251 af.newView("Not the PCA View", true);
1252 PCAPanel pcaPanel = new PCAPanel(origView, "BLOSUM62",
1253 new SimilarityParams(true, true, true, false));
1254 // we're in the test exec thread, so we can just run synchronously here
1257 // now switch the linked view
1258 pcaPanel.selectAssociatedView(newview);
1260 assertTrue(pcaPanel.getAlignViewport() == newview.getAlignViewport(),
1261 "PCA should be associated with 'With PCA' view: test is broken");
1263 // now save and reload project
1264 Jalview2XML jv2xml = new jalview.project.Jalview2XML(false);
1266 jv2xml.saveState(tempfile);
1267 assertTrue(jv2xml.errorMessage == null,
1268 "Failed to save dummy project with PCA: test broken");
1272 Desktop.instance.closeAll_actionPerformed(null);
1273 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1274 tempfile.getCanonicalPath(), DataSourceType.FILE);
1275 JInternalFrame[] frames = Desktop.instance.getAllFrames();
1276 // PCA and the tabbed alignment view should be the only two windows on the
1278 assertEquals(frames.length, 2,
1279 "PCA and the tabbed alignment view should be the only two windows on the desktop");
1280 PCAPanel pcaPanel = (PCAPanel) frames[frames[0] == af ? 1 : 0];
1282 AlignmentViewPanel restoredNewView = null;
1283 for (AlignmentViewPanel alignpanel : Desktop.getAlignmentPanels(null))
1285 if (alignpanel.getAlignViewport() == pcaPanel.getAlignViewport())
1287 restoredNewView = alignpanel;
1290 assertEquals(restoredNewView.getViewName(), PCAVIEWNAME);
1292 restoredNewView.getAlignViewport() == pcaPanel
1293 .getAlignViewport(),
1294 "Didn't restore correct view association for the PCA view");
1298 * Test save and reload of DBRefEntry including GeneLocus in project
1302 @Test(groups = { "Functional" })
1303 public void testStoreAndRecoverGeneLocus() throws Exception
1305 Desktop.instance.closeAll_actionPerformed(null);
1306 String seqData = ">P30419\nACDE\n>X1235\nGCCTGTGACGAA";
1307 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqData,
1308 DataSourceType.PASTE);
1309 assertNotNull(af, "Didn't read in the example file correctly.");
1311 AlignmentViewPanel ap = Desktop.getAlignmentPanels(null)[0];
1312 SequenceI pep = ap.getAlignment().getSequenceAt(0);
1313 SequenceI cds = ap.getAlignment().getSequenceAt(1);
1316 * give 'protein' a dbref to self, a dbref with map to CDS,
1317 * and a dbref with map to gene 'locus'
1319 DBRefEntry dbref1 = new DBRefEntry("Uniprot", "1", "P30419", null);
1320 pep.addDBRef(dbref1);
1321 Mapping cdsmap = new Mapping(cds,
1322 new MapList(new int[]
1323 { 1, 4 }, new int[] { 1, 12 }, 1, 3));
1324 DBRefEntry dbref2 = new DBRefEntry("EMBLCDS", "2", "X1235", cdsmap);
1325 pep.addDBRef(dbref2);
1326 Mapping locusmap = new Mapping(null,
1327 new MapList(new int[]
1328 { 1, 4 }, new int[] { 2674123, 2674135 }, 1, 3));
1329 DBRefEntry dbref3 = new GeneLocus("human", "GRCh38", "5", locusmap);
1330 pep.addDBRef(dbref3);
1332 File tfile = File.createTempFile("testStoreAndRecoverGeneLocus",
1336 new Jalview2XML(false).saveState(tfile);
1337 } catch (Throwable e)
1339 Assert.fail("Didn't save the state", e);
1341 Desktop.instance.closeAll_actionPerformed(null);
1343 new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1344 DataSourceType.FILE);
1345 AlignmentViewPanel rap = Desktop.getAlignmentPanels(null)[0];
1346 SequenceI rpep = rap.getAlignment().getSequenceAt(0);
1347 DBModList<DBRefEntry> dbrefs = rpep.getDBRefs();
1348 assertEquals(rpep.getName(), "P30419");
1349 assertEquals(dbrefs.size(), 3);
1350 DBRefEntry dbRef = dbrefs.get(0);
1351 assertFalse(dbRef instanceof GeneLocus);
1352 assertNull(dbRef.getMap());
1353 assertEquals(dbRef, dbref1);
1356 * restored dbrefs with mapping have a different 'map to'
1357 * sequence but otherwise match the original dbrefs
1359 dbRef = dbrefs.get(1);
1360 assertFalse(dbRef instanceof GeneLocus);
1361 assertTrue(dbRef.equalRef(dbref2));
1362 assertNotNull(dbRef.getMap());
1363 SequenceI rcds = rap.getAlignment().getSequenceAt(1);
1364 assertSame(dbRef.getMap().getTo(), rcds);
1365 // compare MapList but not map.to
1366 assertEquals(dbRef.getMap().getMap(), dbref2.getMap().getMap());
1369 * GeneLocus map.to is null so can compare Mapping objects
1371 dbRef = dbrefs.get(2);
1372 assertTrue(dbRef instanceof GeneLocus);
1373 assertEquals(dbRef, dbref3);
1377 * test store and recovery of Overview windows
1381 @Test(groups = { "Functional" }, enabled = true)
1382 public void testStoreAndRecoverOverview() throws Exception
1384 Desktop.instance.closeAll_actionPerformed(null);
1386 Cache.setProperty("SHOW_OVERVIEW", "false");
1387 Cache.setProperty(Preferences.USE_LEGACY_GAP, "false");
1388 Cache.setColourProperty(Preferences.GAP_COLOUR, Color.green);
1389 Cache.setColourProperty(Preferences.HIDDEN_COLOUR, Color.yellow);
1390 Cache.setProperty(Preferences.SHOW_OV_HIDDEN_AT_START, "true");
1392 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1393 "examples/uniref50.fa", DataSourceType.FILE);
1396 * open and resize / reposition overview
1398 af.overviewMenuItem_actionPerformed(null);
1399 OverviewPanel ov1 = af.alignPanel.getOverviewPanel();
1401 ov1.setFrameBounds(20, 30, 200, 400);
1402 assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa");
1403 assertTrue(ov1.isShowHiddenRegions());
1406 * open a New View and its Overview and reposition it
1408 af.newView_actionPerformed(null);
1409 af.overviewMenuItem_actionPerformed(null);
1410 OverviewPanel ov2 = af.alignPanel.getOverviewPanel();
1412 assertNotSame(ov1, ov2);
1413 ov2.setFrameBounds(25, 35, 205, 405);
1414 assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa Original");
1415 assertEquals(ov2.getTitle(), "Overview examples/uniref50.fa View 1");
1417 File tfile = File.createTempFile("testStoreAndRecoverOverview", ".jvp");
1418 new Jalview2XML(false).saveState(tfile);
1419 Desktop.instance.closeAll_actionPerformed(null);
1422 * change preferences (should _not_ affect reloaded Overviews)
1424 Cache.setProperty("SHOW_OVERVIEW", "true");
1425 Cache.setProperty(Preferences.USE_LEGACY_GAP, "true");
1426 Cache.setColourProperty(Preferences.GAP_COLOUR, Color.blue);
1427 Cache.setColourProperty(Preferences.HIDDEN_COLOUR, Color.orange);
1428 Cache.setProperty(Preferences.SHOW_OV_HIDDEN_AT_START, "false");
1430 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1431 DataSourceType.FILE);
1434 * workaround: explicitly select View 1 (not in focus after restore)
1436 af.tabSelectionChanged(1);
1439 * verify restored overview for View 1
1441 ov2 = af.alignPanel.getOverviewPanel();
1442 assertEquals(ov2.getCanvas().getGapColour(), Color.green);
1443 // 'non-legacy' colouring uses white for non-gapped residues
1444 assertEquals(ov2.getCanvas().getResidueColour(), Color.white);
1445 assertEquals(ov2.getCanvas().getHiddenColour(), Color.yellow);
1446 assertEquals(ov2.getTitle(), "Overview examples/uniref50.fa View 1");
1447 assertEquals(ov2.getFrameBounds(), new Rectangle(25, 35, 205, 405));
1448 assertTrue(ov2.isShowHiddenRegions());
1451 * verify restored overview for Original view
1453 af.tabSelectionChanged(0);
1454 ov1 = af.alignPanel.getOverviewPanel();
1455 assertEquals(ov1.getCanvas().getGapColour(), Color.green);
1456 // 'non-legacy' colouring uses white for non-gapped residues
1457 assertEquals(ov1.getCanvas().getResidueColour(), Color.white);
1458 assertEquals(ov1.getCanvas().getHiddenColour(), Color.yellow);
1459 assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa Original");
1460 assertEquals(ov1.getFrameBounds(), new Rectangle(20, 30, 200, 400));
1461 assertTrue(ov1.isShowHiddenRegions());
1465 * Test that a view with no Overview is restored with no Overview, even if
1466 * 'Open Overview' is selected in Preferences
1470 @Test(groups = { "Functional" }, enabled = true)
1471 public void testStoreAndRecoverNoOverview() throws Exception
1473 Cache.setProperty("SHOW_OVERVIEW", "false");
1474 Desktop.instance.closeAll_actionPerformed(null);
1475 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1476 ">seq1\nMATRSQFLVNF\n", DataSourceType.PASTE);
1478 File tfile = File.createTempFile("testStoreAndRecoverOverview", ".jvp");
1479 new Jalview2XML(false).saveState(tfile);
1480 Desktop.instance.closeAll_actionPerformed(null);
1482 Cache.setProperty("SHOW_OVERVIEW", "true");
1483 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1484 DataSourceType.FILE);
1486 assertNull(af.alignPanel.getOverviewPanel());
1490 * Test that a view from an older version of Jalview is restored with Overview automatically shown when the preference is set
1494 @Test(groups = { "Functional" }, enabled = true)
1495 public void testAutoShowOverviewForLegacyProjects() throws Exception
1497 Desktop.instance.closeAll_actionPerformed(null);
1498 Cache.setProperty("SHOW_OVERVIEW", "true");
1499 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1500 "examples/exampleFile.jvp", DataSourceType.FILE);
1502 Cache.setProperty("SHOW_OVERVIEW", "false");
1503 assertNotNull(af.alignPanel.getOverviewPanel());
1507 * Test that loading example.jvp, doing some stuff, then hitting reload
1508 * doesn't leave the modified window still open
1510 * See JAL-4127 - interactively performing the same actions and reloading
1511 * works fine, but programmatically they do not
1515 @Test(groups = {"Functional"}, enabled=false)
1516 public void testReloadActuallyReloads() throws Exception
1518 Desktop.instance.closeAll_actionPerformed(null);
1519 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1520 "examples/exampleFile.jvp", DataSourceType.FILE);
1521 af.getViewport().getColumnSelection().addElement(3);
1522 af.hideSelColumns_actionPerformed(null);
1523 af.newView("new", true);
1524 af.reload_actionPerformed(null);
1526 // af exists still but isn't shown
1527 assertTrue(af.isClosed());