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.assertFalse;
24 import static org.testng.AssertJUnit.assertTrue;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.api.ViewStyleI;
28 import jalview.bin.Cache;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.SequenceGroup;
31 import jalview.datamodel.SequenceI;
32 import jalview.gui.AlignFrame;
33 import jalview.gui.Desktop;
34 import jalview.gui.Jalview2XML;
35 import jalview.schemes.AnnotationColourGradient;
36 import jalview.schemes.ColourSchemeI;
40 import org.testng.Assert;
41 import org.testng.AssertJUnit;
42 import org.testng.annotations.AfterClass;
43 import org.testng.annotations.BeforeClass;
44 import org.testng.annotations.Test;
46 public class Jalview2xmlTests
50 * @throws java.lang.Exception
52 @BeforeClass(alwaysRun = true)
53 public static void setUpBeforeClass() throws Exception
55 jalview.bin.Jalview.main(new String[] { "-props",
56 "test/jalview/io/testProps.jvprops" });
60 * @throws java.lang.Exception
63 public static void tearDownAfterClass() throws Exception
65 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
69 public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
72 for (SequenceI sq : avp.getAlignment().getDataset().getSequences())
74 if (sq.getAnnotation() != null)
76 for (AlignmentAnnotation dssa : sq.getAnnotation())
78 if (dssa.isValidStruc())
88 @Test(groups = { "Functional" })
89 public void testRNAStructureRecovery() throws Exception
91 String inFile = "examples/RF00031_folded.stk";
92 String tfile = File.createTempFile("JalviewTest", ".jvp")
94 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
95 inFile, FormatAdapter.FILE);
96 assertTrue("Didn't read input file " + inFile, af != null);
97 int olddsann = countDsAnn(af.getViewport());
98 assertTrue("Didn't find any dataset annotations", olddsann > 0);
99 af.rnahelicesColour_actionPerformed(null);
101 "Couldn't apply RNA helices colourscheme",
102 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
103 assertTrue("Failed to store as a project.",
104 af.saveAlignment(tfile, "Jalview"));
105 af.closeMenuItem_actionPerformed(true);
107 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
109 assertTrue("Failed to import new project", af != null);
110 int newdsann = countDsAnn(af.getViewport());
112 "Differing numbers of dataset sequence annotation\nOriginally "
113 + olddsann + " and now " + newdsann,
114 olddsann == newdsann);
116 .println("Read in same number of annotations as originally present ("
119 "RNA helices colourscheme was not applied on import.",
120 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
123 @Test(groups = { "Functional" })
124 public void testTCoffeeScores() throws Exception
126 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
127 String tfile = File.createTempFile("JalviewTest", ".jvp")
129 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
130 inFile, FormatAdapter.FILE);
131 assertTrue("Didn't read input file " + inFile, af != null);
132 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
134 "Didn't set T-coffee colourscheme",
135 af.getViewport().getGlobalColourScheme().getClass()
136 .equals(jalview.schemes.TCoffeeColourScheme.class));
138 "Recognise T-Coffee score from string",
139 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
141 jalview.schemes.ColourSchemeProperty.getColourName(af
142 .getViewport().getGlobalColourScheme())) != null);
144 assertTrue("Failed to store as a project.",
145 af.saveAlignment(tfile, "Jalview"));
146 af.closeMenuItem_actionPerformed(true);
148 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
150 assertTrue("Failed to import new project", af != null);
152 "Didn't set T-coffee colourscheme for imported project.",
153 af.getViewport().getGlobalColourScheme().getClass()
154 .equals(jalview.schemes.TCoffeeColourScheme.class));
156 .println("T-Coffee score shading successfully recovered from project.");
159 @Test(groups = { "Functional" })
160 public void testColourByAnnotScores() throws Exception
162 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
163 String tfile = File.createTempFile("JalviewTest", ".jvp")
165 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
166 inFile, FormatAdapter.FILE);
167 assertTrue("Didn't read input file " + inFile, af != null);
168 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
169 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
170 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
172 "Didn't find any IUPred annotation to use to shade alignment.",
173 aa != null && aa.length > 0);
174 AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient(
175 aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD);
176 AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient(
177 aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD);
178 cs.setSeqAssociated(true);
179 gcs.setSeqAssociated(true);
181 SequenceGroup sg = new SequenceGroup();
185 af.getViewport().getAlignment().addGroup(sg);
186 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
187 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
188 af.alignPanel.alignmentChanged();
189 assertTrue("Failed to store as a project.",
190 af.saveAlignment(tfile, "Jalview"));
191 af.closeMenuItem_actionPerformed(true);
193 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
195 assertTrue("Failed to import new project", af != null);
197 // check for group and alignment colourschemes
199 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
200 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
202 assertTrue("Didn't recover global colourscheme", _rcs != null);
203 assertTrue("Didn't recover annotation colour global scheme",
204 _rcs instanceof AnnotationColourGradient);
205 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
206 assertTrue("Annotation colourscheme wasn't sequence associated",
207 __rcs.isSeqAssociated());
209 boolean diffseqcols = false, diffgseqcols = false;
210 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
211 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
212 && (!diffseqcols || !diffgseqcols); p++)
214 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0]) != _rcs
215 .findColour(sqs[5].getCharAt(p), p, sqs[5]))
220 assertTrue("Got Different sequence colours", diffseqcols);
222 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
224 assertTrue("Didn't recover group colourscheme", _rgcs != null);
225 assertTrue("Didn't recover annotation colour group colourscheme",
226 _rgcs instanceof AnnotationColourGradient);
227 __rcs = (AnnotationColourGradient) _rgcs;
228 assertTrue("Group Annotation colourscheme wasn't sequence associated",
229 __rcs.isSeqAssociated());
231 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
232 && (!diffseqcols || !diffgseqcols); p++)
234 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1]) != _rgcs
235 .findColour(sqs[2].getCharAt(p), p, sqs[2]))
240 assertTrue("Got Different group sequence colours", diffgseqcols);
242 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
245 @Test(groups = { "Functional" })
246 public void gatherViewsHere() throws Exception
248 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
249 .getAlignFrames().length;
250 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
251 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
252 assertTrue("Didn't read in the example file correctly.", af != null);
253 assertTrue("Didn't gather the views in the example file.",
254 Desktop.getAlignFrames().length == 1 + origCount);
258 @Test(groups = { "Functional" })
259 public void viewRefPdbAnnotation() throws Exception
261 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
262 Boolean.TRUE.toString());
263 Cache.applicationProperties.setProperty("ADD_SS_ANN",
264 Boolean.TRUE.toString());
265 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
266 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
267 assertTrue("Didn't read in the example file correctly.", af != null);
268 AlignmentViewPanel sps = null;
269 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
271 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
277 assertTrue("Couldn't find the structure view", sps != null);
278 SequenceI sq = sps.getAlignment().findName("1A70|");
279 AlignmentAnnotation refan = null;
280 for (AlignmentAnnotation ra : sps.getAlignment()
281 .getAlignmentAnnotation())
289 assertTrue("Annotation secondary structure not found.", refan != null);
290 assertTrue("Couldn't find 1a70 null chain", sq != null);
291 // compare the manually added temperature factor annotation
292 // to the track automatically transferred from the pdb structure on load
293 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
295 AlignmentAnnotation alaa;
296 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
297 alaa.adjustForAlignment();
298 if (ala.graph == refan.graph)
300 for (int p = 0; p < ala.annotations.length; p++)
306 "Mismatch at alignment position " + p,
307 (alaa.annotations[p] == null && refan.annotations[p] == null)
308 || alaa.annotations[p].value == refan.annotations[p].value);
309 } catch (NullPointerException q)
311 Assert.fail("Mismatch of alignment annotations at position "
312 + p + " Ref seq ann: " + refan.annotations[p]
313 + " alignment " + alaa.annotations[p]);
321 @Test(groups = { "Functional" })
322 public void testCopyViewSettings() throws Exception
324 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
325 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
326 assertTrue("Didn't read in the example file correctly.", af != null);
327 AlignmentViewPanel sps = null, groups = null;
328 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
330 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
334 if (ap.getViewName().contains("MAFFT"))
339 assertTrue("Couldn't find the structure view", sps != null);
340 assertTrue("Couldn't find the MAFFT view", groups != null);
342 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
343 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
344 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
346 groups.getAlignViewport().setViewStyle(structureStyle);
347 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
349 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
355 * test store and recovery of expanded views - currently this is disabled
356 * since the Desktop.explodeViews method doesn't seem to result in the views
357 * being expanded to distinct align frames when executed programmatically.
361 @Test(groups = { "Functional" }, enabled = false)
362 public void testStoreAndRecoverExpandedviews() throws Exception
364 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
365 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
366 assertTrue("Didn't read in the example file correctly.", af != null);
367 String afid = af.getViewport().getSequenceSetId();
369 final AlignFrame xaf = af;
371 new Thread(new Runnable()
376 Desktop.instance.explodeViews(xaf);
382 // while (++times < 5 && Desktop.getAlignFrames().length < )
384 // Thread.sleep(300);
386 int oldviews = Desktop.getAlignFrames().length;
387 Assert.assertEquals(Desktop.getAlignFrames().length,
388 Desktop.getAlignmentPanels(afid).length);
389 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
392 new Jalview2XML(false).saveState(tfile);
395 Assert.fail("Didn't save the expanded view state", e);
396 } catch (Exception e)
398 Assert.fail("Didn't save the expanded view state", e);
400 Desktop.instance.closeAll_actionPerformed(null);
401 if (Desktop.getAlignFrames() != null)
403 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
405 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
406 tfile.getAbsolutePath(), FormatAdapter.FILE);
407 Assert.assertNotNull(af);
409 Desktop.getAlignFrames().length,
410 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
413 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
416 @Test(groups = { "Functional" })
417 public void testIsVersionStringLaterThan()
420 * No version / development / test / autobuild is leniently assumed to be
423 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
424 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
425 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
426 "Development Build"));
427 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
428 "DEVELOPMENT BUILD"));
429 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
430 "Development Build"));
431 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
432 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
433 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
434 assertTrue(Jalview2XML
435 .isVersionStringLaterThan(null, "Automated Build"));
436 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
438 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
442 * same version returns true i.e. compatible
444 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
445 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
446 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
447 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
448 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
451 * later version returns true
453 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
454 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
455 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
456 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
457 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
460 * earlier version returns false
462 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
463 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
464 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
465 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
466 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));