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.analysis.scoremodels.SimilarityParams;
31 import jalview.api.AlignViewportI;
32 import jalview.api.AlignmentViewPanel;
33 import jalview.api.FeatureColourI;
34 import jalview.api.ViewStyleI;
35 import jalview.datamodel.AlignmentAnnotation;
36 import jalview.datamodel.AlignmentI;
37 import jalview.datamodel.DBRefEntry;
38 import jalview.datamodel.GeneLocus;
39 import jalview.datamodel.HiddenMarkovModel;
40 import jalview.datamodel.HiddenSequences;
41 import jalview.datamodel.Mapping;
42 import jalview.datamodel.PDBEntry;
43 import jalview.datamodel.PDBEntry.Type;
44 import jalview.datamodel.SequenceCollectionI;
45 import jalview.datamodel.SequenceFeature;
46 import jalview.datamodel.SequenceGroup;
47 import jalview.datamodel.SequenceI;
48 import jalview.datamodel.features.FeatureMatcher;
49 import jalview.datamodel.features.FeatureMatcherSet;
50 import jalview.datamodel.features.FeatureMatcherSetI;
51 import jalview.gui.AlignFrame;
52 import jalview.gui.AlignmentPanel;
53 import jalview.gui.Desktop;
54 import jalview.gui.JvOptionPane;
55 import jalview.gui.PCAPanel;
56 import jalview.gui.PopupMenu;
57 import jalview.gui.SliderPanel;
58 import jalview.io.DataSourceType;
59 import jalview.io.FileFormat;
60 import jalview.io.FileLoader;
61 import jalview.io.Jalview2xmlBase;
62 import jalview.renderer.ResidueShaderI;
63 import jalview.schemes.AnnotationColourGradient;
64 import jalview.schemes.BuriedColourScheme;
65 import jalview.schemes.ColourSchemeI;
66 import jalview.schemes.ColourSchemeProperty;
67 import jalview.schemes.FeatureColour;
68 import jalview.schemes.JalviewColourScheme;
69 import jalview.schemes.RNAHelicesColour;
70 import jalview.schemes.StrandColourScheme;
71 import jalview.schemes.TCoffeeColourScheme;
72 import jalview.structure.StructureImportSettings;
73 import jalview.util.MapList;
74 import jalview.util.matcher.Condition;
75 import jalview.viewmodel.AlignmentViewport;
76 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
78 import java.awt.Color;
80 import java.io.IOException;
81 import java.util.ArrayList;
82 import java.util.HashMap;
83 import java.util.List;
86 import javax.swing.JInternalFrame;
88 import org.testng.Assert;
89 import org.testng.AssertJUnit;
90 import org.testng.annotations.BeforeClass;
91 import org.testng.annotations.Test;
93 import junit.extensions.PA;
95 @Test(singleThreaded = true)
96 public class Jalview2xmlTests extends Jalview2xmlBase
100 @BeforeClass(alwaysRun = true)
101 public void setUpJvOptionPane()
103 JvOptionPane.setInteractiveMode(false);
104 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
107 @Test(groups = { "Functional" })
108 public void testRNAStructureRecovery() throws Exception
110 String inFile = "examples/RF00031_folded.stk";
111 String tfile = File.createTempFile("JalviewTest", ".jvp")
113 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
114 DataSourceType.FILE);
115 assertNotNull(af, "Didn't read input file " + inFile);
116 int olddsann = countDsAnn(af.getViewport());
117 assertTrue(olddsann > 0, "Didn't find any dataset annotations");
118 af.changeColour_actionPerformed(
119 JalviewColourScheme.RNAHelices.toString());
122 .getGlobalColourScheme() instanceof RNAHelicesColour,
123 "Couldn't apply RNA helices colourscheme");
124 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
125 "Failed to store as a project.");
126 af.closeMenuItem_actionPerformed(true);
128 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
129 DataSourceType.FILE);
130 assertNotNull(af, "Failed to import new project");
131 int newdsann = countDsAnn(af.getViewport());
132 assertEquals(olddsann, newdsann,
133 "Differing numbers of dataset sequence annotation\nOriginally "
134 + olddsann + " and now " + newdsann);
136 "Read in same number of annotations as originally present ("
141 .getGlobalColourScheme() instanceof RNAHelicesColour,
142 "RNA helices colourscheme was not applied on import.");
145 @Test(groups = { "Functional" })
146 public void testTCoffeeScores() throws Exception
148 String inFile = "examples/uniref50.fa",
149 inAnnot = "examples/uniref50.score_ascii";
150 String tfile = File.createTempFile("JalviewTest", ".jvp")
152 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
153 DataSourceType.FILE);
154 assertNotNull(af, "Didn't read input file " + inFile);
155 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
156 AlignViewportI viewport = af.getViewport();
157 assertSame(viewport.getGlobalColourScheme().getClass(),
158 TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
160 ColourSchemeProperty.getColourScheme(viewport,
161 viewport.getAlignment(),
162 viewport.getGlobalColourScheme()
164 "Recognise T-Coffee score from string");
166 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
167 "Failed to store as a project.");
168 af.closeMenuItem_actionPerformed(true);
170 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
171 DataSourceType.FILE);
172 assertNotNull(af, "Failed to import new project");
173 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
174 TCoffeeColourScheme.class,
175 "Didn't set T-coffee colourscheme for imported project.");
177 "T-Coffee score shading successfully recovered from project.");
180 @Test(groups = { "Functional" })
181 public void testColourByAnnotScores() throws Exception
183 String inFile = "examples/uniref50.fa",
184 inAnnot = "examples/testdata/uniref50_iupred.jva";
185 String tfile = File.createTempFile("JalviewTest", ".jvp")
187 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
188 DataSourceType.FILE);
189 assertNotNull(af, "Didn't read input file " + inFile);
190 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
191 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
192 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
195 aa != null && aa.length > 0,
196 "Didn't find any IUPred annotation to use to shade alignment.");
197 AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
198 AnnotationColourGradient.ABOVE_THRESHOLD);
199 AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0], null,
200 AnnotationColourGradient.BELOW_THRESHOLD);
201 cs.setSeqAssociated(true);
202 gcs.setSeqAssociated(true);
204 SequenceGroup sg = new SequenceGroup();
207 sg.cs.setColourScheme(gcs);
208 af.getViewport().getAlignment().addGroup(sg);
209 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
210 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
211 af.alignPanel.alignmentChanged();
212 assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
213 "Failed to store as a project.");
214 af.closeMenuItem_actionPerformed(true);
216 af = new FileLoader().LoadFileWaitTillLoaded(tfile,
217 DataSourceType.FILE);
218 assertNotNull(af, "Failed to import new project");
220 // check for group and alignment colourschemes
222 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
223 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups().get(0)
225 assertNotNull(_rcs, "Didn't recover global colourscheme");
226 assertTrue(_rcs instanceof AnnotationColourGradient,
227 "Didn't recover annotation colour global scheme");
228 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
229 assertTrue(__rcs.isSeqAssociated(),
230 "Annotation colourscheme wasn't sequence associated");
232 boolean diffseqcols = false, diffgseqcols = false;
233 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
234 for (int p = 0, pSize = af.getViewport().getAlignment()
235 .getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++)
237 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
238 .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
243 assertTrue(diffseqcols, "Got Different sequence colours");
245 "Per sequence colourscheme (Background) successfully applied and recovered.");
247 assertNotNull(_rgcs, "Didn't recover group colourscheme");
248 assertTrue(_rgcs instanceof AnnotationColourGradient,
249 "Didn't recover annotation colour group colourscheme");
250 __rcs = (AnnotationColourGradient) _rgcs;
251 assertTrue(__rcs.isSeqAssociated(),
252 "Group Annotation colourscheme wasn't sequence associated");
254 for (int p = 0, pSize = af.getViewport().getAlignment()
255 .getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++)
257 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null,
258 0f) != _rgcs.findColour(sqs[2].getCharAt(p), p, sqs[2], null,
264 assertTrue(diffgseqcols, "Got Different group sequence colours");
266 "Per sequence (Group) colourscheme successfully applied and recovered.");
269 @Test(groups = { "Functional" })
270 public void gatherViewsHere() throws Exception
272 int origCount = Desktop.getAlignFrames() == null ? 0
273 : Desktop.getAlignFrames().length;
274 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
275 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
276 assertNotNull(af, "Didn't read in the example file correctly.");
277 assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
278 "Didn't gather the views in the example file.");
283 * Test for JAL-2223 - multiple mappings in View Mapping report
287 @Test(groups = { "Functional" })
288 public void noDuplicatePdbMappingsMade() throws Exception
290 StructureImportSettings.setProcessSecondaryStructure(true);
291 StructureImportSettings.setVisibleChainAnnotation(true);
292 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
293 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
294 assertNotNull(af, "Didn't read in the example file correctly.");
296 // locate Jmol viewer
297 // count number of PDB mappings the structure selection manager holds -
298 String pdbFile = af.getCurrentView().getStructureSelectionManager()
299 .findFileForPDBId("1A70");
301 af.getCurrentView().getStructureSelectionManager()
302 .getMapping(pdbFile).length,
303 2, "Expected only two mappings for 1A70");
307 @Test(groups = { "Functional" })
308 public void viewRefPdbAnnotation() throws Exception
310 StructureImportSettings.setProcessSecondaryStructure(true);
311 StructureImportSettings.setVisibleChainAnnotation(true);
312 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
313 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
314 assertNotNull(af, "Didn't read in the example file correctly.");
315 AlignmentViewPanel sps = null;
316 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
318 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
324 assertNotNull(sps, "Couldn't find the structure view");
325 AlignmentAnnotation refan = null;
326 for (AlignmentAnnotation ra : sps.getAlignment()
327 .getAlignmentAnnotation())
335 assertNotNull(refan, "Annotation secondary structure not found.");
336 SequenceI sq = sps.getAlignment().findName("1A70|");
337 assertNotNull(sq, "Couldn't find 1a70 null chain");
338 // compare the manually added temperature factor annotation
339 // to the track automatically transferred from the pdb structure on load
340 assertNotNull(sq.getDatasetSequence().getAnnotation(),
341 "1a70 has no annotation");
342 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
344 AlignmentAnnotation alaa;
345 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
346 alaa.adjustForAlignment();
347 if (ala.graph == refan.graph)
349 for (int p = 0; p < ala.annotations.length; p++)
354 assertTrue((alaa.annotations[p] == null
355 && refan.annotations[p] == null)
356 || alaa.annotations[p].value == refan.annotations[p].value,
357 "Mismatch at alignment position " + p);
358 } catch (NullPointerException q)
360 Assert.fail("Mismatch of alignment annotations at position " + p
361 + " Ref seq ann: " + refan.annotations[p]
362 + " alignment " + alaa.annotations[p]);
370 @Test(groups = { "Functional" })
371 public void testCopyViewSettings() throws Exception
373 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
374 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
375 assertNotNull(af, "Didn't read in the example file correctly.");
376 AlignmentViewPanel sps = null, groups = null;
377 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
379 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
383 if (ap.getViewName().contains("MAFFT"))
388 assertNotNull(sps, "Couldn't find the structure view");
389 assertNotNull(groups, "Couldn't find the MAFFT view");
391 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
392 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
393 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
395 groups.getAlignViewport().setViewStyle(structureStyle);
396 AssertJUnit.assertFalse(
397 groupStyle.sameStyle(groups.getAlignViewport().getViewStyle()));
398 Assert.assertTrue(structureStyle
399 .sameStyle(groups.getAlignViewport().getViewStyle()));
404 * test store and recovery of expanded views
408 @Test(groups = { "Functional" }, enabled = true)
409 public void testStoreAndRecoverExpandedviews() throws Exception
411 Desktop.instance.closeAll_actionPerformed(null);
413 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
414 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
415 Assert.assertEquals(Desktop.getAlignFrames().length, 1);
416 String afid = af.getViewport().getSequenceSetId();
418 // check FileLoader returned a reference to the one alignFrame that is
419 // actually on the Desktop
420 assertSame(af, Desktop.getAlignFrameFor(af.getViewport()),
421 "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
423 Desktop.explodeViews(af);
425 int oldviews = Desktop.getAlignFrames().length;
426 Assert.assertEquals(Desktop.getAlignFrames().length,
427 Desktop.getAlignmentPanels(afid).length);
428 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
431 new Jalview2XML(false).saveState(tfile);
434 Assert.fail("Didn't save the expanded view state", e);
435 } catch (Exception e)
437 Assert.fail("Didn't save the expanded view state", e);
439 Desktop.instance.closeAll_actionPerformed(null);
440 if (Desktop.getAlignFrames() != null)
442 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
444 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
445 DataSourceType.FILE);
446 Assert.assertNotNull(af);
447 Assert.assertEquals(Desktop.getAlignFrames().length,
448 Desktop.getAlignmentPanels(
449 af.getViewport().getSequenceSetId()).length);
451 Desktop.getAlignmentPanels(
452 af.getViewport().getSequenceSetId()).length,
457 * Test save and reload of a project with a different representative sequence
462 @Test(groups = { "Functional" })
463 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
465 Desktop.instance.closeAll_actionPerformed(null);
466 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
467 "examples/exampleFile_2_7.jar", DataSourceType.FILE);
468 assertNotNull(af, "Didn't read in the example file correctly.");
469 String afid = af.getViewport().getSequenceSetId();
471 // remember reference sequence for each panel
472 Map<String, SequenceI> refseqs = new HashMap<>();
475 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
476 * as reference sequence for itself and the preceding sequence
479 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
481 AlignViewportI av = ap.getAlignViewport();
482 AlignmentI alignment = ap.getAlignment();
483 int repIndex = n % alignment.getHeight();
484 SequenceI rep = alignment.getSequenceAt(repIndex);
485 refseqs.put(ap.getViewName(), rep);
487 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
488 // todo refactor this to an alignment view controller
489 av.setDisplayReferenceSeq(true);
490 av.setColourByReferenceSeq(true);
491 av.getAlignment().setSeqrep(rep);
495 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
499 new Jalview2XML(false).saveState(tfile);
500 } catch (Throwable e)
502 Assert.fail("Didn't save the expanded view state", e);
504 Desktop.instance.closeAll_actionPerformed(null);
505 if (Desktop.getAlignFrames() != null)
507 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
510 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
511 DataSourceType.FILE);
512 afid = af.getViewport().getSequenceSetId();
514 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
516 // check representative
517 AlignmentI alignment = ap.getAlignment();
518 SequenceI rep = alignment.getSeqrep();
519 Assert.assertNotNull(rep,
520 "Couldn't restore sequence representative from project");
521 // can't use a strong equals here, because by definition, the sequence IDs
522 // will be different.
523 // could set vamsas session save/restore flag to preserve IDs across
525 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
527 "Representative wasn't the same when recovered.");
528 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
529 "Display reference sequence view setting not set.");
530 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
531 "Colour By Reference Seq view setting not set.");
535 @Test(groups = { "Functional" })
536 public void testIsVersionStringLaterThan()
539 * No version / development / test / autobuild is leniently assumed to be
542 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
543 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
544 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
545 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
546 "Development Build"));
547 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
548 "DEVELOPMENT BUILD"));
549 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
550 "Development Build"));
551 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
552 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
553 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
555 Jalview2XML.isVersionStringLaterThan(null, "Automated Build"));
556 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
558 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
562 * same version returns true i.e. compatible
564 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
565 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
566 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
567 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
568 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
571 * later version returns true
573 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
574 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
575 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
576 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
577 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
580 * earlier version returns false
582 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
583 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
584 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
585 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
586 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
590 * Test save and reload of a project with a different sequence group (and
591 * representative sequence) in each view.
595 @Test(groups = { "Functional" })
596 public void testStoreAndRecoverGroupRepSeqs() throws Exception
598 Desktop.instance.closeAll_actionPerformed(null);
599 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
600 "examples/uniref50.fa", DataSourceType.FILE);
601 assertNotNull(af, "Didn't read in the example file correctly.");
602 String afid = af.getViewport().getSequenceSetId();
603 // make a second view of the alignment
604 af.newView_actionPerformed(null);
607 * remember representative and hidden sequences marked
610 Map<String, SequenceI> repSeqs = new HashMap<>();
611 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
614 * mark sequence 2, 3, 4.. in panels 1, 2, 3...
615 * as reference sequence for itself and the preceding sequence
618 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
620 AlignViewportI av = ap.getAlignViewport();
621 AlignmentI alignment = ap.getAlignment();
622 int repIndex = n % alignment.getHeight();
623 // ensure at least one preceding sequence i.e. index >= 1
624 repIndex = Math.max(repIndex, 1);
625 SequenceI repSeq = alignment.getSequenceAt(repIndex);
626 repSeqs.put(ap.getViewName(), repSeq);
627 List<String> hiddenNames = new ArrayList<>();
628 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
631 * have rep sequence represent itself and the one before it
632 * this hides the group (except for the rep seq)
634 SequenceGroup sg = new SequenceGroup();
635 sg.addSequence(repSeq, false);
636 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
637 sg.addSequence(precedingSeq, false);
638 sg.setSeqrep(repSeq);
639 assertTrue(sg.getSequences().contains(repSeq));
640 assertTrue(sg.getSequences().contains(precedingSeq));
641 av.setSelectionGroup(sg);
642 assertSame(repSeq, sg.getSeqrep());
645 * represent group with sequence adds to a map of hidden rep sequences
646 * (it does not create a group on the alignment)
648 ((AlignmentViewport) av).hideSequences(repSeq, true);
649 assertSame(repSeq, sg.getSeqrep());
650 assertTrue(sg.getSequences().contains(repSeq));
651 assertTrue(sg.getSequences().contains(precedingSeq));
652 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
653 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
654 .getHiddenRepSequences();
655 assertNotNull(hiddenRepSeqsMap);
656 assertEquals(1, hiddenRepSeqsMap.size());
657 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
658 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
659 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
660 hiddenNames.add(precedingSeq.getName());
664 File tfile = File.createTempFile("testStoreAndRecoverGroupReps",
668 new Jalview2XML(false).saveState(tfile);
669 } catch (Throwable e)
671 Assert.fail("Didn't save the expanded view state", e);
673 Desktop.instance.closeAll_actionPerformed(null);
674 if (Desktop.getAlignFrames() != null)
676 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
679 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
680 DataSourceType.FILE);
681 afid = af.getViewport().getSequenceSetId();
683 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
685 String viewName = ap.getViewName();
686 AlignViewportI av = ap.getAlignViewport();
687 AlignmentI alignment = ap.getAlignment();
688 List<SequenceGroup> groups = alignment.getGroups();
689 assertNotNull(groups);
690 assertTrue(groups.isEmpty(), "Alignment has groups");
691 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
692 .getHiddenRepSequences();
693 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
694 assertEquals(1, hiddenRepSeqsMap.size());
695 assertEquals(repSeqs.get(viewName).getDisplayId(true),
696 hiddenRepSeqsMap.keySet().iterator().next()
697 .getDisplayId(true));
700 * verify hidden sequences in restored panel
702 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
703 HiddenSequences hs = alignment.getHiddenSequences();
704 assertEquals(hidden.size(), hs.getSize(),
705 "wrong number of restored hidden sequences in "
711 * Test save and reload of PDBEntry in Jalview project
715 @Test(groups = { "Functional" })
716 public void testStoreAndRecoverPDBEntry() throws Exception
718 Desktop.instance.closeAll_actionPerformed(null);
719 String exampleFile = "examples/3W5V.pdb";
720 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
721 DataSourceType.FILE);
722 assertNotNull(af, "Didn't read in the example file correctly.");
723 String afid = af.getViewport().getSequenceSetId();
725 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
726 System.out.println();
727 AlignmentViewPanel ap = alignPanels[0];
728 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
729 String testFile = tfileBase + exampleFile;
730 AlignmentI alignment = ap.getAlignment();
731 System.out.println("blah");
732 SequenceI[] seqs = alignment.getSequencesArray();
733 Assert.assertNotNull(seqs[0]);
734 Assert.assertNotNull(seqs[1]);
735 Assert.assertNotNull(seqs[2]);
736 Assert.assertNotNull(seqs[3]);
737 Assert.assertNotNull(seqs[0].getDatasetSequence());
738 Assert.assertNotNull(seqs[1].getDatasetSequence());
739 Assert.assertNotNull(seqs[2].getDatasetSequence());
740 Assert.assertNotNull(seqs[3].getDatasetSequence());
741 PDBEntry[] pdbEntries = new PDBEntry[4];
742 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
743 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
744 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
745 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
747 seqs[0].getDatasetSequence().getAllPDBEntries().get(0),
750 seqs[1].getDatasetSequence().getAllPDBEntries().get(0),
753 seqs[2].getDatasetSequence().getAllPDBEntries().get(0),
756 seqs[3].getDatasetSequence().getAllPDBEntries().get(0),
759 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
762 new Jalview2XML(false).saveState(tfile);
763 } catch (Throwable e)
765 Assert.fail("Didn't save the state", e);
767 Desktop.instance.closeAll_actionPerformed(null);
768 if (Desktop.getAlignFrames() != null)
770 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
773 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
774 tfile.getAbsolutePath(), DataSourceType.FILE);
775 String rfid = restoredFrame.getViewport().getSequenceSetId();
776 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
777 AlignmentViewPanel rap = rAlignPanels[0];
778 AlignmentI rAlignment = rap.getAlignment();
779 System.out.println("blah");
780 SequenceI[] rseqs = rAlignment.getSequencesArray();
781 Assert.assertNotNull(rseqs[0]);
782 Assert.assertNotNull(rseqs[1]);
783 Assert.assertNotNull(rseqs[2]);
784 Assert.assertNotNull(rseqs[3]);
785 Assert.assertNotNull(rseqs[0].getDatasetSequence());
786 Assert.assertNotNull(rseqs[1].getDatasetSequence());
787 Assert.assertNotNull(rseqs[2].getDatasetSequence());
788 Assert.assertNotNull(rseqs[3].getDatasetSequence());
790 // The Asserts below are expected to fail until the PDB chainCode is
791 // recoverable from a Jalview projects
792 for (int chain = 0; chain < 4; chain++)
794 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
796 PDBEntry expected = pdbEntries[chain];
797 Assert.assertEquals(recov.getId(), expected.getId(),
799 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
801 Assert.assertEquals(recov.getType(), expected.getType(),
802 "Mismatch PDBEntry 'Type'");
803 Assert.assertNotNull(recov.getFile(),
804 "Recovered PDBEntry should have a non-null file entry");
809 * Configure an alignment and a sub-group each with distinct colour schemes,
810 * Conservation and PID thresholds, and confirm these are restored from the
813 * @throws IOException
815 @Test(groups = { "Functional" })
816 public void testStoreAndRecoverColourThresholds() throws IOException
818 Desktop.instance.closeAll_actionPerformed(null);
819 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
820 "examples/uniref50.fa", DataSourceType.FILE);
822 AlignViewportI av = af.getViewport();
823 AlignmentI al = av.getAlignment();
826 * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
828 av.setColourAppliesToAllGroups(false);
829 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
830 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
831 af.abovePIDThreshold_actionPerformed(true);
832 SliderPanel sp = SliderPanel.getSliderPanel();
833 assertFalse(sp.isForConservation());
835 af.conservationMenuItem_actionPerformed(true);
836 sp = SliderPanel.getSliderPanel();
837 assertTrue(sp.isForConservation());
839 ResidueShaderI rs = av.getResidueShading();
840 assertEquals(rs.getThreshold(), 10);
841 assertTrue(rs.conservationApplied());
842 assertEquals(rs.getConservationInc(), 20);
845 * create a group with Strand colouring, 30% Conservation
846 * and 40% PID threshold
847 * (notice menu action applies to selection group even if mouse click
848 * is at a sequence not in the group)
850 SequenceGroup sg = new SequenceGroup();
851 sg.addSequence(al.getSequenceAt(0), false);
854 av.setSelectionGroup(sg);
855 PopupMenu popupMenu = new PopupMenu(af.alignPanel, al.getSequenceAt(2),
857 popupMenu.changeColour_actionPerformed(
858 JalviewColourScheme.Strand.toString());
859 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
860 assertEquals(al.getGroups().size(), 1);
861 assertSame(al.getGroups().get(0), sg);
862 popupMenu.conservationMenuItem_actionPerformed(true);
863 sp = SliderPanel.getSliderPanel();
864 assertTrue(sp.isForConservation());
866 popupMenu.abovePIDColour_actionPerformed(true);
867 sp = SliderPanel.getSliderPanel();
868 assertFalse(sp.isForConservation());
870 assertTrue(sg.getGroupColourScheme().conservationApplied());
871 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
872 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
875 * save project, close windows, reload project, verify
877 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
879 tfile.deleteOnExit();
880 new Jalview2XML(false).saveState(tfile);
881 Desktop.instance.closeAll_actionPerformed(null);
882 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
883 DataSourceType.FILE);
884 Assert.assertNotNull(af, "Failed to reload project");
887 * verify alignment (background) colouring
889 rs = af.getViewport().getResidueShading();
890 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
891 assertEquals(rs.getThreshold(), 10);
892 assertTrue(rs.conservationApplied());
893 assertEquals(rs.getConservationInc(), 20);
896 * verify group colouring
898 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
899 rs = af.getViewport().getAlignment().getGroups().get(0)
900 .getGroupColourScheme();
901 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
902 assertEquals(rs.getThreshold(), 40);
903 assertTrue(rs.conservationApplied());
904 assertEquals(rs.getConservationInc(), 30);
908 * Test save and reload of feature colour schemes and filter settings
910 * @throws IOException
912 @Test(groups = { "Functional" })
913 public void testSaveLoadFeatureColoursAndFilters() throws IOException
915 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
916 ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
917 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
920 * add some features to the sequence
923 addFeatures(seq1, "type1", score++);
924 addFeatures(seq1, "type2", score++);
925 addFeatures(seq1, "type3", score++);
926 addFeatures(seq1, "type4", score++);
927 addFeatures(seq1, "type5", score++);
930 * set colour schemes for features
932 FeatureRendererModel fr = af.getFeatureRenderer();
933 fr.findAllFeatures(true);
936 fr.setColour("type1", new FeatureColour(Color.red));
939 FeatureColourI byLabel = new FeatureColour();
940 byLabel.setColourByLabel(true);
941 fr.setColour("type2", byLabel);
943 // type3: by score above threshold
944 FeatureColourI byScore = new FeatureColour(null, Color.BLACK,
945 Color.BLUE, null, 1, 10);
946 byScore.setAboveThreshold(true);
947 byScore.setThreshold(2f);
948 fr.setColour("type3", byScore);
950 // type4: by attribute AF
951 FeatureColourI byAF = new FeatureColour();
952 byAF.setColourByLabel(true);
953 byAF.setAttributeName("AF");
954 fr.setColour("type4", byAF);
956 // type5: by attribute CSQ:PolyPhen below threshold
957 FeatureColourI byPolyPhen = new FeatureColour(null, Color.BLACK,
958 Color.BLUE, null, 1, 10);
959 byPolyPhen.setBelowThreshold(true);
960 byPolyPhen.setThreshold(3f);
961 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
962 fr.setColour("type5", byPolyPhen);
965 * set filters for feature types
968 // filter type1 features by (label contains "x")
969 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
970 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
971 fr.setFeatureFilter("type1", filterByX);
973 // filter type2 features by (score <= 2.4 and score > 1.1)
974 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
975 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
976 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
977 fr.setFeatureFilter("type2", filterByScore);
979 // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
980 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
982 .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
983 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
985 fr.setFeatureFilter("type3", filterByXY);
988 * save as Jalview project
990 File tfile = File.createTempFile("JalviewTest", ".jvp");
991 tfile.deleteOnExit();
992 String filePath = tfile.getAbsolutePath();
993 assertTrue(af.saveAlignment(filePath, FileFormat.Jalview),
994 "Failed to store as a project.");
997 * close current alignment and load the saved project
999 af.closeMenuItem_actionPerformed(true);
1001 af = new FileLoader().LoadFileWaitTillLoaded(filePath,
1002 DataSourceType.FILE);
1003 assertNotNull(af, "Failed to import new project");
1006 * verify restored feature colour schemes and filters
1008 fr = af.getFeatureRenderer();
1009 FeatureColourI fc = fr.getFeatureStyle("type1");
1010 assertTrue(fc.isSimpleColour());
1011 assertEquals(fc.getColour(), Color.red);
1012 fc = fr.getFeatureStyle("type2");
1013 assertTrue(fc.isColourByLabel());
1014 fc = fr.getFeatureStyle("type3");
1015 assertTrue(fc.isGraduatedColour());
1016 assertNull(fc.getAttributeName());
1017 assertTrue(fc.isAboveThreshold());
1018 assertEquals(fc.getThreshold(), 2f);
1019 fc = fr.getFeatureStyle("type4");
1020 assertTrue(fc.isColourByLabel());
1021 assertTrue(fc.isColourByAttribute());
1022 assertEquals(fc.getAttributeName(), new String[] { "AF" });
1023 fc = fr.getFeatureStyle("type5");
1024 assertTrue(fc.isGraduatedColour());
1025 assertTrue(fc.isColourByAttribute());
1026 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
1027 assertTrue(fc.isBelowThreshold());
1028 assertEquals(fc.getThreshold(), 3f);
1030 assertEquals(fr.getFeatureFilter("type1").toStableString(),
1031 "Label Contains x");
1032 assertEquals(fr.getFeatureFilter("type2").toStableString(),
1033 "(Score LE 2.4) AND (Score GT 1.1)");
1034 assertEquals(fr.getFeatureFilter("type3").toStableString(),
1035 "(AF Contains X) OR (CSQ:PolyPhen NE 0.0)");
1038 private void addFeature(SequenceI seq, String featureType, int score)
1040 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
1042 sf.setValue("AF", score);
1043 sf.setValue("CSQ", new HashMap<String, String>()
1046 put("PolyPhen", Integer.toString(score));
1049 seq.addSequenceFeature(sf);
1053 * Adds two features of the given type to the given sequence, also setting the
1054 * score as the value of attribute "AF" and sub-attribute "CSQ:PolyPhen"
1057 * @param featureType
1060 private void addFeatures(SequenceI seq, String featureType, int score)
1062 addFeature(seq, featureType, score++);
1063 addFeature(seq, featureType, score);
1067 * Load an HMM profile to an alignment, and confirm it is correctly restored
1068 * when reloaded from project
1070 * @throws IOException
1072 @Test(groups = { "Functional" })
1073 public void testStoreAndRecoverHmmProfile() throws IOException
1075 Desktop.instance.closeAll_actionPerformed(null);
1076 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1077 "examples/uniref50.fa", DataSourceType.FILE);
1079 AlignViewportI av = af.getViewport();
1080 AlignmentI al = av.getAlignment();
1083 * mimic drag and drop of hmm file on to alignment
1085 AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
1086 "examples/uniref50.hmm", DataSourceType.FILE);
1087 al.insertSequenceAt(0,
1088 af2.getViewport().getAlignment().getSequenceAt(0));
1091 * check it loaded in
1093 SequenceI hmmSeq = al.getSequenceAt(0);
1094 assertTrue(hmmSeq.hasHMMProfile());
1095 HiddenMarkovModel hmm = hmmSeq.getHMM();
1096 assertSame(hmm.getConsensusSequence(), hmmSeq);
1099 * save project, close windows, reload project, verify
1101 File tfile = File.createTempFile("testStoreAndRecoverHmmProfile",
1103 tfile.deleteOnExit();
1104 new Jalview2XML(false).saveState(tfile);
1105 Desktop.instance.closeAll_actionPerformed(null);
1106 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1107 DataSourceType.FILE);
1108 Assert.assertNotNull(af, "Failed to reload project");
1110 hmmSeq = al.getSequenceAt(0);
1111 assertTrue(hmmSeq.hasHMMProfile());
1112 assertSame(hmm.getConsensusSequence(), hmmSeq);
1113 Mapping mapToHmmConsensus = (Mapping) PA.getValue(hmm,
1114 "mapToHmmConsensus");
1115 assertNotNull(mapToHmmConsensus);
1116 assertSame(mapToHmmConsensus.getTo(), hmmSeq.getDatasetSequence());
1120 * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
1121 * view (JAL-3171) this test ensures we can import and merge those views
1123 @Test(groups = { "Functional" })
1124 public void testMergeDatasetsforViews() throws IOException
1126 // simple project - two views on one alignment
1127 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
1128 "examples/testdata/projects/twoViews.jvp", DataSourceType.FILE);
1130 assertTrue(af.getAlignPanels().size() > 1);
1135 * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
1136 * view (JAL-3171) this test ensures we can import and merge those views This
1137 * is a more complex project
1139 @Test(groups = { "Functional" })
1140 public void testMergeDatasetsforManyViews() throws IOException
1142 Desktop.instance.closeAll_actionPerformed(null);
1144 // complex project - one dataset, several views on several alignments
1145 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
1146 "examples/testdata/projects/manyViews.jvp",
1147 DataSourceType.FILE);
1150 AlignmentI ds = null;
1151 for (AlignFrame alignFrame : Desktop.getAlignFrames())
1155 ds = verifyDs(alignFrame);
1159 // check that this frame's dataset matches the last
1160 assertTrue(ds == verifyDs(alignFrame));
1165 private AlignmentI verifyDs(AlignFrame af)
1167 AlignmentI ds = null;
1168 for (AlignmentViewPanel ap : af.getAlignPanels())
1172 ds = ap.getAlignment().getDataset();
1176 assertTrue(ap.getAlignment().getDataset() == ds,
1177 "Dataset was not the same for imported 2.10.5 project with several alignment views");
1183 @Test(groups = "Functional")
1184 public void testPcaViewAssociation() throws IOException
1186 Desktop.instance.closeAll_actionPerformed(null);
1187 final String PCAVIEWNAME = "With PCA";
1188 // create a new tempfile
1189 File tempfile = File.createTempFile("jvPCAviewAssoc", "jvp");
1192 String exampleFile = "examples/uniref50.fa";
1193 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
1194 DataSourceType.FILE);
1195 assertNotNull(af, "Didn't read in the example file correctly.");
1196 AlignmentPanel origView = (AlignmentPanel) af.getAlignPanels().get(0);
1197 AlignmentPanel newview = af.newView(PCAVIEWNAME, true);
1198 // create another for good measure
1199 af.newView("Not the PCA View", true);
1200 PCAPanel pcaPanel = new PCAPanel(origView, "BLOSUM62",
1201 new SimilarityParams(true, true, true, false));
1202 // we're in the test exec thread, so we can just run synchronously here
1205 // now switch the linked view
1206 pcaPanel.selectAssociatedView(newview);
1208 assertTrue(pcaPanel.getAlignViewport() == newview.getAlignViewport(),
1209 "PCA should be associated with 'With PCA' view: test is broken");
1211 // now save and reload project
1212 Jalview2XML jv2xml = new jalview.project.Jalview2XML(false);
1214 jv2xml.saveState(tempfile);
1215 assertTrue(jv2xml.errorMessage == null,
1216 "Failed to save dummy project with PCA: test broken");
1220 Desktop.instance.closeAll_actionPerformed(null);
1221 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
1222 tempfile.getCanonicalPath(), DataSourceType.FILE);
1223 JInternalFrame[] frames = Desktop.instance.getAllFrames();
1224 // PCA and the tabbed alignment view should be the only two windows on the
1226 assertEquals(frames.length, 2,
1227 "PCA and the tabbed alignment view should be the only two windows on the desktop");
1228 PCAPanel pcaPanel = (PCAPanel) frames[frames[0] == af ? 1 : 0];
1230 AlignmentViewPanel restoredNewView = null;
1231 for (AlignmentViewPanel alignpanel : Desktop.getAlignmentPanels(null))
1233 if (alignpanel.getAlignViewport() == pcaPanel.getAlignViewport())
1235 restoredNewView = alignpanel;
1238 assertEquals(restoredNewView.getViewName(), PCAVIEWNAME);
1240 restoredNewView.getAlignViewport() == pcaPanel
1241 .getAlignViewport(),
1242 "Didn't restore correct view association for the PCA view");
1246 * Test save and reload of DBRefEntry including GeneLocus in project
1250 @Test(groups = { "Functional" })
1251 public void testStoreAndRecoverGeneLocus() throws Exception
1253 Desktop.instance.closeAll_actionPerformed(null);
1254 String seqData = ">P30419\nACDE\n>X1235\nGCCTGTGACGAA";
1255 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqData,
1256 DataSourceType.PASTE);
1257 assertNotNull(af, "Didn't read in the example file correctly.");
1259 AlignmentViewPanel ap = Desktop.getAlignmentPanels(null)[0];
1260 SequenceI pep = ap.getAlignment().getSequenceAt(0);
1261 SequenceI cds = ap.getAlignment().getSequenceAt(1);
1264 * give 'protein' a dbref to self, a dbref with map to CDS,
1265 * and a dbref with map to gene 'locus'
1267 DBRefEntry dbref1 = new DBRefEntry("Uniprot", "1", "P30419", null);
1268 pep.addDBRef(dbref1);
1269 Mapping cdsmap = new Mapping(cds,
1270 new MapList(new int[]
1271 { 1, 4 }, new int[] { 1, 12 }, 1, 3));
1272 DBRefEntry dbref2 = new DBRefEntry("EMBLCDS", "2", "X1235", cdsmap);
1273 pep.addDBRef(dbref2);
1274 Mapping locusmap = new Mapping(null,
1275 new MapList(new int[]
1276 { 1, 4 }, new int[] { 2674123, 2674135 }, 1, 3));
1277 DBRefEntry dbref3 = new GeneLocus("human", "GRCh38", "5", locusmap);
1278 pep.addDBRef(dbref3);
1280 File tfile = File.createTempFile("testStoreAndRecoverGeneLocus",
1284 new Jalview2XML(false).saveState(tfile);
1285 } catch (Throwable e)
1287 Assert.fail("Didn't save the state", e);
1289 Desktop.instance.closeAll_actionPerformed(null);
1291 new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
1292 DataSourceType.FILE);
1293 AlignmentViewPanel rap = Desktop.getAlignmentPanels(null)[0];
1294 SequenceI rpep = rap.getAlignment().getSequenceAt(0);
1295 assertEquals(rpep.getName(), "P30419");
1296 DBRefEntry[] dbrefs = rpep.getDBRefs();
1297 assertEquals(dbrefs.length, 3);
1298 DBRefEntry dbRef = dbrefs[0];
1299 assertFalse(dbRef instanceof GeneLocus);
1300 assertNull(dbRef.getMap());
1301 assertEquals(dbRef, dbref1);
1304 * restored dbrefs with mapping have a different 'map to'
1305 * sequence but otherwise match the original dbrefs
1308 assertFalse(dbRef instanceof GeneLocus);
1309 assertTrue(dbRef.equalRef(dbref2));
1310 assertNotNull(dbRef.getMap());
1311 SequenceI rcds = rap.getAlignment().getSequenceAt(1);
1312 assertSame(dbRef.getMap().getTo(), rcds);
1313 // compare MapList but not map.to
1314 assertEquals(dbRef.getMap().getMap(), dbref2.getMap().getMap());
1317 * GeneLocus map.to is null so can compare Mapping objects
1320 assertTrue(dbRef instanceof GeneLocus);
1321 assertEquals(dbRef, dbref3);