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.DBRefEntry;
57 import jalview.datamodel.GeneLocus;
58 import jalview.datamodel.HiddenSequences;
59 import jalview.datamodel.Mapping;
60 import jalview.datamodel.PDBEntry;
61 import jalview.datamodel.PDBEntry.Type;
62 import jalview.datamodel.Sequence.DBModList;
63 import jalview.datamodel.SequenceCollectionI;
64 import jalview.datamodel.SequenceFeature;
65 import jalview.datamodel.SequenceGroup;
66 import jalview.datamodel.SequenceI;
67 import jalview.datamodel.features.FeatureMatcher;
68 import jalview.datamodel.features.FeatureMatcherSet;
69 import jalview.datamodel.features.FeatureMatcherSetI;
70 import jalview.gui.AlignFrame;
71 import jalview.gui.AlignViewport;
72 import jalview.gui.AlignmentPanel;
73 import jalview.gui.Desktop;
74 import jalview.gui.JvOptionPane;
75 import jalview.gui.OverviewPanel;
76 import jalview.gui.PCAPanel;
77 import jalview.gui.PopupMenu;
78 import jalview.gui.Preferences;
79 import jalview.gui.SliderPanel;
80 import jalview.io.DataSourceType;
81 import jalview.io.FileFormat;
82 import jalview.io.FileLoader;
83 import jalview.io.Jalview2xmlBase;
84 import jalview.renderer.ResidueShaderI;
85 import jalview.schemes.AnnotationColourGradient;
86 import jalview.schemes.BuriedColourScheme;
87 import jalview.schemes.ColourSchemeI;
88 import jalview.schemes.ColourSchemeProperty;
89 import jalview.schemes.FeatureColour;
90 import jalview.schemes.JalviewColourScheme;
91 import jalview.schemes.RNAHelicesColour;
92 import jalview.schemes.StrandColourScheme;
93 import jalview.schemes.TCoffeeColourScheme;
94 import jalview.structure.StructureImportSettings;
95 import jalview.util.MapList;
96 import jalview.util.matcher.Condition;
97 import jalview.viewmodel.AlignmentViewport;
98 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
100 @Test(singleThreaded = true)
101 public class Jalview2xmlTests extends Jalview2xmlBase
105 @BeforeClass(alwaysRun = true)
106 public void setUpJvOptionPane()
108 JvOptionPane.setInteractiveMode(false);
109 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
112 @Test(groups = { "Functional" })
113 public void testRNAStructureRecovery() throws Exception
115 String inFile = "examples/RF00031_folded.stk";
116 String tfile = File.createTempFile("JalviewTest", ".jvp")
118 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
119 DataSourceType.FILE);
120 assertNotNull(af, "Didn't read input file " + inFile);
121 int olddsann = countDsAnn(af.getViewport());
122 assertTrue(olddsann > 0, "Didn't find any dataset annotations");
123 af.changeColour_actionPerformed(
124 JalviewColourScheme.RNAHelices.toString());
127 .getGlobalColourScheme() instanceof RNAHelicesColour,
128 "Couldn't apply RNA helices colourscheme");
129 af.saveAlignment(tfile, FileFormat.Jalview);
130 assertTrue(af.isSaveAlignmentSuccessful(),
131 "Failed to store as a project.");
132 af.closeMenuItem_actionPerformed(true);
134 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
135 DataSourceType.FILE);
136 assertNotNull(af, "Failed to import new project");
137 int newdsann = countDsAnn(af.getViewport());
138 assertEquals(olddsann, newdsann,
139 "Differing numbers of dataset sequence annotation\nOriginally "
140 + olddsann + " and now " + newdsann);
142 "Read in same number of annotations as originally present ("
147 .getGlobalColourScheme() instanceof RNAHelicesColour,
148 "RNA helices colourscheme was not applied on import.");
151 @Test(groups = { "Functional" })
152 public void testTCoffeeScores() throws Exception
154 String inFile = "examples/uniref50.fa",
155 inAnnot = "examples/uniref50.score_ascii";
156 String tfile = File.createTempFile("JalviewTest", ".jvp")
158 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
159 DataSourceType.FILE);
160 assertNotNull(af, "Didn't read input file " + inFile);
161 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
162 AlignViewport viewport = af.getViewport();
163 assertSame(viewport.getGlobalColourScheme().getClass(),
164 TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
166 ColourSchemeProperty.getColourScheme(viewport,
167 viewport.getAlignment(),
168 viewport.getGlobalColourScheme().getSchemeName()),
169 "Recognise T-Coffee score from string");
171 af.saveAlignment(tfile, FileFormat.Jalview);
172 assertTrue(af.isSaveAlignmentSuccessful(),
173 "Failed to store as a project.");
174 af.closeMenuItem_actionPerformed(true);
176 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
177 DataSourceType.FILE);
178 assertNotNull(af, "Failed to import new project");
179 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
180 TCoffeeColourScheme.class,
181 "Didn't set T-coffee colourscheme for imported project.");
183 "T-Coffee score shading successfully recovered from project.");
186 @Test(groups = { "Functional" })
187 public void testColourByAnnotScores() throws Exception
189 String inFile = "examples/uniref50.fa",
190 inAnnot = "examples/testdata/uniref50_iupred.jva";
191 String tfile = File.createTempFile("JalviewTest", ".jvp")
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)");
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], null,
206 AnnotationColourGradient.BELOW_THRESHOLD);
207 cs.setSeqAssociated(true);
208 gcs.setSeqAssociated(true);
210 SequenceGroup sg = new SequenceGroup();
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 af.saveAlignment(tfile, FileFormat.Jalview);
219 assertTrue(af.isSaveAlignmentSuccessful(),
220 "Failed to store as a project.");
221 af.closeMenuItem_actionPerformed(true);
223 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
224 DataSourceType.FILE);
225 assertNotNull(af, "Failed to import new project");
227 // check for group and alignment colourschemes
229 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
230 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups().get(0)
232 assertNotNull(_rcs, "Didn't recover global colourscheme");
233 assertTrue(_rcs instanceof AnnotationColourGradient,
234 "Didn't recover annotation colour global scheme");
235 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
236 assertTrue(__rcs.isSeqAssociated(),
237 "Annotation colourscheme wasn't sequence associated");
239 boolean diffseqcols = false, diffgseqcols = false;
240 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
241 for (int p = 0, pSize = af.getViewport().getAlignment()
242 .getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++)
244 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
245 .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
250 assertTrue(diffseqcols, "Got Different sequence colours");
252 "Per sequence colourscheme (Background) successfully applied and recovered.");
254 assertNotNull(_rgcs, "Didn't recover group colourscheme");
255 assertTrue(_rgcs instanceof AnnotationColourGradient,
256 "Didn't recover annotation colour group colourscheme");
257 __rcs = (AnnotationColourGradient) _rgcs;
258 assertTrue(__rcs.isSeqAssociated(),
259 "Group Annotation colourscheme wasn't sequence associated");
261 for (int p = 0, pSize = af.getViewport().getAlignment()
262 .getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++)
264 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null,
265 0f) != _rgcs.findColour(sqs[2].getCharAt(p), p, sqs[2], null,
271 assertTrue(diffgseqcols, "Got Different group sequence colours");
273 "Per sequence (Group) colourscheme successfully applied and recovered.");
276 @Test(groups = { "Functional" })
277 public void gatherViewsHere() throws Exception
279 int origCount = Desktop.getAlignFrames() == null ? 0
280 : Desktop.getAlignFrames().length;
281 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
282 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
283 assertNotNull(af, "Didn't read in the example file correctly.");
284 assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
285 "Didn't gather the views in the example file.");
290 * Test for JAL-2223 - multiple mappings in View Mapping report
294 @Test(groups = { "Functional" })
295 public void noDuplicatePdbMappingsMade() throws Exception
297 StructureImportSettings.setProcessSecondaryStructure(true);
298 StructureImportSettings.setVisibleChainAnnotation(true);
299 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
300 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
301 assertNotNull(af, "Didn't read in the example file correctly.");
303 // locate Jmol viewer
304 // count number of PDB mappings the structure selection manager holds -
305 String pdbFile = af.getCurrentView().getStructureSelectionManager()
306 .findFileForPDBId("1A70");
308 af.getCurrentView().getStructureSelectionManager()
309 .getMapping(pdbFile).length,
310 2, "Expected only two mappings for 1A70");
314 @Test(groups = { "Functional" })
315 public void viewRefPdbAnnotation() throws Exception
317 StructureImportSettings.setProcessSecondaryStructure(true);
318 StructureImportSettings.setVisibleChainAnnotation(true);
319 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
320 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
321 assertNotNull(af, "Didn't read in the example file correctly.");
322 AlignmentViewPanel sps = null;
323 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
325 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
331 assertNotNull(sps, "Couldn't find the structure view");
332 AlignmentAnnotation refan = null;
333 for (AlignmentAnnotation ra : sps.getAlignment()
334 .getAlignmentAnnotation())
342 assertNotNull(refan, "Annotation secondary structure not found.");
343 SequenceI sq = sps.getAlignment().findName("1A70|");
344 assertNotNull(sq, "Couldn't find 1a70 null chain");
345 // compare the manually added temperature factor annotation
346 // to the track automatically transferred from the pdb structure on load
347 assertNotNull(sq.getDatasetSequence().getAnnotation(),
348 "1a70 has no annotation");
349 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
351 AlignmentAnnotation alaa;
352 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
353 alaa.adjustForAlignment();
354 if (ala.graph == refan.graph)
356 for (int p = 0; p < ala.annotations.length; p++)
361 assertTrue((alaa.annotations[p] == null
362 && refan.annotations[p] == null)
363 || alaa.annotations[p].value == refan.annotations[p].value,
364 "Mismatch at alignment position " + p);
365 } catch (NullPointerException q)
367 Assert.fail("Mismatch of alignment annotations at position " + p
368 + " Ref seq ann: " + refan.annotations[p]
369 + " alignment " + alaa.annotations[p]);
377 @Test(groups = { "Functional" })
378 public void testCopyViewSettings() throws Exception
380 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
381 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
382 assertNotNull(af, "Didn't read in the example file correctly.");
383 AlignmentViewPanel sps = null, groups = null;
384 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
386 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
390 if (ap.getViewName().contains("MAFFT"))
395 assertNotNull(sps, "Couldn't find the structure view");
396 assertNotNull(groups, "Couldn't find the MAFFT view");
398 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
399 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
400 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
402 groups.getAlignViewport().setViewStyle(structureStyle);
403 AssertJUnit.assertFalse(
404 groupStyle.sameStyle(groups.getAlignViewport().getViewStyle()));
405 Assert.assertTrue(structureStyle
406 .sameStyle(groups.getAlignViewport().getViewStyle()));
411 * test store and recovery of expanded views
415 @Test(groups = { "Functional" }, enabled = true)
416 public void testStoreAndRecoverExpandedviews() throws Exception
418 Desktop.instance.closeAll_actionPerformed(null);
420 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
421 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
422 Assert.assertEquals(Desktop.getAlignFrames().length, 1);
423 String afid = af.getViewport().getSequenceSetId();
425 // check FileLoader returned a reference to the one alignFrame that is
426 // actually on the Desktop
427 assertSame(af, Desktop.getAlignFrameFor(af.getViewport()),
428 "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
430 Desktop.explodeViews(af);
432 int oldviews = Desktop.getAlignFrames().length;
433 Assert.assertEquals(Desktop.getAlignFrames().length,
434 Desktop.getAlignmentPanels(afid).length);
435 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
438 new Jalview2XML(false).saveState(tfile);
441 Assert.fail("Didn't save the expanded view state", e);
442 } catch (Exception e)
444 Assert.fail("Didn't save the expanded view state", e);
446 Desktop.instance.closeAll_actionPerformed(null);
447 if (Desktop.getAlignFrames() != null)
449 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
451 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
452 DataSourceType.FILE);
453 Assert.assertNotNull(af);
454 Assert.assertEquals(Desktop.getAlignFrames().length,
455 Desktop.getAlignmentPanels(
456 af.getViewport().getSequenceSetId()).length);
457 Assert.assertEquals(Desktop
458 .getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
463 * Test save and reload of a project with a different representative sequence
468 @Test(groups = { "Functional" })
469 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
471 Desktop.instance.closeAll_actionPerformed(null);
472 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
473 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
474 assertNotNull(af, "Didn't read in the example file correctly.");
475 String afid = af.getViewport().getSequenceSetId();
477 // remember reference sequence for each panel
478 Map<String, SequenceI> refseqs = new HashMap<>();
481 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
482 * as reference sequence for itself and the preceding sequence
485 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
487 AlignViewportI av = ap.getAlignViewport();
488 AlignmentI alignment = ap.getAlignment();
489 int repIndex = n % alignment.getHeight();
490 SequenceI rep = alignment.getSequenceAt(repIndex);
491 refseqs.put(ap.getViewName(), rep);
493 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
494 // todo refactor this to an alignment view controller
495 av.setDisplayReferenceSeq(true);
496 av.setColourByReferenceSeq(true);
497 av.getAlignment().setSeqrep(rep);
501 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
505 new Jalview2XML(false).saveState(tfile);
506 } catch (Throwable e)
508 Assert.fail("Didn't save the expanded view state", e);
510 Desktop.instance.closeAll_actionPerformed(null);
511 if (Desktop.getAlignFrames() != null)
513 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
516 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
517 DataSourceType.FILE);
518 afid = af.getViewport().getSequenceSetId();
520 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
522 // check representative
523 AlignmentI alignment = ap.getAlignment();
524 SequenceI rep = alignment.getSeqrep();
525 Assert.assertNotNull(rep,
526 "Couldn't restore sequence representative from project");
527 // can't use a strong equals here, because by definition, the sequence IDs
528 // will be different.
529 // could set vamsas session save/restore flag to preserve IDs across
531 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
533 "Representative wasn't the same when recovered.");
534 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
535 "Display reference sequence view setting not set.");
536 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
537 "Colour By Reference Seq view setting not set.");
541 @Test(groups = { "Functional" })
542 public void testIsVersionStringLaterThan()
545 * No version / development / test / autobuild is leniently assumed to be
548 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
549 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
550 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
551 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
552 "Development Build"));
553 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
554 "DEVELOPMENT BUILD"));
555 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
556 "Development Build"));
557 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
558 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
559 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
561 Jalview2XML.isVersionStringLaterThan(null, "Automated Build"));
562 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
564 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
568 * same version returns true i.e. compatible
570 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
571 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
572 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
573 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
574 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
577 * later version returns true
579 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
580 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
581 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
582 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
583 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
586 * earlier version returns false
588 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
589 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
590 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
591 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
592 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
596 * Test save and reload of a project with a different sequence group (and
597 * representative sequence) in each view.
601 @Test(groups = { "Functional" })
602 public void testStoreAndRecoverGroupRepSeqs() throws Exception
604 Desktop.instance.closeAll_actionPerformed(null);
605 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
606 "examples/uniref50.fa", DataSourceType.FILE);
607 assertNotNull(af, "Didn't read in the example file correctly.");
608 String afid = af.getViewport().getSequenceSetId();
609 // make a second view of the alignment
610 af.newView_actionPerformed(null);
613 * remember representative and hidden sequences marked
616 Map<String, SequenceI> repSeqs = new HashMap<>();
617 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
620 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
621 * as reference sequence for itself and the preceding sequence
624 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
626 AlignViewportI av = ap.getAlignViewport();
627 AlignmentI alignment = ap.getAlignment();
628 int repIndex = n % alignment.getHeight();
629 // ensure at least one preceding sequence i.e. index >= 1
630 repIndex = Math.max(repIndex, 1);
631 SequenceI repSeq = alignment.getSequenceAt(repIndex);
632 repSeqs.put(ap.getViewName(), repSeq);
633 List<String> hiddenNames = new ArrayList<>();
634 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
637 * have rep sequence represent itself and the one before it
638 * this hides the group (except for the rep seq)
640 SequenceGroup sg = new SequenceGroup();
641 sg.addSequence(repSeq, false);
642 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
643 sg.addSequence(precedingSeq, false);
644 sg.setSeqrep(repSeq);
645 assertTrue(sg.getSequences().contains(repSeq));
646 assertTrue(sg.getSequences().contains(precedingSeq));
647 av.setSelectionGroup(sg);
648 assertSame(repSeq, sg.getSeqrep());
651 * represent group with sequence adds to a map of hidden rep sequences
652 * (it does not create a group on the alignment)
654 ((AlignmentViewport) av).hideSequences(repSeq, true);
655 assertSame(repSeq, sg.getSeqrep());
656 assertTrue(sg.getSequences().contains(repSeq));
657 assertTrue(sg.getSequences().contains(precedingSeq));
658 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
659 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
660 .getHiddenRepSequences();
661 assertNotNull(hiddenRepSeqsMap);
662 assertEquals(1, hiddenRepSeqsMap.size());
663 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
664 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
665 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
666 hiddenNames.add(precedingSeq.getName());
670 File tfile = File.createTempFile("testStoreAndRecoverGroupReps",
674 new Jalview2XML(false).saveState(tfile);
675 } catch (Throwable e)
677 Assert.fail("Didn't save the expanded view state", e);
679 Desktop.instance.closeAll_actionPerformed(null);
680 if (Desktop.getAlignFrames() != null)
682 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
685 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
686 DataSourceType.FILE);
687 afid = af.getViewport().getSequenceSetId();
689 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
691 String viewName = ap.getViewName();
692 AlignViewportI av = ap.getAlignViewport();
693 AlignmentI alignment = ap.getAlignment();
694 List<SequenceGroup> groups = alignment.getGroups();
695 assertNotNull(groups);
696 assertTrue(groups.isEmpty(), "Alignment has groups");
697 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
698 .getHiddenRepSequences();
699 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
700 assertEquals(1, hiddenRepSeqsMap.size());
701 assertEquals(repSeqs.get(viewName).getDisplayId(true),
702 hiddenRepSeqsMap.keySet().iterator().next()
703 .getDisplayId(true));
706 * verify hidden sequences in restored panel
708 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
709 HiddenSequences hs = alignment.getHiddenSequences();
710 assertEquals(hidden.size(), hs.getSize(),
711 "wrong number of restored hidden sequences in "
717 * Test save and reload of PDBEntry in Jalview project
721 @Test(groups = { "Functional" })
722 public void testStoreAndRecoverPDBEntry() throws Exception
724 Desktop.instance.closeAll_actionPerformed(null);
725 String exampleFile = "examples/3W5V.pdb";
726 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
727 DataSourceType.FILE);
728 assertNotNull(af, "Didn't read in the example file correctly.");
729 String afid = af.getViewport().getSequenceSetId();
731 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
732 System.out.println();
733 AlignmentViewPanel ap = alignPanels[0];
734 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
735 String testFile = tfileBase + exampleFile;
736 AlignmentI alignment = ap.getAlignment();
737 System.out.println("blah");
738 SequenceI[] seqs = alignment.getSequencesArray();
739 Assert.assertNotNull(seqs[0]);
740 Assert.assertNotNull(seqs[1]);
741 Assert.assertNotNull(seqs[2]);
742 Assert.assertNotNull(seqs[3]);
743 Assert.assertNotNull(seqs[0].getDatasetSequence());
744 Assert.assertNotNull(seqs[1].getDatasetSequence());
745 Assert.assertNotNull(seqs[2].getDatasetSequence());
746 Assert.assertNotNull(seqs[3].getDatasetSequence());
747 PDBEntry[] pdbEntries = new PDBEntry[4];
748 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
749 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
750 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
751 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
753 seqs[0].getDatasetSequence().getAllPDBEntries().get(0),
756 seqs[1].getDatasetSequence().getAllPDBEntries().get(0),
759 seqs[2].getDatasetSequence().getAllPDBEntries().get(0),
762 seqs[3].getDatasetSequence().getAllPDBEntries().get(0),
765 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
768 new Jalview2XML(false).saveState(tfile);
769 } catch (Throwable e)
771 Assert.fail("Didn't save the state", e);
773 Desktop.instance.closeAll_actionPerformed(null);
774 if (Desktop.getAlignFrames() != null)
776 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
779 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
780 tfile.getAbsolutePath(), DataSourceType.FILE);
781 String rfid = restoredFrame.getViewport().getSequenceSetId();
782 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
783 AlignmentViewPanel rap = rAlignPanels[0];
784 AlignmentI rAlignment = rap.getAlignment();
785 System.out.println("blah");
786 SequenceI[] rseqs = rAlignment.getSequencesArray();
787 Assert.assertNotNull(rseqs[0]);
788 Assert.assertNotNull(rseqs[1]);
789 Assert.assertNotNull(rseqs[2]);
790 Assert.assertNotNull(rseqs[3]);
791 Assert.assertNotNull(rseqs[0].getDatasetSequence());
792 Assert.assertNotNull(rseqs[1].getDatasetSequence());
793 Assert.assertNotNull(rseqs[2].getDatasetSequence());
794 Assert.assertNotNull(rseqs[3].getDatasetSequence());
796 // The Asserts below are expected to fail until the PDB chainCode is
797 // recoverable from a Jalview projects
798 for (int chain = 0; chain < 4; chain++)
800 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
802 PDBEntry expected = pdbEntries[chain];
803 Assert.assertEquals(recov.getId(), expected.getId(),
805 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
807 Assert.assertEquals(recov.getType(), expected.getType(),
808 "Mismatch PDBEntry 'Type'");
809 Assert.assertNotNull(recov.getFile(),
810 "Recovered PDBEntry should have a non-null file entry");
811 Assert.assertEquals(recov.getFile().toLowerCase(Locale.ENGLISH).lastIndexOf("pdb"),recov.getFile().length()-3, "Recovered PDBEntry file should have PDB suffix");
816 * Configure an alignment and a sub-group each with distinct colour schemes,
817 * Conservation and PID thresholds, and confirm these are restored from the
820 * @throws IOException
822 @Test(groups = { "Functional" })
823 public void testStoreAndRecoverColourThresholds() throws IOException
825 Desktop.instance.closeAll_actionPerformed(null);
826 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
827 "examples/uniref50.fa", DataSourceType.FILE);
829 AlignViewport av = af.getViewport();
830 AlignmentI al = av.getAlignment();
833 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
835 av.setColourAppliesToAllGroups(false);
836 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
837 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
838 af.abovePIDThreshold_actionPerformed(true);
839 SliderPanel sp = SliderPanel.getSliderPanel();
840 assertFalse(sp.isForConservation());
842 af.conservationMenuItem_actionPerformed(true);
843 sp = SliderPanel.getSliderPanel();
844 assertTrue(sp.isForConservation());
846 ResidueShaderI rs = av.getResidueShading();
847 assertEquals(rs.getThreshold(), 10);
848 assertTrue(rs.conservationApplied());
849 assertEquals(rs.getConservationInc(), 20);
852 * create a group with Strand colouring, 30% Conservation
853 * and 40% PID threshold
854 * (notice menu action applies to selection group even if mouse click
855 * is at a sequence not in the group)
857 SequenceGroup sg = new SequenceGroup();
858 sg.addSequence(al.getSequenceAt(0), false);
861 av.setSelectionGroup(sg);
862 PopupMenu popupMenu = new PopupMenu(af.alignPanel, al.getSequenceAt(2),
864 popupMenu.changeColour_actionPerformed(
865 JalviewColourScheme.Strand.toString());
866 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
867 assertEquals(al.getGroups().size(), 1);
868 assertSame(al.getGroups().get(0), sg);
869 popupMenu.conservationMenuItem_actionPerformed(true);
870 sp = SliderPanel.getSliderPanel();
871 assertTrue(sp.isForConservation());
873 popupMenu.abovePIDColour_actionPerformed(true);
874 sp = SliderPanel.getSliderPanel();
875 assertFalse(sp.isForConservation());
877 assertTrue(sg.getGroupColourScheme().conservationApplied());
878 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
879 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
882 * save project, close windows, reload project, verify
884 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
886 tfile.deleteOnExit();
887 new Jalview2XML(false).saveState(tfile);
888 Desktop.instance.closeAll_actionPerformed(null);
889 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
890 DataSourceType.FILE);
891 Assert.assertNotNull(af, "Failed to reload project");
894 * verify alignment (background) colouring
896 rs = af.getViewport().getResidueShading();
897 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
898 assertEquals(rs.getThreshold(), 10);
899 assertTrue(rs.conservationApplied());
900 assertEquals(rs.getConservationInc(), 20);
903 * verify group colouring
905 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
906 rs = af.getViewport().getAlignment().getGroups().get(0)
907 .getGroupColourScheme();
908 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
909 assertEquals(rs.getThreshold(), 40);
910 assertTrue(rs.conservationApplied());
911 assertEquals(rs.getConservationInc(), 30);
915 * Test save and reload of feature colour schemes and filter settings
917 * @throws IOException
919 @Test(groups = { "Functional" })
920 public void testSaveLoadFeatureColoursAndFilters() throws IOException
922 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
923 ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
924 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
927 * add some features to the sequence
930 addFeatures(seq1, "type1", score++);
931 addFeatures(seq1, "type2", score++);
932 addFeatures(seq1, "type3", score++);
933 addFeatures(seq1, "type4", score++);
934 addFeatures(seq1, "type5", score++);
937 * set colour schemes for features
939 FeatureRendererModel fr = af.getFeatureRenderer();
940 fr.findAllFeatures(true);
943 fr.setColour("type1", new FeatureColour(Color.red));
946 FeatureColourI byLabel = new FeatureColour();
947 byLabel.setColourByLabel(true);
948 fr.setColour("type2", byLabel);
950 // type3: by score above threshold
951 FeatureColourI byScore = new FeatureColour(null, Color.BLACK,
952 Color.BLUE, null, 1, 10);
953 byScore.setAboveThreshold(true);
954 byScore.setThreshold(2f);
955 fr.setColour("type3", byScore);
957 // type4: by attribute AF
958 FeatureColourI byAF = new FeatureColour();
959 byAF.setColourByLabel(true);
960 byAF.setAttributeName("AF");
961 fr.setColour("type4", byAF);
963 // type5: by attribute CSQ:PolyPhen below threshold
964 FeatureColourI byPolyPhen = new FeatureColour(null, Color.BLACK,
965 Color.BLUE, null, 1, 10);
966 byPolyPhen.setBelowThreshold(true);
967 byPolyPhen.setThreshold(3f);
968 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
969 fr.setColour("type5", byPolyPhen);
972 * set filters for feature types
975 // filter type1 features by (label contains "x")
976 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
977 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
978 fr.setFeatureFilter("type1", filterByX);
980 // filter type2 features by (score <= 2.4 and score > 1.1)
981 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
982 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
983 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
984 fr.setFeatureFilter("type2", filterByScore);
986 // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
987 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
989 .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
990 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
992 fr.setFeatureFilter("type3", filterByXY);
995 * save as Jalview project
997 File tfile = File.createTempFile("JalviewTest", ".jvp");
998 tfile.deleteOnExit();
999 String filePath = tfile.getAbsolutePath();
1000 af.saveAlignment(filePath, FileFormat.Jalview);
1001 assertTrue(af.isSaveAlignmentSuccessful(),
1002 "Failed to store as a project.");
1005 * close current alignment and load the saved project
1007 af.closeMenuItem_actionPerformed(true);
1009 af = new FileLoader().LoadFileWaitTillLoaded(filePath,
1010 DataSourceType.FILE);
1011 assertNotNull(af, "Failed to import new project");
1014 * verify restored feature colour schemes and filters
1016 fr = af.getFeatureRenderer();
1017 FeatureColourI fc = fr.getFeatureStyle("type1");
1018 assertTrue(fc.isSimpleColour());
1019 assertEquals(fc.getColour(), Color.red);
1020 fc = fr.getFeatureStyle("type2");
1021 assertTrue(fc.isColourByLabel());
1022 fc = fr.getFeatureStyle("type3");
1023 assertTrue(fc.isGraduatedColour());
1024 assertNull(fc.getAttributeName());
1025 assertTrue(fc.isAboveThreshold());
1026 assertEquals(fc.getThreshold(), 2f);
1027 fc = fr.getFeatureStyle("type4");
1028 assertTrue(fc.isColourByLabel());
1029 assertTrue(fc.isColourByAttribute());
1030 assertEquals(fc.getAttributeName(), new String[] { "AF" });
1031 fc = fr.getFeatureStyle("type5");
1032 assertTrue(fc.isGraduatedColour());
1033 assertTrue(fc.isColourByAttribute());
1034 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
1035 assertTrue(fc.isBelowThreshold());
1036 assertEquals(fc.getThreshold(), 3f);
1038 assertEquals(fr.getFeatureFilter("type1").toStableString(),
1039 "Label Contains x");
1040 assertEquals(fr.getFeatureFilter("type2").toStableString(),
1041 "(Score LE 2.4) AND (Score GT 1.1)");
1042 assertEquals(fr.getFeatureFilter("type3").toStableString(),
1043 "(AF Contains X) OR (CSQ:PolyPhen NE 0)");
1046 private void addFeature(SequenceI seq, String featureType, int score)
1048 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
1050 sf.setValue("AF", score);
1051 sf.setValue("CSQ", new HashMap<String, String>()
1054 put("PolyPhen", Integer.toString(score));
1057 seq.addSequenceFeature(sf);
1061 * Adds two features of the given type to the given sequence, also setting the
1062 * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1065 * @param featureType
1068 private void addFeatures(SequenceI seq, String featureType, int score)
1070 addFeature(seq, featureType, score++);
1071 addFeature(seq, featureType, score);
1075 * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
1076 * view (JAL-3171) this test ensures we can import and merge those views
1078 @Test(groups = { "Functional" })
1079 public void testMergeDatasetsforViews() throws IOException
1081 // simple project - two views on one alignment
1082 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
1083 "examples/testdata/projects/twoViews.jvp", DataSourceType.FILE);
1085 assertTrue(af.getAlignPanels().size() > 1);
1090 * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
1091 * view (JAL-3171) this test ensures we can import and merge those views This
1092 * is a more complex project
1094 @Test(groups = { "Functional" })
1095 public void testMergeDatasetsforManyViews() throws IOException
1097 Desktop.instance.closeAll_actionPerformed(null);
1099 // complex project - one dataset, several views on several alignments
1100 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
1101 "examples/testdata/projects/manyViews.jvp",
1102 DataSourceType.FILE);
1105 AlignmentI ds = null;
1106 for (AlignFrame alignFrame : Desktop.getAlignFrames())
1110 ds = verifyDs(alignFrame);
1114 // check that this frame's dataset matches the last
1115 assertTrue(ds == verifyDs(alignFrame));
1120 private AlignmentI verifyDs(AlignFrame af)
1122 AlignmentI ds = null;
1123 for (AlignmentViewPanel ap : af.getAlignPanels())
1127 ds = ap.getAlignment().getDataset();
1131 assertTrue(ap.getAlignment().getDataset() == ds,
1132 "Dataset was not the same for imported 2.10.5 project with several alignment views");
1138 @Test(groups = "Functional")
1139 public void testPcaViewAssociation() throws IOException
1141 Desktop.instance.closeAll_actionPerformed(null);
1142 final String PCAVIEWNAME = "With PCA";
1143 // create a new tempfile
1144 File tempfile = File.createTempFile("jvPCAviewAssoc", "jvp");
1147 String exampleFile = "examples/uniref50.fa";
1148 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
1149 DataSourceType.FILE);
1150 assertNotNull(af, "Didn't read in the example file correctly.");
1151 AlignmentPanel origView = (AlignmentPanel) af.getAlignPanels().get(0);
1152 AlignmentPanel newview = af.newView(PCAVIEWNAME, true);
1153 // create another for good measure
1154 af.newView("Not the PCA View", true);
1155 PCAPanel pcaPanel = new PCAPanel(origView, "BLOSUM62",
1156 new SimilarityParams(true, true, true, false));
1157 // we're in the test exec thread, so we can just run synchronously here
1160 // now switch the linked view
1161 pcaPanel.selectAssociatedView(newview);
1163 assertTrue(pcaPanel.getAlignViewport() == newview.getAlignViewport(),
1164 "PCA should be associated with 'With PCA' view: test is broken");
1166 // now save and reload project
1167 Jalview2XML jv2xml = new jalview.project.Jalview2XML(false);
1169 jv2xml.saveState(tempfile);
1170 assertTrue(jv2xml.errorMessage == null,
1171 "Failed to save dummy project with PCA: test broken");
1175 Desktop.instance.closeAll_actionPerformed(null);
1176 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1177 tempfile.getCanonicalPath(), DataSourceType.FILE);
1178 JInternalFrame[] frames = Desktop.instance.getAllFrames();
1179 // PCA and the tabbed alignment view should be the only two windows on the
1181 assertEquals(frames.length, 2,
1182 "PCA and the tabbed alignment view should be the only two windows on the desktop");
1183 PCAPanel pcaPanel = (PCAPanel) frames[frames[0] == af ? 1 : 0];
1185 AlignmentViewPanel restoredNewView = null;
1186 for (AlignmentViewPanel alignpanel : Desktop.getAlignmentPanels(null))
1188 if (alignpanel.getAlignViewport() == pcaPanel.getAlignViewport())
1190 restoredNewView = alignpanel;
1193 assertEquals(restoredNewView.getViewName(), PCAVIEWNAME);
1195 restoredNewView.getAlignViewport() == pcaPanel
1196 .getAlignViewport(),
1197 "Didn't restore correct view association for the PCA view");
1201 * Test save and reload of DBRefEntry including GeneLocus in project
1205 @Test(groups = { "Functional" })
1206 public void testStoreAndRecoverGeneLocus() throws Exception
1208 Desktop.instance.closeAll_actionPerformed(null);
1209 String seqData = ">P30419\nACDE\n>X1235\nGCCTGTGACGAA";
1210 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqData,
1211 DataSourceType.PASTE);
1212 assertNotNull(af, "Didn't read in the example file correctly.");
1214 AlignmentViewPanel ap = Desktop.getAlignmentPanels(null)[0];
1215 SequenceI pep = ap.getAlignment().getSequenceAt(0);
1216 SequenceI cds = ap.getAlignment().getSequenceAt(1);
1219 * give 'protein' a dbref to self, a dbref with map to CDS,
1220 * and a dbref with map to gene 'locus'
1222 DBRefEntry dbref1 = new DBRefEntry("Uniprot", "1", "P30419", null);
1223 pep.addDBRef(dbref1);
1224 Mapping cdsmap = new Mapping(cds,
1225 new MapList(new int[]
1226 { 1, 4 }, new int[] { 1, 12 }, 1, 3));
1227 DBRefEntry dbref2 = new DBRefEntry("EMBLCDS", "2", "X1235", cdsmap);
1228 pep.addDBRef(dbref2);
1229 Mapping locusmap = new Mapping(null,
1230 new MapList(new int[]
1231 { 1, 4 }, new int[] { 2674123, 2674135 }, 1, 3));
1232 DBRefEntry dbref3 = new GeneLocus("human", "GRCh38", "5", locusmap);
1233 pep.addDBRef(dbref3);
1235 File tfile = File.createTempFile("testStoreAndRecoverGeneLocus",
1239 new Jalview2XML(false).saveState(tfile);
1240 } catch (Throwable e)
1242 Assert.fail("Didn't save the state", e);
1244 Desktop.instance.closeAll_actionPerformed(null);
1246 new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1247 DataSourceType.FILE);
1248 AlignmentViewPanel rap = Desktop.getAlignmentPanels(null)[0];
1249 SequenceI rpep = rap.getAlignment().getSequenceAt(0);
1250 DBModList<DBRefEntry> dbrefs = rpep.getDBRefs();
1251 assertEquals(rpep.getName(), "P30419");
1252 assertEquals(dbrefs.size(), 3);
1253 DBRefEntry dbRef = dbrefs.get(0);
1254 assertFalse(dbRef instanceof GeneLocus);
1255 assertNull(dbRef.getMap());
1256 assertEquals(dbRef, dbref1);
1259 * restored dbrefs with mapping have a different 'map to'
1260 * sequence but otherwise match the original dbrefs
1262 dbRef = dbrefs.get(1);
1263 assertFalse(dbRef instanceof GeneLocus);
1264 assertTrue(dbRef.equalRef(dbref2));
1265 assertNotNull(dbRef.getMap());
1266 SequenceI rcds = rap.getAlignment().getSequenceAt(1);
1267 assertSame(dbRef.getMap().getTo(), rcds);
1268 // compare MapList but not map.to
1269 assertEquals(dbRef.getMap().getMap(), dbref2.getMap().getMap());
1272 * GeneLocus map.to is null so can compare Mapping objects
1274 dbRef = dbrefs.get(2);
1275 assertTrue(dbRef instanceof GeneLocus);
1276 assertEquals(dbRef, dbref3);
1280 * test store and recovery of Overview windows
1284 @Test(groups = { "Functional" }, enabled = true)
1285 public void testStoreAndRecoverOverview() throws Exception
1287 Desktop.instance.closeAll_actionPerformed(null);
1289 Cache.setProperty("SHOW_OVERVIEW", "false");
1290 Cache.setProperty(Preferences.USE_LEGACY_GAP, "false");
1291 Cache.setColourProperty(Preferences.GAP_COLOUR, Color.green);
1292 Cache.setColourProperty(Preferences.HIDDEN_COLOUR, Color.yellow);
1293 Cache.setProperty(Preferences.SHOW_OV_HIDDEN_AT_START, "true");
1295 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1296 "examples/uniref50.fa", DataSourceType.FILE);
1299 * open and resize / reposition overview
1301 af.overviewMenuItem_actionPerformed(null);
1302 OverviewPanel ov1 = af.alignPanel.getOverviewPanel();
1304 ov1.setFrameBounds(20, 30, 200, 400);
1305 assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa");
1306 assertTrue(ov1.isShowHiddenRegions());
1309 * open a New View and its Overview and reposition it
1311 af.newView_actionPerformed(null);
1312 af.overviewMenuItem_actionPerformed(null);
1313 OverviewPanel ov2 = af.alignPanel.getOverviewPanel();
1315 assertNotSame(ov1, ov2);
1316 ov2.setFrameBounds(25, 35, 205, 405);
1317 assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa Original");
1318 assertEquals(ov2.getTitle(), "Overview examples/uniref50.fa View 1");
1320 File tfile = File.createTempFile("testStoreAndRecoverOverview", ".jvp");
1321 new Jalview2XML(false).saveState(tfile);
1322 Desktop.instance.closeAll_actionPerformed(null);
1325 * change preferences (should _not_ affect reloaded Overviews)
1327 Cache.setProperty("SHOW_OVERVIEW", "true");
1328 Cache.setProperty(Preferences.USE_LEGACY_GAP, "true");
1329 Cache.setColourProperty(Preferences.GAP_COLOUR, Color.blue);
1330 Cache.setColourProperty(Preferences.HIDDEN_COLOUR, Color.orange);
1331 Cache.setProperty(Preferences.SHOW_OV_HIDDEN_AT_START, "false");
1333 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1334 DataSourceType.FILE);
1337 * workaround: explicitly select View 1 (not in focus after restore)
1339 af.tabSelectionChanged(1);
1342 * verify restored overview for View 1
1344 ov2 = af.alignPanel.getOverviewPanel();
1345 assertEquals(ov2.getCanvas().getGapColour(), Color.green);
1346 // 'non-legacy' colouring uses white for non-gapped residues
1347 assertEquals(ov2.getCanvas().getResidueColour(), Color.white);
1348 assertEquals(ov2.getCanvas().getHiddenColour(), Color.yellow);
1349 assertEquals(ov2.getTitle(), "Overview examples/uniref50.fa View 1");
1350 assertEquals(ov2.getFrameBounds(), new Rectangle(25, 35, 205, 405));
1351 assertTrue(ov2.isShowHiddenRegions());
1354 * verify restored overview for Original view
1356 af.tabSelectionChanged(0);
1357 ov1 = af.alignPanel.getOverviewPanel();
1358 assertEquals(ov1.getCanvas().getGapColour(), Color.green);
1359 // 'non-legacy' colouring uses white for non-gapped residues
1360 assertEquals(ov1.getCanvas().getResidueColour(), Color.white);
1361 assertEquals(ov1.getCanvas().getHiddenColour(), Color.yellow);
1362 assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa Original");
1363 assertEquals(ov1.getFrameBounds(), new Rectangle(20, 30, 200, 400));
1364 assertTrue(ov1.isShowHiddenRegions());
1368 * Test that a view with no Overview is restored with no Overview, even if
1369 * 'Open Overview' is selected in Preferences
1373 @Test(groups = { "Functional" }, enabled = true)
1374 public void testStoreAndRecoverNoOverview() throws Exception
1376 Cache.setProperty("SHOW_OVERVIEW", "false");
1377 Desktop.instance.closeAll_actionPerformed(null);
1378 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1379 ">seq1\nMATRSQFLVNF\n", DataSourceType.PASTE);
1381 File tfile = File.createTempFile("testStoreAndRecoverOverview", ".jvp");
1382 new Jalview2XML(false).saveState(tfile);
1383 Desktop.instance.closeAll_actionPerformed(null);
1385 Cache.setProperty("SHOW_OVERVIEW", "true");
1386 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1387 DataSourceType.FILE);
1389 assertNull(af.alignPanel.getOverviewPanel());