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.
21 package jalview.project;
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.JvOptionPane;
52 import jalview.gui.PopupMenu;
53 import jalview.gui.SliderPanel;
54 import jalview.io.DataSourceType;
55 import jalview.io.FileFormat;
56 import jalview.io.FileLoader;
57 import jalview.io.Jalview2xmlBase;
58 import jalview.renderer.ResidueShaderI;
59 import jalview.schemes.AnnotationColourGradient;
60 import jalview.schemes.BuriedColourScheme;
61 import jalview.schemes.ColourSchemeI;
62 import jalview.schemes.ColourSchemeProperty;
63 import jalview.schemes.FeatureColour;
64 import jalview.schemes.JalviewColourScheme;
65 import jalview.schemes.RNAHelicesColour;
66 import jalview.schemes.StrandColourScheme;
67 import jalview.schemes.TCoffeeColourScheme;
68 import jalview.structure.StructureImportSettings;
69 import jalview.util.matcher.Condition;
70 import jalview.viewmodel.AlignmentViewport;
72 import java.awt.Color;
74 import java.io.IOException;
75 import java.util.ArrayList;
76 import java.util.HashMap;
77 import java.util.List;
80 import org.testng.Assert;
81 import org.testng.AssertJUnit;
82 import org.testng.annotations.BeforeClass;
83 import org.testng.annotations.Test;
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 af.saveAlignment(tfile, FileFormat.Jalview);
114 assertTrue(af.isSaveAlignmentSuccessful(),
115 "Failed to store as a project.");
116 af.closeMenuItem_actionPerformed(true);
118 af = new FileLoader()
119 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
120 assertNotNull(af, "Failed to import new project");
121 int newdsann = countDsAnn(af.getViewport());
122 assertEquals(olddsann, newdsann,
123 "Differing numbers of dataset sequence annotation\nOriginally "
124 + olddsann + " and now " + newdsann);
126 .println("Read in same number of annotations as originally present ("
130 af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
131 "RNA helices colourscheme was not applied on import.");
134 @Test(groups = { "Functional" })
135 public void testTCoffeeScores() throws Exception
137 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
138 String tfile = File.createTempFile("JalviewTest", ".jvp")
140 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
141 DataSourceType.FILE);
142 assertNotNull(af, "Didn't read input file " + inFile);
143 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
144 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
145 TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
146 assertNotNull(ColourSchemeProperty.getColourScheme(af.getViewport()
147 .getAlignment(), af.getViewport().getGlobalColourScheme()
148 .getSchemeName()), "Recognise T-Coffee score from string");
150 af.saveAlignment(tfile, FileFormat.Jalview);
151 assertTrue(af.isSaveAlignmentSuccessful(),
152 "Failed to store as a project.");
153 af.closeMenuItem_actionPerformed(true);
155 af = new FileLoader()
156 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
157 assertNotNull(af, "Failed to import new project");
158 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
159 TCoffeeColourScheme.class,
160 "Didn't set T-coffee colourscheme for imported project.");
162 .println("T-Coffee score shading successfully recovered from project.");
165 @Test(groups = { "Functional" })
166 public void testColourByAnnotScores() throws Exception
168 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
169 String tfile = File.createTempFile("JalviewTest", ".jvp")
171 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
172 DataSourceType.FILE);
173 assertNotNull(af, "Didn't read input file " + inFile);
174 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
175 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
176 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
179 aa != null && aa.length > 0,
180 "Didn't find any IUPred annotation to use to shade alignment.");
181 AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
182 AnnotationColourGradient.ABOVE_THRESHOLD);
183 AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0],
184 null, AnnotationColourGradient.BELOW_THRESHOLD);
185 cs.setSeqAssociated(true);
186 gcs.setSeqAssociated(true);
188 SequenceGroup sg = new SequenceGroup();
191 sg.cs.setColourScheme(gcs);
192 af.getViewport().getAlignment().addGroup(sg);
193 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
194 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
195 af.alignPanel.alignmentChanged();
196 af.saveAlignment(tfile, FileFormat.Jalview);
197 assertTrue(af.isSaveAlignmentSuccessful(),
198 "Failed to store as a project.");
199 af.closeMenuItem_actionPerformed(true);
201 af = new FileLoader()
202 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
203 assertNotNull(af, "Failed to import new project");
205 // check for group and alignment colourschemes
207 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
208 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
209 .get(0).getColourScheme();
210 assertNotNull(_rcs, "Didn't recover global colourscheme");
211 assertTrue(_rcs instanceof AnnotationColourGradient,
212 "Didn't recover annotation colour global scheme");
213 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
214 assertTrue(__rcs.isSeqAssociated(),
215 "Annotation colourscheme wasn't sequence associated");
217 boolean diffseqcols = false, diffgseqcols = false;
218 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
219 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
220 && (!diffseqcols || !diffgseqcols); p++)
222 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
223 .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
228 assertTrue(diffseqcols, "Got Different sequence colours");
230 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
232 assertNotNull(_rgcs, "Didn't recover group colourscheme");
233 assertTrue(_rgcs instanceof AnnotationColourGradient,
234 "Didn't recover annotation colour group colourscheme");
235 __rcs = (AnnotationColourGradient) _rgcs;
236 assertTrue(__rcs.isSeqAssociated(),
237 "Group Annotation colourscheme wasn't sequence associated");
239 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
240 && (!diffseqcols || !diffgseqcols); p++)
242 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null, 0f) != _rgcs
243 .findColour(sqs[2].getCharAt(p), p, sqs[2], null, 0f))
248 assertTrue(diffgseqcols, "Got Different group sequence colours");
250 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
253 @Test(groups = { "Functional" })
254 public void gatherViewsHere() throws Exception
256 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
257 .getAlignFrames().length;
258 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
259 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
260 assertNotNull(af, "Didn't read in the example file correctly.");
261 assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
262 "Didn't gather the views in the example file.");
267 * Test for JAL-2223 - multiple mappings in View Mapping report
271 @Test(groups = { "Functional" })
272 public void noDuplicatePdbMappingsMade() throws Exception
274 StructureImportSettings.setProcessSecondaryStructure(true);
275 StructureImportSettings.setVisibleChainAnnotation(true);
276 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
277 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
278 assertNotNull(af, "Didn't read in the example file correctly.");
280 // locate Jmol viewer
281 // count number of PDB mappings the structure selection manager holds -
282 String pdbFile = af.getCurrentView().getStructureSelectionManager()
283 .findFileForPDBId("1A70");
285 af.getCurrentView().getStructureSelectionManager()
286 .getMapping(pdbFile).length,
287 2, "Expected only two mappings for 1A70");
291 @Test(groups = { "Functional" })
292 public void viewRefPdbAnnotation() throws Exception
294 StructureImportSettings.setProcessSecondaryStructure(true);
295 StructureImportSettings.setVisibleChainAnnotation(true);
296 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
297 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
298 assertNotNull(af, "Didn't read in the example file correctly.");
299 AlignmentViewPanel sps = null;
300 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
302 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
308 assertNotNull(sps, "Couldn't find the structure view");
309 AlignmentAnnotation refan = null;
310 for (AlignmentAnnotation ra : sps.getAlignment()
311 .getAlignmentAnnotation())
319 assertNotNull(refan, "Annotation secondary structure not found.");
320 SequenceI sq = sps.getAlignment().findName("1A70|");
321 assertNotNull(sq, "Couldn't find 1a70 null chain");
322 // compare the manually added temperature factor annotation
323 // to the track automatically transferred from the pdb structure on load
324 assertNotNull(sq.getDatasetSequence().getAnnotation(),
325 "1a70 has no annotation");
326 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
328 AlignmentAnnotation alaa;
329 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
330 alaa.adjustForAlignment();
331 if (ala.graph == refan.graph)
333 for (int p = 0; p < ala.annotations.length; p++)
339 (alaa.annotations[p] == null && refan.annotations[p] == null)
340 || alaa.annotations[p].value == refan.annotations[p].value,
341 "Mismatch at alignment position " + p);
342 } catch (NullPointerException q)
344 Assert.fail("Mismatch of alignment annotations at position "
345 + p + " Ref seq ann: " + refan.annotations[p]
346 + " alignment " + alaa.annotations[p]);
354 @Test(groups = { "Functional" })
355 public void testCopyViewSettings() throws Exception
357 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
358 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
359 assertNotNull(af, "Didn't read in the example file correctly.");
360 AlignmentViewPanel sps = null, groups = null;
361 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
363 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
367 if (ap.getViewName().contains("MAFFT"))
372 assertNotNull(sps, "Couldn't find the structure view");
373 assertNotNull(groups, "Couldn't find the MAFFT view");
375 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
376 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
377 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
379 groups.getAlignViewport().setViewStyle(structureStyle);
380 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
382 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
388 * test store and recovery of expanded views
392 @Test(groups = { "Functional" }, enabled = true)
393 public void testStoreAndRecoverExpandedviews() throws Exception
395 Desktop.instance.closeAll_actionPerformed(null);
397 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
398 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
399 Assert.assertEquals(Desktop.getAlignFrames().length, 1);
400 String afid = af.getViewport().getSequenceSetId();
402 // check FileLoader returned a reference to the one alignFrame that is
403 // actually on the Desktop
406 Desktop.getAlignFrameFor(af.getViewport()),
407 "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
409 Desktop.explodeViews(af);
411 int oldviews = Desktop.getAlignFrames().length;
412 Assert.assertEquals(Desktop.getAlignFrames().length,
413 Desktop.getAlignmentPanels(afid).length);
414 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
417 new Jalview2XML(false).saveState(tfile);
420 Assert.fail("Didn't save the expanded view state", e);
421 } catch (Exception e)
423 Assert.fail("Didn't save the expanded view state", e);
425 Desktop.instance.closeAll_actionPerformed(null);
426 if (Desktop.getAlignFrames() != null)
428 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
430 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
431 DataSourceType.FILE);
432 Assert.assertNotNull(af);
434 Desktop.getAlignFrames().length,
435 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
437 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
442 * Test save and reload of a project with a different representative sequence
447 @Test(groups = { "Functional" })
448 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
450 Desktop.instance.closeAll_actionPerformed(null);
451 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
452 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
453 assertNotNull(af, "Didn't read in the example file correctly.");
454 String afid = af.getViewport().getSequenceSetId();
456 // remember reference sequence for each panel
457 Map<String, SequenceI> refseqs = new HashMap<>();
460 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
461 * as reference sequence for itself and the preceding sequence
464 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
466 AlignViewportI av = ap.getAlignViewport();
467 AlignmentI alignment = ap.getAlignment();
468 int repIndex = n % alignment.getHeight();
469 SequenceI rep = alignment.getSequenceAt(repIndex);
470 refseqs.put(ap.getViewName(), rep);
472 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
473 // todo refactor this to an alignment view controller
474 av.setDisplayReferenceSeq(true);
475 av.setColourByReferenceSeq(true);
476 av.getAlignment().setSeqrep(rep);
480 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
484 new Jalview2XML(false).saveState(tfile);
485 } catch (Throwable e)
487 Assert.fail("Didn't save the expanded view state", e);
489 Desktop.instance.closeAll_actionPerformed(null);
490 if (Desktop.getAlignFrames() != null)
492 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
495 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
496 DataSourceType.FILE);
497 afid = af.getViewport().getSequenceSetId();
499 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
501 // check representative
502 AlignmentI alignment = ap.getAlignment();
503 SequenceI rep = alignment.getSeqrep();
504 Assert.assertNotNull(rep,
505 "Couldn't restore sequence representative from project");
506 // can't use a strong equals here, because by definition, the sequence IDs
507 // will be different.
508 // could set vamsas session save/restore flag to preserve IDs across
510 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
512 "Representative wasn't the same when recovered.");
513 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
514 "Display reference sequence view setting not set.");
515 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
516 "Colour By Reference Seq view setting not set.");
520 @Test(groups = { "Functional" })
521 public void testIsVersionStringLaterThan()
524 * No version / development / test / autobuild is leniently assumed to be
527 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
528 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
529 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
530 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
531 "Development Build"));
532 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
533 "DEVELOPMENT BUILD"));
534 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
535 "Development Build"));
536 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
537 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
538 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
539 assertTrue(Jalview2XML
540 .isVersionStringLaterThan(null, "Automated Build"));
541 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
543 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
547 * same version returns true i.e. compatible
549 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
550 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
551 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
552 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
553 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
556 * later version returns true
558 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
559 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
560 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
561 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
562 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
565 * earlier version returns false
567 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
568 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
569 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
570 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
571 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
575 * Test save and reload of a project with a different sequence group (and
576 * representative sequence) in each view.
580 @Test(groups = { "Functional" })
581 public void testStoreAndRecoverGroupRepSeqs() throws Exception
583 Desktop.instance.closeAll_actionPerformed(null);
584 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
585 "examples/uniref50.fa", DataSourceType.FILE);
586 assertNotNull(af, "Didn't read in the example file correctly.");
587 String afid = af.getViewport().getSequenceSetId();
588 // make a second view of the alignment
589 af.newView_actionPerformed(null);
592 * remember representative and hidden sequences marked
595 Map<String, SequenceI> repSeqs = new HashMap<>();
596 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
599 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
600 * as reference sequence for itself and the preceding sequence
603 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
605 AlignViewportI av = ap.getAlignViewport();
606 AlignmentI alignment = ap.getAlignment();
607 int repIndex = n % alignment.getHeight();
608 // ensure at least one preceding sequence i.e. index >= 1
609 repIndex = Math.max(repIndex, 1);
610 SequenceI repSeq = alignment.getSequenceAt(repIndex);
611 repSeqs.put(ap.getViewName(), repSeq);
612 List<String> hiddenNames = new ArrayList<>();
613 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
616 * have rep sequence represent itself and the one before it
617 * this hides the group (except for the rep seq)
619 SequenceGroup sg = new SequenceGroup();
620 sg.addSequence(repSeq, false);
621 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
622 sg.addSequence(precedingSeq, false);
623 sg.setSeqrep(repSeq);
624 assertTrue(sg.getSequences().contains(repSeq));
625 assertTrue(sg.getSequences().contains(precedingSeq));
626 av.setSelectionGroup(sg);
627 assertSame(repSeq, sg.getSeqrep());
630 * represent group with sequence adds to a map of hidden rep sequences
631 * (it does not create a group on the alignment)
633 ((AlignmentViewport) av).hideSequences(repSeq, true);
634 assertSame(repSeq, sg.getSeqrep());
635 assertTrue(sg.getSequences().contains(repSeq));
636 assertTrue(sg.getSequences().contains(precedingSeq));
637 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
638 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
639 .getHiddenRepSequences();
640 assertNotNull(hiddenRepSeqsMap);
641 assertEquals(1, hiddenRepSeqsMap.size());
642 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
643 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
644 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
645 hiddenNames.add(precedingSeq.getName());
650 .createTempFile("testStoreAndRecoverGroupReps", ".jvp");
653 new Jalview2XML(false).saveState(tfile);
654 } catch (Throwable e)
656 Assert.fail("Didn't save the expanded view state", e);
658 Desktop.instance.closeAll_actionPerformed(null);
659 if (Desktop.getAlignFrames() != null)
661 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
664 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
665 DataSourceType.FILE);
666 afid = af.getViewport().getSequenceSetId();
668 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
670 String viewName = ap.getViewName();
671 AlignViewportI av = ap.getAlignViewport();
672 AlignmentI alignment = ap.getAlignment();
673 List<SequenceGroup> groups = alignment.getGroups();
674 assertNotNull(groups);
675 assertTrue(groups.isEmpty(), "Alignment has groups");
676 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
677 .getHiddenRepSequences();
678 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
679 assertEquals(1, hiddenRepSeqsMap.size());
680 assertEquals(repSeqs.get(viewName).getDisplayId(true),
681 hiddenRepSeqsMap.keySet().iterator().next()
682 .getDisplayId(true));
685 * verify hidden sequences in restored panel
687 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
688 HiddenSequences hs = alignment.getHiddenSequences();
692 "wrong number of restored hidden sequences in "
698 * Test save and reload of PDBEntry in Jalview project
702 @Test(groups = { "Functional" })
703 public void testStoreAndRecoverPDBEntry() throws Exception
705 Desktop.instance.closeAll_actionPerformed(null);
706 String exampleFile = "examples/3W5V.pdb";
707 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
708 DataSourceType.FILE);
709 assertNotNull(af, "Didn't read in the example file correctly.");
710 String afid = af.getViewport().getSequenceSetId();
712 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
713 System.out.println();
714 AlignmentViewPanel ap = alignPanels[0];
715 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
716 String testFile = tfileBase + exampleFile;
717 AlignmentI alignment = ap.getAlignment();
718 System.out.println("blah");
719 SequenceI[] seqs = alignment.getSequencesArray();
720 Assert.assertNotNull(seqs[0]);
721 Assert.assertNotNull(seqs[1]);
722 Assert.assertNotNull(seqs[2]);
723 Assert.assertNotNull(seqs[3]);
724 Assert.assertNotNull(seqs[0].getDatasetSequence());
725 Assert.assertNotNull(seqs[1].getDatasetSequence());
726 Assert.assertNotNull(seqs[2].getDatasetSequence());
727 Assert.assertNotNull(seqs[3].getDatasetSequence());
728 PDBEntry[] pdbEntries = new PDBEntry[4];
729 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
730 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
731 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
732 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
733 Assert.assertEquals(seqs[0].getDatasetSequence().getAllPDBEntries()
734 .get(0), pdbEntries[0]);
735 Assert.assertEquals(seqs[1].getDatasetSequence().getAllPDBEntries()
736 .get(0), pdbEntries[1]);
737 Assert.assertEquals(seqs[2].getDatasetSequence().getAllPDBEntries()
738 .get(0), pdbEntries[2]);
739 Assert.assertEquals(seqs[3].getDatasetSequence().getAllPDBEntries()
740 .get(0), pdbEntries[3]);
742 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
745 new Jalview2XML(false).saveState(tfile);
746 } catch (Throwable e)
748 Assert.fail("Didn't save the state", e);
750 Desktop.instance.closeAll_actionPerformed(null);
751 if (Desktop.getAlignFrames() != null)
753 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
756 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
757 tfile.getAbsolutePath(), DataSourceType.FILE);
758 String rfid = restoredFrame.getViewport().getSequenceSetId();
759 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
760 AlignmentViewPanel rap = rAlignPanels[0];
761 AlignmentI rAlignment = rap.getAlignment();
762 System.out.println("blah");
763 SequenceI[] rseqs = rAlignment.getSequencesArray();
764 Assert.assertNotNull(rseqs[0]);
765 Assert.assertNotNull(rseqs[1]);
766 Assert.assertNotNull(rseqs[2]);
767 Assert.assertNotNull(rseqs[3]);
768 Assert.assertNotNull(rseqs[0].getDatasetSequence());
769 Assert.assertNotNull(rseqs[1].getDatasetSequence());
770 Assert.assertNotNull(rseqs[2].getDatasetSequence());
771 Assert.assertNotNull(rseqs[3].getDatasetSequence());
773 // The Asserts below are expected to fail until the PDB chainCode is
774 // recoverable from a Jalview projects
775 for (int chain = 0; chain < 4; chain++)
777 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
779 PDBEntry expected = pdbEntries[chain];
780 Assert.assertEquals(recov.getId(), expected.getId(),
782 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
784 Assert.assertEquals(recov.getType(), expected.getType(),
785 "Mismatch PDBEntry 'Type'");
786 Assert.assertNotNull(recov.getFile(),
787 "Recovered PDBEntry should have a non-null file entry");
792 * Configure an alignment and a sub-group each with distinct colour schemes,
793 * Conservation and PID thresholds, and confirm these are restored from the
796 * @throws IOException
798 @Test(groups = { "Functional" })
799 public void testStoreAndRecoverColourThresholds() throws IOException
801 Desktop.instance.closeAll_actionPerformed(null);
802 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
803 "examples/uniref50.fa", DataSourceType.FILE);
805 AlignViewport av = af.getViewport();
806 AlignmentI al = av.getAlignment();
809 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
811 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
812 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
813 af.abovePIDThreshold_actionPerformed(true);
814 SliderPanel sp = SliderPanel.getSliderPanel();
815 assertFalse(sp.isForConservation());
817 af.conservationMenuItem_actionPerformed(true);
818 sp = SliderPanel.getSliderPanel();
819 assertTrue(sp.isForConservation());
821 ResidueShaderI rs = av.getResidueShading();
822 assertEquals(rs.getThreshold(), 10);
823 assertTrue(rs.conservationApplied());
824 assertEquals(rs.getConservationInc(), 20);
827 * create a group with Strand colouring, 30% Conservation
828 * and 40% PID threshold
830 SequenceGroup sg = new SequenceGroup();
831 sg.addSequence(al.getSequenceAt(0), false);
834 av.setSelectionGroup(sg);
835 PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
836 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
838 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
839 assertEquals(al.getGroups().size(), 1);
840 assertSame(al.getGroups().get(0), sg);
841 popupMenu.conservationMenuItem_actionPerformed(true);
842 sp = SliderPanel.getSliderPanel();
843 assertTrue(sp.isForConservation());
845 popupMenu.abovePIDColour_actionPerformed(true);
846 sp = SliderPanel.getSliderPanel();
847 assertFalse(sp.isForConservation());
849 assertTrue(sg.getGroupColourScheme().conservationApplied());
850 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
851 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
854 * save project, close windows, reload project, verify
856 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
858 tfile.deleteOnExit();
859 new Jalview2XML(false).saveState(tfile);
860 Desktop.instance.closeAll_actionPerformed(null);
861 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
862 DataSourceType.FILE);
863 Assert.assertNotNull(af, "Failed to reload project");
866 * verify alignment (background) colouring
868 rs = af.getViewport().getResidueShading();
869 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
870 assertEquals(rs.getThreshold(), 10);
871 assertTrue(rs.conservationApplied());
872 assertEquals(rs.getConservationInc(), 20);
875 * verify group colouring
877 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
878 rs = af.getViewport().getAlignment().getGroups().get(0)
879 .getGroupColourScheme();
880 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
881 assertEquals(rs.getThreshold(), 40);
882 assertTrue(rs.conservationApplied());
883 assertEquals(rs.getConservationInc(), 30);
887 * Test save and reload of feature colour schemes and filter settings
889 * @throws IOException
891 @Test(groups = { "Functional" })
892 public void testSaveLoadFeatureColoursAndFilters() throws IOException
894 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
895 ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
896 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
899 * add some features to the sequence
902 addFeatures(seq1, "type1", score++);
903 addFeatures(seq1, "type2", score++);
904 addFeatures(seq1, "type3", score++);
905 addFeatures(seq1, "type4", score++);
906 addFeatures(seq1, "type5", score++);
909 * set colour schemes for features
911 FeatureRenderer fr = af.getFeatureRenderer();
912 fr.findAllFeatures(true);
915 fr.setColour("type1", new FeatureColour(Color.red));
918 FeatureColourI byLabel = new FeatureColour();
919 byLabel.setColourByLabel(true);
920 fr.setColour("type2", byLabel);
922 // type3: by score above threshold
923 FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1,
925 byScore.setAboveThreshold(true);
926 byScore.setThreshold(2f);
927 fr.setColour("type3", byScore);
929 // type4: by attribute AF
930 FeatureColourI byAF = new FeatureColour();
931 byAF.setColourByLabel(true);
932 byAF.setAttributeName("AF");
933 fr.setColour("type4", byAF);
935 // type5: by attribute CSQ:PolyPhen below threshold
936 FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE,
938 byPolyPhen.setBelowThreshold(true);
939 byPolyPhen.setThreshold(3f);
940 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
941 fr.setColour("type5", byPolyPhen);
944 * set filters for feature types
947 // filter type1 features by (label contains "x")
948 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
949 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
950 fr.setFeatureFilter("type1", filterByX);
952 // filter type2 features by (score <= 2.4 and score > 1.1)
953 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
954 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
955 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
956 fr.setFeatureFilter("type2", filterByScore);
958 // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
959 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
961 .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
962 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
964 fr.setFeatureFilter("type3", filterByXY);
967 * save as Jalview project
969 File tfile = File.createTempFile("JalviewTest", ".jvp");
970 tfile.deleteOnExit();
971 String filePath = tfile.getAbsolutePath();
972 af.saveAlignment(filePath, FileFormat.Jalview);
973 assertTrue(af.isSaveAlignmentSuccessful(),
974 "Failed to store as a project.");
977 * close current alignment and load the saved project
979 af.closeMenuItem_actionPerformed(true);
981 af = new FileLoader()
982 .LoadFileWaitTillLoaded(filePath, DataSourceType.FILE);
983 assertNotNull(af, "Failed to import new project");
986 * verify restored feature colour schemes and filters
988 fr = af.getFeatureRenderer();
989 FeatureColourI fc = fr.getFeatureStyle("type1");
990 assertTrue(fc.isSimpleColour());
991 assertEquals(fc.getColour(), Color.red);
992 fc = fr.getFeatureStyle("type2");
993 assertTrue(fc.isColourByLabel());
994 fc = fr.getFeatureStyle("type3");
995 assertTrue(fc.isGraduatedColour());
996 assertNull(fc.getAttributeName());
997 assertTrue(fc.isAboveThreshold());
998 assertEquals(fc.getThreshold(), 2f);
999 fc = fr.getFeatureStyle("type4");
1000 assertTrue(fc.isColourByLabel());
1001 assertTrue(fc.isColourByAttribute());
1002 assertEquals(fc.getAttributeName(), new String[] { "AF" });
1003 fc = fr.getFeatureStyle("type5");
1004 assertTrue(fc.isGraduatedColour());
1005 assertTrue(fc.isColourByAttribute());
1006 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
1007 assertTrue(fc.isBelowThreshold());
1008 assertEquals(fc.getThreshold(), 3f);
1010 assertEquals(fr.getFeatureFilter("type1").toStableString(),
1011 "Label Contains x");
1012 assertEquals(fr.getFeatureFilter("type2").toStableString(),
1013 "(Score LE 2.4) AND (Score GT 1.1)");
1014 assertEquals(fr.getFeatureFilter("type3").toStableString(),
1015 "(AF Contains X) OR (CSQ:PolyPhen NE 0.0)");
1018 private void addFeature(SequenceI seq, String featureType, int score)
1020 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
1022 sf.setValue("AF", score);
1023 sf.setValue("CSQ", new HashMap<String, String>()
1026 put("PolyPhen", Integer.toString(score));
1029 seq.addSequenceFeature(sf);
1033 * Adds two features of the given type to the given sequence, also setting the
1034 * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1037 * @param featureType
1040 private void addFeatures(SequenceI seq, String featureType, int score)
1042 addFeature(seq, featureType, score++);
1043 addFeature(seq, featureType, score);