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.math.BigInteger;
36 import java.util.ArrayList;
37 import java.util.BitSet;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Locale;
43 import javax.swing.JInternalFrame;
45 import org.testng.Assert;
46 import org.testng.AssertJUnit;
47 import org.testng.annotations.BeforeClass;
48 import org.testng.annotations.Test;
50 import jalview.analysis.AlignmentUtils;
51 import jalview.analysis.scoremodels.SimilarityParams;
52 import jalview.api.AlignViewportI;
53 import jalview.api.AlignmentViewPanel;
54 import jalview.api.FeatureColourI;
55 import jalview.api.ViewStyleI;
56 import jalview.bin.Cache;
57 import jalview.datamodel.AlignmentAnnotation;
58 import jalview.datamodel.AlignmentI;
59 import jalview.datamodel.Annotation;
60 import jalview.datamodel.ContactListI;
61 import jalview.datamodel.ContactMatrix;
62 import jalview.datamodel.ContactMatrixI;
63 import jalview.datamodel.DBRefEntry;
64 import jalview.datamodel.GeneLocus;
65 import jalview.datamodel.GroupSet;
66 import jalview.datamodel.HiddenSequences;
67 import jalview.datamodel.Mapping;
68 import jalview.datamodel.PDBEntry;
69 import jalview.datamodel.PDBEntry.Type;
70 import jalview.datamodel.Sequence;
71 import jalview.datamodel.Sequence.DBModList;
72 import jalview.datamodel.SequenceCollectionI;
73 import jalview.datamodel.SequenceFeature;
74 import jalview.datamodel.SequenceGroup;
75 import jalview.datamodel.SequenceI;
76 import jalview.datamodel.features.FeatureMatcher;
77 import jalview.datamodel.features.FeatureMatcherSet;
78 import jalview.datamodel.features.FeatureMatcherSetI;
79 import jalview.gui.AlignFrame;
80 import jalview.gui.AlignViewport;
81 import jalview.gui.AlignmentPanel;
82 import jalview.gui.Desktop;
83 import jalview.gui.JvOptionPane;
84 import jalview.gui.OverviewPanel;
85 import jalview.gui.PCAPanel;
86 import jalview.gui.PopupMenu;
87 import jalview.gui.Preferences;
88 import jalview.gui.SliderPanel;
89 import jalview.io.DataSourceType;
90 import jalview.io.FileFormat;
91 import jalview.io.FileLoader;
92 import jalview.io.Jalview2xmlBase;
93 import jalview.renderer.ResidueShaderI;
94 import jalview.schemes.AnnotationColourGradient;
95 import jalview.schemes.BuriedColourScheme;
96 import jalview.schemes.ColourSchemeI;
97 import jalview.schemes.ColourSchemeProperty;
98 import jalview.schemes.FeatureColour;
99 import jalview.schemes.JalviewColourScheme;
100 import jalview.schemes.RNAHelicesColour;
101 import jalview.schemes.StrandColourScheme;
102 import jalview.schemes.TCoffeeColourScheme;
103 import jalview.structure.StructureImportSettings;
104 import jalview.util.MapList;
105 import jalview.util.matcher.Condition;
106 import jalview.viewmodel.AlignmentViewport;
107 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
108 import jalview.ws.datamodel.MappableContactMatrixI;
109 import jalview.ws.datamodel.alphafold.PAEContactMatrix;
111 @Test(singleThreaded = true)
112 public class Jalview2xmlTests extends Jalview2xmlBase
116 @BeforeClass(alwaysRun = true)
117 public void setUpJvOptionPane()
119 if (Desktop.instance != null)
120 Desktop.instance.closeAll_actionPerformed(null);
121 JvOptionPane.setInteractiveMode(false);
122 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
125 @Test(groups = { "Functional" })
126 public void testRNAStructureRecovery() throws Exception
128 String inFile = "examples/RF00031_folded.stk";
129 String tfile = File.createTempFile("JalviewTest", ".jvp")
131 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
132 DataSourceType.FILE);
133 assertNotNull(af, "Didn't read input file " + inFile);
134 int olddsann = countDsAnn(af.getViewport());
135 assertTrue(olddsann > 0, "Didn't find any dataset annotations");
136 af.changeColour_actionPerformed(
137 JalviewColourScheme.RNAHelices.toString());
140 .getGlobalColourScheme() instanceof RNAHelicesColour,
141 "Couldn't apply RNA helices colourscheme");
142 af.saveAlignment(tfile, FileFormat.Jalview);
143 assertTrue(af.isSaveAlignmentSuccessful(),
144 "Failed to store as a project.");
145 af.closeMenuItem_actionPerformed(true);
147 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
148 DataSourceType.FILE);
149 assertNotNull(af, "Failed to import new project");
150 int newdsann = countDsAnn(af.getViewport());
151 assertEquals(olddsann, newdsann,
152 "Differing numbers of dataset sequence annotation\nOriginally "
153 + olddsann + " and now " + newdsann);
155 "Read in same number of annotations as originally present ("
160 .getGlobalColourScheme() instanceof RNAHelicesColour,
161 "RNA helices colourscheme was not applied on import.");
164 @Test(groups = { "Functional" })
165 public void testTCoffeeScores() throws Exception
167 String inFile = "examples/uniref50.fa",
168 inAnnot = "examples/uniref50.score_ascii";
169 String tfile = File.createTempFile("JalviewTest", ".jvp")
171 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
172 DataSourceType.FILE);
173 assertNotNull(af, "Didn't read input file " + inFile);
174 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
175 AlignViewport viewport = af.getViewport();
176 assertSame(viewport.getGlobalColourScheme().getClass(),
177 TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
179 ColourSchemeProperty.getColourScheme(viewport,
180 viewport.getAlignment(),
181 viewport.getGlobalColourScheme().getSchemeName()),
182 "Recognise T-Coffee score from string");
184 af.saveAlignment(tfile, FileFormat.Jalview);
185 assertTrue(af.isSaveAlignmentSuccessful(),
186 "Failed to store as a project.");
187 af.closeMenuItem_actionPerformed(true);
189 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
190 DataSourceType.FILE);
191 assertNotNull(af, "Failed to import new project");
192 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
193 TCoffeeColourScheme.class,
194 "Didn't set T-coffee colourscheme for imported project.");
196 "T-Coffee score shading successfully recovered from project.");
199 @Test(groups = { "Functional" })
200 public void testColourByAnnotScores() throws Exception
202 String inFile = "examples/uniref50.fa",
203 inAnnot = "examples/testdata/uniref50_iupred.jva";
204 String tfile = File.createTempFile("JalviewTest", ".jvp")
206 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
207 DataSourceType.FILE);
208 assertNotNull(af, "Didn't read input file " + inFile);
209 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
210 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
211 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
214 aa != null && aa.length > 0,
215 "Didn't find any IUPred annotation to use to shade alignment.");
216 AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
217 AnnotationColourGradient.ABOVE_THRESHOLD);
218 AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0], null,
219 AnnotationColourGradient.BELOW_THRESHOLD);
220 cs.setSeqAssociated(true);
221 gcs.setSeqAssociated(true);
223 SequenceGroup sg = new SequenceGroup();
226 sg.cs.setColourScheme(gcs);
227 af.getViewport().getAlignment().addGroup(sg);
228 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
229 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
230 af.alignPanel.alignmentChanged();
231 af.saveAlignment(tfile, FileFormat.Jalview);
232 assertTrue(af.isSaveAlignmentSuccessful(),
233 "Failed to store as a project.");
234 af.closeMenuItem_actionPerformed(true);
236 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
237 DataSourceType.FILE);
238 assertNotNull(af, "Failed to import new project");
240 // check for group and alignment colourschemes
242 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
243 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups().get(0)
245 assertNotNull(_rcs, "Didn't recover global colourscheme");
246 assertTrue(_rcs instanceof AnnotationColourGradient,
247 "Didn't recover annotation colour global scheme");
248 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
249 assertTrue(__rcs.isSeqAssociated(),
250 "Annotation colourscheme wasn't sequence associated");
252 boolean diffseqcols = false, diffgseqcols = false;
253 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
254 for (int p = 0, pSize = af.getViewport().getAlignment()
255 .getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++)
257 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
258 .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
263 assertTrue(diffseqcols, "Got Different sequence colours");
265 "Per sequence colourscheme (Background) successfully applied and recovered.");
267 assertNotNull(_rgcs, "Didn't recover group colourscheme");
268 assertTrue(_rgcs instanceof AnnotationColourGradient,
269 "Didn't recover annotation colour group colourscheme");
270 __rcs = (AnnotationColourGradient) _rgcs;
271 assertTrue(__rcs.isSeqAssociated(),
272 "Group Annotation colourscheme wasn't sequence associated");
274 for (int p = 0, pSize = af.getViewport().getAlignment()
275 .getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++)
277 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null,
278 0f) != _rgcs.findColour(sqs[2].getCharAt(p), p, sqs[2], null,
284 assertTrue(diffgseqcols, "Got Different group sequence colours");
286 "Per sequence (Group) colourscheme successfully applied and recovered.");
289 @Test(groups = { "Functional" })
290 public void gatherViewsHere() throws Exception
292 int origCount = Desktop.getDesktopAlignFrames() == null ? 0
293 : Desktop.getDesktopAlignFrames().length;
294 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
295 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
296 assertNotNull(af, "Didn't read in the example file correctly.");
297 assertTrue(Desktop.getDesktopAlignFrames().length == 1 + origCount,
298 "Didn't gather the views in the example file.");
303 * Test for JAL-2223 - multiple mappings in View Mapping report
307 @Test(groups = { "Functional" })
308 public void noDuplicatePdbMappingsMade() throws Exception
310 StructureImportSettings.setProcessSecondaryStructure(true);
311 StructureImportSettings.setVisibleChainAnnotation(true);
312 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
313 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
314 assertNotNull(af, "Didn't read in the example file correctly.");
316 // locate Jmol viewer
317 // count number of PDB mappings the structure selection manager holds -
318 String pdbFile = af.getCurrentView().getStructureSelectionManager()
319 .findFileForPDBId("1A70");
321 af.getCurrentView().getStructureSelectionManager()
322 .getMapping(pdbFile).length,
323 2, "Expected only two mappings for 1A70");
327 @Test(groups = { "Functional" })
328 public void viewRefPdbAnnotation() throws Exception
330 StructureImportSettings.setProcessSecondaryStructure(true);
331 StructureImportSettings.setVisibleChainAnnotation(true);
332 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
333 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
334 assertNotNull(af, "Didn't read in the example file correctly.");
335 AlignmentViewPanel sps = null;
336 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
338 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
344 assertNotNull(sps, "Couldn't find the structure view");
345 AlignmentAnnotation refan = null;
346 for (AlignmentAnnotation ra : sps.getAlignment()
347 .getAlignmentAnnotation())
355 assertNotNull(refan, "Annotation secondary structure not found.");
356 SequenceI sq = sps.getAlignment().findName("1A70|");
357 assertNotNull(sq, "Couldn't find 1a70 null chain");
358 // compare the manually added temperature factor annotation
359 // to the track automatically transferred from the pdb structure on load
360 assertNotNull(sq.getDatasetSequence().getAnnotation(),
361 "1a70 has no annotation");
362 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
364 AlignmentAnnotation alaa;
365 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
366 alaa.adjustForAlignment();
367 if (ala.graph == refan.graph)
369 for (int p = 0; p < ala.annotations.length; p++)
374 assertTrue((alaa.annotations[p] == null
375 && refan.annotations[p] == null)
376 || alaa.annotations[p].value == refan.annotations[p].value,
377 "Mismatch at alignment position " + p);
378 } catch (NullPointerException q)
380 Assert.fail("Mismatch of alignment annotations at position " + p
381 + " Ref seq ann: " + refan.annotations[p]
382 + " alignment " + alaa.annotations[p]);
390 @Test(groups = { "Functional" })
391 public void testCopyViewSettings() throws Exception
393 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
394 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
395 assertNotNull(af, "Didn't read in the example file correctly.");
396 AlignmentViewPanel sps = null, groups = null;
397 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
399 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
403 if (ap.getViewName().contains("MAFFT"))
408 assertNotNull(sps, "Couldn't find the structure view");
409 assertNotNull(groups, "Couldn't find the MAFFT view");
411 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
412 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
413 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
415 groups.getAlignViewport().setViewStyle(structureStyle);
416 AssertJUnit.assertFalse(
417 groupStyle.sameStyle(groups.getAlignViewport().getViewStyle()));
418 Assert.assertTrue(structureStyle
419 .sameStyle(groups.getAlignViewport().getViewStyle()));
424 * test store and recovery of expanded views
428 @Test(groups = { "Functional" }, enabled = true)
429 public void testStoreAndRecoverExpandedviews() throws Exception
431 Desktop.instance.closeAll_actionPerformed(null);
433 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
434 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
435 Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 1);
436 String afid = af.getViewport().getSequenceSetId();
438 // check FileLoader returned a reference to the one alignFrame that is
439 // actually on the Desktop
440 assertSame(af, Desktop.getAlignFrameFor(af.getViewport()),
441 "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
443 Desktop.explodeViews(af);
445 int oldviews = Desktop.getDesktopAlignFrames().length;
446 Assert.assertEquals(Desktop.getDesktopAlignFrames().length,
447 Desktop.getAlignmentPanels(afid).length);
448 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
451 new Jalview2XML(false).saveState(tfile);
454 Assert.fail("Didn't save the expanded view state", e);
455 } catch (Exception e)
457 Assert.fail("Didn't save the expanded view state", e);
459 Desktop.instance.closeAll_actionPerformed(null);
460 if (Desktop.getDesktopAlignFrames() != null)
462 Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
464 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
465 DataSourceType.FILE);
466 Assert.assertNotNull(af);
467 Assert.assertEquals(Desktop.getDesktopAlignFrames().length,
468 Desktop.getAlignmentPanels(
469 af.getViewport().getSequenceSetId()).length);
470 Assert.assertEquals(Desktop
471 .getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
476 * Test save and reload of a project with a different representative sequence
481 @Test(groups = { "Functional" })
482 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
484 Desktop.instance.closeAll_actionPerformed(null);
485 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
486 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
487 assertNotNull(af, "Didn't read in the example file correctly.");
488 String afid = af.getViewport().getSequenceSetId();
490 // remember reference sequence for each panel
491 Map<String, SequenceI> refseqs = new HashMap<>();
494 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
495 * as reference sequence for itself and the preceding sequence
498 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
500 AlignViewportI av = ap.getAlignViewport();
501 AlignmentI alignment = ap.getAlignment();
502 int repIndex = n % alignment.getHeight();
503 SequenceI rep = alignment.getSequenceAt(repIndex);
504 refseqs.put(ap.getViewName(), rep);
506 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
507 // todo refactor this to an alignment view controller
508 av.setDisplayReferenceSeq(true);
509 av.setColourByReferenceSeq(true);
510 av.getAlignment().setSeqrep(rep);
514 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
518 new Jalview2XML(false).saveState(tfile);
519 } catch (Throwable e)
521 Assert.fail("Didn't save the expanded view state", e);
523 Desktop.instance.closeAll_actionPerformed(null);
524 if (Desktop.getDesktopAlignFrames() != null)
526 Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
529 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
530 DataSourceType.FILE);
531 afid = af.getViewport().getSequenceSetId();
533 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
535 // check representative
536 AlignmentI alignment = ap.getAlignment();
537 SequenceI rep = alignment.getSeqrep();
538 Assert.assertNotNull(rep,
539 "Couldn't restore sequence representative from project");
540 // can't use a strong equals here, because by definition, the sequence IDs
541 // will be different.
542 // could set vamsas session save/restore flag to preserve IDs across
544 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
546 "Representative wasn't the same when recovered.");
547 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
548 "Display reference sequence view setting not set.");
549 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
550 "Colour By Reference Seq view setting not set.");
554 @Test(groups = { "Functional" })
555 public void testIsVersionStringLaterThan()
558 * No version / development / test / autobuild is leniently assumed to be
561 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
562 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
563 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
564 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
565 "Development Build"));
566 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
567 "DEVELOPMENT BUILD"));
568 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
569 "Development Build"));
570 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
571 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
572 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
574 Jalview2XML.isVersionStringLaterThan(null, "Automated Build"));
575 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
577 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
581 * same version returns true i.e. compatible
583 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
584 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
585 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
586 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
587 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
590 * later version returns true
592 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
593 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
594 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
595 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
596 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
599 * earlier version returns false
601 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
602 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
603 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
604 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
605 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
607 * test for patch release versions
609 assertFalse(Jalview2XML.isVersionStringLaterThan("2.11.3.0", "2.11.2"));
610 assertTrue(Jalview2XML.isVersionStringLaterThan("2.11.3.0", "2.11.4"));
612 Jalview2XML.isVersionStringLaterThan("2.12.2.0b1", "2.12.2.0"));
614 Jalview2XML.isVersionStringLaterThan("2.12.2.3", "2.12.2.2"));
619 * Test save and reload of a project with a different sequence group (and
620 * representative sequence) in each view.
624 @Test(groups = { "Functional" })
625 public void testStoreAndRecoverGroupRepSeqs() throws Exception
627 Desktop.instance.closeAll_actionPerformed(null);
628 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
629 "examples/uniref50.fa", DataSourceType.FILE);
630 assertNotNull(af, "Didn't read in the example file correctly.");
631 String afid = af.getViewport().getSequenceSetId();
632 // make a second view of the alignment
633 af.newView_actionPerformed(null);
636 * remember representative and hidden sequences marked
639 Map<String, SequenceI> repSeqs = new HashMap<>();
640 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
643 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
644 * as reference sequence for itself and the preceding sequence
647 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
649 AlignViewportI av = ap.getAlignViewport();
650 AlignmentI alignment = ap.getAlignment();
651 int repIndex = n % alignment.getHeight();
652 // ensure at least one preceding sequence i.e. index >= 1
653 repIndex = Math.max(repIndex, 1);
654 SequenceI repSeq = alignment.getSequenceAt(repIndex);
655 repSeqs.put(ap.getViewName(), repSeq);
656 List<String> hiddenNames = new ArrayList<>();
657 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
660 * have rep sequence represent itself and the one before it
661 * this hides the group (except for the rep seq)
663 SequenceGroup sg = new SequenceGroup();
664 sg.addSequence(repSeq, false);
665 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
666 sg.addSequence(precedingSeq, false);
667 sg.setSeqrep(repSeq);
668 assertTrue(sg.getSequences().contains(repSeq));
669 assertTrue(sg.getSequences().contains(precedingSeq));
670 av.setSelectionGroup(sg);
671 assertSame(repSeq, sg.getSeqrep());
674 * represent group with sequence adds to a map of hidden rep sequences
675 * (it does not create a group on the alignment)
677 ((AlignmentViewport) av).hideSequences(repSeq, true);
678 assertSame(repSeq, sg.getSeqrep());
679 assertTrue(sg.getSequences().contains(repSeq));
680 assertTrue(sg.getSequences().contains(precedingSeq));
681 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
682 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
683 .getHiddenRepSequences();
684 assertNotNull(hiddenRepSeqsMap);
685 assertEquals(1, hiddenRepSeqsMap.size());
686 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
687 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
688 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
689 hiddenNames.add(precedingSeq.getName());
693 File tfile = File.createTempFile("testStoreAndRecoverGroupReps",
697 new Jalview2XML(false).saveState(tfile);
698 } catch (Throwable e)
700 Assert.fail("Didn't save the expanded view state", e);
702 Desktop.instance.closeAll_actionPerformed(null);
703 if (Desktop.getDesktopAlignFrames() != null)
705 Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
708 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
709 DataSourceType.FILE);
710 afid = af.getViewport().getSequenceSetId();
712 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
714 String viewName = ap.getViewName();
715 AlignViewportI av = ap.getAlignViewport();
716 AlignmentI alignment = ap.getAlignment();
717 List<SequenceGroup> groups = alignment.getGroups();
718 assertNotNull(groups);
719 assertTrue(groups.isEmpty(), "Alignment has groups");
720 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
721 .getHiddenRepSequences();
722 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
723 assertEquals(1, hiddenRepSeqsMap.size());
724 assertEquals(repSeqs.get(viewName).getDisplayId(true),
725 hiddenRepSeqsMap.keySet().iterator().next()
726 .getDisplayId(true));
729 * verify hidden sequences in restored panel
731 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
732 HiddenSequences hs = alignment.getHiddenSequences();
733 assertEquals(hidden.size(), hs.getSize(),
734 "wrong number of restored hidden sequences in "
740 * Test save and reload of PDBEntry in Jalview project
744 @Test(groups = { "Functional" })
745 public void testStoreAndRecoverPDBEntry() throws Exception
747 Desktop.instance.closeAll_actionPerformed(null);
748 String exampleFile = "examples/3W5V.pdb";
749 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
750 DataSourceType.FILE);
751 assertNotNull(af, "Didn't read in the example file correctly.");
752 String afid = af.getViewport().getSequenceSetId();
754 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
755 System.out.println();
756 AlignmentViewPanel ap = alignPanels[0];
757 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
758 String testFile = tfileBase + exampleFile;
759 AlignmentI alignment = ap.getAlignment();
760 System.out.println("blah");
761 SequenceI[] seqs = alignment.getSequencesArray();
762 Assert.assertNotNull(seqs[0]);
763 Assert.assertNotNull(seqs[1]);
764 Assert.assertNotNull(seqs[2]);
765 Assert.assertNotNull(seqs[3]);
766 Assert.assertNotNull(seqs[0].getDatasetSequence());
767 Assert.assertNotNull(seqs[1].getDatasetSequence());
768 Assert.assertNotNull(seqs[2].getDatasetSequence());
769 Assert.assertNotNull(seqs[3].getDatasetSequence());
770 PDBEntry[] pdbEntries = new PDBEntry[4];
771 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
772 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
773 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
774 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
776 seqs[0].getDatasetSequence().getAllPDBEntries().get(0),
779 seqs[1].getDatasetSequence().getAllPDBEntries().get(0),
782 seqs[2].getDatasetSequence().getAllPDBEntries().get(0),
785 seqs[3].getDatasetSequence().getAllPDBEntries().get(0),
788 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
791 new Jalview2XML(false).saveState(tfile);
792 } catch (Throwable e)
794 Assert.fail("Didn't save the state", e);
796 Desktop.instance.closeAll_actionPerformed(null);
797 if (Desktop.getDesktopAlignFrames() != null)
799 Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
802 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
803 tfile.getAbsolutePath(), DataSourceType.FILE);
804 String rfid = restoredFrame.getViewport().getSequenceSetId();
805 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
806 AlignmentViewPanel rap = rAlignPanels[0];
807 AlignmentI rAlignment = rap.getAlignment();
808 System.out.println("blah");
809 SequenceI[] rseqs = rAlignment.getSequencesArray();
810 Assert.assertNotNull(rseqs[0]);
811 Assert.assertNotNull(rseqs[1]);
812 Assert.assertNotNull(rseqs[2]);
813 Assert.assertNotNull(rseqs[3]);
814 Assert.assertNotNull(rseqs[0].getDatasetSequence());
815 Assert.assertNotNull(rseqs[1].getDatasetSequence());
816 Assert.assertNotNull(rseqs[2].getDatasetSequence());
817 Assert.assertNotNull(rseqs[3].getDatasetSequence());
819 // The Asserts below are expected to fail until the PDB chainCode is
820 // recoverable from a Jalview projects
821 for (int chain = 0; chain < 4; chain++)
823 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
825 PDBEntry expected = pdbEntries[chain];
826 Assert.assertEquals(recov.getId(), expected.getId(),
828 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
830 Assert.assertEquals(recov.getType(), expected.getType(),
831 "Mismatch PDBEntry 'Type'");
832 Assert.assertNotNull(recov.getFile(),
833 "Recovered PDBEntry should have a non-null file entry");
835 recov.getFile().toLowerCase(Locale.ENGLISH)
837 recov.getFile().length() - 3,
838 "Recovered PDBEntry file should have PDB suffix");
843 * Configure an alignment and a sub-group each with distinct colour schemes,
844 * Conservation and PID thresholds, and confirm these are restored from the
847 * @throws IOException
849 @Test(groups = { "Functional" })
850 public void testStoreAndRecoverAnnotationRowElementColours()
853 Desktop.instance.closeAll_actionPerformed(null);
854 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded("SEQ\tMNQ",
855 DataSourceType.PASTE);
857 AlignViewport av = af.getViewport();
858 AlignmentI al = av.getAlignment();
860 fsq = al.getSequenceAt(0);
861 Annotation annots[] = new Annotation[fsq.getLength()];
862 AlignmentAnnotation ala = new AlignmentAnnotation("Colour", "Annots",
864 annots[0] = new Annotation(1.0f);
865 annots[1] = new Annotation(2.0f);
866 annots[2] = new Annotation(3.0f);
867 annots[0].colour = Color.RED;
868 annots[1].colour = Color.GREEN;
869 annots[2].colour = Color.BLUE;
870 ala.validateRangeAndDisplay();
871 al.getSequenceAt(0).addAlignmentAnnotation(ala);
872 al.addAnnotation(ala);
874 * and colour by annotation
876 AnnotationColourGradient acg = new AnnotationColourGradient(ala,
877 af.alignPanel.av.getGlobalColourScheme(), 0);
878 acg.setSeqAssociated(true);
879 acg.setPredefinedColours(true);
880 af.changeColour(acg);
881 Color seqcol[] = new Color[3];
882 for (int iStart = fsq.findIndex(fsq.getStart()), i = 0; i < 3; i++)
884 seqcol[i] = af.alignPanel.getSeqPanel().seqCanvas
885 .getSequenceRenderer()
886 .getResidueColour(fsq, iStart + i, null);
889 * save project, close windows, reload project, verify
891 File tfile = File.createTempFile(
892 "testStoreAndRecoverAnnotRowElemColors", ".jvp");
893 tfile.deleteOnExit();
894 new Jalview2XML(false).saveState(tfile);
895 // Desktop.instance.closeAll_actionPerformed(null);
896 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
897 DataSourceType.FILE);
898 Assert.assertNotNull(af, "Failed to reload project");
900 * verify alignment annotation has colors
902 av = af.getViewport();
904 ColourSchemeI loadedCscheme = av.getGlobalColourScheme();
905 Assert.assertTrue(loadedCscheme instanceof AnnotationColourGradient,
906 "Didn't apply Annotation colour gradient");
907 acg = (AnnotationColourGradient) loadedCscheme;
908 assertTrue(acg.isSeqAssociated());
909 assertTrue(acg.isPredefinedColours());
911 al = av.getAlignment();
912 fsq = al.getSequenceAt(0);
913 ala = fsq.getAnnotation()[0];
914 Assert.assertNotNull(ala, "No annotation row recovered");
915 Assert.assertNotNull(ala.annotations);
916 for (int iStart = al.getSequenceAt(0)
917 .findIndex(al.getSequenceAt(0).getStart()), i = 0; i < 3; i++)
919 Assert.assertTrue(ala.annotations[i].colour != null);
920 Assert.assertTrue(ala.annotations[i].colour.equals(annots[i].colour));
921 Color newseqcol = af.alignPanel.getSeqPanel().seqCanvas
922 .getSequenceRenderer()
923 .getResidueColour(fsq, iStart + i, null);
924 Assert.assertTrue(seqcol[i].equals(newseqcol),
925 "Sequence shading is different");
932 * Configure an alignment and a sub-group each with distinct colour schemes,
933 * Conservation and PID thresholds, and confirm these are restored from the
936 * @throws IOException
938 @Test(groups = { "Functional" })
939 public void testStoreAndRecoverColourThresholds() throws IOException
941 Desktop.instance.closeAll_actionPerformed(null);
942 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
943 "examples/uniref50.fa", DataSourceType.FILE);
945 AlignViewport av = af.getViewport();
946 AlignmentI al = av.getAlignment();
949 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
951 av.setColourAppliesToAllGroups(false);
952 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
953 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
954 af.abovePIDThreshold_actionPerformed(true);
955 SliderPanel sp = SliderPanel.getSliderPanel();
956 assertFalse(sp.isForConservation());
958 af.conservationMenuItem_actionPerformed(true);
959 sp = SliderPanel.getSliderPanel();
960 assertTrue(sp.isForConservation());
962 ResidueShaderI rs = av.getResidueShading();
963 assertEquals(rs.getThreshold(), 10);
964 assertTrue(rs.conservationApplied());
965 assertEquals(rs.getConservationInc(), 20);
968 * create a group with Strand colouring, 30% Conservation
969 * and 40% PID threshold
970 * (notice menu action applies to selection group even if mouse click
971 * is at a sequence not in the group)
973 SequenceGroup sg = new SequenceGroup();
974 sg.addSequence(al.getSequenceAt(0), false);
977 av.setSelectionGroup(sg);
978 PopupMenu popupMenu = new PopupMenu(af.alignPanel, al.getSequenceAt(2),
980 popupMenu.changeColour_actionPerformed(
981 JalviewColourScheme.Strand.toString());
982 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
983 assertEquals(al.getGroups().size(), 1);
984 assertSame(al.getGroups().get(0), sg);
985 popupMenu.conservationMenuItem_actionPerformed(true);
986 sp = SliderPanel.getSliderPanel();
987 assertTrue(sp.isForConservation());
989 popupMenu.abovePIDColour_actionPerformed(true);
990 sp = SliderPanel.getSliderPanel();
991 assertFalse(sp.isForConservation());
993 assertTrue(sg.getGroupColourScheme().conservationApplied());
994 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
995 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
998 * save project, close windows, reload project, verify
1000 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
1002 tfile.deleteOnExit();
1003 new Jalview2XML(false).saveState(tfile);
1004 Desktop.instance.closeAll_actionPerformed(null);
1005 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1006 DataSourceType.FILE);
1007 Assert.assertNotNull(af, "Failed to reload project");
1010 * verify alignment (background) colouring
1012 rs = af.getViewport().getResidueShading();
1013 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
1014 assertEquals(rs.getThreshold(), 10);
1015 assertTrue(rs.conservationApplied());
1016 assertEquals(rs.getConservationInc(), 20);
1019 * verify group colouring
1021 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
1022 rs = af.getViewport().getAlignment().getGroups().get(0)
1023 .getGroupColourScheme();
1024 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
1025 assertEquals(rs.getThreshold(), 40);
1026 assertTrue(rs.conservationApplied());
1027 assertEquals(rs.getConservationInc(), 30);
1031 * Test save and reload of feature colour schemes and filter settings
1033 * @throws IOException
1035 @Test(groups = { "Functional" })
1036 public void testSaveLoadFeatureColoursAndFilters() throws IOException
1038 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1039 ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
1040 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
1043 * add some features to the sequence
1046 addFeatures(seq1, "type1", score++);
1047 addFeatures(seq1, "type2", score++);
1048 addFeatures(seq1, "type3", score++);
1049 addFeatures(seq1, "type4", score++);
1050 addFeatures(seq1, "type5", score++);
1053 * set colour schemes for features
1055 FeatureRendererModel fr = af.getFeatureRenderer();
1056 fr.findAllFeatures(true);
1059 fr.setColour("type1", new FeatureColour(Color.red));
1062 FeatureColourI byLabel = new FeatureColour();
1063 byLabel.setColourByLabel(true);
1064 fr.setColour("type2", byLabel);
1066 // type3: by score above threshold
1067 FeatureColourI byScore = new FeatureColour(null, Color.BLACK,
1068 Color.BLUE, null, 1, 10);
1069 byScore.setAboveThreshold(true);
1070 byScore.setThreshold(2f);
1071 fr.setColour("type3", byScore);
1073 // type4: by attribute AF
1074 FeatureColourI byAF = new FeatureColour();
1075 byAF.setColourByLabel(true);
1076 byAF.setAttributeName("AF");
1077 fr.setColour("type4", byAF);
1079 // type5: by attribute CSQ:PolyPhen below threshold
1080 FeatureColourI byPolyPhen = new FeatureColour(null, Color.BLACK,
1081 Color.BLUE, null, 1, 10);
1082 byPolyPhen.setBelowThreshold(true);
1083 byPolyPhen.setThreshold(3f);
1084 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
1085 fr.setColour("type5", byPolyPhen);
1088 * set filters for feature types
1091 // filter type1 features by (label contains "x")
1092 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
1093 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
1094 fr.setFeatureFilter("type1", filterByX);
1096 // filter type2 features by (score <= 2.4 and score > 1.1)
1097 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
1098 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
1099 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
1100 fr.setFeatureFilter("type2", filterByScore);
1102 // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
1103 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
1105 .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
1106 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
1108 fr.setFeatureFilter("type3", filterByXY);
1111 * save as Jalview project
1113 File tfile = File.createTempFile("JalviewTest", ".jvp");
1114 tfile.deleteOnExit();
1115 String filePath = tfile.getAbsolutePath();
1116 af.saveAlignment(filePath, FileFormat.Jalview);
1117 assertTrue(af.isSaveAlignmentSuccessful(),
1118 "Failed to store as a project.");
1121 * close current alignment and load the saved project
1123 af.closeMenuItem_actionPerformed(true);
1125 af = new FileLoader().LoadFileWaitTillLoaded(filePath,
1126 DataSourceType.FILE);
1127 assertNotNull(af, "Failed to import new project");
1130 * verify restored feature colour schemes and filters
1132 fr = af.getFeatureRenderer();
1133 FeatureColourI fc = fr.getFeatureStyle("type1");
1134 assertTrue(fc.isSimpleColour());
1135 assertEquals(fc.getColour(), Color.red);
1136 fc = fr.getFeatureStyle("type2");
1137 assertTrue(fc.isColourByLabel());
1138 fc = fr.getFeatureStyle("type3");
1139 assertTrue(fc.isGraduatedColour());
1140 assertNull(fc.getAttributeName());
1141 assertTrue(fc.isAboveThreshold());
1142 assertEquals(fc.getThreshold(), 2f);
1143 fc = fr.getFeatureStyle("type4");
1144 assertTrue(fc.isColourByLabel());
1145 assertTrue(fc.isColourByAttribute());
1146 assertEquals(fc.getAttributeName(), new String[] { "AF" });
1147 fc = fr.getFeatureStyle("type5");
1148 assertTrue(fc.isGraduatedColour());
1149 assertTrue(fc.isColourByAttribute());
1150 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
1151 assertTrue(fc.isBelowThreshold());
1152 assertEquals(fc.getThreshold(), 3f);
1154 assertEquals(fr.getFeatureFilter("type1").toStableString(),
1155 "Label Contains x");
1156 assertEquals(fr.getFeatureFilter("type2").toStableString(),
1157 "(Score LE 2.4) AND (Score GT 1.1)");
1158 assertEquals(fr.getFeatureFilter("type3").toStableString(),
1159 "(AF Contains X) OR (CSQ:PolyPhen NE 0)");
1162 private void addFeature(SequenceI seq, String featureType, int score)
1164 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
1166 sf.setValue("AF", score);
1167 sf.setValue("CSQ", new HashMap<String, String>()
1170 put("PolyPhen", Integer.toString(score));
1173 seq.addSequenceFeature(sf);
1177 * Adds two features of the given type to the given sequence, also setting the
1178 * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1181 * @param featureType
1184 private void addFeatures(SequenceI seq, String featureType, int score)
1186 addFeature(seq, featureType, score++);
1187 addFeature(seq, featureType, score);
1191 * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
1192 * view (JAL-3171) this test ensures we can import and merge those views
1194 @Test(groups = { "Functional" })
1195 public void testMergeDatasetsforViews() throws IOException
1197 // simple project - two views on one alignment
1198 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
1199 "examples/testdata/projects/twoViews.jvp", DataSourceType.FILE);
1201 assertTrue(af.getAlignPanels().size() > 1);
1206 * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
1207 * view (JAL-3171) this test ensures we can import and merge those views This
1208 * is a more complex project
1210 @Test(groups = { "Functional" })
1211 public void testMergeDatasetsforManyViews() throws IOException
1213 Desktop.instance.closeAll_actionPerformed(null);
1215 // complex project - one dataset, several views on several alignments
1216 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
1217 "examples/testdata/projects/manyViews.jvp",
1218 DataSourceType.FILE);
1221 AlignmentI ds = null;
1222 for (AlignFrame alignFrame : Desktop.getDesktopAlignFrames())
1226 ds = verifyDs(alignFrame);
1230 // check that this frame's dataset matches the last
1231 assertTrue(ds == verifyDs(alignFrame));
1236 private AlignmentI verifyDs(AlignFrame af)
1238 AlignmentI ds = null;
1239 for (AlignmentViewPanel ap : af.getAlignPanels())
1243 ds = ap.getAlignment().getDataset();
1247 assertTrue(ap.getAlignment().getDataset() == ds,
1248 "Dataset was not the same for imported 2.10.5 project with several alignment views");
1254 @Test(groups = "Functional")
1255 public void testPcaViewAssociation() throws IOException
1257 Desktop.instance.closeAll_actionPerformed(null);
1258 final String PCAVIEWNAME = "With PCA";
1259 // create a new tempfile
1260 File tempfile = File.createTempFile("jvPCAviewAssoc", "jvp");
1263 String exampleFile = "examples/uniref50.fa";
1264 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
1265 DataSourceType.FILE);
1266 assertNotNull(af, "Didn't read in the example file correctly.");
1267 AlignmentPanel origView = (AlignmentPanel) af.getAlignPanels().get(0);
1268 AlignmentPanel newview = af.newView(PCAVIEWNAME, true);
1269 // create another for good measure
1270 af.newView("Not the PCA View", true);
1271 PCAPanel pcaPanel = new PCAPanel(origView, "BLOSUM62",
1272 new SimilarityParams(true, true, true, false));
1273 // we're in the test exec thread, so we can just run synchronously here
1276 // now switch the linked view
1277 pcaPanel.selectAssociatedView(newview);
1279 assertTrue(pcaPanel.getAlignViewport() == newview.getAlignViewport(),
1280 "PCA should be associated with 'With PCA' view: test is broken");
1282 // now save and reload project
1283 Jalview2XML jv2xml = new jalview.project.Jalview2XML(false);
1285 jv2xml.saveState(tempfile);
1286 assertTrue(jv2xml.errorMessage == null,
1287 "Failed to save dummy project with PCA: test broken");
1291 Desktop.instance.closeAll_actionPerformed(null);
1292 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1293 tempfile.getCanonicalPath(), DataSourceType.FILE);
1294 JInternalFrame[] frames = Desktop.instance.getAllFrames();
1295 // PCA and the tabbed alignment view should be the only two windows on the
1297 assertEquals(frames.length, 2,
1298 "PCA and the tabbed alignment view should be the only two windows on the desktop");
1299 PCAPanel pcaPanel = (PCAPanel) frames[frames[0] == af ? 1 : 0];
1301 AlignmentViewPanel restoredNewView = null;
1302 for (AlignmentViewPanel alignpanel : Desktop.getAlignmentPanels(null))
1304 if (alignpanel.getAlignViewport() == pcaPanel.getAlignViewport())
1306 restoredNewView = alignpanel;
1309 assertEquals(restoredNewView.getViewName(), PCAVIEWNAME);
1311 restoredNewView.getAlignViewport() == pcaPanel
1312 .getAlignViewport(),
1313 "Didn't restore correct view association for the PCA view");
1317 * Test save and reload of DBRefEntry including GeneLocus in project
1321 @Test(groups = { "Functional" })
1322 public void testStoreAndRecoverGeneLocus() throws Exception
1324 Desktop.instance.closeAll_actionPerformed(null);
1325 String seqData = ">P30419\nACDE\n>X1235\nGCCTGTGACGAA";
1326 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqData,
1327 DataSourceType.PASTE);
1328 assertNotNull(af, "Didn't read in the example file correctly.");
1330 AlignmentViewPanel ap = Desktop.getAlignmentPanels(null)[0];
1331 SequenceI pep = ap.getAlignment().getSequenceAt(0);
1332 SequenceI cds = ap.getAlignment().getSequenceAt(1);
1335 * give 'protein' a dbref to self, a dbref with map to CDS,
1336 * and a dbref with map to gene 'locus'
1338 DBRefEntry dbref1 = new DBRefEntry("Uniprot", "1", "P30419", null);
1339 pep.addDBRef(dbref1);
1340 Mapping cdsmap = new Mapping(cds,
1341 new MapList(new int[]
1342 { 1, 4 }, new int[] { 1, 12 }, 1, 3));
1343 DBRefEntry dbref2 = new DBRefEntry("EMBLCDS", "2", "X1235", cdsmap);
1344 pep.addDBRef(dbref2);
1345 Mapping locusmap = new Mapping(null,
1346 new MapList(new int[]
1347 { 1, 4 }, new int[] { 2674123, 2674135 }, 1, 3));
1348 DBRefEntry dbref3 = new GeneLocus("human", "GRCh38", "5", locusmap);
1349 pep.addDBRef(dbref3);
1351 File tfile = File.createTempFile("testStoreAndRecoverGeneLocus",
1355 new Jalview2XML(false).saveState(tfile);
1356 } catch (Throwable e)
1358 Assert.fail("Didn't save the state", e);
1360 Desktop.instance.closeAll_actionPerformed(null);
1362 new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1363 DataSourceType.FILE);
1364 AlignmentViewPanel rap = Desktop.getAlignmentPanels(null)[0];
1365 SequenceI rpep = rap.getAlignment().getSequenceAt(0);
1366 DBModList<DBRefEntry> dbrefs = rpep.getDBRefs();
1367 assertEquals(rpep.getName(), "P30419");
1368 assertEquals(dbrefs.size(), 3);
1369 DBRefEntry dbRef = dbrefs.get(0);
1370 assertFalse(dbRef instanceof GeneLocus);
1371 assertNull(dbRef.getMap());
1372 assertEquals(dbRef, dbref1);
1375 * restored dbrefs with mapping have a different 'map to'
1376 * sequence but otherwise match the original dbrefs
1378 dbRef = dbrefs.get(1);
1379 assertFalse(dbRef instanceof GeneLocus);
1380 assertTrue(dbRef.equalRef(dbref2));
1381 assertNotNull(dbRef.getMap());
1382 SequenceI rcds = rap.getAlignment().getSequenceAt(1);
1383 assertSame(dbRef.getMap().getTo(), rcds);
1384 // compare MapList but not map.to
1385 assertEquals(dbRef.getMap().getMap(), dbref2.getMap().getMap());
1388 * GeneLocus map.to is null so can compare Mapping objects
1390 dbRef = dbrefs.get(2);
1391 assertTrue(dbRef instanceof GeneLocus);
1392 assertEquals(dbRef, dbref3);
1396 * test store and recovery of Overview windows
1400 @Test(groups = { "Functional" }, enabled = true)
1401 public void testStoreAndRecoverOverview() throws Exception
1403 Desktop.instance.closeAll_actionPerformed(null);
1405 Cache.setProperty("SHOW_OVERVIEW", "false");
1406 Cache.setProperty(Preferences.USE_LEGACY_GAP, "false");
1407 Cache.setColourProperty(Preferences.GAP_COLOUR, Color.green);
1408 Cache.setColourProperty(Preferences.HIDDEN_COLOUR, Color.yellow);
1409 Cache.setProperty(Preferences.SHOW_OV_HIDDEN_AT_START, "true");
1411 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1412 "examples/uniref50.fa", DataSourceType.FILE);
1415 * open and resize / reposition overview
1417 af.overviewMenuItem_actionPerformed(null);
1418 OverviewPanel ov1 = af.alignPanel.getOverviewPanel();
1420 ov1.setFrameBounds(20, 30, 200, 400);
1421 assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa");
1422 assertTrue(ov1.isShowHiddenRegions());
1425 * open a New View and its Overview and reposition it
1427 af.newView_actionPerformed(null);
1428 af.overviewMenuItem_actionPerformed(null);
1429 OverviewPanel ov2 = af.alignPanel.getOverviewPanel();
1431 assertNotSame(ov1, ov2);
1432 ov2.setFrameBounds(25, 35, 205, 405);
1433 assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa Original");
1434 assertEquals(ov2.getTitle(), "Overview examples/uniref50.fa View 1");
1436 File tfile = File.createTempFile("testStoreAndRecoverOverview", ".jvp");
1437 new Jalview2XML(false).saveState(tfile);
1438 Desktop.instance.closeAll_actionPerformed(null);
1441 * change preferences (should _not_ affect reloaded Overviews)
1443 Cache.setProperty("SHOW_OVERVIEW", "true");
1444 Cache.setProperty(Preferences.USE_LEGACY_GAP, "true");
1445 Cache.setColourProperty(Preferences.GAP_COLOUR, Color.blue);
1446 Cache.setColourProperty(Preferences.HIDDEN_COLOUR, Color.orange);
1447 Cache.setProperty(Preferences.SHOW_OV_HIDDEN_AT_START, "false");
1449 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1450 DataSourceType.FILE);
1453 * workaround: explicitly select View 1 (not in focus after restore)
1455 af.tabSelectionChanged(1);
1458 * verify restored overview for View 1
1460 ov2 = af.alignPanel.getOverviewPanel();
1461 assertEquals(ov2.getCanvas().getGapColour(), Color.green);
1462 // 'non-legacy' colouring uses white for non-gapped residues
1463 assertEquals(ov2.getCanvas().getResidueColour(), Color.white);
1464 assertEquals(ov2.getCanvas().getHiddenColour(), Color.yellow);
1465 assertEquals(ov2.getTitle(), "Overview examples/uniref50.fa View 1");
1466 assertEquals(ov2.getFrameBounds(), new Rectangle(25, 35, 205, 405));
1467 assertTrue(ov2.isShowHiddenRegions());
1470 * verify restored overview for Original view
1472 af.tabSelectionChanged(0);
1473 ov1 = af.alignPanel.getOverviewPanel();
1474 assertEquals(ov1.getCanvas().getGapColour(), Color.green);
1475 // 'non-legacy' colouring uses white for non-gapped residues
1476 assertEquals(ov1.getCanvas().getResidueColour(), Color.white);
1477 assertEquals(ov1.getCanvas().getHiddenColour(), Color.yellow);
1478 assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa Original");
1479 assertEquals(ov1.getFrameBounds(), new Rectangle(20, 30, 200, 400));
1480 assertTrue(ov1.isShowHiddenRegions());
1484 * Test that a view with no Overview is restored with no Overview, even if
1485 * 'Open Overview' is selected in Preferences
1489 @Test(groups = { "Functional" }, enabled = true)
1490 public void testStoreAndRecoverNoOverview() throws Exception
1492 Cache.setProperty("SHOW_OVERVIEW", "false");
1493 Desktop.instance.closeAll_actionPerformed(null);
1494 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1495 ">seq1\nMATRSQFLVNF\n", DataSourceType.PASTE);
1497 File tfile = File.createTempFile("testStoreAndRecoverOverview", ".jvp");
1498 new Jalview2XML(false).saveState(tfile);
1499 Desktop.instance.closeAll_actionPerformed(null);
1501 Cache.setProperty("SHOW_OVERVIEW", "true");
1502 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1503 DataSourceType.FILE);
1505 assertNull(af.alignPanel.getOverviewPanel());
1509 * Test that a view from an older version of Jalview is restored with Overview
1510 * automatically shown when the preference is set
1514 @Test(groups = { "Functional" }, enabled = true)
1515 public void testAutoShowOverviewForLegacyProjects() throws Exception
1517 Desktop.instance.closeAll_actionPerformed(null);
1518 Cache.setProperty("SHOW_OVERVIEW", "true");
1519 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1520 "examples/exampleFile.jvp", DataSourceType.FILE);
1522 Cache.setProperty("SHOW_OVERVIEW", "false");
1523 assertNotNull(af.alignPanel.getOverviewPanel());
1527 * Test that loading example.jvp, doing some stuff, then hitting reload
1528 * doesn't leave the modified window still open
1530 * See JAL-4127 - interactively performing the same actions and reloading
1531 * works fine, but programmatically they do not
1535 @Test(groups = { "Functional" }, enabled = false)
1536 public void testReloadActuallyReloads() throws Exception
1538 Desktop.instance.closeAll_actionPerformed(null);
1539 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1540 "examples/exampleFile.jvp", DataSourceType.FILE);
1541 af.getViewport().getColumnSelection().addElement(3);
1542 af.hideSelColumns_actionPerformed(null);
1543 af.newView("new", true);
1544 af.reload_actionPerformed(null);
1546 // af exists still but isn't shown
1547 assertTrue(af.isClosed());
1550 @Test(groups = { "Functional" })
1551 public void testMatrixToFloatsAndBack()
1555 SequenceI sq = new Sequence("dummy","SEQ");
1556 while (sq.getLength()<i)
1558 sq.setSequence(sq.getSequenceAsString()+'Q');
1560 float[][] paevals = new float[i][i];
1561 for (i = imax - 1; i >= 0; i--)
1563 for (int j = 0; j <= i; j++)
1565 paevals[i][j] = ((i - j < 2)
1566 || ((i > 1 && i < 5) && (j > 1 && i < 5))) ? 1 : 0f;
1567 paevals[j][i] = -paevals[i][j];
1570 PAEContactMatrix dummyMat = new PAEContactMatrix(sq, paevals);
1571 String content = ContactMatrix.contactToFloatString(dummyMat);
1572 Assert.assertTrue(content.contains("\t1.")); // at least one element must be
1574 float[][] vals = ContactMatrix.fromFloatStringToContacts(content,
1575 sq.getLength(), sq.getLength());
1576 assertEquals(vals[3][4], paevals[3][4]);
1577 assertEquals(vals[4][3], paevals[4][3]);
1580 for (i=0;i<imax;i++)
1582 for (int j=0;j<imax;j++)
1584 assertEquals(vals[i][j],paevals[i][j]);
1588 @Test(groups = { "Functional" })
1589 public void testPAEsaveRestore() throws Exception
1591 Desktop.instance.closeAll_actionPerformed(null);
1592 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1593 ">seq1\nMATRSQFLVNF\n", DataSourceType.PASTE);
1594 AlignmentI al = af.getViewport().getAlignment();
1595 // PAE matrices are added as reference annotation to the dataset sequence
1596 // at least for now.
1597 SequenceI sq = al.getSequenceAt(0).getDatasetSequence();
1598 int i = sq.getLength();
1599 float[][] paevals = new float[i][i];
1600 for (i = i - 1; i >= 0; i--)
1602 for (int j = 0; j <= i; j++)
1604 paevals[i][j] = ((i - j < 2)
1605 || ((i > 1 && i < 5) && (j > 1 && i < 5))) ? 1 : 0f;
1606 paevals[j][i] = -paevals[i][j];
1609 PAEContactMatrix dummyMat = new PAEContactMatrix(sq, paevals);
1610 String content = ContactMatrix.contactToFloatString(dummyMat);
1611 Assert.assertTrue(content.contains("\t1.")); // at least one element must be
1613 float[][] vals = ContactMatrix.fromFloatStringToContacts(content,
1614 sq.getLength(), sq.getLength());
1615 assertEquals(vals[3][4], paevals[3][4]);
1616 assertEquals(vals[4][3], paevals[4][3]);
1617 dummyMat.setGroupSet(GroupSet.makeGroups(dummyMat, false,0.5f, false));
1618 Assert.assertNotSame(dummyMat.getNewick(), "");
1619 AlignmentAnnotation paeCm = sq.addContactList(dummyMat);
1620 al.addAnnotation(paeCm);
1621 // verify store/restore of group bitsets
1622 for (BitSet gp : dummyMat.getGroups())
1624 StringBuilder sb = new StringBuilder();
1625 for (long val : gp.toLongArray())
1627 if (sb.length() > 0)
1633 String[] longvals = sb.toString().split(",");
1634 long[] newlongvals = new long[longvals.length];
1635 for (int lv = 0; lv < longvals.length; lv++)
1639 newlongvals[lv] = Long.valueOf(longvals[lv]);
1640 } catch (Exception x)
1642 Assert.fail("failed to deserialise bitset element ");
1645 BitSet newGp = BitSet.valueOf(newlongvals);
1646 assertTrue(gp.equals(newGp));
1648 File tfile = File.createTempFile("testStoreAndRecoverPAEmatrix",
1650 new Jalview2XML(false).saveState(tfile);
1651 Desktop.instance.closeAll_actionPerformed(null);
1653 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1654 DataSourceType.FILE);
1655 AlignmentI newAl = af.getViewport().getAlignment();
1656 SequenceI newSeq = newAl.getSequenceAt(0).getDatasetSequence();
1657 // check annotation of the expected type exists
1658 Assert.assertEquals(newSeq.getAnnotation().length, 1);
1659 Assert.assertEquals(newSeq.getAnnotation()[0].graph, paeCm.graph);
1661 // check a contact matrix was recovered
1662 Assert.assertEquals(newSeq.getContactMaps().size(), 1);
1663 // and can be found for the annotation on the sequence
1664 ContactMatrixI restoredMat = newSeq
1665 .getContactMatrixFor(newSeq.getAnnotation()[0]);
1666 Assert.assertNotNull(restoredMat);
1667 MapList oldMap = ((MappableContactMatrixI) dummyMat).getMapFor(sq);
1668 MapList newMap = ((MappableContactMatrixI) restoredMat)
1670 Assert.assertEquals(oldMap.getFromRanges(), newMap.getFromRanges());
1671 Assert.assertEquals(oldMap.getToRanges(), newMap.getToRanges());
1672 Assert.assertEquals(oldMap.getFromRatio(), newMap.getFromRatio());
1673 Assert.assertEquals(oldMap.getToRatio(), newMap.getToRatio());
1674 for (i = sq.getLength() - 1; i >= 0; i--)
1676 ContactListI oldCM = dummyMat.getContactList(i),
1677 newCM = restoredMat.getContactList(i);
1678 for (int j = oldCM.getContactHeight(); j >= 0; j--)
1680 double old_j = oldCM.getContactAt(j);
1681 double new_j = newCM.getContactAt(j);
1682 Assert.assertEquals(old_j, new_j);
1685 Assert.assertEquals(restoredMat.hasGroups(), dummyMat.hasGroups());
1686 Assert.assertEquals(restoredMat.getGroups(), dummyMat.getGroups());
1687 Assert.assertEquals(restoredMat.hasTree(), dummyMat.hasTree());
1688 Assert.assertEquals(restoredMat.getNewick(), dummyMat.getNewick());
1690 // verify no duplicate PAE matrix data when new view created and saved
1692 // add reference annotations to view first, then copy
1693 AlignmentUtils.addReferenceAnnotationTo(newAl, newAl.getSequenceAt(0), newSeq.getAnnotation()[0],null);
1695 AlignmentViewPanel newview = af.newView("copy of PAE", true);
1697 // redundant asserts here check all is good with the new view firest...
1698 AlignmentI newviewAl = newview.getAlignment();
1699 SequenceI newviewSeq = newviewAl.getSequenceAt(0);
1700 // check annotation of the expected type exists
1701 Assert.assertEquals(newviewSeq.getAnnotation().length, 1);
1702 Assert.assertEquals(newviewSeq.getAnnotation()[0].graph, paeCm.graph);
1703 // check we have just one contact matrix mapping
1704 Assert.assertEquals(newviewSeq.getContactMaps().size(), 1);
1706 // and can be found for the annotation on the sequence
1707 ContactMatrixI newviewMat = newviewSeq
1708 .getContactMatrixFor(newviewSeq.getAnnotation()[0]);
1709 Assert.assertNotNull(newviewMat);
1711 Assert.assertTrue(newviewMat == restoredMat);
1713 // save the two views and restore. Now look at visible annotation to check all views have shared refs.
1715 tfile = File.createTempFile("testStoreAndRecoverPAEmatrixTwoViews",
1717 new Jalview2XML(false).saveState(tfile);
1718 Desktop.instance.closeAll_actionPerformed(null);
1720 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1721 DataSourceType.FILE);
1722 newAl = af.getAlignPanels().get(0).getAlignment();
1723 AlignmentAnnotation view1aa = newAl.getSequenceAt(0).getAnnotation()[0];
1725 newviewAl = af.getAlignPanels().get(1).getAlignment();
1726 AlignmentAnnotation view2aa = newviewAl.getSequenceAt(0).getAnnotation()[0];
1728 // annotations are shared across alignment views - so should still have an identical pair of annotations.
1729 Assert.assertTrue(view1aa==view2aa);
1730 // identical annotations means identical contact matrix mappings
1731 Assert.assertEquals(newAl.getDataset().getSequenceAt(0).getContactMaps().size(), 1);
1733 // TODO Verify when distinct mappable PAEs are created, only one PAE dataset is actually held.
1734 // Assert.assertTrue(view1aa!=view2aa);
1735 // restoredMat = newAl.getContactMatrixFor(view1aa);
1736 // newviewMat = newviewAl.getContactMatrixFor(view2aa);
1737 // Assert.assertTrue(restoredMat!=newviewMat);