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.AlignmentPanel;
48 import jalview.gui.Desktop;
49 import jalview.gui.FeatureRenderer;
50 import jalview.gui.Jalview2XML;
51 import jalview.gui.JvOptionPane;
52 import jalview.gui.PopupMenu;
53 import jalview.gui.SliderPanel;
54 import jalview.renderer.ResidueShaderI;
55 import jalview.schemes.AnnotationColourGradient;
56 import jalview.schemes.BuriedColourScheme;
57 import jalview.schemes.ColourSchemeI;
58 import jalview.schemes.ColourSchemeProperty;
59 import jalview.schemes.FeatureColour;
60 import jalview.schemes.JalviewColourScheme;
61 import jalview.schemes.RNAHelicesColour;
62 import jalview.schemes.StrandColourScheme;
63 import jalview.schemes.TCoffeeColourScheme;
64 import jalview.structure.StructureImportSettings;
65 import jalview.util.matcher.Condition;
66 import jalview.viewmodel.AlignmentViewport;
68 import java.awt.Color;
70 import java.io.IOException;
71 import java.util.ArrayList;
72 import java.util.HashMap;
73 import java.util.List;
76 import org.testng.Assert;
77 import org.testng.AssertJUnit;
78 import org.testng.annotations.BeforeClass;
79 import org.testng.annotations.Test;
81 @Test(singleThreaded = true)
82 public class Jalview2xmlTests extends Jalview2xmlBase
86 @BeforeClass(alwaysRun = true)
87 public void setUpJvOptionPane()
89 JvOptionPane.setInteractiveMode(false);
90 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
93 @Test(groups = { "Functional" })
94 public void testRNAStructureRecovery() throws Exception
96 String inFile = "examples/RF00031_folded.stk";
97 String tfile = File.createTempFile("JalviewTest", ".jvp")
99 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
100 DataSourceType.FILE);
101 assertNotNull(af, "Didn't read input file " + inFile);
102 int olddsann = countDsAnn(af.getViewport());
103 assertTrue(olddsann > 0, "Didn't find any dataset annotations");
104 af.changeColour_actionPerformed(JalviewColourScheme.RNAHelices
107 af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
108 "Couldn't apply RNA helices colourscheme");
109 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
110 "Failed to store as a project.");
111 af.closeMenuItem_actionPerformed(true);
113 af = new FileLoader()
114 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
115 assertNotNull(af, "Failed to import new project");
116 int newdsann = countDsAnn(af.getViewport());
117 assertEquals(olddsann, newdsann,
118 "Differing numbers of dataset sequence annotation\nOriginally "
119 + olddsann + " and now " + newdsann);
121 .println("Read in same number of annotations as originally present ("
125 af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
126 "RNA helices colourscheme was not applied on import.");
129 @Test(groups = { "Functional" })
130 public void testTCoffeeScores() throws Exception
132 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
133 String tfile = File.createTempFile("JalviewTest", ".jvp")
135 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
136 DataSourceType.FILE);
137 assertNotNull(af, "Didn't read input file " + inFile);
138 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
139 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
140 TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
141 assertNotNull(ColourSchemeProperty.getColourScheme(af.getViewport()
142 .getAlignment(), af.getViewport().getGlobalColourScheme()
143 .getSchemeName()), "Recognise T-Coffee score from string");
145 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
146 "Failed to store as a project.");
147 af.closeMenuItem_actionPerformed(true);
149 af = new FileLoader()
150 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
151 assertNotNull(af, "Failed to import new project");
152 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
153 TCoffeeColourScheme.class,
154 "Didn't set T-coffee colourscheme for imported project.");
156 .println("T-Coffee score shading successfully recovered from project.");
159 @Test(groups = { "Functional" })
160 public void testColourByAnnotScores() throws Exception
162 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
163 String tfile = File.createTempFile("JalviewTest", ".jvp")
165 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
166 DataSourceType.FILE);
167 assertNotNull(af, "Didn't read input file " + inFile);
168 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
169 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
170 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
173 aa != null && aa.length > 0,
174 "Didn't find any IUPred annotation to use to shade alignment.");
175 AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
176 AnnotationColourGradient.ABOVE_THRESHOLD);
177 AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0],
178 null, AnnotationColourGradient.BELOW_THRESHOLD);
179 cs.setSeqAssociated(true);
180 gcs.setSeqAssociated(true);
182 SequenceGroup sg = new SequenceGroup();
185 sg.cs.setColourScheme(gcs);
186 af.getViewport().getAlignment().addGroup(sg);
187 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
188 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
189 af.alignPanel.alignmentChanged();
190 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
191 "Failed to store as a project.");
192 af.closeMenuItem_actionPerformed(true);
194 af = new FileLoader()
195 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
196 assertNotNull(af, "Failed to import new project");
198 // check for group and alignment colourschemes
200 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
201 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
202 .get(0).getColourScheme();
203 assertNotNull(_rcs, "Didn't recover global colourscheme");
204 assertTrue(_rcs instanceof AnnotationColourGradient,
205 "Didn't recover annotation colour global scheme");
206 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
207 assertTrue(__rcs.isSeqAssociated(),
208 "Annotation colourscheme wasn't sequence associated");
210 boolean diffseqcols = false, diffgseqcols = false;
211 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
212 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
213 && (!diffseqcols || !diffgseqcols); p++)
215 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
216 .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
221 assertTrue(diffseqcols, "Got Different sequence colours");
223 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
225 assertNotNull(_rgcs, "Didn't recover group colourscheme");
226 assertTrue(_rgcs instanceof AnnotationColourGradient,
227 "Didn't recover annotation colour group colourscheme");
228 __rcs = (AnnotationColourGradient) _rgcs;
229 assertTrue(__rcs.isSeqAssociated(),
230 "Group Annotation colourscheme wasn't sequence associated");
232 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
233 && (!diffseqcols || !diffgseqcols); p++)
235 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null, 0f) != _rgcs
236 .findColour(sqs[2].getCharAt(p), p, sqs[2], null, 0f))
241 assertTrue(diffgseqcols, "Got Different group sequence colours");
243 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
246 @Test(groups = { "Functional" })
247 public void gatherViewsHere() throws Exception
249 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
250 .getAlignFrames().length;
251 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
252 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
253 assertNotNull(af, "Didn't read in the example file correctly.");
254 assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
255 "Didn't gather the views in the example file.");
259 @Test(groups = { "Functional" })
260 public void viewRefPdbAnnotation() throws Exception
262 StructureImportSettings.setProcessSecondaryStructure(true);
263 StructureImportSettings.setVisibleChainAnnotation(true);
264 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
265 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
266 assertNotNull(af, "Didn't read in the example file correctly.");
267 AlignmentViewPanel sps = null;
268 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
270 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
276 assertNotNull(sps, "Couldn't find the structure view");
277 AlignmentAnnotation refan = null;
278 for (AlignmentAnnotation ra : sps.getAlignment()
279 .getAlignmentAnnotation())
287 assertNotNull(refan, "Annotation secondary structure not found.");
288 SequenceI sq = sps.getAlignment().findName("1A70|");
289 assertNotNull(sq, "Couldn't find 1a70 null chain");
290 // compare the manually added temperature factor annotation
291 // to the track automatically transferred from the pdb structure on load
292 assertNotNull(sq.getDatasetSequence().getAnnotation(),
293 "1a70 has no annotation");
294 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
296 AlignmentAnnotation alaa;
297 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
298 alaa.adjustForAlignment();
299 if (ala.graph == refan.graph)
301 for (int p = 0; p < ala.annotations.length; p++)
307 (alaa.annotations[p] == null && refan.annotations[p] == null)
308 || alaa.annotations[p].value == refan.annotations[p].value,
309 "Mismatch at alignment position " + p);
310 } catch (NullPointerException q)
312 Assert.fail("Mismatch of alignment annotations at position "
313 + p + " Ref seq ann: " + refan.annotations[p]
314 + " alignment " + alaa.annotations[p]);
322 @Test(groups = { "Functional" })
323 public void testCopyViewSettings() throws Exception
325 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
326 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
327 assertNotNull(af, "Didn't read in the example file correctly.");
328 AlignmentViewPanel sps = null, groups = null;
329 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
331 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
335 if (ap.getViewName().contains("MAFFT"))
340 assertNotNull(sps, "Couldn't find the structure view");
341 assertNotNull(groups, "Couldn't find the MAFFT view");
343 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
344 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
345 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
347 groups.getAlignViewport().setViewStyle(structureStyle);
348 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
350 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
356 * test store and recovery of expanded views
360 @Test(groups = { "Functional" }, enabled = true)
361 public void testStoreAndRecoverExpandedviews() throws Exception
363 Desktop.instance.closeAll_actionPerformed(null);
365 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
366 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
367 Assert.assertEquals(Desktop.getAlignFrames().length, 1);
368 String afid = af.getViewport().getSequenceSetId();
370 // check FileLoader returned a reference to the one alignFrame that is
371 // actually on the Desktop
374 Desktop.getAlignFrameFor(af.getViewport()),
375 "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
377 Desktop.explodeViews(af);
379 int oldviews = Desktop.getAlignFrames().length;
380 Assert.assertEquals(Desktop.getAlignFrames().length,
381 Desktop.getAlignmentPanels(afid).length);
382 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
385 new Jalview2XML(false).saveState(tfile);
388 Assert.fail("Didn't save the expanded view state", e);
389 } catch (Exception e)
391 Assert.fail("Didn't save the expanded view state", e);
393 Desktop.instance.closeAll_actionPerformed(null);
394 if (Desktop.getAlignFrames() != null)
396 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
398 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
399 DataSourceType.FILE);
400 Assert.assertNotNull(af);
402 Desktop.getAlignFrames().length,
403 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
405 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
410 * Test save and reload of a project with a different representative sequence
415 @Test(groups = { "Functional" })
416 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
418 Desktop.instance.closeAll_actionPerformed(null);
419 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
420 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
421 assertNotNull(af, "Didn't read in the example file correctly.");
422 String afid = af.getViewport().getSequenceSetId();
424 // remember reference sequence for each panel
425 Map<String, SequenceI> refseqs = new HashMap<>();
428 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
429 * as reference sequence for itself and the preceding sequence
432 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
434 AlignViewportI av = ap.getAlignViewport();
435 AlignmentI alignment = ap.getAlignment();
436 int repIndex = n % alignment.getHeight();
437 SequenceI rep = alignment.getSequenceAt(repIndex);
438 refseqs.put(ap.getViewName(), rep);
440 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
441 // todo refactor this to an alignment view controller
442 av.setDisplayReferenceSeq(true);
443 av.setColourByReferenceSeq(true);
444 av.getAlignment().setSeqrep(rep);
448 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
452 new Jalview2XML(false).saveState(tfile);
453 } catch (Throwable e)
455 Assert.fail("Didn't save the expanded view state", e);
457 Desktop.instance.closeAll_actionPerformed(null);
458 if (Desktop.getAlignFrames() != null)
460 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
463 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
464 DataSourceType.FILE);
465 afid = af.getViewport().getSequenceSetId();
467 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
469 // check representative
470 AlignmentI alignment = ap.getAlignment();
471 SequenceI rep = alignment.getSeqrep();
472 Assert.assertNotNull(rep,
473 "Couldn't restore sequence representative from project");
474 // can't use a strong equals here, because by definition, the sequence IDs
475 // will be different.
476 // could set vamsas session save/restore flag to preserve IDs across
478 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
480 "Representative wasn't the same when recovered.");
481 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
482 "Display reference sequence view setting not set.");
483 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
484 "Colour By Reference Seq view setting not set.");
488 @Test(groups = { "Functional" })
489 public void testIsVersionStringLaterThan()
492 * No version / development / test / autobuild is leniently assumed to be
495 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
496 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
497 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
498 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
499 "Development Build"));
500 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
501 "DEVELOPMENT BUILD"));
502 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
503 "Development Build"));
504 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
505 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
506 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
507 assertTrue(Jalview2XML
508 .isVersionStringLaterThan(null, "Automated Build"));
509 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
511 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
515 * same version returns true i.e. compatible
517 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
518 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
519 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
520 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
521 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
524 * later version returns true
526 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
527 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
528 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
529 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
530 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
533 * earlier version returns false
535 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
536 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
537 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
538 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
539 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
543 * Test save and reload of a project with a different sequence group (and
544 * representative sequence) in each view.
548 @Test(groups = { "Functional" })
549 public void testStoreAndRecoverGroupRepSeqs() throws Exception
551 Desktop.instance.closeAll_actionPerformed(null);
552 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
553 "examples/uniref50.fa", DataSourceType.FILE);
554 assertNotNull(af, "Didn't read in the example file correctly.");
555 String afid = af.getViewport().getSequenceSetId();
556 // make a second view of the alignment
557 af.newView_actionPerformed(null);
560 * remember representative and hidden sequences marked
563 Map<String, SequenceI> repSeqs = new HashMap<>();
564 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
567 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
568 * as reference sequence for itself and the preceding sequence
571 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
573 AlignViewportI av = ap.getAlignViewport();
574 AlignmentI alignment = ap.getAlignment();
575 int repIndex = n % alignment.getHeight();
576 // ensure at least one preceding sequence i.e. index >= 1
577 repIndex = Math.max(repIndex, 1);
578 SequenceI repSeq = alignment.getSequenceAt(repIndex);
579 repSeqs.put(ap.getViewName(), repSeq);
580 List<String> hiddenNames = new ArrayList<>();
581 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
584 * have rep sequence represent itself and the one before it
585 * this hides the group (except for the rep seq)
587 SequenceGroup sg = new SequenceGroup();
588 sg.addSequence(repSeq, false);
589 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
590 sg.addSequence(precedingSeq, false);
591 sg.setSeqrep(repSeq);
592 assertTrue(sg.getSequences().contains(repSeq));
593 assertTrue(sg.getSequences().contains(precedingSeq));
594 av.setSelectionGroup(sg);
595 assertSame(repSeq, sg.getSeqrep());
598 * represent group with sequence adds to a map of hidden rep sequences
599 * (it does not create a group on the alignment)
601 ((AlignmentViewport) av).hideSequences(repSeq, true);
602 assertSame(repSeq, sg.getSeqrep());
603 assertTrue(sg.getSequences().contains(repSeq));
604 assertTrue(sg.getSequences().contains(precedingSeq));
605 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
606 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
607 .getHiddenRepSequences();
608 assertNotNull(hiddenRepSeqsMap);
609 assertEquals(1, hiddenRepSeqsMap.size());
610 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
611 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
612 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
613 hiddenNames.add(precedingSeq.getName());
618 .createTempFile("testStoreAndRecoverGroupReps", ".jvp");
621 new Jalview2XML(false).saveState(tfile);
622 } catch (Throwable e)
624 Assert.fail("Didn't save the expanded view state", e);
626 Desktop.instance.closeAll_actionPerformed(null);
627 if (Desktop.getAlignFrames() != null)
629 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
632 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
633 DataSourceType.FILE);
634 afid = af.getViewport().getSequenceSetId();
636 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
638 String viewName = ap.getViewName();
639 AlignViewportI av = ap.getAlignViewport();
640 AlignmentI alignment = ap.getAlignment();
641 List<SequenceGroup> groups = alignment.getGroups();
642 assertNotNull(groups);
643 assertTrue(groups.isEmpty(), "Alignment has groups");
644 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
645 .getHiddenRepSequences();
646 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
647 assertEquals(1, hiddenRepSeqsMap.size());
648 assertEquals(repSeqs.get(viewName).getDisplayId(true),
649 hiddenRepSeqsMap.keySet().iterator().next()
650 .getDisplayId(true));
653 * verify hidden sequences in restored panel
655 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
656 HiddenSequences hs = alignment.getHiddenSequences();
660 "wrong number of restored hidden sequences in "
666 * Test save and reload of PDBEntry in Jalview project
670 @Test(groups = { "Functional" })
671 public void testStoreAndRecoverPDBEntry() throws Exception
673 Desktop.instance.closeAll_actionPerformed(null);
674 String exampleFile = "examples/3W5V.pdb";
675 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
676 DataSourceType.FILE);
677 assertNotNull(af, "Didn't read in the example file correctly.");
678 String afid = af.getViewport().getSequenceSetId();
680 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
681 System.out.println();
682 AlignmentViewPanel ap = alignPanels[0];
683 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
684 String testFile = tfileBase + exampleFile;
685 AlignmentI alignment = ap.getAlignment();
686 System.out.println("blah");
687 SequenceI[] seqs = alignment.getSequencesArray();
688 Assert.assertNotNull(seqs[0]);
689 Assert.assertNotNull(seqs[1]);
690 Assert.assertNotNull(seqs[2]);
691 Assert.assertNotNull(seqs[3]);
692 Assert.assertNotNull(seqs[0].getDatasetSequence());
693 Assert.assertNotNull(seqs[1].getDatasetSequence());
694 Assert.assertNotNull(seqs[2].getDatasetSequence());
695 Assert.assertNotNull(seqs[3].getDatasetSequence());
696 PDBEntry[] pdbEntries = new PDBEntry[4];
697 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
698 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
699 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
700 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
701 Assert.assertEquals(seqs[0].getDatasetSequence().getAllPDBEntries()
702 .get(0), pdbEntries[0]);
703 Assert.assertEquals(seqs[1].getDatasetSequence().getAllPDBEntries()
704 .get(0), pdbEntries[1]);
705 Assert.assertEquals(seqs[2].getDatasetSequence().getAllPDBEntries()
706 .get(0), pdbEntries[2]);
707 Assert.assertEquals(seqs[3].getDatasetSequence().getAllPDBEntries()
708 .get(0), pdbEntries[3]);
710 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
713 new Jalview2XML(false).saveState(tfile);
714 } catch (Throwable e)
716 Assert.fail("Didn't save the state", e);
718 Desktop.instance.closeAll_actionPerformed(null);
719 if (Desktop.getAlignFrames() != null)
721 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
724 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
725 tfile.getAbsolutePath(), DataSourceType.FILE);
726 String rfid = restoredFrame.getViewport().getSequenceSetId();
727 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
728 AlignmentViewPanel rap = rAlignPanels[0];
729 AlignmentI rAlignment = rap.getAlignment();
730 System.out.println("blah");
731 SequenceI[] rseqs = rAlignment.getSequencesArray();
732 Assert.assertNotNull(rseqs[0]);
733 Assert.assertNotNull(rseqs[1]);
734 Assert.assertNotNull(rseqs[2]);
735 Assert.assertNotNull(rseqs[3]);
736 Assert.assertNotNull(rseqs[0].getDatasetSequence());
737 Assert.assertNotNull(rseqs[1].getDatasetSequence());
738 Assert.assertNotNull(rseqs[2].getDatasetSequence());
739 Assert.assertNotNull(rseqs[3].getDatasetSequence());
741 // The Asserts below are expected to fail until the PDB chainCode is
742 // recoverable from a Jalview projects
743 for (int chain = 0; chain < 4; chain++)
745 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
747 PDBEntry expected = pdbEntries[chain];
748 Assert.assertEquals(recov.getId(), expected.getId(),
750 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
752 Assert.assertEquals(recov.getType(), expected.getType(),
753 "Mismatch PDBEntry 'Type'");
754 Assert.assertNotNull(recov.getFile(),
755 "Recovered PDBEntry should have a non-null file entry");
760 * Configure an alignment and a sub-group each with distinct colour schemes,
761 * Conservation and PID thresholds, and confirm these are restored from the
764 * @throws IOException
766 @Test(groups = { "Functional" })
767 public void testStoreAndRecoverColourThresholds() throws IOException
769 Desktop.instance.closeAll_actionPerformed(null);
770 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
771 "examples/uniref50.fa", DataSourceType.FILE);
773 AlignViewportI av = af.getViewport();
774 AlignmentI al = av.getAlignment();
777 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
779 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
780 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
781 af.abovePIDThreshold_actionPerformed(true);
782 SliderPanel sp = SliderPanel.getSliderPanel();
783 assertFalse(sp.isForConservation());
785 af.conservationMenuItem_actionPerformed(true);
786 sp = SliderPanel.getSliderPanel();
787 assertTrue(sp.isForConservation());
789 ResidueShaderI rs = av.getResidueShading();
790 assertEquals(rs.getThreshold(), 10);
791 assertTrue(rs.conservationApplied());
792 assertEquals(rs.getConservationInc(), 20);
795 * create a group with Strand colouring, 30% Conservation
796 * and 40% PID threshold
798 SequenceGroup sg = new SequenceGroup();
799 sg.addSequence(al.getSequenceAt(0), false);
802 av.setSelectionGroup(sg);
803 PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
804 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
806 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
807 assertEquals(al.getGroups().size(), 1);
808 assertSame(al.getGroups().get(0), sg);
809 popupMenu.conservationMenuItem_actionPerformed(true);
810 sp = SliderPanel.getSliderPanel();
811 assertTrue(sp.isForConservation());
813 popupMenu.abovePIDColour_actionPerformed(true);
814 sp = SliderPanel.getSliderPanel();
815 assertFalse(sp.isForConservation());
817 assertTrue(sg.getGroupColourScheme().conservationApplied());
818 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
819 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
822 * save project, close windows, reload project, verify
824 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
826 tfile.deleteOnExit();
827 new Jalview2XML(false).saveState(tfile);
828 Desktop.instance.closeAll_actionPerformed(null);
829 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
830 DataSourceType.FILE);
831 Assert.assertNotNull(af, "Failed to reload project");
834 * verify alignment (background) colouring
836 rs = af.getViewport().getResidueShading();
837 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
838 assertEquals(rs.getThreshold(), 10);
839 assertTrue(rs.conservationApplied());
840 assertEquals(rs.getConservationInc(), 20);
843 * verify group colouring
845 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
846 rs = af.getViewport().getAlignment().getGroups().get(0)
847 .getGroupColourScheme();
848 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
849 assertEquals(rs.getThreshold(), 40);
850 assertTrue(rs.conservationApplied());
851 assertEquals(rs.getConservationInc(), 30);
855 * Test save and reload of feature colour schemes and filter settings
857 * @throws IOException
859 @Test(groups = { "Functional" })
860 public void testSaveLoadFeatureColoursAndFilters() throws IOException
862 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
863 ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
864 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
867 * add some features to the sequence
870 addFeatures(seq1, "type1", score++);
871 addFeatures(seq1, "type2", score++);
872 addFeatures(seq1, "type3", score++);
873 addFeatures(seq1, "type4", score++);
874 addFeatures(seq1, "type5", score++);
877 * set colour schemes for features
879 FeatureRenderer fr = af.getFeatureRenderer();
880 fr.findAllFeatures(true);
883 fr.setColour("type1", new FeatureColour(Color.red));
886 FeatureColourI byLabel = new FeatureColour();
887 byLabel.setColourByLabel(true);
888 fr.setColour("type2", byLabel);
890 // type3: by score above threshold
891 FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1,
893 byScore.setAboveThreshold(true);
894 byScore.setThreshold(2f);
895 fr.setColour("type3", byScore);
897 // type4: by attribute AF
898 FeatureColourI byAF = new FeatureColour();
899 byAF.setColourByLabel(true);
900 byAF.setAttributeName("AF");
901 fr.setColour("type4", byAF);
903 // type5: by attribute CSQ:PolyPhen below threshold
904 FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE,
906 byPolyPhen.setBelowThreshold(true);
907 byPolyPhen.setThreshold(3f);
908 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
909 fr.setColour("type5", byPolyPhen);
912 * set filters for feature types
915 // filter type1 features by (label contains "x")
916 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
917 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
918 fr.setFeatureFilter("type1", filterByX);
920 // filter type2 features by (score <= 2.4 and score > 1.1)
921 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
922 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
923 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
924 fr.setFeatureFilter("type2", filterByScore);
926 // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
927 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
929 .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
930 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
932 fr.setFeatureFilter("type3", filterByXY);
935 * save as Jalview project
937 File tfile = File.createTempFile("JalviewTest", ".jvp");
938 tfile.deleteOnExit();
939 String filePath = tfile.getAbsolutePath();
940 assertTrue(af.saveAlignment(filePath, FileFormat.Jalview),
941 "Failed to store as a project.");
944 * close current alignment and load the saved project
946 af.closeMenuItem_actionPerformed(true);
948 af = new FileLoader()
949 .LoadFileWaitTillLoaded(filePath, DataSourceType.FILE);
950 assertNotNull(af, "Failed to import new project");
953 * verify restored feature colour schemes and filters
955 fr = af.getFeatureRenderer();
956 FeatureColourI fc = fr.getFeatureStyle("type1");
957 assertTrue(fc.isSimpleColour());
958 assertEquals(fc.getColour(), Color.red);
959 fc = fr.getFeatureStyle("type2");
960 assertTrue(fc.isColourByLabel());
961 fc = fr.getFeatureStyle("type3");
962 assertTrue(fc.isGraduatedColour());
963 assertNull(fc.getAttributeName());
964 assertTrue(fc.isAboveThreshold());
965 assertEquals(fc.getThreshold(), 2f);
966 fc = fr.getFeatureStyle("type4");
967 assertTrue(fc.isColourByLabel());
968 assertTrue(fc.isColourByAttribute());
969 assertEquals(fc.getAttributeName(), new String[] { "AF" });
970 fc = fr.getFeatureStyle("type5");
971 assertTrue(fc.isGraduatedColour());
972 assertTrue(fc.isColourByAttribute());
973 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
974 assertTrue(fc.isBelowThreshold());
975 assertEquals(fc.getThreshold(), 3f);
977 assertEquals(fr.getFeatureFilter("type1").toStableString(),
979 assertEquals(fr.getFeatureFilter("type2").toStableString(),
980 "(Score LE 2.4) AND (Score GT 1.1)");
981 assertEquals(fr.getFeatureFilter("type3").toStableString(),
982 "(AF Contains X) OR (CSQ:PolyPhen NE 0.0)");
985 private void addFeature(SequenceI seq, String featureType, int score)
987 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
989 sf.setValue("AF", score);
990 sf.setValue("CSQ", new HashMap<String, String>()
993 put("PolyPhen", Integer.toString(score));
996 seq.addSequenceFeature(sf);
1000 * Adds two features of the given type to the given sequence, also setting the
1001 * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1004 * @param featureType
1007 private void addFeatures(SequenceI seq, String featureType, int score)
1009 addFeature(seq, featureType, score++);
1010 addFeature(seq, featureType, score);