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 public class Jalview2xmlTests
52 * @throws java.lang.Exception
54 @BeforeClass(alwaysRun = true)
55 public static void setUpBeforeClass() throws Exception
57 jalview.bin.Jalview.main(new String[] { "-props",
58 "test/jalview/io/testProps.jvprops" });
62 * @throws java.lang.Exception
65 public static void tearDownAfterClass() throws Exception
67 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
71 public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
74 for (SequenceI sq : avp.getAlignment().getDataset().getSequences())
76 if (sq.getAnnotation() != null)
78 for (AlignmentAnnotation dssa : sq.getAnnotation())
80 if (dssa.isValidStruc())
90 @Test(groups = { "Functional" })
91 public void testRNAStructureRecovery() throws Exception
93 String inFile = "examples/RF00031_folded.stk";
94 String tfile = File.createTempFile("JalviewTest", ".jvp")
96 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
97 inFile, FormatAdapter.FILE);
98 assertTrue("Didn't read input file " + inFile, af != null);
99 int olddsann = countDsAnn(af.getViewport());
100 assertTrue("Didn't find any dataset annotations", olddsann > 0);
101 af.rnahelicesColour_actionPerformed(null);
103 "Couldn't apply RNA helices colourscheme",
104 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
105 assertTrue("Failed to store as a project.",
106 af.saveAlignment(tfile, "Jalview"));
107 af.closeMenuItem_actionPerformed(true);
109 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
111 assertTrue("Failed to import new project", af != null);
112 int newdsann = countDsAnn(af.getViewport());
114 "Differing numbers of dataset sequence annotation\nOriginally "
115 + olddsann + " and now " + newdsann,
116 olddsann == newdsann);
118 .println("Read in same number of annotations as originally present ("
121 "RNA helices colourscheme was not applied on import.",
122 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
125 @Test(groups = { "Functional" })
126 public void testTCoffeeScores() throws Exception
128 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
129 String tfile = File.createTempFile("JalviewTest", ".jvp")
131 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
132 inFile, FormatAdapter.FILE);
133 assertTrue("Didn't read input file " + inFile, af != null);
134 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
136 "Didn't set T-coffee colourscheme",
137 af.getViewport().getGlobalColourScheme().getClass()
138 .equals(jalview.schemes.TCoffeeColourScheme.class));
140 "Recognise T-Coffee score from string",
141 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
143 jalview.schemes.ColourSchemeProperty.getColourName(af
144 .getViewport().getGlobalColourScheme())) != null);
146 assertTrue("Failed to store as a project.",
147 af.saveAlignment(tfile, "Jalview"));
148 af.closeMenuItem_actionPerformed(true);
150 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
152 assertTrue("Failed to import new project", af != null);
154 "Didn't set T-coffee colourscheme for imported project.",
155 af.getViewport().getGlobalColourScheme().getClass()
156 .equals(jalview.schemes.TCoffeeColourScheme.class));
158 .println("T-Coffee score shading successfully recovered from project.");
161 @Test(groups = { "Functional" })
162 public void testColourByAnnotScores() throws Exception
164 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
165 String tfile = File.createTempFile("JalviewTest", ".jvp")
167 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
168 inFile, FormatAdapter.FILE);
169 assertTrue("Didn't read input file " + inFile, af != null);
170 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
171 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
172 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
174 "Didn't find any IUPred annotation to use to shade alignment.",
175 aa != null && aa.length > 0);
176 AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient(
177 aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD);
178 AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient(
179 aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD);
180 cs.setSeqAssociated(true);
181 gcs.setSeqAssociated(true);
183 SequenceGroup sg = new SequenceGroup();
187 af.getViewport().getAlignment().addGroup(sg);
188 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
189 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
190 af.alignPanel.alignmentChanged();
191 assertTrue("Failed to store as a project.",
192 af.saveAlignment(tfile, "Jalview"));
193 af.closeMenuItem_actionPerformed(true);
195 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
197 assertTrue("Failed to import new project", af != null);
199 // check for group and alignment colourschemes
201 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
202 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
204 assertTrue("Didn't recover global colourscheme", _rcs != null);
205 assertTrue("Didn't recover annotation colour global scheme",
206 _rcs instanceof AnnotationColourGradient);
207 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
208 assertTrue("Annotation colourscheme wasn't sequence associated",
209 __rcs.isSeqAssociated());
211 boolean diffseqcols = false, diffgseqcols = false;
212 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
213 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
214 && (!diffseqcols || !diffgseqcols); p++)
216 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0]) != _rcs
217 .findColour(sqs[5].getCharAt(p), p, sqs[5]))
222 assertTrue("Got Different sequence colours", diffseqcols);
224 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
226 assertTrue("Didn't recover group colourscheme", _rgcs != null);
227 assertTrue("Didn't recover annotation colour group colourscheme",
228 _rgcs instanceof AnnotationColourGradient);
229 __rcs = (AnnotationColourGradient) _rgcs;
230 assertTrue("Group Annotation colourscheme wasn't sequence associated",
231 __rcs.isSeqAssociated());
233 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
234 && (!diffseqcols || !diffgseqcols); p++)
236 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1]) != _rgcs
237 .findColour(sqs[2].getCharAt(p), p, sqs[2]))
242 assertTrue("Got Different group sequence colours", diffgseqcols);
244 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
247 @Test(groups = { "Functional" })
248 public void gatherViewsHere() throws Exception
250 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
251 .getAlignFrames().length;
252 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
253 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
254 assertTrue("Didn't read in the example file correctly.", af != null);
255 assertTrue("Didn't gather the views in the example file.",
256 Desktop.getAlignFrames().length == 1 + origCount);
260 @Test(groups = { "Functional" })
261 public void viewRefPdbAnnotation() throws Exception
263 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
264 Boolean.TRUE.toString());
265 Cache.applicationProperties.setProperty("ADD_SS_ANN",
266 Boolean.TRUE.toString());
267 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
268 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
269 assertTrue("Didn't read in the example file correctly.", af != null);
270 AlignmentViewPanel sps = null;
271 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
273 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
279 assertTrue("Couldn't find the structure view", sps != null);
280 SequenceI sq = sps.getAlignment().findName("1A70|");
281 AlignmentAnnotation refan = null;
282 for (AlignmentAnnotation ra : sps.getAlignment()
283 .getAlignmentAnnotation())
291 assertTrue("Annotation secondary structure not found.", refan != null);
292 assertTrue("Couldn't find 1a70 null chain", sq != null);
293 // compare the manually added temperature factor annotation
294 // to the track automatically transferred from the pdb structure on load
295 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
297 AlignmentAnnotation alaa;
298 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
299 alaa.adjustForAlignment();
300 if (ala.graph == refan.graph)
302 for (int p = 0; p < ala.annotations.length; p++)
308 "Mismatch at alignment position " + p,
309 (alaa.annotations[p] == null && refan.annotations[p] == null)
310 || alaa.annotations[p].value == refan.annotations[p].value);
311 } catch (NullPointerException q)
313 Assert.fail("Mismatch of alignment annotations at position "
314 + p + " Ref seq ann: " + refan.annotations[p]
315 + " alignment " + alaa.annotations[p]);
323 @Test(groups = { "Functional" })
324 public void testCopyViewSettings() throws Exception
326 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
327 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
328 assertTrue("Didn't read in the example file correctly.", af != null);
329 AlignmentViewPanel sps = null, groups = null;
330 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
332 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
336 if (ap.getViewName().contains("MAFFT"))
341 assertTrue("Couldn't find the structure view", sps != null);
342 assertTrue("Couldn't find the MAFFT view", groups != null);
344 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
345 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
346 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
348 groups.getAlignViewport().setViewStyle(structureStyle);
349 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
351 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
357 * test store and recovery of expanded views - currently this is disabled
358 * since the Desktop.explodeViews method doesn't seem to result in the views
359 * being expanded to distinct align frames when executed programmatically.
363 @Test(groups = { "Functional" }, enabled = false)
364 public void testStoreAndRecoverExpandedviews() throws Exception
366 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
367 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
368 assertTrue("Didn't read in the example file correctly.", af != null);
369 String afid = af.getViewport().getSequenceSetId();
371 final AlignFrame xaf = af;
373 new Thread(new Runnable()
378 Desktop.instance.explodeViews(xaf);
384 // while (++times < 5 && Desktop.getAlignFrames().length < )
386 // Thread.sleep(300);
388 int oldviews = Desktop.getAlignFrames().length;
389 Assert.assertEquals(Desktop.getAlignFrames().length,
390 Desktop.getAlignmentPanels(afid).length);
391 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
394 new Jalview2XML(false).saveState(tfile);
397 Assert.fail("Didn't save the expanded view state", e);
398 } catch (Exception e)
400 Assert.fail("Didn't save the expanded view state", e);
402 Desktop.instance.closeAll_actionPerformed(null);
403 if (Desktop.getAlignFrames() != null)
405 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
407 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
408 tfile.getAbsolutePath(), FormatAdapter.FILE);
409 Assert.assertNotNull(af);
411 Desktop.getAlignFrames().length,
412 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
415 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
419 * based on above test store and recovery of expanded views.
423 @Test(groups = { "Functional" }, enabled = true)
424 public void testStoreAndRecoverReferenceSeqSettings() throws Exception
428 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
429 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
430 assertTrue("Didn't read in the example file correctly.", af != null);
431 afid = af.getViewport().getSequenceSetId();
433 Map<String, SequenceI> refs = new HashMap<String, SequenceI>();
435 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
437 // mark representative
438 SequenceI rep = ap.getAlignment().getSequenceAt(
439 n++ % ap.getAlignment().getHeight());
440 refs.put(ap.getViewName(), rep);
441 // code from mark/unmark sequence as reference in jalview.gui.PopupMenu
442 // todo refactor the to an alignment view controller
443 ap.getAlignViewport().setDisplayReferenceSeq(true);
444 ap.getAlignViewport().setColourByReferenceSeq(true);
445 ap.getAlignViewport().getAlignment().setSeqrep(rep);
447 File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
451 new Jalview2XML(false).saveState(tfile);
454 Assert.fail("Didn't save the expanded view state", e);
455 } catch (Exception e)
457 Assert.fail("Didn't save the expanded view state", e);
459 Desktop.instance.closeAll_actionPerformed(null);
460 if (Desktop.getAlignFrames() != null)
462 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
465 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
466 tfile.getAbsolutePath(), FormatAdapter.FILE);
467 afid = af.getViewport().getSequenceSetId();
469 for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
471 // check representative
472 SequenceI rep = ap.getAlignment().getSeqrep();
473 Assert.assertNotNull(rep,
474 "Couldn't restore sequence representative from project");
475 // can't use a strong equals here, because by definition, the sequence IDs
476 // will be different.
477 // could set vamsas session save/restore flag to preserve IDs across
479 Assert.assertEquals(refs.get(ap.getViewName()).toString(),
481 "Representative wasn't the same when recovered.");
482 Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
483 "Display reference sequence view setting not set.");
484 Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
485 "Colour By Reference Seq view setting not set.");
489 @Test(groups = { "Functional" })
490 public void testIsVersionStringLaterThan()
493 * No version / development / test / autobuild is leniently assumed to be
496 assertTrue(Jalview2XML.isVersionStringLaterThan(null, null));
497 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null));
498 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3"));
499 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
500 "Development Build"));
501 assertTrue(Jalview2XML.isVersionStringLaterThan(null,
502 "DEVELOPMENT BUILD"));
503 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
504 "Development Build"));
505 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test"));
506 assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST"));
507 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test"));
508 assertTrue(Jalview2XML
509 .isVersionStringLaterThan(null, "Automated Build"));
510 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
512 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3",
516 * same version returns true i.e. compatible
518 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8"));
519 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3"));
520 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1"));
521 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1"));
522 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1"));
525 * later version returns true
527 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4"));
528 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9"));
529 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2"));
530 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3"));
531 assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1"));
534 * earlier version returns false
536 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8"));
537 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3"));
538 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3"));
539 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1"));
540 assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1"));