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.HiddenMarkovModel;
37 import jalview.datamodel.HiddenSequences;
38 import jalview.datamodel.Mapping;
39 import jalview.datamodel.PDBEntry;
40 import jalview.datamodel.PDBEntry.Type;
41 import jalview.datamodel.SequenceCollectionI;
42 import jalview.datamodel.SequenceFeature;
43 import jalview.datamodel.SequenceGroup;
44 import jalview.datamodel.SequenceI;
45 import jalview.datamodel.features.FeatureMatcher;
46 import jalview.datamodel.features.FeatureMatcherSet;
47 import jalview.datamodel.features.FeatureMatcherSetI;
48 import jalview.gui.AlignFrame;
49 import jalview.gui.AlignmentPanel;
50 import jalview.gui.Desktop;
51 import jalview.gui.FeatureRenderer;
52 import jalview.gui.Jalview2XML;
53 import jalview.gui.JvOptionPane;
54 import jalview.gui.PopupMenu;
55 import jalview.gui.SliderPanel;
56 import jalview.renderer.ResidueShaderI;
57 import jalview.schemes.AnnotationColourGradient;
58 import jalview.schemes.BuriedColourScheme;
59 import jalview.schemes.ColourSchemeI;
60 import jalview.schemes.ColourSchemeProperty;
61 import jalview.schemes.FeatureColour;
62 import jalview.schemes.JalviewColourScheme;
63 import jalview.schemes.RNAHelicesColour;
64 import jalview.schemes.StrandColourScheme;
65 import jalview.schemes.TCoffeeColourScheme;
66 import jalview.structure.StructureImportSettings;
67 import jalview.util.matcher.Condition;
68 import jalview.viewmodel.AlignmentViewport;
70 import java.awt.Color;
72 import java.io.IOException;
73 import java.util.ArrayList;
74 import java.util.HashMap;
75 import java.util.List;
78 import org.testng.Assert;
79 import org.testng.AssertJUnit;
80 import org.testng.annotations.BeforeClass;
81 import org.testng.annotations.Test;
83 import junit.extensions.PA;
85 @Test(singleThreaded = true)
86 public class Jalview2xmlTests extends Jalview2xmlBase
90 @BeforeClass(alwaysRun = true)
91 public void setUpJvOptionPane()
93 JvOptionPane.setInteractiveMode(false);
94 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
97 @Test(groups = { "Functional" })
98 public void testRNAStructureRecovery() throws Exception
100 String inFile = "examples/RF00031_folded.stk";
101 String tfile = File.createTempFile("JalviewTest", ".jvp")
103 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
104 DataSourceType.FILE);
105 assertNotNull(af, "Didn't read input file " + inFile);
106 int olddsann = countDsAnn(af.getViewport());
107 assertTrue(olddsann > 0, "Didn't find any dataset annotations");
108 af.changeColour_actionPerformed(JalviewColourScheme.RNAHelices
111 af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
112 "Couldn't apply RNA helices colourscheme");
113 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
114 "Failed to store as a project.");
115 af.closeMenuItem_actionPerformed(true);
117 af = new FileLoader()
118 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
119 assertNotNull(af, "Failed to import new project");
120 int newdsann = countDsAnn(af.getViewport());
121 assertEquals(olddsann, newdsann,
122 "Differing numbers of dataset sequence annotation\nOriginally "
123 + olddsann + " and now " + newdsann);
125 .println("Read in same number of annotations as originally present ("
129 af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
130 "RNA helices colourscheme was not applied on import.");
133 @Test(groups = { "Functional" })
134 public void testTCoffeeScores() throws Exception
136 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
137 String tfile = File.createTempFile("JalviewTest", ".jvp")
139 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
140 DataSourceType.FILE);
141 assertNotNull(af, "Didn't read input file " + inFile);
142 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
143 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
144 TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
145 assertNotNull(ColourSchemeProperty.getColourScheme(af.getViewport()
146 .getAlignment(), af.getViewport().getGlobalColourScheme()
147 .getSchemeName()), "Recognise T-Coffee score from string");
149 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
150 "Failed to store as a project.");
151 af.closeMenuItem_actionPerformed(true);
153 af = new FileLoader()
154 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
155 assertNotNull(af, "Failed to import new project");
156 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
157 TCoffeeColourScheme.class,
158 "Didn't set T-coffee colourscheme for imported project.");
160 .println("T-Coffee score shading successfully recovered from project.");
163 @Test(groups = { "Functional" })
164 public void testColourByAnnotScores() throws Exception
166 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
167 String tfile = File.createTempFile("JalviewTest", ".jvp")
169 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
170 DataSourceType.FILE);
171 assertNotNull(af, "Didn't read input file " + inFile);
172 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
173 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
174 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
177 aa != null && aa.length > 0,
178 "Didn't find any IUPred annotation to use to shade alignment.");
179 AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
180 AnnotationColourGradient.ABOVE_THRESHOLD);
181 AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0],
182 null, AnnotationColourGradient.BELOW_THRESHOLD);
183 cs.setSeqAssociated(true);
184 gcs.setSeqAssociated(true);
186 SequenceGroup sg = new SequenceGroup();
189 sg.cs.setColourScheme(gcs);
190 af.getViewport().getAlignment().addGroup(sg);
191 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
192 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
193 af.alignPanel.alignmentChanged();
194 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
195 "Failed to store as a project.");
196 af.closeMenuItem_actionPerformed(true);
198 af = new FileLoader()
199 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
200 assertNotNull(af, "Failed to import new project");
202 // check for group and alignment colourschemes
204 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
205 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
206 .get(0).getColourScheme();
207 assertNotNull(_rcs, "Didn't recover global colourscheme");
208 assertTrue(_rcs instanceof AnnotationColourGradient,
209 "Didn't recover annotation colour global scheme");
210 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
211 assertTrue(__rcs.isSeqAssociated(),
212 "Annotation colourscheme wasn't sequence associated");
214 boolean diffseqcols = false, diffgseqcols = false;
215 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
216 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
217 && (!diffseqcols || !diffgseqcols); p++)
219 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
220 .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
225 assertTrue(diffseqcols, "Got Different sequence colours");
227 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
229 assertNotNull(_rgcs, "Didn't recover group colourscheme");
230 assertTrue(_rgcs instanceof AnnotationColourGradient,
231 "Didn't recover annotation colour group colourscheme");
232 __rcs = (AnnotationColourGradient) _rgcs;
233 assertTrue(__rcs.isSeqAssociated(),
234 "Group Annotation colourscheme wasn't sequence associated");
236 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
237 && (!diffseqcols || !diffgseqcols); p++)
239 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null, 0f) != _rgcs
240 .findColour(sqs[2].getCharAt(p), p, sqs[2], null, 0f))
245 assertTrue(diffgseqcols, "Got Different group sequence colours");
247 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
250 @Test(groups = { "Functional" })
251 public void gatherViewsHere() throws Exception
253 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
254 .getAlignFrames().length;
255 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
256 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
257 assertNotNull(af, "Didn't read in the example file correctly.");
258 assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
259 "Didn't gather the views in the example file.");
263 @Test(groups = { "Functional" })
264 public void viewRefPdbAnnotation() throws Exception
266 StructureImportSettings.setProcessSecondaryStructure(true);
267 StructureImportSettings.setVisibleChainAnnotation(true);
268 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
269 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
270 assertNotNull(af, "Didn't read in the example file correctly.");
271 AlignmentViewPanel sps = null;
272 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
274 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
280 assertNotNull(sps, "Couldn't find the structure view");
281 AlignmentAnnotation refan = null;
282 for (AlignmentAnnotation ra : sps.getAlignment()
283 .getAlignmentAnnotation())
291 assertNotNull(refan, "Annotation secondary structure not found.");
292 SequenceI sq = sps.getAlignment().findName("1A70|");
293 assertNotNull(sq, "Couldn't find 1a70 null chain");
294 // compare the manually added temperature factor annotation
295 // to the track automatically transferred from the pdb structure on load
296 assertNotNull(sq.getDatasetSequence().getAnnotation(),
297 "1a70 has no annotation");
298 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
300 AlignmentAnnotation alaa;
301 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
302 alaa.adjustForAlignment();
303 if (ala.graph == refan.graph)
305 for (int p = 0; p < ala.annotations.length; p++)
311 (alaa.annotations[p] == null && refan.annotations[p] == null)
312 || alaa.annotations[p].value == refan.annotations[p].value,
313 "Mismatch at alignment position " + p);
314 } catch (NullPointerException q)
316 Assert.fail("Mismatch of alignment annotations at position "
317 + p + " Ref seq ann: " + refan.annotations[p]
318 + " alignment " + alaa.annotations[p]);
326 @Test(groups = { "Functional" })
327 public void testCopyViewSettings() throws Exception
329 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
330 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
331 assertNotNull(af, "Didn't read in the example file correctly.");
332 AlignmentViewPanel sps = null, groups = null;
333 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
335 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
339 if (ap.getViewName().contains("MAFFT"))
344 assertNotNull(sps, "Couldn't find the structure view");
345 assertNotNull(groups, "Couldn't find the MAFFT view");
347 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
348 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
349 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
351 groups.getAlignViewport().setViewStyle(structureStyle);
352 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
354 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
360 * test store and recovery of expanded views
364 @Test(groups = { "Functional" }, enabled = true)
365 public void testStoreAndRecoverExpandedviews() throws Exception
367 Desktop.instance.closeAll_actionPerformed(null);
369 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
370 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
371 Assert.assertEquals(Desktop.getAlignFrames().length, 1);
372 String afid = af.getViewport().getSequenceSetId();
374 // check FileLoader returned a reference to the one alignFrame that is
375 // actually on the Desktop
378 Desktop.getAlignFrameFor(af.getViewport()),
379 "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
381 Desktop.explodeViews(af);
383 int oldviews = Desktop.getAlignFrames().length;
384 Assert.assertEquals(Desktop.getAlignFrames().length,
385 Desktop.getAlignmentPanels(afid).length);
386 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
389 new Jalview2XML(false).saveState(tfile);
392 Assert.fail("Didn't save the expanded view state", e);
393 } catch (Exception e)
395 Assert.fail("Didn't save the expanded view state", e);
397 Desktop.instance.closeAll_actionPerformed(null);
398 if (Desktop.getAlignFrames() != null)
400 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
402 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
403 DataSourceType.FILE);
404 Assert.assertNotNull(af);
406 Desktop.getAlignFrames().length,
407 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
409 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
414 * Test save and reload of a project with a different representative sequence
419 @Test(groups = { "Functional" })
420 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
422 Desktop.instance.closeAll_actionPerformed(null);
423 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
424 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
425 assertNotNull(af, "Didn't read in the example file correctly.");
426 String afid = af.getViewport().getSequenceSetId();
428 // remember reference sequence for each panel
429 Map<String, SequenceI> refseqs = new HashMap<>();
432 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
433 * as reference sequence for itself and the preceding sequence
436 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
438 AlignViewportI av = ap.getAlignViewport();
439 AlignmentI alignment = ap.getAlignment();
440 int repIndex = n % alignment.getHeight();
441 SequenceI rep = alignment.getSequenceAt(repIndex);
442 refseqs.put(ap.getViewName(), rep);
444 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
445 // todo refactor this to an alignment view controller
446 av.setDisplayReferenceSeq(true);
447 av.setColourByReferenceSeq(true);
448 av.getAlignment().setSeqrep(rep);
452 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
456 new Jalview2XML(false).saveState(tfile);
457 } catch (Throwable e)
459 Assert.fail("Didn't save the expanded view state", e);
461 Desktop.instance.closeAll_actionPerformed(null);
462 if (Desktop.getAlignFrames() != null)
464 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
467 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
468 DataSourceType.FILE);
469 afid = af.getViewport().getSequenceSetId();
471 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
473 // check representative
474 AlignmentI alignment = ap.getAlignment();
475 SequenceI rep = alignment.getSeqrep();
476 Assert.assertNotNull(rep,
477 "Couldn't restore sequence representative from project");
478 // can't use a strong equals here, because by definition, the sequence IDs
479 // will be different.
480 // could set vamsas session save/restore flag to preserve IDs across
482 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
484 "Representative wasn't the same when recovered.");
485 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
486 "Display reference sequence view setting not set.");
487 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
488 "Colour By Reference Seq view setting not set.");
492 @Test(groups = { "Functional" })
493 public void testIsVersionStringLaterThan()
496 * No version / development / test / autobuild is leniently assumed to be
499 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
500 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
501 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
502 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
503 "Development Build"));
504 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
505 "DEVELOPMENT BUILD"));
506 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
507 "Development Build"));
508 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
509 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
510 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
511 assertTrue(Jalview2XML
512 .isVersionStringLaterThan(null, "Automated Build"));
513 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
515 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
519 * same version returns true i.e. compatible
521 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
522 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
523 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
524 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
525 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
528 * later version returns true
530 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
531 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
532 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
533 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
534 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
537 * earlier version returns false
539 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
540 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
541 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
542 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
543 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
547 * Test save and reload of a project with a different sequence group (and
548 * representative sequence) in each view.
552 @Test(groups = { "Functional" })
553 public void testStoreAndRecoverGroupRepSeqs() throws Exception
555 Desktop.instance.closeAll_actionPerformed(null);
556 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
557 "examples/uniref50.fa", DataSourceType.FILE);
558 assertNotNull(af, "Didn't read in the example file correctly.");
559 String afid = af.getViewport().getSequenceSetId();
560 // make a second view of the alignment
561 af.newView_actionPerformed(null);
564 * remember representative and hidden sequences marked
567 Map<String, SequenceI> repSeqs = new HashMap<>();
568 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
571 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
572 * as reference sequence for itself and the preceding sequence
575 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
577 AlignViewportI av = ap.getAlignViewport();
578 AlignmentI alignment = ap.getAlignment();
579 int repIndex = n % alignment.getHeight();
580 // ensure at least one preceding sequence i.e. index >= 1
581 repIndex = Math.max(repIndex, 1);
582 SequenceI repSeq = alignment.getSequenceAt(repIndex);
583 repSeqs.put(ap.getViewName(), repSeq);
584 List<String> hiddenNames = new ArrayList<>();
585 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
588 * have rep sequence represent itself and the one before it
589 * this hides the group (except for the rep seq)
591 SequenceGroup sg = new SequenceGroup();
592 sg.addSequence(repSeq, false);
593 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
594 sg.addSequence(precedingSeq, false);
595 sg.setSeqrep(repSeq);
596 assertTrue(sg.getSequences().contains(repSeq));
597 assertTrue(sg.getSequences().contains(precedingSeq));
598 av.setSelectionGroup(sg);
599 assertSame(repSeq, sg.getSeqrep());
602 * represent group with sequence adds to a map of hidden rep sequences
603 * (it does not create a group on the alignment)
605 ((AlignmentViewport) av).hideSequences(repSeq, true);
606 assertSame(repSeq, sg.getSeqrep());
607 assertTrue(sg.getSequences().contains(repSeq));
608 assertTrue(sg.getSequences().contains(precedingSeq));
609 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
610 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
611 .getHiddenRepSequences();
612 assertNotNull(hiddenRepSeqsMap);
613 assertEquals(1, hiddenRepSeqsMap.size());
614 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
615 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
616 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
617 hiddenNames.add(precedingSeq.getName());
622 .createTempFile("testStoreAndRecoverGroupReps", ".jvp");
625 new Jalview2XML(false).saveState(tfile);
626 } catch (Throwable e)
628 Assert.fail("Didn't save the expanded view state", e);
630 Desktop.instance.closeAll_actionPerformed(null);
631 if (Desktop.getAlignFrames() != null)
633 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
636 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
637 DataSourceType.FILE);
638 afid = af.getViewport().getSequenceSetId();
640 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
642 String viewName = ap.getViewName();
643 AlignViewportI av = ap.getAlignViewport();
644 AlignmentI alignment = ap.getAlignment();
645 List<SequenceGroup> groups = alignment.getGroups();
646 assertNotNull(groups);
647 assertTrue(groups.isEmpty(), "Alignment has groups");
648 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
649 .getHiddenRepSequences();
650 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
651 assertEquals(1, hiddenRepSeqsMap.size());
652 assertEquals(repSeqs.get(viewName).getDisplayId(true),
653 hiddenRepSeqsMap.keySet().iterator().next()
654 .getDisplayId(true));
657 * verify hidden sequences in restored panel
659 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
660 HiddenSequences hs = alignment.getHiddenSequences();
664 "wrong number of restored hidden sequences in "
670 * Test save and reload of PDBEntry in Jalview project
674 @Test(groups = { "Functional" })
675 public void testStoreAndRecoverPDBEntry() throws Exception
677 Desktop.instance.closeAll_actionPerformed(null);
678 String exampleFile = "examples/3W5V.pdb";
679 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
680 DataSourceType.FILE);
681 assertNotNull(af, "Didn't read in the example file correctly.");
682 String afid = af.getViewport().getSequenceSetId();
684 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
685 System.out.println();
686 AlignmentViewPanel ap = alignPanels[0];
687 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
688 String testFile = tfileBase + exampleFile;
689 AlignmentI alignment = ap.getAlignment();
690 System.out.println("blah");
691 SequenceI[] seqs = alignment.getSequencesArray();
692 Assert.assertNotNull(seqs[0]);
693 Assert.assertNotNull(seqs[1]);
694 Assert.assertNotNull(seqs[2]);
695 Assert.assertNotNull(seqs[3]);
696 Assert.assertNotNull(seqs[0].getDatasetSequence());
697 Assert.assertNotNull(seqs[1].getDatasetSequence());
698 Assert.assertNotNull(seqs[2].getDatasetSequence());
699 Assert.assertNotNull(seqs[3].getDatasetSequence());
700 PDBEntry[] pdbEntries = new PDBEntry[4];
701 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
702 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
703 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
704 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
705 Assert.assertEquals(seqs[0].getDatasetSequence().getAllPDBEntries()
706 .get(0), pdbEntries[0]);
707 Assert.assertEquals(seqs[1].getDatasetSequence().getAllPDBEntries()
708 .get(0), pdbEntries[1]);
709 Assert.assertEquals(seqs[2].getDatasetSequence().getAllPDBEntries()
710 .get(0), pdbEntries[2]);
711 Assert.assertEquals(seqs[3].getDatasetSequence().getAllPDBEntries()
712 .get(0), pdbEntries[3]);
714 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
717 new Jalview2XML(false).saveState(tfile);
718 } catch (Throwable e)
720 Assert.fail("Didn't save the state", e);
722 Desktop.instance.closeAll_actionPerformed(null);
723 if (Desktop.getAlignFrames() != null)
725 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
728 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
729 tfile.getAbsolutePath(), DataSourceType.FILE);
730 String rfid = restoredFrame.getViewport().getSequenceSetId();
731 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
732 AlignmentViewPanel rap = rAlignPanels[0];
733 AlignmentI rAlignment = rap.getAlignment();
734 System.out.println("blah");
735 SequenceI[] rseqs = rAlignment.getSequencesArray();
736 Assert.assertNotNull(rseqs[0]);
737 Assert.assertNotNull(rseqs[1]);
738 Assert.assertNotNull(rseqs[2]);
739 Assert.assertNotNull(rseqs[3]);
740 Assert.assertNotNull(rseqs[0].getDatasetSequence());
741 Assert.assertNotNull(rseqs[1].getDatasetSequence());
742 Assert.assertNotNull(rseqs[2].getDatasetSequence());
743 Assert.assertNotNull(rseqs[3].getDatasetSequence());
745 // The Asserts below are expected to fail until the PDB chainCode is
746 // recoverable from a Jalview projects
747 for (int chain = 0; chain < 4; chain++)
749 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
751 PDBEntry expected = pdbEntries[chain];
752 Assert.assertEquals(recov.getId(), expected.getId(),
754 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
756 Assert.assertEquals(recov.getType(), expected.getType(),
757 "Mismatch PDBEntry 'Type'");
758 Assert.assertNotNull(recov.getFile(),
759 "Recovered PDBEntry should have a non-null file entry");
764 * Configure an alignment and a sub-group each with distinct colour schemes,
765 * Conservation and PID thresholds, and confirm these are restored from the
768 * @throws IOException
770 @Test(groups = { "Functional" })
771 public void testStoreAndRecoverColourThresholds() throws IOException
773 Desktop.instance.closeAll_actionPerformed(null);
774 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
775 "examples/uniref50.fa", DataSourceType.FILE);
777 AlignViewportI av = af.getViewport();
778 AlignmentI al = av.getAlignment();
781 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
783 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
784 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
785 af.abovePIDThreshold_actionPerformed(true);
786 SliderPanel sp = SliderPanel.getSliderPanel();
787 assertFalse(sp.isForConservation());
789 af.conservationMenuItem_actionPerformed(true);
790 sp = SliderPanel.getSliderPanel();
791 assertTrue(sp.isForConservation());
793 ResidueShaderI rs = av.getResidueShading();
794 assertEquals(rs.getThreshold(), 10);
795 assertTrue(rs.conservationApplied());
796 assertEquals(rs.getConservationInc(), 20);
799 * create a group with Strand colouring, 30% Conservation
800 * and 40% PID threshold
802 SequenceGroup sg = new SequenceGroup();
803 sg.addSequence(al.getSequenceAt(0), false);
806 av.setSelectionGroup(sg);
807 PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
808 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
810 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
811 assertEquals(al.getGroups().size(), 1);
812 assertSame(al.getGroups().get(0), sg);
813 popupMenu.conservationMenuItem_actionPerformed(true);
814 sp = SliderPanel.getSliderPanel();
815 assertTrue(sp.isForConservation());
817 popupMenu.abovePIDColour_actionPerformed(true);
818 sp = SliderPanel.getSliderPanel();
819 assertFalse(sp.isForConservation());
821 assertTrue(sg.getGroupColourScheme().conservationApplied());
822 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
823 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
826 * save project, close windows, reload project, verify
828 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
830 tfile.deleteOnExit();
831 new Jalview2XML(false).saveState(tfile);
832 Desktop.instance.closeAll_actionPerformed(null);
833 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
834 DataSourceType.FILE);
835 Assert.assertNotNull(af, "Failed to reload project");
838 * verify alignment (background) colouring
840 rs = af.getViewport().getResidueShading();
841 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
842 assertEquals(rs.getThreshold(), 10);
843 assertTrue(rs.conservationApplied());
844 assertEquals(rs.getConservationInc(), 20);
847 * verify group colouring
849 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
850 rs = af.getViewport().getAlignment().getGroups().get(0)
851 .getGroupColourScheme();
852 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
853 assertEquals(rs.getThreshold(), 40);
854 assertTrue(rs.conservationApplied());
855 assertEquals(rs.getConservationInc(), 30);
859 * Test save and reload of feature colour schemes and filter settings
861 * @throws IOException
863 @Test(groups = { "Functional" })
864 public void testStoreAndRecoverFeatureColoursAndFilters()
867 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
868 ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
869 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
872 * add some features to the sequence
875 addFeatures(seq1, "type1", score++);
876 addFeatures(seq1, "type2", score++);
877 addFeatures(seq1, "type3", score++);
878 addFeatures(seq1, "type4", score++);
879 addFeatures(seq1, "type5", score++);
882 * set colour schemes for features
884 FeatureRenderer fr = af.getFeatureRenderer();
885 fr.findAllFeatures(true);
888 fr.setColour("type1", new FeatureColour(Color.red));
891 FeatureColourI byLabel = new FeatureColour();
892 byLabel.setColourByLabel(true);
893 fr.setColour("type2", byLabel);
895 // type3: by score above threshold
896 FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1,
898 byScore.setAboveThreshold(true);
899 byScore.setThreshold(2f);
900 fr.setColour("type3", byScore);
902 // type4: by attribute AF
903 FeatureColourI byAF = new FeatureColour();
904 byAF.setColourByLabel(true);
905 byAF.setAttributeName("AF");
906 fr.setColour("type4", byAF);
908 // type5: by attribute CSQ:PolyPhen below threshold
909 FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE,
911 byPolyPhen.setBelowThreshold(true);
912 byPolyPhen.setThreshold(3f);
913 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
914 fr.setColour("type5", byPolyPhen);
917 * set filters for feature types
920 // filter type1 features by (label contains "x")
921 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
922 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
923 fr.setFeatureFilter("type1", filterByX);
925 // filter type2 features by (score <= 2.4 and score > 1.1)
926 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
927 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
928 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
929 fr.setFeatureFilter("type2", filterByScore);
931 // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
932 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
934 .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
935 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
937 fr.setFeatureFilter("type3", filterByXY);
940 * save as Jalview project
942 File tfile = File.createTempFile("JalviewTest", ".jvp");
943 tfile.deleteOnExit();
944 String filePath = tfile.getAbsolutePath();
945 assertTrue(af.saveAlignment(filePath, FileFormat.Jalview),
946 "Failed to store as a project.");
949 * close current alignment and load the saved project
951 af.closeMenuItem_actionPerformed(true);
953 af = new FileLoader()
954 .LoadFileWaitTillLoaded(filePath, DataSourceType.FILE);
955 assertNotNull(af, "Failed to import new project");
958 * verify restored feature colour schemes and filters
960 fr = af.getFeatureRenderer();
961 FeatureColourI fc = fr.getFeatureStyle("type1");
962 assertTrue(fc.isSimpleColour());
963 assertEquals(fc.getColour(), Color.red);
964 fc = fr.getFeatureStyle("type2");
965 assertTrue(fc.isColourByLabel());
966 fc = fr.getFeatureStyle("type3");
967 assertTrue(fc.isGraduatedColour());
968 assertNull(fc.getAttributeName());
969 assertTrue(fc.isAboveThreshold());
970 assertEquals(fc.getThreshold(), 2f);
971 fc = fr.getFeatureStyle("type4");
972 assertTrue(fc.isColourByLabel());
973 assertTrue(fc.isColourByAttribute());
974 assertEquals(fc.getAttributeName(), new String[] { "AF" });
975 fc = fr.getFeatureStyle("type5");
976 assertTrue(fc.isGraduatedColour());
977 assertTrue(fc.isColourByAttribute());
978 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
979 assertTrue(fc.isBelowThreshold());
980 assertEquals(fc.getThreshold(), 3f);
982 assertEquals(fr.getFeatureFilter("type1").toStableString(),
984 assertEquals(fr.getFeatureFilter("type2").toStableString(),
985 "(Score LE 2.4) AND (Score GT 1.1)");
986 assertEquals(fr.getFeatureFilter("type3").toStableString(),
987 "(AF Contains X) OR (CSQ:PolyPhen NE 0.0)");
990 private void addFeature(SequenceI seq, String featureType, int score)
992 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
994 sf.setValue("AF", score);
995 sf.setValue("CSQ", new HashMap<String, String>()
998 put("PolyPhen", Integer.toString(score));
1001 seq.addSequenceFeature(sf);
1005 * Adds two features of the given type to the given sequence, also setting the
1006 * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1009 * @param featureType
1012 private void addFeatures(SequenceI seq, String featureType, int score)
1014 addFeature(seq, featureType, score++);
1015 addFeature(seq, featureType, score);
1019 * Load an HMM profile to an alignment, and confirm it is correctly restored
1020 * when reloaded from project
1022 * @throws IOException
1024 @Test(groups = { "Functional" })
1025 public void testStoreAndRecoverHmmProfile() throws IOException
1027 Desktop.instance.closeAll_actionPerformed(null);
1028 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1029 "examples/uniref50.fa", DataSourceType.FILE);
1031 AlignViewportI av = af.getViewport();
1032 AlignmentI al = av.getAlignment();
1035 * mimic drag and drop of hmm file on to alignment
1037 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
1038 "examples/uniref50.hmm", DataSourceType.FILE);
1039 al.insertSequenceAt(0,
1040 af2.getViewport().getAlignment().getSequenceAt(0));
1043 * check it loaded in
1045 SequenceI hmmSeq = al.getSequenceAt(0);
1046 assertTrue(hmmSeq.hasHMMProfile());
1047 HiddenMarkovModel hmm = hmmSeq.getHMM();
1048 assertSame(hmm.getConsensusSequence(), hmmSeq);
1051 * save project, close windows, reload project, verify
1053 File tfile = File.createTempFile("testStoreAndRecoverHmmProfile",
1055 tfile.deleteOnExit();
1056 new Jalview2XML(false).saveState(tfile);
1057 Desktop.instance.closeAll_actionPerformed(null);
1058 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1059 DataSourceType.FILE);
1060 Assert.assertNotNull(af, "Failed to reload project");
1062 hmmSeq = al.getSequenceAt(0);
1063 assertTrue(hmmSeq.hasHMMProfile());
1064 assertSame(hmm.getConsensusSequence(), hmmSeq);
1065 Mapping mapToHmmConsensus = (Mapping) PA.getValue(hmm,
1066 "mapToHmmConsensus");
1067 assertNotNull(mapToHmmConsensus);
1068 assertSame(mapToHmmConsensus.getTo(), hmmSeq.getDatasetSequence());