2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertFalse;
25 import static org.testng.Assert.assertNotNull;
26 import static org.testng.Assert.assertNull;
27 import static org.testng.Assert.assertSame;
28 import static org.testng.Assert.assertTrue;
30 import jalview.api.AlignViewportI;
31 import jalview.api.AlignmentViewPanel;
32 import jalview.api.FeatureColourI;
33 import jalview.api.ViewStyleI;
34 import jalview.datamodel.AlignmentAnnotation;
35 import jalview.datamodel.AlignmentI;
36 import jalview.datamodel.HiddenMarkovModel;
37 import jalview.datamodel.HiddenSequences;
38 import jalview.datamodel.Mapping;
39 import jalview.datamodel.PDBEntry;
40 import jalview.datamodel.PDBEntry.Type;
41 import jalview.datamodel.SequenceCollectionI;
42 import jalview.datamodel.SequenceFeature;
43 import jalview.datamodel.SequenceGroup;
44 import jalview.datamodel.SequenceI;
45 import jalview.datamodel.features.FeatureMatcher;
46 import jalview.datamodel.features.FeatureMatcherSet;
47 import jalview.datamodel.features.FeatureMatcherSetI;
48 import jalview.gui.AlignFrame;
49 import jalview.gui.AlignmentPanel;
50 import jalview.gui.Desktop;
51 import jalview.gui.FeatureRenderer;
52 import jalview.gui.Jalview2XML;
53 import jalview.gui.JvOptionPane;
54 import jalview.gui.PopupMenu;
55 import jalview.gui.SliderPanel;
56 import jalview.renderer.ResidueShaderI;
57 import jalview.schemes.AnnotationColourGradient;
58 import jalview.schemes.BuriedColourScheme;
59 import jalview.schemes.ColourSchemeI;
60 import jalview.schemes.ColourSchemeProperty;
61 import jalview.schemes.FeatureColour;
62 import jalview.schemes.JalviewColourScheme;
63 import jalview.schemes.RNAHelicesColour;
64 import jalview.schemes.StrandColourScheme;
65 import jalview.schemes.TCoffeeColourScheme;
66 import jalview.structure.StructureImportSettings;
67 import jalview.util.matcher.Condition;
68 import jalview.viewmodel.AlignmentViewport;
70 import java.awt.Color;
72 import java.io.IOException;
73 import java.util.ArrayList;
74 import java.util.HashMap;
75 import java.util.List;
78 import org.testng.Assert;
79 import org.testng.AssertJUnit;
80 import org.testng.annotations.BeforeClass;
81 import org.testng.annotations.Test;
83 import junit.extensions.PA;
85 @Test(singleThreaded = true)
86 public class Jalview2xmlTests extends Jalview2xmlBase
90 @BeforeClass(alwaysRun = true)
91 public void setUpJvOptionPane()
93 JvOptionPane.setInteractiveMode(false);
94 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
97 @Test(groups = { "Functional" })
98 public void testRNAStructureRecovery() throws Exception
100 String inFile = "examples/RF00031_folded.stk";
101 String tfile = File.createTempFile("JalviewTest", ".jvp")
103 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
104 DataSourceType.FILE);
105 assertNotNull(af, "Didn't read input file " + inFile);
106 int olddsann = countDsAnn(af.getViewport());
107 assertTrue(olddsann > 0, "Didn't find any dataset annotations");
108 af.changeColour_actionPerformed(JalviewColourScheme.RNAHelices
111 af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
112 "Couldn't apply RNA helices colourscheme");
113 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
114 "Failed to store as a project.");
115 af.closeMenuItem_actionPerformed(true);
117 af = new FileLoader()
118 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
119 assertNotNull(af, "Failed to import new project");
120 int newdsann = countDsAnn(af.getViewport());
121 assertEquals(olddsann, newdsann,
122 "Differing numbers of dataset sequence annotation\nOriginally "
123 + olddsann + " and now " + newdsann);
125 .println("Read in same number of annotations as originally present ("
129 af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
130 "RNA helices colourscheme was not applied on import.");
133 @Test(groups = { "Functional" })
134 public void testTCoffeeScores() throws Exception
136 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
137 String tfile = File.createTempFile("JalviewTest", ".jvp")
139 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
140 DataSourceType.FILE);
141 assertNotNull(af, "Didn't read input file " + inFile);
142 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
143 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
144 TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
145 assertNotNull(ColourSchemeProperty.getColourScheme(af.getViewport()
146 .getAlignment(), af.getViewport().getGlobalColourScheme()
147 .getSchemeName()), "Recognise T-Coffee score from string");
149 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
150 "Failed to store as a project.");
151 af.closeMenuItem_actionPerformed(true);
153 af = new FileLoader()
154 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
155 assertNotNull(af, "Failed to import new project");
156 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
157 TCoffeeColourScheme.class,
158 "Didn't set T-coffee colourscheme for imported project.");
160 .println("T-Coffee score shading successfully recovered from project.");
163 @Test(groups = { "Functional" })
164 public void testColourByAnnotScores() throws Exception
166 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
167 String tfile = File.createTempFile("JalviewTest", ".jvp")
169 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
170 DataSourceType.FILE);
171 assertNotNull(af, "Didn't read input file " + inFile);
172 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
173 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
174 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
177 aa != null && aa.length > 0,
178 "Didn't find any IUPred annotation to use to shade alignment.");
179 AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
180 AnnotationColourGradient.ABOVE_THRESHOLD);
181 AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0],
182 null, AnnotationColourGradient.BELOW_THRESHOLD);
183 cs.setSeqAssociated(true);
184 gcs.setSeqAssociated(true);
186 SequenceGroup sg = new SequenceGroup();
189 sg.cs.setColourScheme(gcs);
190 af.getViewport().getAlignment().addGroup(sg);
191 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
192 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
193 af.alignPanel.alignmentChanged();
194 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
195 "Failed to store as a project.");
196 af.closeMenuItem_actionPerformed(true);
198 af = new FileLoader()
199 .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
200 assertNotNull(af, "Failed to import new project");
202 // check for group and alignment colourschemes
204 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
205 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
206 .get(0).getColourScheme();
207 assertNotNull(_rcs, "Didn't recover global colourscheme");
208 assertTrue(_rcs instanceof AnnotationColourGradient,
209 "Didn't recover annotation colour global scheme");
210 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
211 assertTrue(__rcs.isSeqAssociated(),
212 "Annotation colourscheme wasn't sequence associated");
214 boolean diffseqcols = false, diffgseqcols = false;
215 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
216 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
217 && (!diffseqcols || !diffgseqcols); p++)
219 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
220 .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
225 assertTrue(diffseqcols, "Got Different sequence colours");
227 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
229 assertNotNull(_rgcs, "Didn't recover group colourscheme");
230 assertTrue(_rgcs instanceof AnnotationColourGradient,
231 "Didn't recover annotation colour group colourscheme");
232 __rcs = (AnnotationColourGradient) _rgcs;
233 assertTrue(__rcs.isSeqAssociated(),
234 "Group Annotation colourscheme wasn't sequence associated");
236 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
237 && (!diffseqcols || !diffgseqcols); p++)
239 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null, 0f) != _rgcs
240 .findColour(sqs[2].getCharAt(p), p, sqs[2], null, 0f))
245 assertTrue(diffgseqcols, "Got Different group sequence colours");
247 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
250 @Test(groups = { "Functional" })
251 public void gatherViewsHere() throws Exception
253 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
254 .getAlignFrames().length;
255 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
256 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
257 assertNotNull(af, "Didn't read in the example file correctly.");
258 assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
259 "Didn't gather the views in the example file.");
264 * Test for JAL-2223 - multiple mappings in View Mapping report
268 @Test(groups = { "Functional" })
269 public void noDuplicatePdbMappingsMade() throws Exception
271 StructureImportSettings.setProcessSecondaryStructure(true);
272 StructureImportSettings.setVisibleChainAnnotation(true);
273 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
274 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
275 assertNotNull(af, "Didn't read in the example file correctly.");
277 // locate Jmol viewer
278 // count number of PDB mappings the structure selection manager holds -
279 String pdbFile = af.getCurrentView().getStructureSelectionManager()
280 .findFileForPDBId("1A70");
282 af.getCurrentView().getStructureSelectionManager()
283 .getMapping(pdbFile).length,
284 2, "Expected only two mappings for 1A70");
288 @Test(groups = { "Functional" })
289 public void viewRefPdbAnnotation() throws Exception
291 StructureImportSettings.setProcessSecondaryStructure(true);
292 StructureImportSettings.setVisibleChainAnnotation(true);
293 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
294 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
295 assertNotNull(af, "Didn't read in the example file correctly.");
296 AlignmentViewPanel sps = null;
297 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
299 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
305 assertNotNull(sps, "Couldn't find the structure view");
306 AlignmentAnnotation refan = null;
307 for (AlignmentAnnotation ra : sps.getAlignment()
308 .getAlignmentAnnotation())
316 assertNotNull(refan, "Annotation secondary structure not found.");
317 SequenceI sq = sps.getAlignment().findName("1A70|");
318 assertNotNull(sq, "Couldn't find 1a70 null chain");
319 // compare the manually added temperature factor annotation
320 // to the track automatically transferred from the pdb structure on load
321 assertNotNull(sq.getDatasetSequence().getAnnotation(),
322 "1a70 has no annotation");
323 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
325 AlignmentAnnotation alaa;
326 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
327 alaa.adjustForAlignment();
328 if (ala.graph == refan.graph)
330 for (int p = 0; p < ala.annotations.length; p++)
336 (alaa.annotations[p] == null && refan.annotations[p] == null)
337 || alaa.annotations[p].value == refan.annotations[p].value,
338 "Mismatch at alignment position " + p);
339 } catch (NullPointerException q)
341 Assert.fail("Mismatch of alignment annotations at position "
342 + p + " Ref seq ann: " + refan.annotations[p]
343 + " alignment " + alaa.annotations[p]);
351 @Test(groups = { "Functional" })
352 public void testCopyViewSettings() throws Exception
354 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
355 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
356 assertNotNull(af, "Didn't read in the example file correctly.");
357 AlignmentViewPanel sps = null, groups = null;
358 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
360 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
364 if (ap.getViewName().contains("MAFFT"))
369 assertNotNull(sps, "Couldn't find the structure view");
370 assertNotNull(groups, "Couldn't find the MAFFT view");
372 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
373 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
374 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
376 groups.getAlignViewport().setViewStyle(structureStyle);
377 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
379 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
385 * test store and recovery of expanded views
389 @Test(groups = { "Functional" }, enabled = true)
390 public void testStoreAndRecoverExpandedviews() throws Exception
392 Desktop.instance.closeAll_actionPerformed(null);
394 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
395 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
396 Assert.assertEquals(Desktop.getAlignFrames().length, 1);
397 String afid = af.getViewport().getSequenceSetId();
399 // check FileLoader returned a reference to the one alignFrame that is
400 // actually on the Desktop
403 Desktop.getAlignFrameFor(af.getViewport()),
404 "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
406 Desktop.explodeViews(af);
408 int oldviews = Desktop.getAlignFrames().length;
409 Assert.assertEquals(Desktop.getAlignFrames().length,
410 Desktop.getAlignmentPanels(afid).length);
411 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
414 new Jalview2XML(false).saveState(tfile);
417 Assert.fail("Didn't save the expanded view state", e);
418 } catch (Exception e)
420 Assert.fail("Didn't save the expanded view state", e);
422 Desktop.instance.closeAll_actionPerformed(null);
423 if (Desktop.getAlignFrames() != null)
425 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
427 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
428 DataSourceType.FILE);
429 Assert.assertNotNull(af);
431 Desktop.getAlignFrames().length,
432 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
434 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
439 * Test save and reload of a project with a different representative sequence
444 @Test(groups = { "Functional" })
445 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
447 Desktop.instance.closeAll_actionPerformed(null);
448 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
449 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
450 assertNotNull(af, "Didn't read in the example file correctly.");
451 String afid = af.getViewport().getSequenceSetId();
453 // remember reference sequence for each panel
454 Map<String, SequenceI> refseqs = new HashMap<>();
457 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
458 * as reference sequence for itself and the preceding sequence
461 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
463 AlignViewportI av = ap.getAlignViewport();
464 AlignmentI alignment = ap.getAlignment();
465 int repIndex = n % alignment.getHeight();
466 SequenceI rep = alignment.getSequenceAt(repIndex);
467 refseqs.put(ap.getViewName(), rep);
469 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
470 // todo refactor this to an alignment view controller
471 av.setDisplayReferenceSeq(true);
472 av.setColourByReferenceSeq(true);
473 av.getAlignment().setSeqrep(rep);
477 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
481 new Jalview2XML(false).saveState(tfile);
482 } catch (Throwable e)
484 Assert.fail("Didn't save the expanded view state", e);
486 Desktop.instance.closeAll_actionPerformed(null);
487 if (Desktop.getAlignFrames() != null)
489 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
492 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
493 DataSourceType.FILE);
494 afid = af.getViewport().getSequenceSetId();
496 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
498 // check representative
499 AlignmentI alignment = ap.getAlignment();
500 SequenceI rep = alignment.getSeqrep();
501 Assert.assertNotNull(rep,
502 "Couldn't restore sequence representative from project");
503 // can't use a strong equals here, because by definition, the sequence IDs
504 // will be different.
505 // could set vamsas session save/restore flag to preserve IDs across
507 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
509 "Representative wasn't the same when recovered.");
510 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
511 "Display reference sequence view setting not set.");
512 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
513 "Colour By Reference Seq view setting not set.");
517 @Test(groups = { "Functional" })
518 public void testIsVersionStringLaterThan()
521 * No version / development / test / autobuild is leniently assumed to be
524 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
525 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
526 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
527 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
528 "Development Build"));
529 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
530 "DEVELOPMENT BUILD"));
531 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
532 "Development Build"));
533 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
534 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
535 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
536 assertTrue(Jalview2XML
537 .isVersionStringLaterThan(null, "Automated Build"));
538 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
540 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
544 * same version returns true i.e. compatible
546 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
547 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
548 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
549 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
550 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
553 * later version returns true
555 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
556 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
557 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
558 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
559 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
562 * earlier version returns false
564 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
565 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
566 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
567 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
568 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
572 * Test save and reload of a project with a different sequence group (and
573 * representative sequence) in each view.
577 @Test(groups = { "Functional" })
578 public void testStoreAndRecoverGroupRepSeqs() throws Exception
580 Desktop.instance.closeAll_actionPerformed(null);
581 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
582 "examples/uniref50.fa", DataSourceType.FILE);
583 assertNotNull(af, "Didn't read in the example file correctly.");
584 String afid = af.getViewport().getSequenceSetId();
585 // make a second view of the alignment
586 af.newView_actionPerformed(null);
589 * remember representative and hidden sequences marked
592 Map<String, SequenceI> repSeqs = new HashMap<>();
593 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
596 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
597 * as reference sequence for itself and the preceding sequence
600 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
602 AlignViewportI av = ap.getAlignViewport();
603 AlignmentI alignment = ap.getAlignment();
604 int repIndex = n % alignment.getHeight();
605 // ensure at least one preceding sequence i.e. index >= 1
606 repIndex = Math.max(repIndex, 1);
607 SequenceI repSeq = alignment.getSequenceAt(repIndex);
608 repSeqs.put(ap.getViewName(), repSeq);
609 List<String> hiddenNames = new ArrayList<>();
610 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
613 * have rep sequence represent itself and the one before it
614 * this hides the group (except for the rep seq)
616 SequenceGroup sg = new SequenceGroup();
617 sg.addSequence(repSeq, false);
618 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
619 sg.addSequence(precedingSeq, false);
620 sg.setSeqrep(repSeq);
621 assertTrue(sg.getSequences().contains(repSeq));
622 assertTrue(sg.getSequences().contains(precedingSeq));
623 av.setSelectionGroup(sg);
624 assertSame(repSeq, sg.getSeqrep());
627 * represent group with sequence adds to a map of hidden rep sequences
628 * (it does not create a group on the alignment)
630 ((AlignmentViewport) av).hideSequences(repSeq, true);
631 assertSame(repSeq, sg.getSeqrep());
632 assertTrue(sg.getSequences().contains(repSeq));
633 assertTrue(sg.getSequences().contains(precedingSeq));
634 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
635 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
636 .getHiddenRepSequences();
637 assertNotNull(hiddenRepSeqsMap);
638 assertEquals(1, hiddenRepSeqsMap.size());
639 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
640 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
641 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
642 hiddenNames.add(precedingSeq.getName());
647 .createTempFile("testStoreAndRecoverGroupReps", ".jvp");
650 new Jalview2XML(false).saveState(tfile);
651 } catch (Throwable e)
653 Assert.fail("Didn't save the expanded view state", e);
655 Desktop.instance.closeAll_actionPerformed(null);
656 if (Desktop.getAlignFrames() != null)
658 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
661 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
662 DataSourceType.FILE);
663 afid = af.getViewport().getSequenceSetId();
665 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
667 String viewName = ap.getViewName();
668 AlignViewportI av = ap.getAlignViewport();
669 AlignmentI alignment = ap.getAlignment();
670 List<SequenceGroup> groups = alignment.getGroups();
671 assertNotNull(groups);
672 assertTrue(groups.isEmpty(), "Alignment has groups");
673 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
674 .getHiddenRepSequences();
675 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
676 assertEquals(1, hiddenRepSeqsMap.size());
677 assertEquals(repSeqs.get(viewName).getDisplayId(true),
678 hiddenRepSeqsMap.keySet().iterator().next()
679 .getDisplayId(true));
682 * verify hidden sequences in restored panel
684 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
685 HiddenSequences hs = alignment.getHiddenSequences();
689 "wrong number of restored hidden sequences in "
695 * Test save and reload of PDBEntry in Jalview project
699 @Test(groups = { "Functional" })
700 public void testStoreAndRecoverPDBEntry() throws Exception
702 Desktop.instance.closeAll_actionPerformed(null);
703 String exampleFile = "examples/3W5V.pdb";
704 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
705 DataSourceType.FILE);
706 assertNotNull(af, "Didn't read in the example file correctly.");
707 String afid = af.getViewport().getSequenceSetId();
709 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
710 System.out.println();
711 AlignmentViewPanel ap = alignPanels[0];
712 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
713 String testFile = tfileBase + exampleFile;
714 AlignmentI alignment = ap.getAlignment();
715 System.out.println("blah");
716 SequenceI[] seqs = alignment.getSequencesArray();
717 Assert.assertNotNull(seqs[0]);
718 Assert.assertNotNull(seqs[1]);
719 Assert.assertNotNull(seqs[2]);
720 Assert.assertNotNull(seqs[3]);
721 Assert.assertNotNull(seqs[0].getDatasetSequence());
722 Assert.assertNotNull(seqs[1].getDatasetSequence());
723 Assert.assertNotNull(seqs[2].getDatasetSequence());
724 Assert.assertNotNull(seqs[3].getDatasetSequence());
725 PDBEntry[] pdbEntries = new PDBEntry[4];
726 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
727 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
728 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
729 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
730 Assert.assertEquals(seqs[0].getDatasetSequence().getAllPDBEntries()
731 .get(0), pdbEntries[0]);
732 Assert.assertEquals(seqs[1].getDatasetSequence().getAllPDBEntries()
733 .get(0), pdbEntries[1]);
734 Assert.assertEquals(seqs[2].getDatasetSequence().getAllPDBEntries()
735 .get(0), pdbEntries[2]);
736 Assert.assertEquals(seqs[3].getDatasetSequence().getAllPDBEntries()
737 .get(0), pdbEntries[3]);
739 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
742 new Jalview2XML(false).saveState(tfile);
743 } catch (Throwable e)
745 Assert.fail("Didn't save the state", e);
747 Desktop.instance.closeAll_actionPerformed(null);
748 if (Desktop.getAlignFrames() != null)
750 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
753 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
754 tfile.getAbsolutePath(), DataSourceType.FILE);
755 String rfid = restoredFrame.getViewport().getSequenceSetId();
756 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
757 AlignmentViewPanel rap = rAlignPanels[0];
758 AlignmentI rAlignment = rap.getAlignment();
759 System.out.println("blah");
760 SequenceI[] rseqs = rAlignment.getSequencesArray();
761 Assert.assertNotNull(rseqs[0]);
762 Assert.assertNotNull(rseqs[1]);
763 Assert.assertNotNull(rseqs[2]);
764 Assert.assertNotNull(rseqs[3]);
765 Assert.assertNotNull(rseqs[0].getDatasetSequence());
766 Assert.assertNotNull(rseqs[1].getDatasetSequence());
767 Assert.assertNotNull(rseqs[2].getDatasetSequence());
768 Assert.assertNotNull(rseqs[3].getDatasetSequence());
770 // The Asserts below are expected to fail until the PDB chainCode is
771 // recoverable from a Jalview projects
772 for (int chain = 0; chain < 4; chain++)
774 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
776 PDBEntry expected = pdbEntries[chain];
777 Assert.assertEquals(recov.getId(), expected.getId(),
779 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
781 Assert.assertEquals(recov.getType(), expected.getType(),
782 "Mismatch PDBEntry 'Type'");
783 Assert.assertNotNull(recov.getFile(),
784 "Recovered PDBEntry should have a non-null file entry");
789 * Configure an alignment and a sub-group each with distinct colour schemes,
790 * Conservation and PID thresholds, and confirm these are restored from the
793 * @throws IOException
795 @Test(groups = { "Functional" })
796 public void testStoreAndRecoverColourThresholds() throws IOException
798 Desktop.instance.closeAll_actionPerformed(null);
799 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
800 "examples/uniref50.fa", DataSourceType.FILE);
802 AlignViewportI av = af.getViewport();
803 AlignmentI al = av.getAlignment();
806 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
808 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
809 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
810 af.abovePIDThreshold_actionPerformed(true);
811 SliderPanel sp = SliderPanel.getSliderPanel();
812 assertFalse(sp.isForConservation());
814 af.conservationMenuItem_actionPerformed(true);
815 sp = SliderPanel.getSliderPanel();
816 assertTrue(sp.isForConservation());
818 ResidueShaderI rs = av.getResidueShading();
819 assertEquals(rs.getThreshold(), 10);
820 assertTrue(rs.conservationApplied());
821 assertEquals(rs.getConservationInc(), 20);
824 * create a group with Strand colouring, 30% Conservation
825 * and 40% PID threshold
827 SequenceGroup sg = new SequenceGroup();
828 sg.addSequence(al.getSequenceAt(0), false);
831 av.setSelectionGroup(sg);
832 PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
833 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
835 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
836 assertEquals(al.getGroups().size(), 1);
837 assertSame(al.getGroups().get(0), sg);
838 popupMenu.conservationMenuItem_actionPerformed(true);
839 sp = SliderPanel.getSliderPanel();
840 assertTrue(sp.isForConservation());
842 popupMenu.abovePIDColour_actionPerformed(true);
843 sp = SliderPanel.getSliderPanel();
844 assertFalse(sp.isForConservation());
846 assertTrue(sg.getGroupColourScheme().conservationApplied());
847 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
848 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
851 * save project, close windows, reload project, verify
853 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
855 tfile.deleteOnExit();
856 new Jalview2XML(false).saveState(tfile);
857 Desktop.instance.closeAll_actionPerformed(null);
858 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
859 DataSourceType.FILE);
860 Assert.assertNotNull(af, "Failed to reload project");
863 * verify alignment (background) colouring
865 rs = af.getViewport().getResidueShading();
866 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
867 assertEquals(rs.getThreshold(), 10);
868 assertTrue(rs.conservationApplied());
869 assertEquals(rs.getConservationInc(), 20);
872 * verify group colouring
874 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
875 rs = af.getViewport().getAlignment().getGroups().get(0)
876 .getGroupColourScheme();
877 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
878 assertEquals(rs.getThreshold(), 40);
879 assertTrue(rs.conservationApplied());
880 assertEquals(rs.getConservationInc(), 30);
884 * Test save and reload of feature colour schemes and filter settings
886 * @throws IOException
888 @Test(groups = { "Functional" })
889 public void testStoreAndRecoverFeatureColoursAndFilters()
892 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
893 ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
894 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
897 * add some features to the sequence
900 addFeatures(seq1, "type1", score++);
901 addFeatures(seq1, "type2", score++);
902 addFeatures(seq1, "type3", score++);
903 addFeatures(seq1, "type4", score++);
904 addFeatures(seq1, "type5", score++);
907 * set colour schemes for features
909 FeatureRenderer fr = af.getFeatureRenderer();
910 fr.findAllFeatures(true);
913 fr.setColour("type1", new FeatureColour(Color.red));
916 FeatureColourI byLabel = new FeatureColour();
917 byLabel.setColourByLabel(true);
918 fr.setColour("type2", byLabel);
920 // type3: by score above threshold
921 FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1,
923 byScore.setAboveThreshold(true);
924 byScore.setThreshold(2f);
925 fr.setColour("type3", byScore);
927 // type4: by attribute AF
928 FeatureColourI byAF = new FeatureColour();
929 byAF.setColourByLabel(true);
930 byAF.setAttributeName("AF");
931 fr.setColour("type4", byAF);
933 // type5: by attribute CSQ:PolyPhen below threshold
934 FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE,
936 byPolyPhen.setBelowThreshold(true);
937 byPolyPhen.setThreshold(3f);
938 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
939 fr.setColour("type5", byPolyPhen);
942 * set filters for feature types
945 // filter type1 features by (label contains "x")
946 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
947 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
948 fr.setFeatureFilter("type1", filterByX);
950 // filter type2 features by (score <= 2.4 and score > 1.1)
951 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
952 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
953 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
954 fr.setFeatureFilter("type2", filterByScore);
956 // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
957 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
959 .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
960 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
962 fr.setFeatureFilter("type3", filterByXY);
965 * save as Jalview project
967 File tfile = File.createTempFile("JalviewTest", ".jvp");
968 tfile.deleteOnExit();
969 String filePath = tfile.getAbsolutePath();
970 assertTrue(af.saveAlignment(filePath, FileFormat.Jalview),
971 "Failed to store as a project.");
974 * close current alignment and load the saved project
976 af.closeMenuItem_actionPerformed(true);
978 af = new FileLoader()
979 .LoadFileWaitTillLoaded(filePath, DataSourceType.FILE);
980 assertNotNull(af, "Failed to import new project");
983 * verify restored feature colour schemes and filters
985 fr = af.getFeatureRenderer();
986 FeatureColourI fc = fr.getFeatureStyle("type1");
987 assertTrue(fc.isSimpleColour());
988 assertEquals(fc.getColour(), Color.red);
989 fc = fr.getFeatureStyle("type2");
990 assertTrue(fc.isColourByLabel());
991 fc = fr.getFeatureStyle("type3");
992 assertTrue(fc.isGraduatedColour());
993 assertNull(fc.getAttributeName());
994 assertTrue(fc.isAboveThreshold());
995 assertEquals(fc.getThreshold(), 2f);
996 fc = fr.getFeatureStyle("type4");
997 assertTrue(fc.isColourByLabel());
998 assertTrue(fc.isColourByAttribute());
999 assertEquals(fc.getAttributeName(), new String[] { "AF" });
1000 fc = fr.getFeatureStyle("type5");
1001 assertTrue(fc.isGraduatedColour());
1002 assertTrue(fc.isColourByAttribute());
1003 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
1004 assertTrue(fc.isBelowThreshold());
1005 assertEquals(fc.getThreshold(), 3f);
1007 assertEquals(fr.getFeatureFilter("type1").toStableString(),
1008 "Label Contains x");
1009 assertEquals(fr.getFeatureFilter("type2").toStableString(),
1010 "(Score LE 2.4) AND (Score GT 1.1)");
1011 assertEquals(fr.getFeatureFilter("type3").toStableString(),
1012 "(AF Contains X) OR (CSQ:PolyPhen NE 0.0)");
1015 private void addFeature(SequenceI seq, String featureType, int score)
1017 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
1019 sf.setValue("AF", score);
1020 sf.setValue("CSQ", new HashMap<String, String>()
1023 put("PolyPhen", Integer.toString(score));
1026 seq.addSequenceFeature(sf);
1030 * Adds two features of the given type to the given sequence, also setting the
1031 * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1034 * @param featureType
1037 private void addFeatures(SequenceI seq, String featureType, int score)
1039 addFeature(seq, featureType, score++);
1040 addFeature(seq, featureType, score);
1044 * Load an HMM profile to an alignment, and confirm it is correctly restored
1045 * when reloaded from project
1047 * @throws IOException
1049 @Test(groups = { "Functional" })
1050 public void testStoreAndRecoverHmmProfile() throws IOException
1052 Desktop.instance.closeAll_actionPerformed(null);
1053 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1054 "examples/uniref50.fa", DataSourceType.FILE);
1056 AlignViewportI av = af.getViewport();
1057 AlignmentI al = av.getAlignment();
1060 * mimic drag and drop of hmm file on to alignment
1062 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
1063 "examples/uniref50.hmm", DataSourceType.FILE);
1064 al.insertSequenceAt(0,
1065 af2.getViewport().getAlignment().getSequenceAt(0));
1068 * check it loaded in
1070 SequenceI hmmSeq = al.getSequenceAt(0);
1071 assertTrue(hmmSeq.hasHMMProfile());
1072 HiddenMarkovModel hmm = hmmSeq.getHMM();
1073 assertSame(hmm.getConsensusSequence(), hmmSeq);
1076 * save project, close windows, reload project, verify
1078 File tfile = File.createTempFile("testStoreAndRecoverHmmProfile",
1080 tfile.deleteOnExit();
1081 new Jalview2XML(false).saveState(tfile);
1082 Desktop.instance.closeAll_actionPerformed(null);
1083 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1084 DataSourceType.FILE);
1085 Assert.assertNotNull(af, "Failed to reload project");
1087 hmmSeq = al.getSequenceAt(0);
1088 assertTrue(hmmSeq.hasHMMProfile());
1089 assertSame(hmm.getConsensusSequence(), hmmSeq);
1090 Mapping mapToHmmConsensus = (Mapping) PA.getValue(hmm,
1091 "mapToHmmConsensus");
1092 assertNotNull(mapToHmmConsensus);
1093 assertSame(mapToHmmConsensus.getTo(), hmmSeq.getDatasetSequence());