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.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertNotNull;
26 import static org.testng.AssertJUnit.assertSame;
27 import static org.testng.AssertJUnit.assertTrue;
29 import jalview.api.AlignViewportI;
30 import jalview.api.AlignmentViewPanel;
31 import jalview.api.ViewStyleI;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.HiddenSequences;
35 import jalview.datamodel.PDBEntry;
36 import jalview.datamodel.PDBEntry.Type;
37 import jalview.datamodel.SequenceCollectionI;
38 import jalview.datamodel.SequenceGroup;
39 import jalview.datamodel.SequenceI;
40 import jalview.gui.AlignFrame;
41 import jalview.gui.AlignmentPanel;
42 import jalview.gui.Desktop;
43 import jalview.gui.Jalview2XML;
44 import jalview.gui.JvOptionPane;
45 import jalview.schemes.AnnotationColourGradient;
46 import jalview.schemes.ColourSchemeI;
47 import jalview.schemes.ColourSchemeProperty;
48 import jalview.schemes.TCoffeeColourScheme;
49 import jalview.structure.StructureImportSettings;
50 import jalview.viewmodel.AlignmentViewport;
53 import java.util.ArrayList;
54 import java.util.HashMap;
55 import java.util.List;
58 import org.testng.Assert;
59 import org.testng.AssertJUnit;
60 import org.testng.annotations.BeforeClass;
61 import org.testng.annotations.Test;
63 @Test(singleThreaded = true)
64 public class Jalview2xmlTests extends Jalview2xmlBase
67 @BeforeClass(alwaysRun = true)
68 public void setUpJvOptionPane()
70 JvOptionPane.setInteractiveMode(false);
71 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
74 @Test(groups = { "Functional" })
75 public void testRNAStructureRecovery() throws Exception
77 String inFile = "examples/RF00031_folded.stk";
78 String tfile = File.createTempFile("JalviewTest", ".jvp")
80 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
81 inFile, DataSourceType.FILE);
82 assertTrue("Didn't read input file " + inFile, af != null);
83 int olddsann = countDsAnn(af.getViewport());
84 assertTrue("Didn't find any dataset annotations", olddsann > 0);
85 af.rnahelicesColour_actionPerformed(null);
87 "Couldn't apply RNA helices colourscheme",
88 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
89 assertTrue("Failed to store as a project.",
90 af.saveAlignment(tfile, FileFormat.Jalview));
91 af.closeMenuItem_actionPerformed(true);
93 af = new FileLoader().LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
94 assertTrue("Failed to import new project", af != null);
95 int newdsann = countDsAnn(af.getViewport());
97 "Differing numbers of dataset sequence annotation\nOriginally "
98 + olddsann + " and now " + newdsann,
99 olddsann == newdsann);
101 .println("Read in same number of annotations as originally present ("
104 "RNA helices colourscheme was not applied on import.",
105 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
108 @Test(groups = { "Functional" })
109 public void testTCoffeeScores() throws Exception
111 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
112 String tfile = File.createTempFile("JalviewTest", ".jvp")
114 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
115 inFile, DataSourceType.FILE);
116 assertNotNull("Didn't read input file " + inFile, af);
117 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
118 assertSame("Didn't set T-coffee colourscheme", af.getViewport()
119 .getGlobalColourScheme().getClass(), TCoffeeColourScheme.class);
120 assertNotNull("Recognise T-Coffee score from string",
121 ColourSchemeProperty.getColour(af.getViewport()
122 .getAlignment(), ColourSchemeProperty.getColourName(af
123 .getViewport().getGlobalColourScheme())));
125 assertTrue("Failed to store as a project.",
126 af.saveAlignment(tfile, FileFormat.Jalview));
127 af.closeMenuItem_actionPerformed(true);
129 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
130 DataSourceType.FILE);
131 assertNotNull("Failed to import new project", af);
132 assertSame("Didn't set T-coffee colourscheme for imported project.", af
133 .getViewport().getGlobalColourScheme().getClass(),
134 TCoffeeColourScheme.class);
136 .println("T-Coffee score shading successfully recovered from project.");
139 @Test(groups = { "Functional" })
140 public void testColourByAnnotScores() throws Exception
142 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
143 String tfile = File.createTempFile("JalviewTest", ".jvp")
145 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, DataSourceType.FILE);
146 assertNotNull("Didn't read input file " + inFile, af);
147 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
148 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
149 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
151 "Didn't find any IUPred annotation to use to shade alignment.",
152 aa != null && aa.length > 0);
153 AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
154 AnnotationColourGradient.ABOVE_THRESHOLD);
155 AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0],
156 null, AnnotationColourGradient.BELOW_THRESHOLD);
157 cs.setSeqAssociated(true);
158 gcs.setSeqAssociated(true);
160 SequenceGroup sg = new SequenceGroup();
164 af.getViewport().getAlignment().addGroup(sg);
165 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
166 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
167 af.alignPanel.alignmentChanged();
168 assertTrue("Failed to store as a project.",
169 af.saveAlignment(tfile, FileFormat.Jalview));
170 af.closeMenuItem_actionPerformed(true);
172 af = new FileLoader().LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
173 assertTrue("Failed to import new project", af != null);
175 // check for group and alignment colourschemes
177 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
178 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
180 assertNotNull("Didn't recover global colourscheme", _rcs);
181 assertTrue("Didn't recover annotation colour global scheme",
182 _rcs instanceof AnnotationColourGradient);
183 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
184 assertTrue("Annotation colourscheme wasn't sequence associated",
185 __rcs.isSeqAssociated());
187 boolean diffseqcols = false, diffgseqcols = false;
188 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
189 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
190 && (!diffseqcols || !diffgseqcols); p++)
192 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0]) != _rcs
193 .findColour(sqs[5].getCharAt(p), p, sqs[5]))
198 assertTrue("Got Different sequence colours", diffseqcols);
200 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
202 assertNotNull("Didn't recover group colourscheme", _rgcs);
203 assertTrue("Didn't recover annotation colour group colourscheme",
204 _rgcs instanceof AnnotationColourGradient);
205 __rcs = (AnnotationColourGradient) _rgcs;
206 assertTrue("Group Annotation colourscheme wasn't sequence associated",
207 __rcs.isSeqAssociated());
209 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
210 && (!diffseqcols || !diffgseqcols); p++)
212 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1]) != _rgcs
213 .findColour(sqs[2].getCharAt(p), p, sqs[2]))
218 assertTrue("Got Different group sequence colours", diffgseqcols);
220 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
223 @Test(groups = { "Functional" })
224 public void gatherViewsHere() throws Exception
226 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
227 .getAlignFrames().length;
228 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
229 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
230 assertNotNull("Didn't read in the example file correctly.", af);
231 assertTrue("Didn't gather the views in the example file.",
232 Desktop.getAlignFrames().length == 1 + origCount);
236 @Test(groups = { "Functional" })
237 public void viewRefPdbAnnotation() throws Exception
239 StructureImportSettings.setProcessSecondaryStructure(true);
240 StructureImportSettings.setVisibleChainAnnotation(true);
241 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
242 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
243 assertNotNull("Didn't read in the example file correctly.", af);
244 AlignmentViewPanel sps = null;
245 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
247 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
253 assertNotNull("Couldn't find the structure view", sps);
254 AlignmentAnnotation refan = null;
255 for (AlignmentAnnotation ra : sps.getAlignment()
256 .getAlignmentAnnotation())
264 assertNotNull("Annotation secondary structure not found.", refan);
265 SequenceI sq = sps.getAlignment().findName("1A70|");
266 assertNotNull("Couldn't find 1a70 null chain", sq);
267 // compare the manually added temperature factor annotation
268 // to the track automatically transferred from the pdb structure on load
269 assertNotNull("1a70 has no annotation", sq.getDatasetSequence()
271 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
273 AlignmentAnnotation alaa;
274 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
275 alaa.adjustForAlignment();
276 if (ala.graph == refan.graph)
278 for (int p = 0; p < ala.annotations.length; p++)
284 "Mismatch at alignment position " + p,
285 (alaa.annotations[p] == null && refan.annotations[p] == null)
286 || alaa.annotations[p].value == refan.annotations[p].value);
287 } catch (NullPointerException q)
289 Assert.fail("Mismatch of alignment annotations at position "
290 + p + " Ref seq ann: " + refan.annotations[p]
291 + " alignment " + alaa.annotations[p]);
299 @Test(groups = { "Functional" })
300 public void testCopyViewSettings() throws Exception
302 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
303 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
304 assertNotNull("Didn't read in the example file correctly.", af);
305 AlignmentViewPanel sps = null, groups = null;
306 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
308 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
312 if (ap.getViewName().contains("MAFFT"))
317 assertNotNull("Couldn't find the structure view", sps);
318 assertNotNull("Couldn't find the MAFFT view", groups);
320 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
321 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
322 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
324 groups.getAlignViewport().setViewStyle(structureStyle);
325 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
327 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
333 * test store and recovery of expanded views
337 @Test(groups = { "Functional" }, enabled = true)
338 public void testStoreAndRecoverExpandedviews() throws Exception
340 Desktop.instance.closeAll_actionPerformed(null);
342 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
343 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
344 Assert.assertEquals(Desktop.getAlignFrames().length, 1);
345 String afid = af.getViewport().getSequenceSetId();
347 // check FileLoader returned a reference to the one alignFrame that is
348 // actually on the Desktop
350 "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window",
351 af == Desktop.getAlignFrameFor(af.getViewport()));
353 Desktop.explodeViews(af);
355 int oldviews = Desktop.getAlignFrames().length;
356 Assert.assertEquals(Desktop.getAlignFrames().length,
357 Desktop.getAlignmentPanels(afid).length);
358 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
361 new Jalview2XML(false).saveState(tfile);
364 Assert.fail("Didn't save the expanded view state", e);
365 } catch (Exception e)
367 Assert.fail("Didn't save the expanded view state", e);
369 Desktop.instance.closeAll_actionPerformed(null);
370 if (Desktop.getAlignFrames() != null)
372 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
374 af = new FileLoader().LoadFileWaitTillLoaded(
375 tfile.getAbsolutePath(), DataSourceType.FILE);
376 Assert.assertNotNull(af);
378 Desktop.getAlignFrames().length,
379 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
382 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
386 * Test save and reload of a project with a different representative sequence
391 @Test(groups = { "Functional" })
392 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
394 Desktop.instance.closeAll_actionPerformed(null);
395 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
396 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
397 assertNotNull("Didn't read in the example file correctly.", af);
398 String afid = af.getViewport().getSequenceSetId();
400 // remember reference sequence for each panel
401 Map<String, SequenceI> refseqs = new HashMap<String, SequenceI>();
404 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
405 * as reference sequence for itself and the preceding sequence
408 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
410 AlignViewportI av = ap.getAlignViewport();
411 AlignmentI alignment = ap.getAlignment();
412 int repIndex = n % alignment.getHeight();
413 SequenceI rep = alignment.getSequenceAt(repIndex);
414 refseqs.put(ap.getViewName(), rep);
416 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
417 // todo refactor this to an alignment view controller
418 av.setDisplayReferenceSeq(true);
419 av.setColourByReferenceSeq(true);
420 av.getAlignment().setSeqrep(rep);
424 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
428 new Jalview2XML(false).saveState(tfile);
429 } catch (Throwable e)
431 Assert.fail("Didn't save the expanded view state", e);
433 Desktop.instance.closeAll_actionPerformed(null);
434 if (Desktop.getAlignFrames() != null)
436 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
439 af = new FileLoader().LoadFileWaitTillLoaded(
440 tfile.getAbsolutePath(), DataSourceType.FILE);
441 afid = af.getViewport().getSequenceSetId();
443 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
445 // check representative
446 AlignmentI alignment = ap.getAlignment();
447 SequenceI rep = alignment.getSeqrep();
448 Assert.assertNotNull(rep,
449 "Couldn't restore sequence representative from project");
450 // can't use a strong equals here, because by definition, the sequence IDs
451 // will be different.
452 // could set vamsas session save/restore flag to preserve IDs across
454 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
456 "Representative wasn't the same when recovered.");
457 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
458 "Display reference sequence view setting not set.");
459 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
460 "Colour By Reference Seq view setting not set.");
464 @Test(groups = { "Functional" })
465 public void testIsVersionStringLaterThan()
468 * No version / development / test / autobuild is leniently assumed to be
471 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
472 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
473 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
474 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
475 "Development Build"));
476 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
477 "DEVELOPMENT BUILD"));
478 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
479 "Development Build"));
480 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
481 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
482 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
483 assertTrue(Jalview2XML
484 .isVersionStringLaterThan(null, "Automated Build"));
485 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
487 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
491 * same version returns true i.e. compatible
493 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
494 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
495 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
496 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
497 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
500 * later version returns true
502 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
503 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
504 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
505 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
506 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
509 * earlier version returns false
511 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
512 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
513 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
514 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
515 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
519 * Test save and reload of a project with a different sequence group (and
520 * representative sequence) in each view.
524 @Test(groups = { "Functional" })
525 public void testStoreAndRecoverGroupRepSeqs() throws Exception
527 Desktop.instance.closeAll_actionPerformed(null);
528 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
529 "examples/uniref50.fa", DataSourceType.FILE);
530 assertNotNull("Didn't read in the example file correctly.", af);
531 String afid = af.getViewport().getSequenceSetId();
532 // make a second view of the alignment
533 af.newView_actionPerformed(null);
536 * remember representative and hidden sequences marked
539 Map<String, SequenceI> repSeqs = new HashMap<String, SequenceI>();
540 Map<String, List<String>> hiddenSeqNames = new HashMap<String, List<String>>();
543 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
544 * as reference sequence for itself and the preceding sequence
547 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
549 AlignViewportI av = ap.getAlignViewport();
550 AlignmentI alignment = ap.getAlignment();
551 int repIndex = n % alignment.getHeight();
552 // ensure at least one preceding sequence i.e. index >= 1
553 repIndex = Math.max(repIndex, 1);
554 SequenceI repSeq = alignment.getSequenceAt(repIndex);
555 repSeqs.put(ap.getViewName(), repSeq);
556 List<String> hiddenNames = new ArrayList<String>();
557 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
560 * have rep sequence represent itself and the one before it
561 * this hides the group (except for the rep seq)
563 SequenceGroup sg = new SequenceGroup();
564 sg.addSequence(repSeq, false);
565 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
566 sg.addSequence(precedingSeq, false);
567 sg.setSeqrep(repSeq);
568 assertTrue(sg.getSequences().contains(repSeq));
569 assertTrue(sg.getSequences().contains(precedingSeq));
570 av.setSelectionGroup(sg);
571 assertSame(repSeq, sg.getSeqrep());
574 * represent group with sequence adds to a map of hidden rep sequences
575 * (it does not create a group on the alignment)
577 ((AlignmentViewport) av).hideSequences(repSeq, true);
578 assertSame(repSeq, sg.getSeqrep());
579 assertTrue(sg.getSequences().contains(repSeq));
580 assertTrue(sg.getSequences().contains(precedingSeq));
581 assertTrue("alignment has groups", alignment.getGroups().isEmpty());
582 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
583 .getHiddenRepSequences();
584 assertNotNull(hiddenRepSeqsMap);
585 assertEquals(1, hiddenRepSeqsMap.size());
586 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
587 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
588 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
589 hiddenNames.add(precedingSeq.getName());
594 .createTempFile("testStoreAndRecoverGroupReps", ".jvp");
597 new Jalview2XML(false).saveState(tfile);
598 } catch (Throwable e)
600 Assert.fail("Didn't save the expanded view state", e);
602 Desktop.instance.closeAll_actionPerformed(null);
603 if (Desktop.getAlignFrames() != null)
605 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
608 af = new FileLoader().LoadFileWaitTillLoaded(
609 tfile.getAbsolutePath(), DataSourceType.FILE);
610 afid = af.getViewport().getSequenceSetId();
612 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
614 String viewName = ap.getViewName();
615 AlignViewportI av = ap.getAlignViewport();
616 AlignmentI alignment = ap.getAlignment();
617 List<SequenceGroup> groups = alignment.getGroups();
618 assertNotNull(groups);
619 assertTrue("Alignment has groups", groups.isEmpty());
620 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
621 .getHiddenRepSequences();
622 assertNotNull("No hidden represented sequences", hiddenRepSeqsMap);
623 assertEquals(1, hiddenRepSeqsMap.size());
624 assertEquals(repSeqs.get(viewName).getDisplayId(true),
625 hiddenRepSeqsMap.keySet().iterator().next()
626 .getDisplayId(true));
629 * verify hidden sequences in restored panel
631 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
632 HiddenSequences hs = alignment.getHiddenSequences();
634 "wrong number of restored hidden sequences in "
635 + ap.getViewName(), hidden.size(), hs.getSize());
640 * Test save and reload of PDBEntry in Jalview project
644 @Test(groups = { "Functional" })
645 public void testStoreAndRecoverPDBEntry() throws Exception
647 Desktop.instance.closeAll_actionPerformed(null);
648 String exampleFile = "examples/3W5V.pdb";
649 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
650 DataSourceType.FILE);
651 assertNotNull("Didn't read in the example file correctly.", af);
652 String afid = af.getViewport().getSequenceSetId();
654 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
655 System.out.println();
656 AlignmentViewPanel ap = alignPanels[0];
657 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
658 String testFile = tfileBase + exampleFile;
659 AlignmentI alignment = ap.getAlignment();
660 System.out.println("blah");
661 SequenceI[] seqs = alignment.getSequencesArray();
662 Assert.assertNotNull(seqs[0]);
663 Assert.assertNotNull(seqs[1]);
664 Assert.assertNotNull(seqs[2]);
665 Assert.assertNotNull(seqs[3]);
666 Assert.assertNotNull(seqs[0].getDatasetSequence());
667 Assert.assertNotNull(seqs[1].getDatasetSequence());
668 Assert.assertNotNull(seqs[2].getDatasetSequence());
669 Assert.assertNotNull(seqs[3].getDatasetSequence());
670 PDBEntry[] pdbEntries = new PDBEntry[4];
671 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
672 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
673 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
674 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
675 Assert.assertEquals(seqs[0].getDatasetSequence().getAllPDBEntries()
676 .get(0), pdbEntries[0]);
677 Assert.assertEquals(seqs[1].getDatasetSequence().getAllPDBEntries()
678 .get(0), pdbEntries[1]);
679 Assert.assertEquals(seqs[2].getDatasetSequence().getAllPDBEntries()
680 .get(0), pdbEntries[2]);
681 Assert.assertEquals(seqs[3].getDatasetSequence().getAllPDBEntries()
682 .get(0), pdbEntries[3]);
684 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
687 new Jalview2XML(false).saveState(tfile);
688 } catch (Throwable e)
690 Assert.fail("Didn't save the state", e);
692 Desktop.instance.closeAll_actionPerformed(null);
693 if (Desktop.getAlignFrames() != null)
695 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
698 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
699 tfile.getAbsolutePath(), DataSourceType.FILE);
700 String rfid = restoredFrame.getViewport().getSequenceSetId();
701 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
702 AlignmentViewPanel rap = rAlignPanels[0];
703 AlignmentI rAlignment = rap.getAlignment();
704 System.out.println("blah");
705 SequenceI[] rseqs = rAlignment.getSequencesArray();
706 Assert.assertNotNull(rseqs[0]);
707 Assert.assertNotNull(rseqs[1]);
708 Assert.assertNotNull(rseqs[2]);
709 Assert.assertNotNull(rseqs[3]);
710 Assert.assertNotNull(rseqs[0].getDatasetSequence());
711 Assert.assertNotNull(rseqs[1].getDatasetSequence());
712 Assert.assertNotNull(rseqs[2].getDatasetSequence());
713 Assert.assertNotNull(rseqs[3].getDatasetSequence());
715 // The Asserts below are expected to fail until the PDB chainCode is
716 // recoverable from a Jalview projects
717 for (int chain = 0; chain < 4; chain++)
719 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
721 PDBEntry expected = pdbEntries[chain];
722 Assert.assertEquals(recov.getId(), expected.getId(),
724 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
726 Assert.assertEquals(recov.getType(), expected.getType(),
727 "Mismatch PDBEntry 'Type'");
728 Assert.assertNotNull(recov.getFile(),
729 "Recovered PDBEntry should have a non-null file entry");