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;
30 import jalview.api.AlignViewportI;
31 import jalview.api.AlignmentViewPanel;
32 import jalview.api.FeatureColourI;
33 import jalview.api.ViewStyleI;
34 import jalview.datamodel.AlignmentAnnotation;
35 import jalview.datamodel.AlignmentI;
36 import jalview.datamodel.HiddenSequences;
37 import jalview.datamodel.PDBEntry;
38 import jalview.datamodel.PDBEntry.Type;
39 import jalview.datamodel.SequenceCollectionI;
40 import jalview.datamodel.SequenceFeature;
41 import jalview.datamodel.SequenceGroup;
42 import jalview.datamodel.SequenceI;
43 import jalview.datamodel.features.FeatureMatcher;
44 import jalview.datamodel.features.FeatureMatcherSet;
45 import jalview.datamodel.features.FeatureMatcherSetI;
46 import jalview.gui.AlignFrame;
47 import jalview.gui.AlignViewport;
48 import jalview.gui.AlignmentPanel;
49 import jalview.gui.Desktop;
50 import jalview.gui.FeatureRenderer;
51 import jalview.gui.Jalview2XML;
52 import jalview.gui.JvOptionPane;
53 import jalview.gui.PopupMenu;
54 import jalview.gui.SliderPanel;
55 import jalview.renderer.ResidueShaderI;
56 import jalview.schemes.AnnotationColourGradient;
57 import jalview.schemes.BuriedColourScheme;
58 import jalview.schemes.ColourSchemeI;
59 import jalview.schemes.ColourSchemeProperty;
60 import jalview.schemes.FeatureColour;
61 import jalview.schemes.JalviewColourScheme;
62 import jalview.schemes.RNAHelicesColour;
63 import jalview.schemes.StrandColourScheme;
64 import jalview.schemes.TCoffeeColourScheme;
65 import jalview.structure.StructureImportSettings;
66 import jalview.util.matcher.Condition;
67 import jalview.viewmodel.AlignmentViewport;
69 import java.awt.Color;
71 import java.io.IOException;
72 import java.util.ArrayList;
73 import java.util.HashMap;
74 import java.util.List;
77 import org.testng.Assert;
78 import org.testng.AssertJUnit;
79 import org.testng.annotations.BeforeClass;
80 import org.testng.annotations.Test;
82 @Test(singleThreaded = true)
83 public class Jalview2xmlTests extends Jalview2xmlBase
87 @BeforeClass(alwaysRun = true)
88 public void setUpJvOptionPane()
90 JvOptionPane.setInteractiveMode(false);
91 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
94 @Test(groups = { "Functional" })
95 public void testRNAStructureRecovery() throws Exception
97 String inFile = "examples/RF00031_folded.stk";
98 String tfile = File.createTempFile("JalviewTest", ".jvp")
100 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
101 DataSourceType.FILE);
102 assertNotNull(af, "Didn't read input file " + inFile);
103 int olddsann = countDsAnn(af.getViewport());
104 assertTrue(olddsann > 0, "Didn't find any dataset annotations");
105 af.changeColour_actionPerformed(JalviewColourScheme.RNAHelices
108 af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
109 "Couldn't apply RNA helices colourscheme");
110 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
111 "Failed to store as a project.");
112 af.closeMenuItem_actionPerformed(true);
114 af = new FileLoader()
115 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
116 assertNotNull(af, "Failed to import new project");
117 int newdsann = countDsAnn(af.getViewport());
118 assertEquals(olddsann, newdsann,
119 "Differing numbers of dataset sequence annotation\nOriginally "
120 + olddsann + " and now " + newdsann);
122 .println("Read in same number of annotations as originally present ("
126 af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
127 "RNA helices colourscheme was not applied on import.");
130 @Test(groups = { "Functional" })
131 public void testTCoffeeScores() throws Exception
133 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
134 String tfile = File.createTempFile("JalviewTest", ".jvp")
136 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
137 DataSourceType.FILE);
138 assertNotNull(af, "Didn't read input file " + inFile);
139 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
140 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
141 TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
142 assertNotNull(ColourSchemeProperty.getColourScheme(af.getViewport()
143 .getAlignment(), af.getViewport().getGlobalColourScheme()
144 .getSchemeName()), "Recognise T-Coffee score from string");
146 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
147 "Failed to store as a project.");
148 af.closeMenuItem_actionPerformed(true);
150 af = new FileLoader()
151 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
152 assertNotNull(af, "Failed to import new project");
153 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
154 TCoffeeColourScheme.class,
155 "Didn't set T-coffee colourscheme for imported project.");
157 .println("T-Coffee score shading successfully recovered from project.");
160 @Test(groups = { "Functional" })
161 public void testColourByAnnotScores() throws Exception
163 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
164 String tfile = File.createTempFile("JalviewTest", ".jvp")
166 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
167 DataSourceType.FILE);
168 assertNotNull(af, "Didn't read input file " + inFile);
169 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
170 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
171 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
174 aa != null && aa.length > 0,
175 "Didn't find any IUPred annotation to use to shade alignment.");
176 AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
177 AnnotationColourGradient.ABOVE_THRESHOLD);
178 AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0],
179 null, AnnotationColourGradient.BELOW_THRESHOLD);
180 cs.setSeqAssociated(true);
181 gcs.setSeqAssociated(true);
183 SequenceGroup sg = new SequenceGroup();
186 sg.cs.setColourScheme(gcs);
187 af.getViewport().getAlignment().addGroup(sg);
188 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
189 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
190 af.alignPanel.alignmentChanged();
191 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
192 "Failed to store as a project.");
193 af.closeMenuItem_actionPerformed(true);
195 af = new FileLoader()
196 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
197 assertNotNull(af, "Failed to import new project");
199 // check for group and alignment colourschemes
201 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
202 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
203 .get(0).getColourScheme();
204 assertNotNull(_rcs, "Didn't recover global colourscheme");
205 assertTrue(_rcs instanceof AnnotationColourGradient,
206 "Didn't recover annotation colour global scheme");
207 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
208 assertTrue(__rcs.isSeqAssociated(),
209 "Annotation colourscheme wasn't sequence associated");
211 boolean diffseqcols = false, diffgseqcols = false;
212 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
213 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
214 && (!diffseqcols || !diffgseqcols); p++)
216 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
217 .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
222 assertTrue(diffseqcols, "Got Different sequence colours");
224 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
226 assertNotNull(_rgcs, "Didn't recover group colourscheme");
227 assertTrue(_rgcs instanceof AnnotationColourGradient,
228 "Didn't recover annotation colour group colourscheme");
229 __rcs = (AnnotationColourGradient) _rgcs;
230 assertTrue(__rcs.isSeqAssociated(),
231 "Group Annotation colourscheme wasn't sequence associated");
233 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
234 && (!diffseqcols || !diffgseqcols); p++)
236 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null, 0f) != _rgcs
237 .findColour(sqs[2].getCharAt(p), p, sqs[2], null, 0f))
242 assertTrue(diffgseqcols, "Got Different group sequence colours");
244 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
247 @Test(groups = { "Functional" })
248 public void gatherViewsHere() throws Exception
250 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
251 .getAlignFrames().length;
252 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
253 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
254 assertNotNull(af, "Didn't read in the example file correctly.");
255 assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
256 "Didn't gather the views in the example file.");
260 @Test(groups = { "Functional" })
261 public void viewRefPdbAnnotation() throws Exception
263 StructureImportSettings.setProcessSecondaryStructure(true);
264 StructureImportSettings.setVisibleChainAnnotation(true);
265 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
266 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
267 assertNotNull(af, "Didn't read in the example file correctly.");
268 AlignmentViewPanel sps = null;
269 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
271 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
277 assertNotNull(sps, "Couldn't find the structure view");
278 AlignmentAnnotation refan = null;
279 for (AlignmentAnnotation ra : sps.getAlignment()
280 .getAlignmentAnnotation())
288 assertNotNull(refan, "Annotation secondary structure not found.");
289 SequenceI sq = sps.getAlignment().findName("1A70|");
290 assertNotNull(sq, "Couldn't find 1a70 null chain");
291 // compare the manually added temperature factor annotation
292 // to the track automatically transferred from the pdb structure on load
293 assertNotNull(sq.getDatasetSequence().getAnnotation(),
294 "1a70 has no annotation");
295 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
297 AlignmentAnnotation alaa;
298 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
299 alaa.adjustForAlignment();
300 if (ala.graph == refan.graph)
302 for (int p = 0; p < ala.annotations.length; p++)
308 (alaa.annotations[p] == null && refan.annotations[p] == null)
309 || alaa.annotations[p].value == refan.annotations[p].value,
310 "Mismatch at alignment position " + p);
311 } catch (NullPointerException q)
313 Assert.fail("Mismatch of alignment annotations at position "
314 + p + " Ref seq ann: " + refan.annotations[p]
315 + " alignment " + alaa.annotations[p]);
323 @Test(groups = { "Functional" })
324 public void testCopyViewSettings() throws Exception
326 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
327 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
328 assertNotNull(af, "Didn't read in the example file correctly.");
329 AlignmentViewPanel sps = null, groups = null;
330 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
332 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
336 if (ap.getViewName().contains("MAFFT"))
341 assertNotNull(sps, "Couldn't find the structure view");
342 assertNotNull(groups, "Couldn't find the MAFFT view");
344 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
345 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
346 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
348 groups.getAlignViewport().setViewStyle(structureStyle);
349 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
351 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
357 * test store and recovery of expanded views
361 @Test(groups = { "Functional" }, enabled = true)
362 public void testStoreAndRecoverExpandedviews() throws Exception
364 Desktop.instance.closeAll_actionPerformed(null);
366 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
367 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
368 Assert.assertEquals(Desktop.getAlignFrames().length, 1);
369 String afid = af.getViewport().getSequenceSetId();
371 // check FileLoader returned a reference to the one alignFrame that is
372 // actually on the Desktop
375 Desktop.getAlignFrameFor(af.getViewport()),
376 "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
378 Desktop.explodeViews(af);
380 int oldviews = Desktop.getAlignFrames().length;
381 Assert.assertEquals(Desktop.getAlignFrames().length,
382 Desktop.getAlignmentPanels(afid).length);
383 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
386 new Jalview2XML(false).saveState(tfile);
389 Assert.fail("Didn't save the expanded view state", e);
390 } catch (Exception e)
392 Assert.fail("Didn't save the expanded view state", e);
394 Desktop.instance.closeAll_actionPerformed(null);
395 if (Desktop.getAlignFrames() != null)
397 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
399 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
400 DataSourceType.FILE);
401 Assert.assertNotNull(af);
403 Desktop.getAlignFrames().length,
404 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
406 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
411 * Test save and reload of a project with a different representative sequence
416 @Test(groups = { "Functional" })
417 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
419 Desktop.instance.closeAll_actionPerformed(null);
420 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
421 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
422 assertNotNull(af, "Didn't read in the example file correctly.");
423 String afid = af.getViewport().getSequenceSetId();
425 // remember reference sequence for each panel
426 Map<String, SequenceI> refseqs = new HashMap<>();
429 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
430 * as reference sequence for itself and the preceding sequence
433 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
435 AlignViewportI av = ap.getAlignViewport();
436 AlignmentI alignment = ap.getAlignment();
437 int repIndex = n % alignment.getHeight();
438 SequenceI rep = alignment.getSequenceAt(repIndex);
439 refseqs.put(ap.getViewName(), rep);
441 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
442 // todo refactor this to an alignment view controller
443 av.setDisplayReferenceSeq(true);
444 av.setColourByReferenceSeq(true);
445 av.getAlignment().setSeqrep(rep);
449 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
453 new Jalview2XML(false).saveState(tfile);
454 } catch (Throwable e)
456 Assert.fail("Didn't save the expanded view state", e);
458 Desktop.instance.closeAll_actionPerformed(null);
459 if (Desktop.getAlignFrames() != null)
461 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
464 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
465 DataSourceType.FILE);
466 afid = af.getViewport().getSequenceSetId();
468 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
470 // check representative
471 AlignmentI alignment = ap.getAlignment();
472 SequenceI rep = alignment.getSeqrep();
473 Assert.assertNotNull(rep,
474 "Couldn't restore sequence representative from project");
475 // can't use a strong equals here, because by definition, the sequence IDs
476 // will be different.
477 // could set vamsas session save/restore flag to preserve IDs across
479 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
481 "Representative wasn't the same when recovered.");
482 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
483 "Display reference sequence view setting not set.");
484 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
485 "Colour By Reference Seq view setting not set.");
489 @Test(groups = { "Functional" })
490 public void testIsVersionStringLaterThan()
493 * No version / development / test / autobuild is leniently assumed to be
496 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
497 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
498 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
499 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
500 "Development Build"));
501 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
502 "DEVELOPMENT BUILD"));
503 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
504 "Development Build"));
505 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
506 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
507 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
508 assertTrue(Jalview2XML
509 .isVersionStringLaterThan(null, "Automated Build"));
510 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
512 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
516 * same version returns true i.e. compatible
518 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
519 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
520 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
521 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
522 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
525 * later version returns true
527 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
528 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
529 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
530 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
531 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
534 * earlier version returns false
536 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
537 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
538 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
539 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
540 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
544 * Test save and reload of a project with a different sequence group (and
545 * representative sequence) in each view.
549 @Test(groups = { "Functional" })
550 public void testStoreAndRecoverGroupRepSeqs() throws Exception
552 Desktop.instance.closeAll_actionPerformed(null);
553 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
554 "examples/uniref50.fa", DataSourceType.FILE);
555 assertNotNull(af, "Didn't read in the example file correctly.");
556 String afid = af.getViewport().getSequenceSetId();
557 // make a second view of the alignment
558 af.newView_actionPerformed(null);
561 * remember representative and hidden sequences marked
564 Map<String, SequenceI> repSeqs = new HashMap<>();
565 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
568 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
569 * as reference sequence for itself and the preceding sequence
572 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
574 AlignViewportI av = ap.getAlignViewport();
575 AlignmentI alignment = ap.getAlignment();
576 int repIndex = n % alignment.getHeight();
577 // ensure at least one preceding sequence i.e. index >= 1
578 repIndex = Math.max(repIndex, 1);
579 SequenceI repSeq = alignment.getSequenceAt(repIndex);
580 repSeqs.put(ap.getViewName(), repSeq);
581 List<String> hiddenNames = new ArrayList<>();
582 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
585 * have rep sequence represent itself and the one before it
586 * this hides the group (except for the rep seq)
588 SequenceGroup sg = new SequenceGroup();
589 sg.addSequence(repSeq, false);
590 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
591 sg.addSequence(precedingSeq, false);
592 sg.setSeqrep(repSeq);
593 assertTrue(sg.getSequences().contains(repSeq));
594 assertTrue(sg.getSequences().contains(precedingSeq));
595 av.setSelectionGroup(sg);
596 assertSame(repSeq, sg.getSeqrep());
599 * represent group with sequence adds to a map of hidden rep sequences
600 * (it does not create a group on the alignment)
602 ((AlignmentViewport) av).hideSequences(repSeq, true);
603 assertSame(repSeq, sg.getSeqrep());
604 assertTrue(sg.getSequences().contains(repSeq));
605 assertTrue(sg.getSequences().contains(precedingSeq));
606 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
607 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
608 .getHiddenRepSequences();
609 assertNotNull(hiddenRepSeqsMap);
610 assertEquals(1, hiddenRepSeqsMap.size());
611 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
612 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
613 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
614 hiddenNames.add(precedingSeq.getName());
619 .createTempFile("testStoreAndRecoverGroupReps", ".jvp");
622 new Jalview2XML(false).saveState(tfile);
623 } catch (Throwable e)
625 Assert.fail("Didn't save the expanded view state", e);
627 Desktop.instance.closeAll_actionPerformed(null);
628 if (Desktop.getAlignFrames() != null)
630 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
633 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
634 DataSourceType.FILE);
635 afid = af.getViewport().getSequenceSetId();
637 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
639 String viewName = ap.getViewName();
640 AlignViewportI av = ap.getAlignViewport();
641 AlignmentI alignment = ap.getAlignment();
642 List<SequenceGroup> groups = alignment.getGroups();
643 assertNotNull(groups);
644 assertTrue(groups.isEmpty(), "Alignment has groups");
645 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
646 .getHiddenRepSequences();
647 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
648 assertEquals(1, hiddenRepSeqsMap.size());
649 assertEquals(repSeqs.get(viewName).getDisplayId(true),
650 hiddenRepSeqsMap.keySet().iterator().next()
651 .getDisplayId(true));
654 * verify hidden sequences in restored panel
656 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
657 HiddenSequences hs = alignment.getHiddenSequences();
661 "wrong number of restored hidden sequences in "
667 * Test save and reload of PDBEntry in Jalview project
671 @Test(groups = { "Functional" })
672 public void testStoreAndRecoverPDBEntry() throws Exception
674 Desktop.instance.closeAll_actionPerformed(null);
675 String exampleFile = "examples/3W5V.pdb";
676 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
677 DataSourceType.FILE);
678 assertNotNull(af, "Didn't read in the example file correctly.");
679 String afid = af.getViewport().getSequenceSetId();
681 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
682 System.out.println();
683 AlignmentViewPanel ap = alignPanels[0];
684 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
685 String testFile = tfileBase + exampleFile;
686 AlignmentI alignment = ap.getAlignment();
687 System.out.println("blah");
688 SequenceI[] seqs = alignment.getSequencesArray();
689 Assert.assertNotNull(seqs[0]);
690 Assert.assertNotNull(seqs[1]);
691 Assert.assertNotNull(seqs[2]);
692 Assert.assertNotNull(seqs[3]);
693 Assert.assertNotNull(seqs[0].getDatasetSequence());
694 Assert.assertNotNull(seqs[1].getDatasetSequence());
695 Assert.assertNotNull(seqs[2].getDatasetSequence());
696 Assert.assertNotNull(seqs[3].getDatasetSequence());
697 PDBEntry[] pdbEntries = new PDBEntry[4];
698 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
699 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
700 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
701 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
702 Assert.assertEquals(seqs[0].getDatasetSequence().getAllPDBEntries()
703 .get(0), pdbEntries[0]);
704 Assert.assertEquals(seqs[1].getDatasetSequence().getAllPDBEntries()
705 .get(0), pdbEntries[1]);
706 Assert.assertEquals(seqs[2].getDatasetSequence().getAllPDBEntries()
707 .get(0), pdbEntries[2]);
708 Assert.assertEquals(seqs[3].getDatasetSequence().getAllPDBEntries()
709 .get(0), pdbEntries[3]);
711 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
714 new Jalview2XML(false).saveState(tfile);
715 } catch (Throwable e)
717 Assert.fail("Didn't save the state", e);
719 Desktop.instance.closeAll_actionPerformed(null);
720 if (Desktop.getAlignFrames() != null)
722 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
725 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
726 tfile.getAbsolutePath(), DataSourceType.FILE);
727 String rfid = restoredFrame.getViewport().getSequenceSetId();
728 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
729 AlignmentViewPanel rap = rAlignPanels[0];
730 AlignmentI rAlignment = rap.getAlignment();
731 System.out.println("blah");
732 SequenceI[] rseqs = rAlignment.getSequencesArray();
733 Assert.assertNotNull(rseqs[0]);
734 Assert.assertNotNull(rseqs[1]);
735 Assert.assertNotNull(rseqs[2]);
736 Assert.assertNotNull(rseqs[3]);
737 Assert.assertNotNull(rseqs[0].getDatasetSequence());
738 Assert.assertNotNull(rseqs[1].getDatasetSequence());
739 Assert.assertNotNull(rseqs[2].getDatasetSequence());
740 Assert.assertNotNull(rseqs[3].getDatasetSequence());
742 // The Asserts below are expected to fail until the PDB chainCode is
743 // recoverable from a Jalview projects
744 for (int chain = 0; chain < 4; chain++)
746 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
748 PDBEntry expected = pdbEntries[chain];
749 Assert.assertEquals(recov.getId(), expected.getId(),
751 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
753 Assert.assertEquals(recov.getType(), expected.getType(),
754 "Mismatch PDBEntry 'Type'");
755 Assert.assertNotNull(recov.getFile(),
756 "Recovered PDBEntry should have a non-null file entry");
761 * Configure an alignment and a sub-group each with distinct colour schemes,
762 * Conservation and PID thresholds, and confirm these are restored from the
765 * @throws IOException
767 @Test(groups = { "Functional" })
768 public void testStoreAndRecoverColourThresholds() throws IOException
770 Desktop.instance.closeAll_actionPerformed(null);
771 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
772 "examples/uniref50.fa", DataSourceType.FILE);
774 AlignViewport av = af.getViewport();
775 AlignmentI al = av.getAlignment();
778 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
780 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
781 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
782 af.abovePIDThreshold_actionPerformed(true);
783 SliderPanel sp = SliderPanel.getSliderPanel();
784 assertFalse(sp.isForConservation());
786 af.conservationMenuItem_actionPerformed(true);
787 sp = SliderPanel.getSliderPanel();
788 assertTrue(sp.isForConservation());
790 ResidueShaderI rs = av.getResidueShading();
791 assertEquals(rs.getThreshold(), 10);
792 assertTrue(rs.conservationApplied());
793 assertEquals(rs.getConservationInc(), 20);
796 * create a group with Strand colouring, 30% Conservation
797 * and 40% PID threshold
799 SequenceGroup sg = new SequenceGroup();
800 sg.addSequence(al.getSequenceAt(0), false);
803 av.setSelectionGroup(sg);
804 PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
805 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
807 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
808 assertEquals(al.getGroups().size(), 1);
809 assertSame(al.getGroups().get(0), sg);
810 popupMenu.conservationMenuItem_actionPerformed(true);
811 sp = SliderPanel.getSliderPanel();
812 assertTrue(sp.isForConservation());
814 popupMenu.abovePIDColour_actionPerformed(true);
815 sp = SliderPanel.getSliderPanel();
816 assertFalse(sp.isForConservation());
818 assertTrue(sg.getGroupColourScheme().conservationApplied());
819 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
820 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
823 * save project, close windows, reload project, verify
825 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
827 tfile.deleteOnExit();
828 new Jalview2XML(false).saveState(tfile);
829 Desktop.instance.closeAll_actionPerformed(null);
830 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
831 DataSourceType.FILE);
832 Assert.assertNotNull(af, "Failed to reload project");
835 * verify alignment (background) colouring
837 rs = af.getViewport().getResidueShading();
838 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
839 assertEquals(rs.getThreshold(), 10);
840 assertTrue(rs.conservationApplied());
841 assertEquals(rs.getConservationInc(), 20);
844 * verify group colouring
846 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
847 rs = af.getViewport().getAlignment().getGroups().get(0)
848 .getGroupColourScheme();
849 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
850 assertEquals(rs.getThreshold(), 40);
851 assertTrue(rs.conservationApplied());
852 assertEquals(rs.getConservationInc(), 30);
856 * Test save and reload of feature colour schemes and filter settings
858 * @throws IOException
860 @Test(groups = { "Functional" })
861 public void testSaveLoadFeatureColoursAndFilters() throws IOException
863 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
864 ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
865 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
868 * add some features to the sequence
871 addFeatures(seq1, "type1", score++);
872 addFeatures(seq1, "type2", score++);
873 addFeatures(seq1, "type3", score++);
874 addFeatures(seq1, "type4", score++);
875 addFeatures(seq1, "type5", score++);
878 * set colour schemes for features
880 FeatureRenderer fr = af.getFeatureRenderer();
881 fr.findAllFeatures(true);
884 fr.setColour("type1", new FeatureColour(Color.red));
887 FeatureColourI byLabel = new FeatureColour();
888 byLabel.setColourByLabel(true);
889 fr.setColour("type2", byLabel);
891 // type3: by score above threshold
892 FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1,
894 byScore.setAboveThreshold(true);
895 byScore.setThreshold(2f);
896 fr.setColour("type3", byScore);
898 // type4: by attribute AF
899 FeatureColourI byAF = new FeatureColour();
900 byAF.setColourByLabel(true);
901 byAF.setAttributeName("AF");
902 fr.setColour("type4", byAF);
904 // type5: by attribute CSQ:PolyPhen below threshold
905 FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE,
907 byPolyPhen.setBelowThreshold(true);
908 byPolyPhen.setThreshold(3f);
909 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
910 fr.setColour("type5", byPolyPhen);
913 * set filters for feature types
916 // filter type1 features by (label contains "x")
917 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
918 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
919 fr.setFeatureFilter("type1", filterByX);
921 // filter type2 features by (score <= 2.4 and score > 1.1)
922 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
923 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
924 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
925 fr.setFeatureFilter("type2", filterByScore);
927 // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
928 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
930 .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
931 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
933 fr.setFeatureFilter("type3", filterByXY);
936 * save as Jalview project
938 File tfile = File.createTempFile("JalviewTest", ".jvp");
939 tfile.deleteOnExit();
940 String filePath = tfile.getAbsolutePath();
941 assertTrue(af.saveAlignment(filePath, FileFormat.Jalview),
942 "Failed to store as a project.");
945 * close current alignment and load the saved project
947 af.closeMenuItem_actionPerformed(true);
949 af = new FileLoader()
950 .LoadFileWaitTillLoaded(filePath, DataSourceType.FILE);
951 assertNotNull(af, "Failed to import new project");
954 * verify restored feature colour schemes and filters
956 fr = af.getFeatureRenderer();
957 FeatureColourI fc = fr.getFeatureStyle("type1");
958 assertTrue(fc.isSimpleColour());
959 assertEquals(fc.getColour(), Color.red);
960 fc = fr.getFeatureStyle("type2");
961 assertTrue(fc.isColourByLabel());
962 fc = fr.getFeatureStyle("type3");
963 assertTrue(fc.isGraduatedColour());
964 assertNull(fc.getAttributeName());
965 assertTrue(fc.isAboveThreshold());
966 assertEquals(fc.getThreshold(), 2f);
967 fc = fr.getFeatureStyle("type4");
968 assertTrue(fc.isColourByLabel());
969 assertTrue(fc.isColourByAttribute());
970 assertEquals(fc.getAttributeName(), new String[] { "AF" });
971 fc = fr.getFeatureStyle("type5");
972 assertTrue(fc.isGraduatedColour());
973 assertTrue(fc.isColourByAttribute());
974 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
975 assertTrue(fc.isBelowThreshold());
976 assertEquals(fc.getThreshold(), 3f);
978 assertEquals(fr.getFeatureFilter("type1").toStableString(),
980 assertEquals(fr.getFeatureFilter("type2").toStableString(),
981 "(Score LE 2.4) AND (Score GT 1.1)");
982 assertEquals(fr.getFeatureFilter("type3").toStableString(),
983 "(AF Contains X) OR (CSQ:PolyPhen NE 0.0)");
986 private void addFeature(SequenceI seq, String featureType, int score)
988 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
990 sf.setValue("AF", score);
991 sf.setValue("CSQ", new HashMap<String, String>()
994 put("PolyPhen", Integer.toString(score));
997 seq.addSequenceFeature(sf);
1001 * Adds two features of the given type to the given sequence, also setting the
1002 * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1005 * @param featureType
1008 private void addFeatures(SequenceI seq, String featureType, int score)
1010 addFeature(seq, featureType, score++);
1011 addFeature(seq, featureType, score);