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.
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertFalse;
25 import static org.testng.Assert.assertNotNull;
26 import static org.testng.Assert.assertNull;
27 import static org.testng.Assert.assertSame;
28 import static org.testng.Assert.assertTrue;
29 import static org.testng.Assert.fail;
31 import jalview.analysis.PCA;
32 import jalview.api.AlignViewportI;
33 import jalview.api.AlignmentViewPanel;
34 import jalview.api.FeatureColourI;
35 import jalview.api.ViewStyleI;
36 import jalview.bin.Cache;
37 import jalview.datamodel.AlignmentAnnotation;
38 import jalview.datamodel.AlignmentI;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.PDBEntry;
41 import jalview.datamodel.PDBEntry.Type;
42 import jalview.datamodel.Point;
43 import jalview.datamodel.SequenceCollectionI;
44 import jalview.datamodel.SequenceFeature;
45 import jalview.datamodel.SequenceGroup;
46 import jalview.datamodel.SequenceI;
47 import jalview.datamodel.SequencePoint;
48 import jalview.datamodel.features.FeatureMatcher;
49 import jalview.datamodel.features.FeatureMatcherSet;
50 import jalview.datamodel.features.FeatureMatcherSetI;
51 import jalview.gui.AlignFrame;
52 import jalview.gui.AlignViewport;
53 import jalview.gui.AlignmentPanel;
54 import jalview.gui.CalculationChooser;
55 import jalview.gui.Desktop;
56 import jalview.gui.FeatureRenderer;
57 import jalview.gui.Jalview2XML;
58 import jalview.gui.JvOptionPane;
59 import jalview.gui.PCAPanel;
60 import jalview.gui.PopupMenu;
61 import jalview.gui.RotatableCanvas;
62 import jalview.gui.SliderPanel;
63 import jalview.math.MatrixTest;
64 import jalview.renderer.ResidueShaderI;
65 import jalview.schemes.AnnotationColourGradient;
66 import jalview.schemes.BuriedColourScheme;
67 import jalview.schemes.ColourSchemeI;
68 import jalview.schemes.ColourSchemeProperty;
69 import jalview.schemes.FeatureColour;
70 import jalview.schemes.JalviewColourScheme;
71 import jalview.schemes.RNAHelicesColour;
72 import jalview.schemes.StrandColourScheme;
73 import jalview.schemes.TCoffeeColourScheme;
74 import jalview.structure.StructureImportSettings;
75 import jalview.util.matcher.Condition;
76 import jalview.viewmodel.AlignmentViewport;
77 import jalview.viewmodel.PCAModel;
79 import java.awt.Color;
81 import java.io.IOException;
82 import java.util.ArrayList;
83 import java.util.HashMap;
84 import java.util.List;
87 import javax.swing.JInternalFrame;
88 import javax.swing.JRadioButton;
90 import org.testng.Assert;
91 import org.testng.AssertJUnit;
92 import org.testng.annotations.BeforeClass;
93 import org.testng.annotations.BeforeMethod;
94 import org.testng.annotations.Test;
96 import junit.extensions.PA;
98 @Test(singleThreaded = true)
99 public class Jalview2xmlTests extends Jalview2xmlBase
101 @BeforeClass(alwaysRun = true)
104 Cache.loadProperties("test/jalview/io/testProps.jvprops");
107 @BeforeMethod(alwaysRun = true)
108 public void setUpMethod()
110 Desktop.instance.closeAll_actionPerformed(null);
114 @BeforeClass(alwaysRun = true)
115 public void setUpJvOptionPane()
117 JvOptionPane.setInteractiveMode(false);
118 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
121 @Test(groups = { "Functional" })
122 public void testRNAStructureRecovery() throws Exception
124 String inFile = "examples/RF00031_folded.stk";
125 String tfile = File.createTempFile("JalviewTest", ".jvp")
127 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
128 DataSourceType.FILE);
129 assertNotNull(af, "Didn't read input file " + inFile);
130 int olddsann = countDsAnn(af.getViewport());
131 assertTrue(olddsann > 0, "Didn't find any dataset annotations");
132 af.changeColour_actionPerformed(JalviewColourScheme.RNAHelices
135 af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
136 "Couldn't apply RNA helices colourscheme");
137 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
138 "Failed to store as a project.");
139 af.closeMenuItem_actionPerformed(true);
141 af = new FileLoader()
142 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
143 assertNotNull(af, "Failed to import new project");
144 int newdsann = countDsAnn(af.getViewport());
145 assertEquals(olddsann, newdsann,
146 "Differing numbers of dataset sequence annotation\nOriginally "
147 + olddsann + " and now " + newdsann);
149 .println("Read in same number of annotations as originally present ("
153 af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
154 "RNA helices colourscheme was not applied on import.");
157 @Test(groups = { "Functional" })
158 public void testTCoffeeScores() throws Exception
160 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
161 String tfile = File.createTempFile("JalviewTest", ".jvp")
163 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
164 DataSourceType.FILE);
165 assertNotNull(af, "Didn't read input file " + inFile);
166 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
167 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
168 TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
169 assertNotNull(ColourSchemeProperty.getColourScheme(af.getViewport()
170 .getAlignment(), af.getViewport().getGlobalColourScheme()
171 .getSchemeName()), "Recognise T-Coffee score from string");
173 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
174 "Failed to store as a project.");
175 af.closeMenuItem_actionPerformed(true);
177 af = new FileLoader()
178 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
179 assertNotNull(af, "Failed to import new project");
180 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
181 TCoffeeColourScheme.class,
182 "Didn't set T-coffee colourscheme for imported project.");
184 .println("T-Coffee score shading successfully recovered from project.");
187 @Test(groups = { "Functional" })
188 public void testColourByAnnotScores() throws Exception
190 String inFile = "examples/uniref50.fa", 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],
206 null, 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 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
219 "Failed to store as a project.");
220 af.closeMenuItem_actionPerformed(true);
222 af = new FileLoader()
223 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
224 assertNotNull(af, "Failed to import new project");
226 // check for group and alignment colourschemes
228 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
229 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
230 .get(0).getColourScheme();
231 assertNotNull(_rcs, "Didn't recover global colourscheme");
232 assertTrue(_rcs instanceof AnnotationColourGradient,
233 "Didn't recover annotation colour global scheme");
234 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
235 assertTrue(__rcs.isSeqAssociated(),
236 "Annotation colourscheme wasn't sequence associated");
238 boolean diffseqcols = false, diffgseqcols = false;
239 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
240 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
241 && (!diffseqcols || !diffgseqcols); p++)
243 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
244 .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
249 assertTrue(diffseqcols, "Got Different sequence colours");
251 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
253 assertNotNull(_rgcs, "Didn't recover group colourscheme");
254 assertTrue(_rgcs instanceof AnnotationColourGradient,
255 "Didn't recover annotation colour group colourscheme");
256 __rcs = (AnnotationColourGradient) _rgcs;
257 assertTrue(__rcs.isSeqAssociated(),
258 "Group Annotation colourscheme wasn't sequence associated");
260 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
261 && (!diffseqcols || !diffgseqcols); p++)
263 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null, 0f) != _rgcs
264 .findColour(sqs[2].getCharAt(p), p, sqs[2], null, 0f))
269 assertTrue(diffgseqcols, "Got Different group sequence colours");
271 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
274 @Test(groups = { "Functional" })
275 public void gatherViewsHere() throws Exception
277 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
278 .getAlignFrames().length;
279 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
280 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
281 assertNotNull(af, "Didn't read in the example file correctly.");
282 assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
283 "Didn't gather the views in the example file.");
287 @Test(groups = { "Functional" })
288 public void viewRefPdbAnnotation() throws Exception
290 StructureImportSettings.setProcessSecondaryStructure(true);
291 StructureImportSettings.setVisibleChainAnnotation(true);
292 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
293 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
294 assertNotNull(af, "Didn't read in the example file correctly.");
295 AlignmentViewPanel sps = null;
296 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
298 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
304 assertNotNull(sps, "Couldn't find the structure view");
305 AlignmentAnnotation refan = null;
306 for (AlignmentAnnotation ra : sps.getAlignment()
307 .getAlignmentAnnotation())
315 assertNotNull(refan, "Annotation secondary structure not found.");
316 SequenceI sq = sps.getAlignment().findName("1A70|");
317 assertNotNull(sq, "Couldn't find 1a70 null chain");
318 // compare the manually added temperature factor annotation
319 // to the track automatically transferred from the pdb structure on load
320 assertNotNull(sq.getDatasetSequence().getAnnotation(),
321 "1a70 has no annotation");
322 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
324 AlignmentAnnotation alaa;
325 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
326 alaa.adjustForAlignment();
327 if (ala.graph == refan.graph)
329 for (int p = 0; p < ala.annotations.length; p++)
335 (alaa.annotations[p] == null && refan.annotations[p] == null)
336 || alaa.annotations[p].value == refan.annotations[p].value,
337 "Mismatch at alignment position " + p);
338 } catch (NullPointerException q)
340 Assert.fail("Mismatch of alignment annotations at position "
341 + p + " Ref seq ann: " + refan.annotations[p]
342 + " alignment " + alaa.annotations[p]);
350 @Test(groups = { "Functional" })
351 public void testCopyViewSettings() throws Exception
353 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
354 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
355 assertNotNull(af, "Didn't read in the example file correctly.");
356 AlignmentViewPanel sps = null, groups = null;
357 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
359 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
363 if (ap.getViewName().contains("MAFFT"))
368 assertNotNull(sps, "Couldn't find the structure view");
369 assertNotNull(groups, "Couldn't find the MAFFT view");
371 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
372 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
373 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
375 groups.getAlignViewport().setViewStyle(structureStyle);
376 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
378 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
384 * test store and recovery of expanded views
388 @Test(groups = { "Functional" }, enabled = true)
389 public void testStoreAndRecoverExpandedviews() throws Exception
391 Desktop.instance.closeAll_actionPerformed(null);
393 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
394 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
395 Assert.assertEquals(Desktop.getAlignFrames().length, 1);
396 String afid = af.getViewport().getSequenceSetId();
398 // check FileLoader returned a reference to the one alignFrame that is
399 // actually on the Desktop
402 Desktop.getAlignFrameFor(af.getViewport()),
403 "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
405 Desktop.explodeViews(af);
407 int oldviews = Desktop.getAlignFrames().length;
408 Assert.assertEquals(Desktop.getAlignFrames().length,
409 Desktop.getAlignmentPanels(afid).length);
410 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
413 new Jalview2XML(false).saveState(tfile);
416 Assert.fail("Didn't save the expanded view state", e);
417 } catch (Exception e)
419 Assert.fail("Didn't save the expanded view state", e);
421 Desktop.instance.closeAll_actionPerformed(null);
422 if (Desktop.getAlignFrames() != null)
424 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
426 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
427 DataSourceType.FILE);
428 Assert.assertNotNull(af);
430 Desktop.getAlignFrames().length,
431 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
433 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
438 * Test save and reload of a project with a different representative sequence
443 @Test(groups = { "Functional" })
444 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
446 Desktop.instance.closeAll_actionPerformed(null);
447 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
448 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
449 assertNotNull(af, "Didn't read in the example file correctly.");
450 String afid = af.getViewport().getSequenceSetId();
452 // remember reference sequence for each panel
453 Map<String, SequenceI> refseqs = new HashMap<>();
456 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
457 * as reference sequence for itself and the preceding sequence
460 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
462 AlignViewportI av = ap.getAlignViewport();
463 AlignmentI alignment = ap.getAlignment();
464 int repIndex = n % alignment.getHeight();
465 SequenceI rep = alignment.getSequenceAt(repIndex);
466 refseqs.put(ap.getViewName(), rep);
468 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
469 // todo refactor this to an alignment view controller
470 av.setDisplayReferenceSeq(true);
471 av.setColourByReferenceSeq(true);
472 av.getAlignment().setSeqrep(rep);
476 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
480 new Jalview2XML(false).saveState(tfile);
481 } catch (Throwable e)
483 Assert.fail("Didn't save the expanded view state", e);
485 Desktop.instance.closeAll_actionPerformed(null);
486 if (Desktop.getAlignFrames() != null)
488 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
491 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
492 DataSourceType.FILE);
493 afid = af.getViewport().getSequenceSetId();
495 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
497 // check representative
498 AlignmentI alignment = ap.getAlignment();
499 SequenceI rep = alignment.getSeqrep();
500 Assert.assertNotNull(rep,
501 "Couldn't restore sequence representative from project");
502 // can't use a strong equals here, because by definition, the sequence IDs
503 // will be different.
504 // could set vamsas session save/restore flag to preserve IDs across
506 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
508 "Representative wasn't the same when recovered.");
509 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
510 "Display reference sequence view setting not set.");
511 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
512 "Colour By Reference Seq view setting not set.");
516 @Test(groups = { "Functional" })
517 public void testIsVersionStringLaterThan()
520 * No version / development / test / autobuild is leniently assumed to be
523 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
524 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
525 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
526 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
527 "Development Build"));
528 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
529 "DEVELOPMENT BUILD"));
530 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
531 "Development Build"));
532 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
533 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
534 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
535 assertTrue(Jalview2XML
536 .isVersionStringLaterThan(null, "Automated Build"));
537 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
539 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
543 * same version returns true i.e. compatible
545 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
546 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
547 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
548 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
549 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
552 * later version returns true
554 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
555 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
556 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
557 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
558 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
561 * earlier version returns false
563 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
564 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
565 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
566 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
567 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
571 * Test save and reload of a project with a different sequence group (and
572 * representative sequence) in each view.
576 @Test(groups = { "Functional" })
577 public void testStoreAndRecoverGroupRepSeqs() throws Exception
579 Desktop.instance.closeAll_actionPerformed(null);
580 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
581 "examples/uniref50.fa", DataSourceType.FILE);
582 assertNotNull(af, "Didn't read in the example file correctly.");
583 String afid = af.getViewport().getSequenceSetId();
584 // make a second view of the alignment
585 af.newView_actionPerformed(null);
588 * remember representative and hidden sequences marked
591 Map<String, SequenceI> repSeqs = new HashMap<>();
592 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
595 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
596 * as reference sequence for itself and the preceding sequence
599 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
601 AlignViewportI av = ap.getAlignViewport();
602 AlignmentI alignment = ap.getAlignment();
603 int repIndex = n % alignment.getHeight();
604 // ensure at least one preceding sequence i.e. index >= 1
605 repIndex = Math.max(repIndex, 1);
606 SequenceI repSeq = alignment.getSequenceAt(repIndex);
607 repSeqs.put(ap.getViewName(), repSeq);
608 List<String> hiddenNames = new ArrayList<>();
609 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
612 * have rep sequence represent itself and the one before it
613 * this hides the group (except for the rep seq)
615 SequenceGroup sg = new SequenceGroup();
616 sg.addSequence(repSeq, false);
617 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
618 sg.addSequence(precedingSeq, false);
619 sg.setSeqrep(repSeq);
620 assertTrue(sg.getSequences().contains(repSeq));
621 assertTrue(sg.getSequences().contains(precedingSeq));
622 av.setSelectionGroup(sg);
623 assertSame(repSeq, sg.getSeqrep());
626 * represent group with sequence adds to a map of hidden rep sequences
627 * (it does not create a group on the alignment)
629 ((AlignmentViewport) av).hideSequences(repSeq, true);
630 assertSame(repSeq, sg.getSeqrep());
631 assertTrue(sg.getSequences().contains(repSeq));
632 assertTrue(sg.getSequences().contains(precedingSeq));
633 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
634 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
635 .getHiddenRepSequences();
636 assertNotNull(hiddenRepSeqsMap);
637 assertEquals(1, hiddenRepSeqsMap.size());
638 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
639 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
640 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
641 hiddenNames.add(precedingSeq.getName());
646 .createTempFile("testStoreAndRecoverGroupReps", ".jvp");
649 new Jalview2XML(false).saveState(tfile);
650 } catch (Throwable e)
652 Assert.fail("Didn't save the expanded view state", e);
654 Desktop.instance.closeAll_actionPerformed(null);
655 if (Desktop.getAlignFrames() != null)
657 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
660 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
661 DataSourceType.FILE);
662 afid = af.getViewport().getSequenceSetId();
664 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
666 String viewName = ap.getViewName();
667 AlignViewportI av = ap.getAlignViewport();
668 AlignmentI alignment = ap.getAlignment();
669 List<SequenceGroup> groups = alignment.getGroups();
670 assertNotNull(groups);
671 assertTrue(groups.isEmpty(), "Alignment has groups");
672 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
673 .getHiddenRepSequences();
674 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
675 assertEquals(1, hiddenRepSeqsMap.size());
676 assertEquals(repSeqs.get(viewName).getDisplayId(true),
677 hiddenRepSeqsMap.keySet().iterator().next()
678 .getDisplayId(true));
681 * verify hidden sequences in restored panel
683 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
684 HiddenSequences hs = alignment.getHiddenSequences();
688 "wrong number of restored hidden sequences in "
694 * Test save and reload of PDBEntry in Jalview project
698 @Test(groups = { "Functional" })
699 public void testStoreAndRecoverPDBEntry() throws Exception
701 Desktop.instance.closeAll_actionPerformed(null);
702 String exampleFile = "examples/3W5V.pdb";
703 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
704 DataSourceType.FILE);
705 assertNotNull(af, "Didn't read in the example file correctly.");
706 String afid = af.getViewport().getSequenceSetId();
708 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
709 System.out.println();
710 AlignmentViewPanel ap = alignPanels[0];
711 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
712 String testFile = tfileBase + exampleFile;
713 AlignmentI alignment = ap.getAlignment();
714 System.out.println("blah");
715 SequenceI[] seqs = alignment.getSequencesArray();
716 Assert.assertNotNull(seqs[0]);
717 Assert.assertNotNull(seqs[1]);
718 Assert.assertNotNull(seqs[2]);
719 Assert.assertNotNull(seqs[3]);
720 Assert.assertNotNull(seqs[0].getDatasetSequence());
721 Assert.assertNotNull(seqs[1].getDatasetSequence());
722 Assert.assertNotNull(seqs[2].getDatasetSequence());
723 Assert.assertNotNull(seqs[3].getDatasetSequence());
724 PDBEntry[] pdbEntries = new PDBEntry[4];
725 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
726 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
727 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
728 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
729 Assert.assertEquals(seqs[0].getDatasetSequence().getAllPDBEntries()
730 .get(0), pdbEntries[0]);
731 Assert.assertEquals(seqs[1].getDatasetSequence().getAllPDBEntries()
732 .get(0), pdbEntries[1]);
733 Assert.assertEquals(seqs[2].getDatasetSequence().getAllPDBEntries()
734 .get(0), pdbEntries[2]);
735 Assert.assertEquals(seqs[3].getDatasetSequence().getAllPDBEntries()
736 .get(0), pdbEntries[3]);
738 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
741 new Jalview2XML(false).saveState(tfile);
742 } catch (Throwable e)
744 Assert.fail("Didn't save the state", e);
746 Desktop.instance.closeAll_actionPerformed(null);
747 if (Desktop.getAlignFrames() != null)
749 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
752 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
753 tfile.getAbsolutePath(), DataSourceType.FILE);
754 String rfid = restoredFrame.getViewport().getSequenceSetId();
755 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
756 AlignmentViewPanel rap = rAlignPanels[0];
757 AlignmentI rAlignment = rap.getAlignment();
758 System.out.println("blah");
759 SequenceI[] rseqs = rAlignment.getSequencesArray();
760 Assert.assertNotNull(rseqs[0]);
761 Assert.assertNotNull(rseqs[1]);
762 Assert.assertNotNull(rseqs[2]);
763 Assert.assertNotNull(rseqs[3]);
764 Assert.assertNotNull(rseqs[0].getDatasetSequence());
765 Assert.assertNotNull(rseqs[1].getDatasetSequence());
766 Assert.assertNotNull(rseqs[2].getDatasetSequence());
767 Assert.assertNotNull(rseqs[3].getDatasetSequence());
769 // The Asserts below are expected to fail until the PDB chainCode is
770 // recoverable from a Jalview projects
771 for (int chain = 0; chain < 4; chain++)
773 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
775 PDBEntry expected = pdbEntries[chain];
776 Assert.assertEquals(recov.getId(), expected.getId(),
778 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
780 Assert.assertEquals(recov.getType(), expected.getType(),
781 "Mismatch PDBEntry 'Type'");
782 Assert.assertNotNull(recov.getFile(),
783 "Recovered PDBEntry should have a non-null file entry");
788 * Configure an alignment and a sub-group each with distinct colour schemes,
789 * Conservation and PID thresholds, and confirm these are restored from the
792 * @throws IOException
794 @Test(groups = { "Functional" })
795 public void testStoreAndRecoverColourThresholds() throws IOException
797 Desktop.instance.closeAll_actionPerformed(null);
798 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
799 "examples/uniref50.fa", DataSourceType.FILE);
801 AlignViewport av = af.getViewport();
802 AlignmentI al = av.getAlignment();
805 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
807 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
808 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
809 af.abovePIDThreshold_actionPerformed(true);
810 SliderPanel sp = SliderPanel.getSliderPanel();
811 assertFalse(sp.isForConservation());
813 af.conservationMenuItem_actionPerformed(true);
814 sp = SliderPanel.getSliderPanel();
815 assertTrue(sp.isForConservation());
817 ResidueShaderI rs = av.getResidueShading();
818 assertEquals(rs.getThreshold(), 10);
819 assertTrue(rs.conservationApplied());
820 assertEquals(rs.getConservationInc(), 20);
823 * create a group with Strand colouring, 30% Conservation
824 * and 40% PID threshold
826 SequenceGroup sg = new SequenceGroup();
827 sg.addSequence(al.getSequenceAt(0), false);
830 av.setSelectionGroup(sg);
831 PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
832 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
834 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
835 assertEquals(al.getGroups().size(), 1);
836 assertSame(al.getGroups().get(0), sg);
837 popupMenu.conservationMenuItem_actionPerformed(true);
838 sp = SliderPanel.getSliderPanel();
839 assertTrue(sp.isForConservation());
841 popupMenu.abovePIDColour_actionPerformed(true);
842 sp = SliderPanel.getSliderPanel();
843 assertFalse(sp.isForConservation());
845 assertTrue(sg.getGroupColourScheme().conservationApplied());
846 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
847 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
850 * save project, close windows, reload project, verify
852 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
854 tfile.deleteOnExit();
855 new Jalview2XML(false).saveState(tfile);
856 Desktop.instance.closeAll_actionPerformed(null);
857 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
858 DataSourceType.FILE);
859 Assert.assertNotNull(af, "Failed to reload project");
862 * verify alignment (background) colouring
864 rs = af.getViewport().getResidueShading();
865 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
866 assertEquals(rs.getThreshold(), 10);
867 assertTrue(rs.conservationApplied());
868 assertEquals(rs.getConservationInc(), 20);
871 * verify group colouring
873 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
874 rs = af.getViewport().getAlignment().getGroups().get(0)
875 .getGroupColourScheme();
876 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
877 assertEquals(rs.getThreshold(), 40);
878 assertTrue(rs.conservationApplied());
879 assertEquals(rs.getConservationInc(), 30);
883 * Test save and reload of feature colour schemes and filter settings
885 * @throws IOException
887 @Test(groups = { "Functional" })
888 public void testSaveLoadFeatureColoursAndFilters() throws IOException
890 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
891 ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
892 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
895 * add some features to the sequence
898 addFeatures(seq1, "type1", score++);
899 addFeatures(seq1, "type2", score++);
900 addFeatures(seq1, "type3", score++);
901 addFeatures(seq1, "type4", score++);
902 addFeatures(seq1, "type5", score++);
905 * set colour schemes for features
907 FeatureRenderer fr = af.getFeatureRenderer();
908 fr.findAllFeatures(true);
911 fr.setColour("type1", new FeatureColour(Color.red));
914 FeatureColourI byLabel = new FeatureColour();
915 byLabel.setColourByLabel(true);
916 fr.setColour("type2", byLabel);
918 // type3: by score above threshold
919 FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1,
921 byScore.setAboveThreshold(true);
922 byScore.setThreshold(2f);
923 fr.setColour("type3", byScore);
925 // type4: by attribute AF
926 FeatureColourI byAF = new FeatureColour();
927 byAF.setColourByLabel(true);
928 byAF.setAttributeName("AF");
929 fr.setColour("type4", byAF);
931 // type5: by attribute CSQ:PolyPhen below threshold
932 FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE,
934 byPolyPhen.setBelowThreshold(true);
935 byPolyPhen.setThreshold(3f);
936 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
937 fr.setColour("type5", byPolyPhen);
940 * set filters for feature types
943 // filter type1 features by (label contains "x")
944 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
945 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
946 fr.setFeatureFilter("type1", filterByX);
948 // filter type2 features by (score <= 2.4 and score > 1.1)
949 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
950 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
951 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
952 fr.setFeatureFilter("type2", filterByScore);
954 // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
955 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
957 .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
958 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
960 fr.setFeatureFilter("type3", filterByXY);
963 * save as Jalview project
965 File tfile = File.createTempFile("JalviewTest", ".jvp");
966 tfile.deleteOnExit();
967 String filePath = tfile.getAbsolutePath();
968 assertTrue(af.saveAlignment(filePath, FileFormat.Jalview),
969 "Failed to store as a project.");
972 * close current alignment and load the saved project
974 af.closeMenuItem_actionPerformed(true);
976 af = new FileLoader()
977 .LoadFileWaitTillLoaded(filePath, DataSourceType.FILE);
978 assertNotNull(af, "Failed to import new project");
981 * verify restored feature colour schemes and filters
983 fr = af.getFeatureRenderer();
984 FeatureColourI fc = fr.getFeatureStyle("type1");
985 assertTrue(fc.isSimpleColour());
986 assertEquals(fc.getColour(), Color.red);
987 fc = fr.getFeatureStyle("type2");
988 assertTrue(fc.isColourByLabel());
989 fc = fr.getFeatureStyle("type3");
990 assertTrue(fc.isGraduatedColour());
991 assertNull(fc.getAttributeName());
992 assertTrue(fc.isAboveThreshold());
993 assertEquals(fc.getThreshold(), 2f);
994 fc = fr.getFeatureStyle("type4");
995 assertTrue(fc.isColourByLabel());
996 assertTrue(fc.isColourByAttribute());
997 assertEquals(fc.getAttributeName(), new String[] { "AF" });
998 fc = fr.getFeatureStyle("type5");
999 assertTrue(fc.isGraduatedColour());
1000 assertTrue(fc.isColourByAttribute());
1001 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
1002 assertTrue(fc.isBelowThreshold());
1003 assertEquals(fc.getThreshold(), 3f);
1005 assertEquals(fr.getFeatureFilter("type1").toStableString(),
1006 "Label Contains x");
1007 assertEquals(fr.getFeatureFilter("type2").toStableString(),
1008 "(Score LE 2.4) AND (Score GT 1.1)");
1009 assertEquals(fr.getFeatureFilter("type3").toStableString(),
1010 "(AF Contains X) OR (CSQ:PolyPhen NE 0.0)");
1013 private void addFeature(SequenceI seq, String featureType, int score)
1015 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
1017 sf.setValue("AF", score);
1018 sf.setValue("CSQ", new HashMap<String, String>()
1021 put("PolyPhen", Integer.toString(score));
1024 seq.addSequenceFeature(sf);
1028 * Adds two features of the given type to the given sequence, also setting the
1029 * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1032 * @param featureType
1035 private void addFeatures(SequenceI seq, String featureType, int score)
1037 addFeature(seq, featureType, score++);
1038 addFeature(seq, featureType, score);
1042 * Test save and reload of a PCA viewer
1044 * @throws IOException
1046 @Test(groups = { "Functional" })
1047 public void testSaveLoadPCA() throws IOException
1049 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1050 "examples/uniref50.fa", DataSourceType.FILE);
1051 assertEquals(af.getViewport().getAlignment().getHeight(), 15);
1054 * calculate and open PCA (calculates in a separate thread)
1056 CalculationChooser chooser = new CalculationChooser(af);
1057 ((JRadioButton) PA.getValue(chooser, "pca")).setSelected(true);
1058 PA.invokeMethod(chooser, "calculate_actionPerformed()");
1059 PCAPanel pcaPanel = (PCAPanel) PA.getValue(chooser, "pcaPanel");
1060 assertNotNull(pcaPanel);
1061 waitFor(50); // let it get started!!
1062 while (pcaPanel.isWorking())
1066 PA.invokeMethod(chooser, "close_actionPerformed()");
1069 * rotate, zoom in, change background colour
1071 RotatableCanvas rc = (RotatableCanvas) PA.getValue(pcaPanel, "rc");
1072 PA.setValue(rc, "bgColour", Color.PINK);
1077 * save as Jalview project
1079 File tfile = File.createTempFile("JalviewTest", ".jvp");
1080 tfile.deleteOnExit();
1081 String filePath = tfile.getAbsolutePath();
1082 assertTrue(af.saveAlignment(filePath, FileFormat.Jalview),
1083 "Failed to store as a project.");
1086 * load the saved project and locate the restored PCA panel
1088 new FileLoader().LoadFileWaitTillLoaded(filePath, DataSourceType.FILE);
1089 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1090 PCAPanel pcaPanel2 = null;
1091 for (JInternalFrame frame : frames)
1093 if (frame instanceof PCAPanel && frame != pcaPanel)
1095 pcaPanel2 = (PCAPanel) frame;
1098 assertNotNull(pcaPanel2);
1101 * compare restored and original PCA
1103 PCAModel pcaModel = (PCAModel) PA.getValue(pcaPanel, "pcaModel");
1104 PCAModel pcaModel2 = (PCAModel) PA.getValue(pcaPanel2, "pcaModel");
1105 RotatableCanvas rc2 = (RotatableCanvas) PA.getValue(pcaPanel2, "rc");
1106 assertNotNull(pcaModel);
1107 assertNotNull(pcaModel2);
1109 assertEquals(rc2.getBackgroundColour(), Color.PINK);
1110 assertEquals(PA.getValue(rc2, "scaleFactor"), 1.9f);
1112 // original has input data
1113 assertNotNull(pcaModel.getInputData());
1114 // restored has no input data (JAL-2647 to do)
1115 assertNull(pcaModel2.getInputData());
1117 // verify sequence points are at the same positions
1118 List<SequencePoint> seqPts = pcaModel.getSequencePoints();
1119 List<SequencePoint> seqPts2 = pcaModel2.getSequencePoints();
1120 assertEquals(seqPts.size(), seqPts2.size());
1121 for (int i = 0; i < seqPts.size(); i++)
1123 SequencePoint sp = seqPts.get(i);
1124 SequencePoint sp2 = seqPts2.get(i);
1125 assertEquals(sp.getSequence().getName(), sp2.getSequence().getName());
1126 assertEquals(sp.coord, sp2.coord);
1129 // verify axis end points are at the same positions
1130 Point[] axes = (Point[]) PA.getValue(rc, "axisEndPoints");
1131 Point[] axes2 = (Point[]) PA.getValue(rc2, "axisEndPoints");
1132 assertEquals(axes.length, 3);
1133 assertEquals(axes2.length, 3);
1134 for (int i = 0; i < 3; i++)
1136 assertEquals(axes[i], axes2[i]);
1140 PCA pca = (PCA) PA.getValue(pcaModel, "pca");
1141 PCA pca2 = (PCA) PA.getValue(pcaModel2, "pca");
1143 assertNotNull(pca2);
1144 // same (BLOSUM62) score model (a singleton object)
1145 assertSame(PA.getValue(pca, "scoreModel"),
1146 PA.getValue(pca2, "scoreModel"));
1147 assertEquals(PA.getValue(pca, "similarityParams"),
1148 PA.getValue(pca2, "similarityParams"));
1149 MatrixTest.assertMatricesMatch(pca.getPairwiseScores(),
1150 pca2.getPairwiseScores());
1151 MatrixTest.assertMatricesMatch(pca.getTridiagonal(),
1152 pca2.getTridiagonal());
1153 MatrixTest.assertMatricesMatch(pca.getEigenmatrix(),
1154 pca2.getEigenmatrix());
1157 protected void waitFor(long t)
1164 } catch (InterruptedException e)
1166 fail(e.getMessage());