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;
39 import java.util.HashMap;
42 import org.testng.Assert;
43 import org.testng.AssertJUnit;
44 import org.testng.annotations.AfterClass;
45 import org.testng.annotations.BeforeClass;
46 import org.testng.annotations.Test;
48 @Test(singleThreaded = true)
49 public class Jalview2xmlTests
53 * @throws java.lang.Exception
55 @BeforeClass(alwaysRun = true)
56 public static void setUpBeforeClass() throws Exception
58 jalview.bin.Jalview.main(new String[] { "-props",
59 "test/jalview/io/testProps.jvprops" });
63 * @throws java.lang.Exception
66 public static void tearDownAfterClass() throws Exception
68 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
72 public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
75 for (SequenceI sq : avp.getAlignment().getDataset().getSequences())
77 if (sq.getAnnotation() != null)
79 for (AlignmentAnnotation dssa : sq.getAnnotation())
81 if (dssa.isValidStruc())
91 @Test(groups = { "Functional" })
92 public void testRNAStructureRecovery() throws Exception
94 String inFile = "examples/RF00031_folded.stk";
95 String tfile = File.createTempFile("JalviewTest", ".jvp")
97 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
98 inFile, FormatAdapter.FILE);
99 assertTrue("Didn't read input file " + inFile, af != null);
100 int olddsann = countDsAnn(af.getViewport());
101 assertTrue("Didn't find any dataset annotations", olddsann > 0);
102 af.rnahelicesColour_actionPerformed(null);
104 "Couldn't apply RNA helices colourscheme",
105 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
106 assertTrue("Failed to store as a project.",
107 af.saveAlignment(tfile, "Jalview"));
108 af.closeMenuItem_actionPerformed(true);
110 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
112 assertTrue("Failed to import new project", af != null);
113 int newdsann = countDsAnn(af.getViewport());
115 "Differing numbers of dataset sequence annotation\nOriginally "
116 + olddsann + " and now " + newdsann,
117 olddsann == newdsann);
119 .println("Read in same number of annotations as originally present ("
122 "RNA helices colourscheme was not applied on import.",
123 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
126 @Test(groups = { "Functional" })
127 public void testTCoffeeScores() throws Exception
129 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
130 String tfile = File.createTempFile("JalviewTest", ".jvp")
132 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
133 inFile, FormatAdapter.FILE);
134 assertTrue("Didn't read input file " + inFile, af != null);
135 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
137 "Didn't set T-coffee colourscheme",
138 af.getViewport().getGlobalColourScheme().getClass()
139 .equals(jalview.schemes.TCoffeeColourScheme.class));
141 "Recognise T-Coffee score from string",
142 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
144 jalview.schemes.ColourSchemeProperty.getColourName(af
145 .getViewport().getGlobalColourScheme())) != null);
147 assertTrue("Failed to store as a project.",
148 af.saveAlignment(tfile, "Jalview"));
149 af.closeMenuItem_actionPerformed(true);
151 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
153 assertTrue("Failed to import new project", af != null);
155 "Didn't set T-coffee colourscheme for imported project.",
156 af.getViewport().getGlobalColourScheme().getClass()
157 .equals(jalview.schemes.TCoffeeColourScheme.class));
159 .println("T-Coffee score shading successfully recovered from project.");
162 @Test(groups = { "Functional" })
163 public void testColourByAnnotScores() throws Exception
165 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
166 String tfile = File.createTempFile("JalviewTest", ".jvp")
168 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
169 inFile, FormatAdapter.FILE);
170 assertTrue("Didn't read input file " + inFile, af != null);
171 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
172 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
173 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
175 "Didn't find any IUPred annotation to use to shade alignment.",
176 aa != null && aa.length > 0);
177 AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient(
178 aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD);
179 AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient(
180 aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD);
181 cs.setSeqAssociated(true);
182 gcs.setSeqAssociated(true);
184 SequenceGroup sg = new SequenceGroup();
188 af.getViewport().getAlignment().addGroup(sg);
189 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
190 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
191 af.alignPanel.alignmentChanged();
192 assertTrue("Failed to store as a project.",
193 af.saveAlignment(tfile, "Jalview"));
194 af.closeMenuItem_actionPerformed(true);
196 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
198 assertTrue("Failed to import new project", af != null);
200 // check for group and alignment colourschemes
202 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
203 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
205 assertTrue("Didn't recover global colourscheme", _rcs != null);
206 assertTrue("Didn't recover annotation colour global scheme",
207 _rcs instanceof AnnotationColourGradient);
208 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
209 assertTrue("Annotation colourscheme wasn't sequence associated",
210 __rcs.isSeqAssociated());
212 boolean diffseqcols = false, diffgseqcols = false;
213 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
214 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
215 && (!diffseqcols || !diffgseqcols); p++)
217 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0]) != _rcs
218 .findColour(sqs[5].getCharAt(p), p, sqs[5]))
223 assertTrue("Got Different sequence colours", diffseqcols);
225 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
227 assertTrue("Didn't recover group colourscheme", _rgcs != null);
228 assertTrue("Didn't recover annotation colour group colourscheme",
229 _rgcs instanceof AnnotationColourGradient);
230 __rcs = (AnnotationColourGradient) _rgcs;
231 assertTrue("Group Annotation colourscheme wasn't sequence associated",
232 __rcs.isSeqAssociated());
234 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
235 && (!diffseqcols || !diffgseqcols); p++)
237 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1]) != _rgcs
238 .findColour(sqs[2].getCharAt(p), p, sqs[2]))
243 assertTrue("Got Different group sequence colours", diffgseqcols);
245 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
248 @Test(groups = { "Functional" })
249 public void gatherViewsHere() throws Exception
251 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
252 .getAlignFrames().length;
253 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
254 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
255 assertTrue("Didn't read in the example file correctly.", af != null);
256 assertTrue("Didn't gather the views in the example file.",
257 Desktop.getAlignFrames().length == 1 + origCount);
261 @Test(groups = { "Functional" })
262 public void viewRefPdbAnnotation() throws Exception
264 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
265 Boolean.TRUE.toString());
266 Cache.applicationProperties.setProperty("ADD_SS_ANN",
267 Boolean.TRUE.toString());
268 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
269 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
270 assertTrue("Didn't read in the example file correctly.", af != null);
271 AlignmentViewPanel sps = null;
272 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
274 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
280 assertTrue("Couldn't find the structure view", sps != null);
281 SequenceI sq = sps.getAlignment().findName("1A70|");
282 AlignmentAnnotation refan = null;
283 for (AlignmentAnnotation ra : sps.getAlignment()
284 .getAlignmentAnnotation())
292 assertTrue("Annotation secondary structure not found.", refan != null);
293 assertTrue("Couldn't find 1a70 null chain", sq != null);
294 // compare the manually added temperature factor annotation
295 // to the track automatically transferred from the pdb structure on load
296 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
298 AlignmentAnnotation alaa;
299 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
300 alaa.adjustForAlignment();
301 if (ala.graph == refan.graph)
303 for (int p = 0; p < ala.annotations.length; p++)
309 "Mismatch at alignment position " + p,
310 (alaa.annotations[p] == null && refan.annotations[p] == null)
311 || alaa.annotations[p].value == refan.annotations[p].value);
312 } catch (NullPointerException q)
314 Assert.fail("Mismatch of alignment annotations at position "
315 + p + " Ref seq ann: " + refan.annotations[p]
316 + " alignment " + alaa.annotations[p]);
324 @Test(groups = { "Functional" })
325 public void testCopyViewSettings() throws Exception
327 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
328 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
329 assertTrue("Didn't read in the example file correctly.", af != null);
330 AlignmentViewPanel sps = null, groups = null;
331 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
333 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
337 if (ap.getViewName().contains("MAFFT"))
342 assertTrue("Couldn't find the structure view", sps != null);
343 assertTrue("Couldn't find the MAFFT view", groups != null);
345 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
346 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
347 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
349 groups.getAlignViewport().setViewStyle(structureStyle);
350 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
352 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
358 * test store and recovery of expanded views - currently this is disabled
359 * since the Desktop.explodeViews method doesn't seem to result in the views
360 * being expanded to distinct align frames when executed programmatically.
364 @Test(groups = { "Functional" }, enabled = false)
365 public void testStoreAndRecoverExpandedviews() throws Exception
367 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
368 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
369 assertTrue("Didn't read in the example file correctly.", af != null);
370 String afid = af.getViewport().getSequenceSetId();
372 final AlignFrame xaf = af;
374 new Thread(new Runnable()
379 Desktop.instance.explodeViews(xaf);
385 // while (++times < 5 && Desktop.getAlignFrames().length < )
387 // Thread.sleep(300);
389 int oldviews = Desktop.getAlignFrames().length;
390 Assert.assertEquals(Desktop.getAlignFrames().length,
391 Desktop.getAlignmentPanels(afid).length);
392 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
395 new Jalview2XML(false).saveState(tfile);
398 Assert.fail("Didn't save the expanded view state", e);
399 } catch (Exception e)
401 Assert.fail("Didn't save the expanded view state", e);
403 Desktop.instance.closeAll_actionPerformed(null);
404 if (Desktop.getAlignFrames() != null)
406 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
408 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
409 tfile.getAbsolutePath(), FormatAdapter.FILE);
410 Assert.assertNotNull(af);
412 Desktop.getAlignFrames().length,
413 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
416 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
420 * based on above test store and recovery of expanded views.
424 @Test(groups = { "Functional" })
425 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
427 Desktop.instance.closeAll_actionPerformed(null);
430 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
431 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
432 assertTrue("Didn't read in the example file correctly.", af != null);
433 afid = af.getViewport().getSequenceSetId();
435 Map<String, SequenceI> refs = new HashMap<String, SequenceI>();
437 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
439 // mark representative
440 SequenceI rep = ap.getAlignment().getSequenceAt(
441 n++ % ap.getAlignment().getHeight());
442 refs.put(ap.getViewName(), rep);
443 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
444 // todo refactor the to an alignment view controller
445 ap.getAlignViewport().setDisplayReferenceSeq(true);
446 ap.getAlignViewport().setColourByReferenceSeq(true);
447 ap.getAlignViewport().getAlignment().setSeqrep(rep);
449 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
453 new Jalview2XML(false).saveState(tfile);
456 Assert.fail("Didn't save the expanded view state", e);
457 } catch (Exception e)
459 Assert.fail("Didn't save the expanded view state", e);
461 Desktop.instance.closeAll_actionPerformed(null);
462 if (Desktop.getAlignFrames() != null)
464 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
467 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
468 tfile.getAbsolutePath(), FormatAdapter.FILE);
469 afid = af.getViewport().getSequenceSetId();
471 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
473 // check representative
474 SequenceI rep = ap.getAlignment().getSeqrep();
475 Assert.assertNotNull(rep,
476 "Couldn't restore sequence representative from project");
477 // can't use a strong equals here, because by definition, the sequence IDs
478 // will be different.
479 // could set vamsas session save/restore flag to preserve IDs across
481 Assert.assertEquals(refs.get(ap.getViewName()).toString(),
483 "Representative wasn't the same when recovered.");
484 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
485 "Display reference sequence view setting not set.");
486 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
487 "Colour By Reference Seq view setting not set.");
491 @Test(groups = { "Functional" })
492 public void testIsVersionStringLaterThan()
495 * No version / development / test / autobuild is leniently assumed to be
498 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
499 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
500 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
501 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
502 "Development Build"));
503 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
504 "DEVELOPMENT BUILD"));
505 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
506 "Development Build"));
507 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
508 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
509 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
510 assertTrue(Jalview2XML
511 .isVersionStringLaterThan(null, "Automated Build"));
512 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
514 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
518 * same version returns true i.e. compatible
520 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
521 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
522 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
523 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
524 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
527 * later version returns true
529 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
530 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
531 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
532 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
533 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
536 * earlier version returns false
538 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
539 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
540 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
541 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
542 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));