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.");
261 * Test for JAL-2223 - multiple mappings in View Mapping report
265 @Test(groups = { "Functional" })
266 public void noDuplicatePdbMappingsMade() throws Exception
268 StructureImportSettings.setProcessSecondaryStructure(true);
269 StructureImportSettings.setVisibleChainAnnotation(true);
270 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
271 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
272 assertNotNull(af, "Didn't read in the example file correctly.");
274 // locate Jmol viewer
275 // count number of PDB mappings the structure selection manager holds -
276 String pdbFile = af.getCurrentView().getStructureSelectionManager()
277 .findFileForPDBId("1A70");
279 af.getCurrentView().getStructureSelectionManager()
280 .getMapping(pdbFile).length,
281 2, "Expected only two mappings for 1A70");
285 @Test(groups = { "Functional" })
286 public void viewRefPdbAnnotation() throws Exception
288 StructureImportSettings.setProcessSecondaryStructure(true);
289 StructureImportSettings.setVisibleChainAnnotation(true);
290 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
291 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
292 assertNotNull(af, "Didn't read in the example file correctly.");
293 AlignmentViewPanel sps = null;
294 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
296 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
302 assertNotNull(sps, "Couldn't find the structure view");
303 AlignmentAnnotation refan = null;
304 for (AlignmentAnnotation ra : sps.getAlignment()
305 .getAlignmentAnnotation())
313 assertNotNull(refan, "Annotation secondary structure not found.");
314 SequenceI sq = sps.getAlignment().findName("1A70|");
315 assertNotNull(sq, "Couldn't find 1a70 null chain");
316 // compare the manually added temperature factor annotation
317 // to the track automatically transferred from the pdb structure on load
318 assertNotNull(sq.getDatasetSequence().getAnnotation(),
319 "1a70 has no annotation");
320 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
322 AlignmentAnnotation alaa;
323 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
324 alaa.adjustForAlignment();
325 if (ala.graph == refan.graph)
327 for (int p = 0; p < ala.annotations.length; p++)
333 (alaa.annotations[p] == null && refan.annotations[p] == null)
334 || alaa.annotations[p].value == refan.annotations[p].value,
335 "Mismatch at alignment position " + p);
336 } catch (NullPointerException q)
338 Assert.fail("Mismatch of alignment annotations at position "
339 + p + " Ref seq ann: " + refan.annotations[p]
340 + " alignment " + alaa.annotations[p]);
348 @Test(groups = { "Functional" })
349 public void testCopyViewSettings() throws Exception
351 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
352 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
353 assertNotNull(af, "Didn't read in the example file correctly.");
354 AlignmentViewPanel sps = null, groups = null;
355 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
357 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
361 if (ap.getViewName().contains("MAFFT"))
366 assertNotNull(sps, "Couldn't find the structure view");
367 assertNotNull(groups, "Couldn't find the MAFFT view");
369 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
370 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
371 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
373 groups.getAlignViewport().setViewStyle(structureStyle);
374 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
376 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
382 * test store and recovery of expanded views
386 @Test(groups = { "Functional" }, enabled = true)
387 public void testStoreAndRecoverExpandedviews() throws Exception
389 Desktop.instance.closeAll_actionPerformed(null);
391 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
392 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
393 Assert.assertEquals(Desktop.getAlignFrames().length, 1);
394 String afid = af.getViewport().getSequenceSetId();
396 // check FileLoader returned a reference to the one alignFrame that is
397 // actually on the Desktop
400 Desktop.getAlignFrameFor(af.getViewport()),
401 "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
403 Desktop.explodeViews(af);
405 int oldviews = Desktop.getAlignFrames().length;
406 Assert.assertEquals(Desktop.getAlignFrames().length,
407 Desktop.getAlignmentPanels(afid).length);
408 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
411 new Jalview2XML(false).saveState(tfile);
414 Assert.fail("Didn't save the expanded view state", e);
415 } catch (Exception e)
417 Assert.fail("Didn't save the expanded view state", e);
419 Desktop.instance.closeAll_actionPerformed(null);
420 if (Desktop.getAlignFrames() != null)
422 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
424 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
425 DataSourceType.FILE);
426 Assert.assertNotNull(af);
428 Desktop.getAlignFrames().length,
429 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
431 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
436 * Test save and reload of a project with a different representative sequence
441 @Test(groups = { "Functional" })
442 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
444 Desktop.instance.closeAll_actionPerformed(null);
445 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
446 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
447 assertNotNull(af, "Didn't read in the example file correctly.");
448 String afid = af.getViewport().getSequenceSetId();
450 // remember reference sequence for each panel
451 Map<String, SequenceI> refseqs = new HashMap<>();
454 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
455 * as reference sequence for itself and the preceding sequence
458 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
460 AlignViewportI av = ap.getAlignViewport();
461 AlignmentI alignment = ap.getAlignment();
462 int repIndex = n % alignment.getHeight();
463 SequenceI rep = alignment.getSequenceAt(repIndex);
464 refseqs.put(ap.getViewName(), rep);
466 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
467 // todo refactor this to an alignment view controller
468 av.setDisplayReferenceSeq(true);
469 av.setColourByReferenceSeq(true);
470 av.getAlignment().setSeqrep(rep);
474 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
478 new Jalview2XML(false).saveState(tfile);
479 } catch (Throwable e)
481 Assert.fail("Didn't save the expanded view state", e);
483 Desktop.instance.closeAll_actionPerformed(null);
484 if (Desktop.getAlignFrames() != null)
486 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
489 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
490 DataSourceType.FILE);
491 afid = af.getViewport().getSequenceSetId();
493 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
495 // check representative
496 AlignmentI alignment = ap.getAlignment();
497 SequenceI rep = alignment.getSeqrep();
498 Assert.assertNotNull(rep,
499 "Couldn't restore sequence representative from project");
500 // can't use a strong equals here, because by definition, the sequence IDs
501 // will be different.
502 // could set vamsas session save/restore flag to preserve IDs across
504 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
506 "Representative wasn't the same when recovered.");
507 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
508 "Display reference sequence view setting not set.");
509 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
510 "Colour By Reference Seq view setting not set.");
514 @Test(groups = { "Functional" })
515 public void testIsVersionStringLaterThan()
518 * No version / development / test / autobuild is leniently assumed to be
521 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
522 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
523 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
524 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
525 "Development Build"));
526 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
527 "DEVELOPMENT BUILD"));
528 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
529 "Development Build"));
530 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
531 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
532 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
533 assertTrue(Jalview2XML
534 .isVersionStringLaterThan(null, "Automated Build"));
535 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
537 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
541 * same version returns true i.e. compatible
543 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
544 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
545 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
546 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
547 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
550 * later version returns true
552 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
553 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
554 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
555 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
556 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
559 * earlier version returns false
561 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
562 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
563 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
564 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
565 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
569 * Test save and reload of a project with a different sequence group (and
570 * representative sequence) in each view.
574 @Test(groups = { "Functional" })
575 public void testStoreAndRecoverGroupRepSeqs() throws Exception
577 Desktop.instance.closeAll_actionPerformed(null);
578 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
579 "examples/uniref50.fa", DataSourceType.FILE);
580 assertNotNull(af, "Didn't read in the example file correctly.");
581 String afid = af.getViewport().getSequenceSetId();
582 // make a second view of the alignment
583 af.newView_actionPerformed(null);
586 * remember representative and hidden sequences marked
589 Map<String, SequenceI> repSeqs = new HashMap<>();
590 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
593 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
594 * as reference sequence for itself and the preceding sequence
597 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
599 AlignViewportI av = ap.getAlignViewport();
600 AlignmentI alignment = ap.getAlignment();
601 int repIndex = n % alignment.getHeight();
602 // ensure at least one preceding sequence i.e. index >= 1
603 repIndex = Math.max(repIndex, 1);
604 SequenceI repSeq = alignment.getSequenceAt(repIndex);
605 repSeqs.put(ap.getViewName(), repSeq);
606 List<String> hiddenNames = new ArrayList<>();
607 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
610 * have rep sequence represent itself and the one before it
611 * this hides the group (except for the rep seq)
613 SequenceGroup sg = new SequenceGroup();
614 sg.addSequence(repSeq, false);
615 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
616 sg.addSequence(precedingSeq, false);
617 sg.setSeqrep(repSeq);
618 assertTrue(sg.getSequences().contains(repSeq));
619 assertTrue(sg.getSequences().contains(precedingSeq));
620 av.setSelectionGroup(sg);
621 assertSame(repSeq, sg.getSeqrep());
624 * represent group with sequence adds to a map of hidden rep sequences
625 * (it does not create a group on the alignment)
627 ((AlignmentViewport) av).hideSequences(repSeq, true);
628 assertSame(repSeq, sg.getSeqrep());
629 assertTrue(sg.getSequences().contains(repSeq));
630 assertTrue(sg.getSequences().contains(precedingSeq));
631 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
632 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
633 .getHiddenRepSequences();
634 assertNotNull(hiddenRepSeqsMap);
635 assertEquals(1, hiddenRepSeqsMap.size());
636 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
637 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
638 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
639 hiddenNames.add(precedingSeq.getName());
644 .createTempFile("testStoreAndRecoverGroupReps", ".jvp");
647 new Jalview2XML(false).saveState(tfile);
648 } catch (Throwable e)
650 Assert.fail("Didn't save the expanded view state", e);
652 Desktop.instance.closeAll_actionPerformed(null);
653 if (Desktop.getAlignFrames() != null)
655 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
658 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
659 DataSourceType.FILE);
660 afid = af.getViewport().getSequenceSetId();
662 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
664 String viewName = ap.getViewName();
665 AlignViewportI av = ap.getAlignViewport();
666 AlignmentI alignment = ap.getAlignment();
667 List<SequenceGroup> groups = alignment.getGroups();
668 assertNotNull(groups);
669 assertTrue(groups.isEmpty(), "Alignment has groups");
670 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
671 .getHiddenRepSequences();
672 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
673 assertEquals(1, hiddenRepSeqsMap.size());
674 assertEquals(repSeqs.get(viewName).getDisplayId(true),
675 hiddenRepSeqsMap.keySet().iterator().next()
676 .getDisplayId(true));
679 * verify hidden sequences in restored panel
681 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
682 HiddenSequences hs = alignment.getHiddenSequences();
686 "wrong number of restored hidden sequences in "
692 * Test save and reload of PDBEntry in Jalview project
696 @Test(groups = { "Functional" })
697 public void testStoreAndRecoverPDBEntry() throws Exception
699 Desktop.instance.closeAll_actionPerformed(null);
700 String exampleFile = "examples/3W5V.pdb";
701 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
702 DataSourceType.FILE);
703 assertNotNull(af, "Didn't read in the example file correctly.");
704 String afid = af.getViewport().getSequenceSetId();
706 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
707 System.out.println();
708 AlignmentViewPanel ap = alignPanels[0];
709 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
710 String testFile = tfileBase + exampleFile;
711 AlignmentI alignment = ap.getAlignment();
712 System.out.println("blah");
713 SequenceI[] seqs = alignment.getSequencesArray();
714 Assert.assertNotNull(seqs[0]);
715 Assert.assertNotNull(seqs[1]);
716 Assert.assertNotNull(seqs[2]);
717 Assert.assertNotNull(seqs[3]);
718 Assert.assertNotNull(seqs[0].getDatasetSequence());
719 Assert.assertNotNull(seqs[1].getDatasetSequence());
720 Assert.assertNotNull(seqs[2].getDatasetSequence());
721 Assert.assertNotNull(seqs[3].getDatasetSequence());
722 PDBEntry[] pdbEntries = new PDBEntry[4];
723 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
724 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
725 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
726 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
727 Assert.assertEquals(seqs[0].getDatasetSequence().getAllPDBEntries()
728 .get(0), pdbEntries[0]);
729 Assert.assertEquals(seqs[1].getDatasetSequence().getAllPDBEntries()
730 .get(0), pdbEntries[1]);
731 Assert.assertEquals(seqs[2].getDatasetSequence().getAllPDBEntries()
732 .get(0), pdbEntries[2]);
733 Assert.assertEquals(seqs[3].getDatasetSequence().getAllPDBEntries()
734 .get(0), pdbEntries[3]);
736 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
739 new Jalview2XML(false).saveState(tfile);
740 } catch (Throwable e)
742 Assert.fail("Didn't save the state", e);
744 Desktop.instance.closeAll_actionPerformed(null);
745 if (Desktop.getAlignFrames() != null)
747 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
750 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
751 tfile.getAbsolutePath(), DataSourceType.FILE);
752 String rfid = restoredFrame.getViewport().getSequenceSetId();
753 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
754 AlignmentViewPanel rap = rAlignPanels[0];
755 AlignmentI rAlignment = rap.getAlignment();
756 System.out.println("blah");
757 SequenceI[] rseqs = rAlignment.getSequencesArray();
758 Assert.assertNotNull(rseqs[0]);
759 Assert.assertNotNull(rseqs[1]);
760 Assert.assertNotNull(rseqs[2]);
761 Assert.assertNotNull(rseqs[3]);
762 Assert.assertNotNull(rseqs[0].getDatasetSequence());
763 Assert.assertNotNull(rseqs[1].getDatasetSequence());
764 Assert.assertNotNull(rseqs[2].getDatasetSequence());
765 Assert.assertNotNull(rseqs[3].getDatasetSequence());
767 // The Asserts below are expected to fail until the PDB chainCode is
768 // recoverable from a Jalview projects
769 for (int chain = 0; chain < 4; chain++)
771 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
773 PDBEntry expected = pdbEntries[chain];
774 Assert.assertEquals(recov.getId(), expected.getId(),
776 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
778 Assert.assertEquals(recov.getType(), expected.getType(),
779 "Mismatch PDBEntry 'Type'");
780 Assert.assertNotNull(recov.getFile(),
781 "Recovered PDBEntry should have a non-null file entry");
786 * Configure an alignment and a sub-group each with distinct colour schemes,
787 * Conservation and PID thresholds, and confirm these are restored from the
790 * @throws IOException
792 @Test(groups = { "Functional" })
793 public void testStoreAndRecoverColourThresholds() throws IOException
795 Desktop.instance.closeAll_actionPerformed(null);
796 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
797 "examples/uniref50.fa", DataSourceType.FILE);
799 AlignViewport av = af.getViewport();
800 AlignmentI al = av.getAlignment();
803 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
805 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
806 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
807 af.abovePIDThreshold_actionPerformed(true);
808 SliderPanel sp = SliderPanel.getSliderPanel();
809 assertFalse(sp.isForConservation());
811 af.conservationMenuItem_actionPerformed(true);
812 sp = SliderPanel.getSliderPanel();
813 assertTrue(sp.isForConservation());
815 ResidueShaderI rs = av.getResidueShading();
816 assertEquals(rs.getThreshold(), 10);
817 assertTrue(rs.conservationApplied());
818 assertEquals(rs.getConservationInc(), 20);
821 * create a group with Strand colouring, 30% Conservation
822 * and 40% PID threshold
824 SequenceGroup sg = new SequenceGroup();
825 sg.addSequence(al.getSequenceAt(0), false);
828 av.setSelectionGroup(sg);
829 PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
830 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
832 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
833 assertEquals(al.getGroups().size(), 1);
834 assertSame(al.getGroups().get(0), sg);
835 popupMenu.conservationMenuItem_actionPerformed(true);
836 sp = SliderPanel.getSliderPanel();
837 assertTrue(sp.isForConservation());
839 popupMenu.abovePIDColour_actionPerformed(true);
840 sp = SliderPanel.getSliderPanel();
841 assertFalse(sp.isForConservation());
843 assertTrue(sg.getGroupColourScheme().conservationApplied());
844 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
845 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
848 * save project, close windows, reload project, verify
850 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
852 tfile.deleteOnExit();
853 new Jalview2XML(false).saveState(tfile);
854 Desktop.instance.closeAll_actionPerformed(null);
855 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
856 DataSourceType.FILE);
857 Assert.assertNotNull(af, "Failed to reload project");
860 * verify alignment (background) colouring
862 rs = af.getViewport().getResidueShading();
863 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
864 assertEquals(rs.getThreshold(), 10);
865 assertTrue(rs.conservationApplied());
866 assertEquals(rs.getConservationInc(), 20);
869 * verify group colouring
871 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
872 rs = af.getViewport().getAlignment().getGroups().get(0)
873 .getGroupColourScheme();
874 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
875 assertEquals(rs.getThreshold(), 40);
876 assertTrue(rs.conservationApplied());
877 assertEquals(rs.getConservationInc(), 30);
881 * Test save and reload of feature colour schemes and filter settings
883 * @throws IOException
885 @Test(groups = { "Functional" })
886 public void testSaveLoadFeatureColoursAndFilters() throws IOException
888 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
889 ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
890 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
893 * add some features to the sequence
896 addFeatures(seq1, "type1", score++);
897 addFeatures(seq1, "type2", score++);
898 addFeatures(seq1, "type3", score++);
899 addFeatures(seq1, "type4", score++);
900 addFeatures(seq1, "type5", score++);
903 * set colour schemes for features
905 FeatureRenderer fr = af.getFeatureRenderer();
906 fr.findAllFeatures(true);
909 fr.setColour("type1", new FeatureColour(Color.red));
912 FeatureColourI byLabel = new FeatureColour();
913 byLabel.setColourByLabel(true);
914 fr.setColour("type2", byLabel);
916 // type3: by score above threshold
917 FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1,
919 byScore.setAboveThreshold(true);
920 byScore.setThreshold(2f);
921 fr.setColour("type3", byScore);
923 // type4: by attribute AF
924 FeatureColourI byAF = new FeatureColour();
925 byAF.setColourByLabel(true);
926 byAF.setAttributeName("AF");
927 fr.setColour("type4", byAF);
929 // type5: by attribute CSQ:PolyPhen below threshold
930 FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE,
932 byPolyPhen.setBelowThreshold(true);
933 byPolyPhen.setThreshold(3f);
934 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
935 fr.setColour("type5", byPolyPhen);
938 * set filters for feature types
941 // filter type1 features by (label contains "x")
942 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
943 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
944 fr.setFeatureFilter("type1", filterByX);
946 // filter type2 features by (score <= 2.4 and score > 1.1)
947 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
948 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
949 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
950 fr.setFeatureFilter("type2", filterByScore);
952 // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
953 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
955 .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
956 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
958 fr.setFeatureFilter("type3", filterByXY);
961 * save as Jalview project
963 File tfile = File.createTempFile("JalviewTest", ".jvp");
964 tfile.deleteOnExit();
965 String filePath = tfile.getAbsolutePath();
966 assertTrue(af.saveAlignment(filePath, FileFormat.Jalview),
967 "Failed to store as a project.");
970 * close current alignment and load the saved project
972 af.closeMenuItem_actionPerformed(true);
974 af = new FileLoader()
975 .LoadFileWaitTillLoaded(filePath, DataSourceType.FILE);
976 assertNotNull(af, "Failed to import new project");
979 * verify restored feature colour schemes and filters
981 fr = af.getFeatureRenderer();
982 FeatureColourI fc = fr.getFeatureStyle("type1");
983 assertTrue(fc.isSimpleColour());
984 assertEquals(fc.getColour(), Color.red);
985 fc = fr.getFeatureStyle("type2");
986 assertTrue(fc.isColourByLabel());
987 fc = fr.getFeatureStyle("type3");
988 assertTrue(fc.isGraduatedColour());
989 assertNull(fc.getAttributeName());
990 assertTrue(fc.isAboveThreshold());
991 assertEquals(fc.getThreshold(), 2f);
992 fc = fr.getFeatureStyle("type4");
993 assertTrue(fc.isColourByLabel());
994 assertTrue(fc.isColourByAttribute());
995 assertEquals(fc.getAttributeName(), new String[] { "AF" });
996 fc = fr.getFeatureStyle("type5");
997 assertTrue(fc.isGraduatedColour());
998 assertTrue(fc.isColourByAttribute());
999 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
1000 assertTrue(fc.isBelowThreshold());
1001 assertEquals(fc.getThreshold(), 3f);
1003 assertEquals(fr.getFeatureFilter("type1").toStableString(),
1004 "Label Contains x");
1005 assertEquals(fr.getFeatureFilter("type2").toStableString(),
1006 "(Score LE 2.4) AND (Score GT 1.1)");
1007 assertEquals(fr.getFeatureFilter("type3").toStableString(),
1008 "(AF Contains X) OR (CSQ:PolyPhen NE 0.0)");
1011 private void addFeature(SequenceI seq, String featureType, int score)
1013 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
1015 sf.setValue("AF", score);
1016 sf.setValue("CSQ", new HashMap<String, String>()
1019 put("PolyPhen", Integer.toString(score));
1022 seq.addSequenceFeature(sf);
1026 * Adds two features of the given type to the given sequence, also setting the
1027 * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1030 * @param featureType
1033 private void addFeatures(SequenceI seq, String featureType, int score)
1035 addFeature(seq, featureType, score++);
1036 addFeature(seq, featureType, score);