Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.io

File Jalview2xmlTests.java

 

Code metrics

32
472
18
1
1,042
795
44
0.09
26.22
18
2.44

Classes

Class Line # Actions
Jalview2xmlTests 83 472 44 16
0.9693486796.9%
 

Contributing tests

This file is covered by 14 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.io;
22   
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;
29   
30    import jalview.api.AlignViewportI;
31    import jalview.api.AlignmentViewPanel;
32    import jalview.api.FeatureColourI;
33    import jalview.api.ViewStyleI;
34    import jalview.datamodel.AlignmentAnnotation;
35    import jalview.datamodel.AlignmentI;
36    import jalview.datamodel.HiddenSequences;
37    import jalview.datamodel.PDBEntry;
38    import jalview.datamodel.PDBEntry.Type;
39    import jalview.datamodel.SequenceCollectionI;
40    import jalview.datamodel.SequenceFeature;
41    import jalview.datamodel.SequenceGroup;
42    import jalview.datamodel.SequenceI;
43    import jalview.datamodel.features.FeatureMatcher;
44    import jalview.datamodel.features.FeatureMatcherSet;
45    import jalview.datamodel.features.FeatureMatcherSetI;
46    import jalview.gui.AlignFrame;
47    import jalview.gui.AlignViewport;
48    import jalview.gui.AlignmentPanel;
49    import jalview.gui.Desktop;
50    import jalview.gui.FeatureRenderer;
51    import jalview.gui.Jalview2XML;
52    import jalview.gui.JvOptionPane;
53    import jalview.gui.PopupMenu;
54    import jalview.gui.SliderPanel;
55    import jalview.renderer.ResidueShaderI;
56    import jalview.schemes.AnnotationColourGradient;
57    import jalview.schemes.BuriedColourScheme;
58    import jalview.schemes.ColourSchemeI;
59    import jalview.schemes.ColourSchemeProperty;
60    import jalview.schemes.FeatureColour;
61    import jalview.schemes.JalviewColourScheme;
62    import jalview.schemes.RNAHelicesColour;
63    import jalview.schemes.StrandColourScheme;
64    import jalview.schemes.TCoffeeColourScheme;
65    import jalview.structure.StructureImportSettings;
66    import jalview.util.matcher.Condition;
67    import jalview.viewmodel.AlignmentViewport;
68   
69    import java.awt.Color;
70    import java.io.File;
71    import java.io.IOException;
72    import java.util.ArrayList;
73    import java.util.HashMap;
74    import java.util.List;
75    import java.util.Map;
76   
77    import org.testng.Assert;
78    import org.testng.AssertJUnit;
79    import org.testng.annotations.BeforeClass;
80    import org.testng.annotations.Test;
81   
82    @Test(singleThreaded = true)
 
83    public class Jalview2xmlTests extends Jalview2xmlBase
84    {
85   
 
86  1 toggle @Override
87    @BeforeClass(alwaysRun = true)
88    public void setUpJvOptionPane()
89    {
90  1 JvOptionPane.setInteractiveMode(false);
91  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
92    }
93   
 
94  1 toggle @Test(groups = { "Functional" })
95    public void testRNAStructureRecovery() throws Exception
96    {
97  1 String inFile = "examples/RF00031_folded.stk";
98  1 String tfile = File.createTempFile("JalviewTest", ".jvp")
99    .getAbsolutePath();
100  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
101    DataSourceType.FILE);
102  1 assertNotNull(af, "Didn't read input file " + inFile);
103  1 int olddsann = countDsAnn(af.getViewport());
104  1 assertTrue(olddsann > 0, "Didn't find any dataset annotations");
105  1 af.changeColour_actionPerformed(JalviewColourScheme.RNAHelices
106    .toString());
107  1 assertTrue(
108    af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
109    "Couldn't apply RNA helices colourscheme");
110  1 af.saveAlignment(tfile, FileFormat.Jalview);
111  1 assertTrue(af.isSaveAlignmentSuccessful(),
112    "Failed to store as a project.");
113  1 af.closeMenuItem_actionPerformed(true);
114  1 af = null;
115  1 af = new FileLoader()
116    .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
117  1 assertNotNull(af, "Failed to import new project");
118  1 int newdsann = countDsAnn(af.getViewport());
119  1 assertEquals(olddsann, newdsann,
120    "Differing numbers of dataset sequence annotation\nOriginally "
121    + olddsann + " and now " + newdsann);
122  1 System.out
123    .println("Read in same number of annotations as originally present ("
124    + olddsann + ")");
125  1 assertTrue(
126   
127    af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
128    "RNA helices colourscheme was not applied on import.");
129    }
130   
 
131  1 toggle @Test(groups = { "Functional" })
132    public void testTCoffeeScores() throws Exception
133    {
134  1 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
135  1 String tfile = File.createTempFile("JalviewTest", ".jvp")
136    .getAbsolutePath();
137  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
138    DataSourceType.FILE);
139  1 assertNotNull(af, "Didn't read input file " + inFile);
140  1 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
141  1 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
142    TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
143  1 assertNotNull(ColourSchemeProperty.getColourScheme(af.getViewport()
144    .getAlignment(), af.getViewport().getGlobalColourScheme()
145    .getSchemeName()), "Recognise T-Coffee score from string");
146   
147  1 af.saveAlignment(tfile, FileFormat.Jalview);
148  1 assertTrue(af.isSaveAlignmentSuccessful(),
149    "Failed to store as a project.");
150  1 af.closeMenuItem_actionPerformed(true);
151  1 af = null;
152  1 af = new FileLoader()
153    .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
154  1 assertNotNull(af, "Failed to import new project");
155  1 assertSame(af.getViewport().getGlobalColourScheme().getClass(),
156    TCoffeeColourScheme.class,
157    "Didn't set T-coffee colourscheme for imported project.");
158  1 System.out
159    .println("T-Coffee score shading successfully recovered from project.");
160    }
161   
 
162  1 toggle @Test(groups = { "Functional" })
163    public void testColourByAnnotScores() throws Exception
164    {
165  1 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
166  1 String tfile = File.createTempFile("JalviewTest", ".jvp")
167    .getAbsolutePath();
168  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
169    DataSourceType.FILE);
170  1 assertNotNull(af, "Didn't read input file " + inFile);
171  1 af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
172  1 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
173    .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
174  1 assertTrue(
175   
176    aa != null && aa.length > 0,
177    "Didn't find any IUPred annotation to use to shade alignment.");
178  1 AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
179    AnnotationColourGradient.ABOVE_THRESHOLD);
180  1 AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0],
181    null, AnnotationColourGradient.BELOW_THRESHOLD);
182  1 cs.setSeqAssociated(true);
183  1 gcs.setSeqAssociated(true);
184  1 af.changeColour(cs);
185  1 SequenceGroup sg = new SequenceGroup();
186  1 sg.setStartRes(57);
187  1 sg.setEndRes(92);
188  1 sg.cs.setColourScheme(gcs);
189  1 af.getViewport().getAlignment().addGroup(sg);
190  1 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
191  1 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
192  1 af.alignPanel.alignmentChanged();
193  1 af.saveAlignment(tfile, FileFormat.Jalview);
194  1 assertTrue(af.isSaveAlignmentSuccessful(),
195    "Failed to store as a project.");
196  1 af.closeMenuItem_actionPerformed(true);
197  1 af = null;
198  1 af = new FileLoader()
199    .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
200  1 assertNotNull(af, "Failed to import new project");
201   
202    // check for group and alignment colourschemes
203   
204  1 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
205  1 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
206    .get(0).getColourScheme();
207  1 assertNotNull(_rcs, "Didn't recover global colourscheme");
208  1 assertTrue(_rcs instanceof AnnotationColourGradient,
209    "Didn't recover annotation colour global scheme");
210  1 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
211  1 assertTrue(__rcs.isSeqAssociated(),
212    "Annotation colourscheme wasn't sequence associated");
213   
214  1 boolean diffseqcols = false, diffgseqcols = false;
215  1 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
216  158 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
217    && (!diffseqcols || !diffgseqcols); p++)
218    {
219  157 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
220    .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
221    {
222  20 diffseqcols = true;
223    }
224    }
225  1 assertTrue(diffseqcols, "Got Different sequence colours");
226  1 System.out
227    .println("Per sequence colourscheme (Background) successfully applied and recovered.");
228   
229  1 assertNotNull(_rgcs, "Didn't recover group colourscheme");
230  1 assertTrue(_rgcs instanceof AnnotationColourGradient,
231    "Didn't recover annotation colour group colourscheme");
232  1 __rcs = (AnnotationColourGradient) _rgcs;
233  1 assertTrue(__rcs.isSeqAssociated(),
234    "Group Annotation colourscheme wasn't sequence associated");
235   
236  14 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
237    && (!diffseqcols || !diffgseqcols); p++)
238    {
239  13 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null, 0f) != _rgcs
240    .findColour(sqs[2].getCharAt(p), p, sqs[2], null, 0f))
241    {
242  1 diffgseqcols = true;
243    }
244    }
245  1 assertTrue(diffgseqcols, "Got Different group sequence colours");
246  1 System.out
247    .println("Per sequence (Group) colourscheme successfully applied and recovered.");
248    }
249   
 
250  1 toggle @Test(groups = { "Functional" })
251    public void gatherViewsHere() throws Exception
252    {
253  1 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
254    .getAlignFrames().length;
255  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
256    "examples/exampleFile_2_7.jar", DataSourceType.FILE);
257  1 assertNotNull(af, "Didn't read in the example file correctly.");
258  1 assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
259    "Didn't gather the views in the example file.");
260   
261    }
262   
263    /**
264    * Test for JAL-2223 - multiple mappings in View Mapping report
265    *
266    * @throws Exception
267    */
 
268  1 toggle @Test(groups = { "Functional" })
269    public void noDuplicatePdbMappingsMade() throws Exception
270    {
271  1 StructureImportSettings.setProcessSecondaryStructure(true);
272  1 StructureImportSettings.setVisibleChainAnnotation(true);
273  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
274    "examples/exampleFile_2_7.jar", DataSourceType.FILE);
275  1 assertNotNull(af, "Didn't read in the example file correctly.");
276   
277    // locate Jmol viewer
278    // count number of PDB mappings the structure selection manager holds -
279  1 String pdbFile = af.getCurrentView().getStructureSelectionManager()
280    .findFileForPDBId("1A70");
281  1 assertEquals(
282    af.getCurrentView().getStructureSelectionManager()
283    .getMapping(pdbFile).length,
284    2, "Expected only two mappings for 1A70");
285   
286    }
287   
 
288  1 toggle @Test(groups = { "Functional" })
289    public void viewRefPdbAnnotation() throws Exception
290    {
291  1 StructureImportSettings.setProcessSecondaryStructure(true);
292  1 StructureImportSettings.setVisibleChainAnnotation(true);
293  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
294    "examples/exampleFile_2_7.jar", DataSourceType.FILE);
295  1 assertNotNull(af, "Didn't read in the example file correctly.");
296  1 AlignmentViewPanel sps = null;
297  1 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
298    {
299  5 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
300    {
301  1 sps = ap;
302  1 break;
303    }
304    }
305  1 assertNotNull(sps, "Couldn't find the structure view");
306  1 AlignmentAnnotation refan = null;
307  1 for (AlignmentAnnotation ra : sps.getAlignment()
308    .getAlignmentAnnotation())
309    {
310  1 if (ra.graph != 0)
311    {
312  1 refan = ra;
313  1 break;
314    }
315    }
316  1 assertNotNull(refan, "Annotation secondary structure not found.");
317  1 SequenceI sq = sps.getAlignment().findName("1A70|");
318  1 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  1 assertNotNull(sq.getDatasetSequence().getAnnotation(),
322    "1a70 has no annotation");
323  1 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
324    {
325  2 AlignmentAnnotation alaa;
326  2 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
327  2 alaa.adjustForAlignment();
328  2 if (ala.graph == refan.graph)
329    {
330  98 for (int p = 0; p < ala.annotations.length; p++)
331    {
332  97 sq.findPosition(p);
333  97 try
334    {
335  97 assertTrue(
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)
340    {
341  0 Assert.fail("Mismatch of alignment annotations at position "
342    + p + " Ref seq ann: " + refan.annotations[p]
343    + " alignment " + alaa.annotations[p]);
344    }
345    }
346    }
347    }
348   
349    }
350   
 
351  1 toggle @Test(groups = { "Functional" })
352    public void testCopyViewSettings() throws Exception
353    {
354  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
355    "examples/exampleFile_2_7.jar", DataSourceType.FILE);
356  1 assertNotNull(af, "Didn't read in the example file correctly.");
357  1 AlignmentViewPanel sps = null, groups = null;
358  1 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
359    {
360  5 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
361    {
362  1 sps = ap;
363    }
364  5 if (ap.getViewName().contains("MAFFT"))
365    {
366  1 groups = ap;
367    }
368    }
369  1 assertNotNull(sps, "Couldn't find the structure view");
370  1 assertNotNull(groups, "Couldn't find the MAFFT view");
371   
372  1 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
373  1 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
374  1 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
375   
376  1 groups.getAlignViewport().setViewStyle(structureStyle);
377  1 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
378    .getViewStyle()));
379  1 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
380    .getViewStyle()));
381   
382    }
383   
384    /**
385    * test store and recovery of expanded views
386    *
387    * @throws Exception
388    */
 
389  1 toggle @Test(groups = { "Functional" }, enabled = true)
390    public void testStoreAndRecoverExpandedviews() throws Exception
391    {
392  1 Desktop.instance.closeAll_actionPerformed(null);
393   
394  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
395    "examples/exampleFile_2_7.jar", DataSourceType.FILE);
396  1 Assert.assertEquals(Desktop.getAlignFrames().length, 1);
397  1 String afid = af.getViewport().getSequenceSetId();
398   
399    // check FileLoader returned a reference to the one alignFrame that is
400    // actually on the Desktop
401  1 assertSame(
402    af,
403    Desktop.getAlignFrameFor(af.getViewport()),
404    "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
405   
406  1 Desktop.explodeViews(af);
407   
408  1 int oldviews = Desktop.getAlignFrames().length;
409  1 Assert.assertEquals(Desktop.getAlignFrames().length,
410    Desktop.getAlignmentPanels(afid).length);
411  1 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
412  1 try
413    {
414  1 new Jalview2XML(false).saveState(tfile);
415    } catch (Error e)
416    {
417  0 Assert.fail("Didn't save the expanded view state", e);
418    } catch (Exception e)
419    {
420  0 Assert.fail("Didn't save the expanded view state", e);
421    }
422  1 Desktop.instance.closeAll_actionPerformed(null);
423  1 if (Desktop.getAlignFrames() != null)
424    {
425  0 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
426    }
427  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
428    DataSourceType.FILE);
429  1 Assert.assertNotNull(af);
430  1 Assert.assertEquals(
431    Desktop.getAlignFrames().length,
432    Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
433  1 Assert.assertEquals(
434    Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
435    oldviews);
436    }
437   
438    /**
439    * Test save and reload of a project with a different representative sequence
440    * in each view.
441    *
442    * @throws Exception
443    */
 
444  1 toggle @Test(groups = { "Functional" })
445    public void testStoreAndRecoverReferenceSeqSettings() throws Exception
446    {
447  1 Desktop.instance.closeAll_actionPerformed(null);
448  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
449    "examples/exampleFile_2_7.jar", DataSourceType.FILE);
450  1 assertNotNull(af, "Didn't read in the example file correctly.");
451  1 String afid = af.getViewport().getSequenceSetId();
452   
453    // remember reference sequence for each panel
454  1 Map<String, SequenceI> refseqs = new HashMap<>();
455   
456    /*
457    * mark sequence 2, 3, 4.. in panels 1, 2, 3...
458    * as reference sequence for itself and the preceding sequence
459    */
460  1 int n = 1;
461  1 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
462    {
463  5 AlignViewportI av = ap.getAlignViewport();
464  5 AlignmentI alignment = ap.getAlignment();
465  5 int repIndex = n % alignment.getHeight();
466  5 SequenceI rep = alignment.getSequenceAt(repIndex);
467  5 refseqs.put(ap.getViewName(), rep);
468   
469    // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
470    // todo refactor this to an alignment view controller
471  5 av.setDisplayReferenceSeq(true);
472  5 av.setColourByReferenceSeq(true);
473  5 av.getAlignment().setSeqrep(rep);
474   
475  5 n++;
476    }
477  1 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
478    ".jvp");
479  1 try
480    {
481  1 new Jalview2XML(false).saveState(tfile);
482    } catch (Throwable e)
483    {
484  0 Assert.fail("Didn't save the expanded view state", e);
485    }
486  1 Desktop.instance.closeAll_actionPerformed(null);
487  1 if (Desktop.getAlignFrames() != null)
488    {
489  0 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
490    }
491   
492  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
493    DataSourceType.FILE);
494  1 afid = af.getViewport().getSequenceSetId();
495   
496  1 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
497    {
498    // check representative
499  5 AlignmentI alignment = ap.getAlignment();
500  5 SequenceI rep = alignment.getSeqrep();
501  5 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
506    // load/saves.
507  5 Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
508    rep.toString(),
509    "Representative wasn't the same when recovered.");
510  5 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
511    "Display reference sequence view setting not set.");
512  5 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
513    "Colour By Reference Seq view setting not set.");
514    }
515    }
516   
 
517  1 toggle @Test(groups = { "Functional" })
518    public void testIsVersionStringLaterThan()
519    {
520    /*
521    * No version / development / test / autobuild is leniently assumed to be
522    * compatible
523    */
524  1 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
525  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
526  1 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
527  1 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
528    "Development Build"));
529  1 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
530    "DEVELOPMENT BUILD"));
531  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
532    "Development Build"));
533  1 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
534  1 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
535  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
536  1 assertTrue(Jalview2XML
537    .isVersionStringLaterThan(null, "Automated Build"));
538  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
539    "Automated Build"));
540  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
541    "AUTOMATED BUILD"));
542   
543    /*
544    * same version returns true i.e. compatible
545    */
546  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
547  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
548  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
549  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
550  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
551   
552    /*
553    * later version returns true
554    */
555  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
556  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
557  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
558  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
559  1 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
560   
561    /*
562    * earlier version returns false
563    */
564  1 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
565  1 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
566  1 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
567  1 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
568  1 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));
569    }
570   
571    /**
572    * Test save and reload of a project with a different sequence group (and
573    * representative sequence) in each view.
574    *
575    * @throws Exception
576    */
 
577  1 toggle @Test(groups = { "Functional" })
578    public void testStoreAndRecoverGroupRepSeqs() throws Exception
579    {
580  1 Desktop.instance.closeAll_actionPerformed(null);
581  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
582    "examples/uniref50.fa", DataSourceType.FILE);
583  1 assertNotNull(af, "Didn't read in the example file correctly.");
584  1 String afid = af.getViewport().getSequenceSetId();
585    // make a second view of the alignment
586  1 af.newView_actionPerformed(null);
587   
588    /*
589    * remember representative and hidden sequences marked
590    * on each panel
591    */
592  1 Map<String, SequenceI> repSeqs = new HashMap<>();
593  1 Map<String, List<String>> hiddenSeqNames = new HashMap<>();
594   
595    /*
596    * mark sequence 2, 3, 4.. in panels 1, 2, 3...
597    * as reference sequence for itself and the preceding sequence
598    */
599  1 int n = 1;
600  1 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
601    {
602  2 AlignViewportI av = ap.getAlignViewport();
603  2 AlignmentI alignment = ap.getAlignment();
604  2 int repIndex = n % alignment.getHeight();
605    // ensure at least one preceding sequence i.e. index >= 1
606  2 repIndex = Math.max(repIndex, 1);
607  2 SequenceI repSeq = alignment.getSequenceAt(repIndex);
608  2 repSeqs.put(ap.getViewName(), repSeq);
609  2 List<String> hiddenNames = new ArrayList<>();
610  2 hiddenSeqNames.put(ap.getViewName(), hiddenNames);
611   
612    /*
613    * have rep sequence represent itself and the one before it
614    * this hides the group (except for the rep seq)
615    */
616  2 SequenceGroup sg = new SequenceGroup();
617  2 sg.addSequence(repSeq, false);
618  2 SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
619  2 sg.addSequence(precedingSeq, false);
620  2 sg.setSeqrep(repSeq);
621  2 assertTrue(sg.getSequences().contains(repSeq));
622  2 assertTrue(sg.getSequences().contains(precedingSeq));
623  2 av.setSelectionGroup(sg);
624  2 assertSame(repSeq, sg.getSeqrep());
625   
626    /*
627    * represent group with sequence adds to a map of hidden rep sequences
628    * (it does not create a group on the alignment)
629    */
630  2 ((AlignmentViewport) av).hideSequences(repSeq, true);
631  2 assertSame(repSeq, sg.getSeqrep());
632  2 assertTrue(sg.getSequences().contains(repSeq));
633  2 assertTrue(sg.getSequences().contains(precedingSeq));
634  2 assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
635  2 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
636    .getHiddenRepSequences();
637  2 assertNotNull(hiddenRepSeqsMap);
638  2 assertEquals(1, hiddenRepSeqsMap.size());
639  2 assertSame(sg, hiddenRepSeqsMap.get(repSeq));
640  2 assertTrue(alignment.getHiddenSequences().isHidden(precedingSeq));
641  2 assertFalse(alignment.getHiddenSequences().isHidden(repSeq));
642  2 hiddenNames.add(precedingSeq.getName());
643   
644  2 n++;
645    }
646  1 File tfile = File
647    .createTempFile("testStoreAndRecoverGroupReps", ".jvp");
648  1 try
649    {
650  1 new Jalview2XML(false).saveState(tfile);
651    } catch (Throwable e)
652    {
653  0 Assert.fail("Didn't save the expanded view state", e);
654    }
655  1 Desktop.instance.closeAll_actionPerformed(null);
656  1 if (Desktop.getAlignFrames() != null)
657    {
658  0 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
659    }
660   
661  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
662    DataSourceType.FILE);
663  1 afid = af.getViewport().getSequenceSetId();
664   
665  1 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
666    {
667  2 String viewName = ap.getViewName();
668  2 AlignViewportI av = ap.getAlignViewport();
669  2 AlignmentI alignment = ap.getAlignment();
670  2 List<SequenceGroup> groups = alignment.getGroups();
671  2 assertNotNull(groups);
672  2 assertTrue(groups.isEmpty(), "Alignment has groups");
673  2 Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
674    .getHiddenRepSequences();
675  2 assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
676  2 assertEquals(1, hiddenRepSeqsMap.size());
677  2 assertEquals(repSeqs.get(viewName).getDisplayId(true),
678    hiddenRepSeqsMap.keySet().iterator().next()
679    .getDisplayId(true));
680   
681    /*
682    * verify hidden sequences in restored panel
683    */
684  2 List<String> hidden = hiddenSeqNames.get(ap.getViewName());
685  2 HiddenSequences hs = alignment.getHiddenSequences();
686  2 assertEquals(
687    hidden.size(),
688    hs.getSize(),
689    "wrong number of restored hidden sequences in "
690    + ap.getViewName());
691    }
692    }
693   
694    /**
695    * Test save and reload of PDBEntry in Jalview project
696    *
697    * @throws Exception
698    */
 
699  1 toggle @Test(groups = { "Functional" })
700    public void testStoreAndRecoverPDBEntry() throws Exception
701    {
702  1 Desktop.instance.closeAll_actionPerformed(null);
703  1 String exampleFile = "examples/3W5V.pdb";
704  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
705    DataSourceType.FILE);
706  1 assertNotNull(af, "Didn't read in the example file correctly.");
707  1 String afid = af.getViewport().getSequenceSetId();
708   
709  1 AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
710  1 System.out.println();
711  1 AlignmentViewPanel ap = alignPanels[0];
712  1 String tfileBase = new File(".").getAbsolutePath().replace(".", "");
713  1 String testFile = tfileBase + exampleFile;
714  1 AlignmentI alignment = ap.getAlignment();
715  1 System.out.println("blah");
716  1 SequenceI[] seqs = alignment.getSequencesArray();
717  1 Assert.assertNotNull(seqs[0]);
718  1 Assert.assertNotNull(seqs[1]);
719  1 Assert.assertNotNull(seqs[2]);
720  1 Assert.assertNotNull(seqs[3]);
721  1 Assert.assertNotNull(seqs[0].getDatasetSequence());
722  1 Assert.assertNotNull(seqs[1].getDatasetSequence());
723  1 Assert.assertNotNull(seqs[2].getDatasetSequence());
724  1 Assert.assertNotNull(seqs[3].getDatasetSequence());
725  1 PDBEntry[] pdbEntries = new PDBEntry[4];
726  1 pdbEntries[0] = new PDBEntry("3W5V", "A", Type.PDB, testFile);
727  1 pdbEntries[1] = new PDBEntry("3W5V", "B", Type.PDB, testFile);
728  1 pdbEntries[2] = new PDBEntry("3W5V", "C", Type.PDB, testFile);
729  1 pdbEntries[3] = new PDBEntry("3W5V", "D", Type.PDB, testFile);
730  1 Assert.assertEquals(seqs[0].getDatasetSequence().getAllPDBEntries()
731    .get(0), pdbEntries[0]);
732  1 Assert.assertEquals(seqs[1].getDatasetSequence().getAllPDBEntries()
733    .get(0), pdbEntries[1]);
734  1 Assert.assertEquals(seqs[2].getDatasetSequence().getAllPDBEntries()
735    .get(0), pdbEntries[2]);
736  1 Assert.assertEquals(seqs[3].getDatasetSequence().getAllPDBEntries()
737    .get(0), pdbEntries[3]);
738   
739  1 File tfile = File.createTempFile("testStoreAndRecoverPDBEntry", ".jvp");
740  1 try
741    {
742  1 new Jalview2XML(false).saveState(tfile);
743    } catch (Throwable e)
744    {
745  0 Assert.fail("Didn't save the state", e);
746    }
747  1 Desktop.instance.closeAll_actionPerformed(null);
748  1 if (Desktop.getAlignFrames() != null)
749    {
750  0 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
751    }
752   
753  1 AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
754    tfile.getAbsolutePath(), DataSourceType.FILE);
755  1 String rfid = restoredFrame.getViewport().getSequenceSetId();
756  1 AlignmentPanel[] rAlignPanels = Desktop.getAlignmentPanels(rfid);
757  1 AlignmentViewPanel rap = rAlignPanels[0];
758  1 AlignmentI rAlignment = rap.getAlignment();
759  1 System.out.println("blah");
760  1 SequenceI[] rseqs = rAlignment.getSequencesArray();
761  1 Assert.assertNotNull(rseqs[0]);
762  1 Assert.assertNotNull(rseqs[1]);
763  1 Assert.assertNotNull(rseqs[2]);
764  1 Assert.assertNotNull(rseqs[3]);
765  1 Assert.assertNotNull(rseqs[0].getDatasetSequence());
766  1 Assert.assertNotNull(rseqs[1].getDatasetSequence());
767  1 Assert.assertNotNull(rseqs[2].getDatasetSequence());
768  1 Assert.assertNotNull(rseqs[3].getDatasetSequence());
769   
770    // The Asserts below are expected to fail until the PDB chainCode is
771    // recoverable from a Jalview projects
772  5 for (int chain = 0; chain < 4; chain++)
773    {
774  4 PDBEntry recov = rseqs[chain].getDatasetSequence().getAllPDBEntries()
775    .get(0);
776  4 PDBEntry expected = pdbEntries[chain];
777  4 Assert.assertEquals(recov.getId(), expected.getId(),
778    "Mismatch PDB ID");
779  4 Assert.assertEquals(recov.getChainCode(), expected.getChainCode(),
780    "Mismatch PDB ID");
781  4 Assert.assertEquals(recov.getType(), expected.getType(),
782    "Mismatch PDBEntry 'Type'");
783  4 Assert.assertNotNull(recov.getFile(),
784    "Recovered PDBEntry should have a non-null file entry");
785    }
786    }
787   
788    /**
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
791    * saved project.
792    *
793    * @throws IOException
794    */
 
795  1 toggle @Test(groups = { "Functional" })
796    public void testStoreAndRecoverColourThresholds() throws IOException
797    {
798  1 Desktop.instance.closeAll_actionPerformed(null);
799  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
800    "examples/uniref50.fa", DataSourceType.FILE);
801   
802  1 AlignViewport av = af.getViewport();
803  1 AlignmentI al = av.getAlignment();
804   
805    /*
806    * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
807    */
808  1 af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
809  1 assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
810  1 af.abovePIDThreshold_actionPerformed(true);
811  1 SliderPanel sp = SliderPanel.getSliderPanel();
812  1 assertFalse(sp.isForConservation());
813  1 sp.valueChanged(10);
814  1 af.conservationMenuItem_actionPerformed(true);
815  1 sp = SliderPanel.getSliderPanel();
816  1 assertTrue(sp.isForConservation());
817  1 sp.valueChanged(20);
818  1 ResidueShaderI rs = av.getResidueShading();
819  1 assertEquals(rs.getThreshold(), 10);
820  1 assertTrue(rs.conservationApplied());
821  1 assertEquals(rs.getConservationInc(), 20);
822   
823    /*
824    * create a group with Strand colouring, 30% Conservation
825    * and 40% PID threshold
826    */
827  1 SequenceGroup sg = new SequenceGroup();
828  1 sg.addSequence(al.getSequenceAt(0), false);
829  1 sg.setStartRes(15);
830  1 sg.setEndRes(25);
831  1 av.setSelectionGroup(sg);
832  1 PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
833  1 popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
834    .toString());
835  1 assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
836  1 assertEquals(al.getGroups().size(), 1);
837  1 assertSame(al.getGroups().get(0), sg);
838  1 popupMenu.conservationMenuItem_actionPerformed(true);
839  1 sp = SliderPanel.getSliderPanel();
840  1 assertTrue(sp.isForConservation());
841  1 sp.valueChanged(30);
842  1 popupMenu.abovePIDColour_actionPerformed(true);
843  1 sp = SliderPanel.getSliderPanel();
844  1 assertFalse(sp.isForConservation());
845  1 sp.valueChanged(40);
846  1 assertTrue(sg.getGroupColourScheme().conservationApplied());
847  1 assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
848  1 assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
849   
850    /*
851    * save project, close windows, reload project, verify
852    */
853  1 File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
854    ".jvp");
855  1 tfile.deleteOnExit();
856  1 new Jalview2XML(false).saveState(tfile);
857  1 Desktop.instance.closeAll_actionPerformed(null);
858  1 af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
859    DataSourceType.FILE);
860  1 Assert.assertNotNull(af, "Failed to reload project");
861   
862    /*
863    * verify alignment (background) colouring
864    */
865  1 rs = af.getViewport().getResidueShading();
866  1 assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
867  1 assertEquals(rs.getThreshold(), 10);
868  1 assertTrue(rs.conservationApplied());
869  1 assertEquals(rs.getConservationInc(), 20);
870   
871    /*
872    * verify group colouring
873    */
874  1 assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
875  1 rs = af.getViewport().getAlignment().getGroups().get(0)
876    .getGroupColourScheme();
877  1 assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
878  1 assertEquals(rs.getThreshold(), 40);
879  1 assertTrue(rs.conservationApplied());
880  1 assertEquals(rs.getConservationInc(), 30);
881    }
882   
883    /**
884    * Test save and reload of feature colour schemes and filter settings
885    *
886    * @throws IOException
887    */
 
888  1 toggle @Test(groups = { "Functional" })
889    public void testSaveLoadFeatureColoursAndFilters() throws IOException
890    {
891  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
892    ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE);
893  1 SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0);
894   
895    /*
896    * add some features to the sequence
897    */
898  1 int score = 1;
899  1 addFeatures(seq1, "type1", score++);
900  1 addFeatures(seq1, "type2", score++);
901  1 addFeatures(seq1, "type3", score++);
902  1 addFeatures(seq1, "type4", score++);
903  1 addFeatures(seq1, "type5", score++);
904   
905    /*
906    * set colour schemes for features
907    */
908  1 FeatureRenderer fr = af.getFeatureRenderer();
909  1 fr.findAllFeatures(true);
910   
911    // type1: red
912  1 fr.setColour("type1", new FeatureColour(Color.red));
913   
914    // type2: by label
915  1 FeatureColourI byLabel = new FeatureColour();
916  1 byLabel.setColourByLabel(true);
917  1 fr.setColour("type2", byLabel);
918   
919    // type3: by score above threshold
920  1 FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1,
921    10);
922  1 byScore.setAboveThreshold(true);
923  1 byScore.setThreshold(2f);
924  1 fr.setColour("type3", byScore);
925   
926    // type4: by attribute AF
927  1 FeatureColourI byAF = new FeatureColour();
928  1 byAF.setColourByLabel(true);
929  1 byAF.setAttributeName("AF");
930  1 fr.setColour("type4", byAF);
931   
932    // type5: by attribute CSQ:PolyPhen below threshold
933  1 FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE,
934    1, 10);
935  1 byPolyPhen.setBelowThreshold(true);
936  1 byPolyPhen.setThreshold(3f);
937  1 byPolyPhen.setAttributeName("CSQ", "PolyPhen");
938  1 fr.setColour("type5", byPolyPhen);
939   
940    /*
941    * set filters for feature types
942    */
943   
944    // filter type1 features by (label contains "x")
945  1 FeatureMatcherSetI filterByX = new FeatureMatcherSet();
946  1 filterByX.and(FeatureMatcher.byLabel(Condition.Contains, "x"));
947  1 fr.setFeatureFilter("type1", filterByX);
948   
949    // filter type2 features by (score <= 2.4 and score > 1.1)
950  1 FeatureMatcherSetI filterByScore = new FeatureMatcherSet();
951  1 filterByScore.and(FeatureMatcher.byScore(Condition.LE, "2.4"));
952  1 filterByScore.and(FeatureMatcher.byScore(Condition.GT, "1.1"));
953  1 fr.setFeatureFilter("type2", filterByScore);
954   
955    // filter type3 features by (AF contains X OR CSQ:PolyPhen != 0)
956  1 FeatureMatcherSetI filterByXY = new FeatureMatcherSet();
957  1 filterByXY
958    .and(FeatureMatcher.byAttribute(Condition.Contains, "X", "AF"));
959  1 filterByXY.or(FeatureMatcher.byAttribute(Condition.NE, "0", "CSQ",
960    "PolyPhen"));
961  1 fr.setFeatureFilter("type3", filterByXY);
962   
963    /*
964    * save as Jalview project
965    */
966  1 File tfile = File.createTempFile("JalviewTest", ".jvp");
967  1 tfile.deleteOnExit();
968  1 String filePath = tfile.getAbsolutePath();
969  1 af.saveAlignment(filePath, FileFormat.Jalview);
970  1 assertTrue(af.isSaveAlignmentSuccessful(),
971    "Failed to store as a project.");
972   
973    /*
974    * close current alignment and load the saved project
975    */
976  1 af.closeMenuItem_actionPerformed(true);
977  1 af = null;
978  1 af = new FileLoader()
979    .LoadFileWaitTillLoaded(filePath, DataSourceType.FILE);
980  1 assertNotNull(af, "Failed to import new project");
981   
982    /*
983    * verify restored feature colour schemes and filters
984    */
985  1 fr = af.getFeatureRenderer();
986  1 FeatureColourI fc = fr.getFeatureStyle("type1");
987  1 assertTrue(fc.isSimpleColour());
988  1 assertEquals(fc.getColour(), Color.red);
989  1 fc = fr.getFeatureStyle("type2");
990  1 assertTrue(fc.isColourByLabel());
991  1 fc = fr.getFeatureStyle("type3");
992  1 assertTrue(fc.isGraduatedColour());
993  1 assertNull(fc.getAttributeName());
994  1 assertTrue(fc.isAboveThreshold());
995  1 assertEquals(fc.getThreshold(), 2f);
996  1 fc = fr.getFeatureStyle("type4");
997  1 assertTrue(fc.isColourByLabel());
998  1 assertTrue(fc.isColourByAttribute());
999  1 assertEquals(fc.getAttributeName(), new String[] { "AF" });
1000  1 fc = fr.getFeatureStyle("type5");
1001  1 assertTrue(fc.isGraduatedColour());
1002  1 assertTrue(fc.isColourByAttribute());
1003  1 assertEquals(fc.getAttributeName(), new String[] { "CSQ", "PolyPhen" });
1004  1 assertTrue(fc.isBelowThreshold());
1005  1 assertEquals(fc.getThreshold(), 3f);
1006   
1007  1 assertEquals(fr.getFeatureFilter("type1").toStableString(),
1008    "Label Contains x");
1009  1 assertEquals(fr.getFeatureFilter("type2").toStableString(),
1010    "(Score LE 2.4) AND (Score GT 1.1)");
1011  1 assertEquals(fr.getFeatureFilter("type3").toStableString(),
1012    "(AF Contains X) OR (CSQ:PolyPhen NE 0.0)");
1013    }
1014   
 
1015  10 toggle private void addFeature(SequenceI seq, String featureType, int score)
1016    {
1017  10 SequenceFeature sf = new SequenceFeature(featureType, "desc", 1, 2,
1018    score, "grp");
1019  10 sf.setValue("AF", score);
1020  10 sf.setValue("CSQ", new HashMap<String, String>()
1021    {
 
1022  10 toggle {
1023  10 put("PolyPhen", Integer.toString(score));
1024    }
1025    });
1026  10 seq.addSequenceFeature(sf);
1027    }
1028   
1029    /**
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"
1032    *
1033    * @param seq
1034    * @param featureType
1035    * @param score
1036    */
 
1037  5 toggle private void addFeatures(SequenceI seq, String featureType, int score)
1038    {
1039  5 addFeature(seq, featureType, score++);
1040  5 addFeature(seq, featureType, score);
1041    }
1042    }