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.assertTrue;
25 import jalview.api.AlignmentViewPanel;
26 import jalview.api.ViewStyleI;
27 import jalview.bin.Cache;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.SequenceGroup;
30 import jalview.datamodel.SequenceI;
31 import jalview.gui.AlignFrame;
32 import jalview.gui.Desktop;
33 import jalview.gui.Jalview2XML;
34 import jalview.schemes.AnnotationColourGradient;
35 import jalview.schemes.ColourSchemeI;
39 import org.testng.Assert;
40 import org.testng.AssertJUnit;
41 import org.testng.annotations.AfterClass;
42 import org.testng.annotations.BeforeClass;
43 import org.testng.annotations.Test;
45 public class Jalview2xmlTests
49 * @throws java.lang.Exception
51 @BeforeClass(alwaysRun = true)
52 public static void setUpBeforeClass() throws Exception
54 jalview.bin.Jalview.main(new String[] { "-props",
55 "test/jalview/io/testProps.jvprops" });
59 * @throws java.lang.Exception
62 public static void tearDownAfterClass() throws Exception
64 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
68 public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
71 for (SequenceI sq : avp.getAlignment().getDataset().getSequences())
73 if (sq.getAnnotation() != null)
75 for (AlignmentAnnotation dssa : sq.getAnnotation())
77 if (dssa.isValidStruc())
87 @Test(groups = { "Functional" })
88 public void testRNAStructureRecovery() throws Exception
90 String inFile = "examples/RF00031_folded.stk";
91 String tfile = File.createTempFile("JalviewTest", ".jvp")
93 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
94 inFile, FormatAdapter.FILE);
95 assertTrue("Didn't read input file " + inFile, af != null);
96 int olddsann = countDsAnn(af.getViewport());
97 assertTrue("Didn't find any dataset annotations", olddsann > 0);
98 af.rnahelicesColour_actionPerformed(null);
100 "Couldn't apply RNA helices colourscheme",
101 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
102 assertTrue("Failed to store as a project.",
103 af.saveAlignment(tfile, "Jalview"));
104 af.closeMenuItem_actionPerformed(true);
106 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
108 assertTrue("Failed to import new project", af != null);
109 int newdsann = countDsAnn(af.getViewport());
111 "Differing numbers of dataset sequence annotation\nOriginally "
112 + olddsann + " and now " + newdsann,
113 olddsann == newdsann);
115 .println("Read in same number of annotations as originally present ("
118 "RNA helices colourscheme was not applied on import.",
119 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
122 @Test(groups = { "Functional" })
123 public void testTCoffeeScores() throws Exception
125 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
126 String tfile = File.createTempFile("JalviewTest", ".jvp")
128 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
129 inFile, FormatAdapter.FILE);
130 assertTrue("Didn't read input file " + inFile, af != null);
131 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
133 "Didn't set T-coffee colourscheme",
134 af.getViewport().getGlobalColourScheme().getClass()
135 .equals(jalview.schemes.TCoffeeColourScheme.class));
137 "Recognise T-Coffee score from string",
138 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
140 jalview.schemes.ColourSchemeProperty.getColourName(af
141 .getViewport().getGlobalColourScheme())) != null);
143 assertTrue("Failed to store as a project.",
144 af.saveAlignment(tfile, "Jalview"));
145 af.closeMenuItem_actionPerformed(true);
147 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
149 assertTrue("Failed to import new project", af != null);
151 "Didn't set T-coffee colourscheme for imported project.",
152 af.getViewport().getGlobalColourScheme().getClass()
153 .equals(jalview.schemes.TCoffeeColourScheme.class));
155 .println("T-Coffee score shading successfully recovered from project.");
158 @Test(groups = { "Functional" })
159 public void testColourByAnnotScores() throws Exception
161 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
162 String tfile = File.createTempFile("JalviewTest", ".jvp")
164 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
165 inFile, FormatAdapter.FILE);
166 assertTrue("Didn't read input file " + inFile, af != null);
167 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
168 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
169 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
171 "Didn't find any IUPred annotation to use to shade alignment.",
172 aa != null && aa.length > 0);
173 AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient(
174 aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD);
175 AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient(
176 aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD);
177 cs.setSeqAssociated(true);
178 gcs.setSeqAssociated(true);
180 SequenceGroup sg = new SequenceGroup();
184 af.getViewport().getAlignment().addGroup(sg);
185 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
186 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
187 af.alignPanel.alignmentChanged();
188 assertTrue("Failed to store as a project.",
189 af.saveAlignment(tfile, "Jalview"));
190 af.closeMenuItem_actionPerformed(true);
192 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
194 assertTrue("Failed to import new project", af != null);
196 // check for group and alignment colourschemes
198 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
199 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
201 assertTrue("Didn't recover global colourscheme", _rcs != null);
202 assertTrue("Didn't recover annotation colour global scheme",
203 _rcs instanceof AnnotationColourGradient);
204 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
205 assertTrue("Annotation colourscheme wasn't sequence associated",
206 __rcs.isSeqAssociated());
208 boolean diffseqcols = false, diffgseqcols = false;
209 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
210 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
211 && (!diffseqcols || !diffgseqcols); p++)
213 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0]) != _rcs
214 .findColour(sqs[5].getCharAt(p), p, sqs[5]))
219 assertTrue("Got Different sequence colours", diffseqcols);
221 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
223 assertTrue("Didn't recover group colourscheme", _rgcs != null);
224 assertTrue("Didn't recover annotation colour group colourscheme",
225 _rgcs instanceof AnnotationColourGradient);
226 __rcs = (AnnotationColourGradient) _rgcs;
227 assertTrue("Group Annotation colourscheme wasn't sequence associated",
228 __rcs.isSeqAssociated());
230 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
231 && (!diffseqcols || !diffgseqcols); p++)
233 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1]) != _rgcs
234 .findColour(sqs[2].getCharAt(p), p, sqs[2]))
239 assertTrue("Got Different group sequence colours", diffgseqcols);
241 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
244 @Test(groups = { "Functional" })
245 public void gatherViewsHere() throws Exception
247 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
248 .getAlignFrames().length;
249 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
250 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
251 assertTrue("Didn't read in the example file correctly.", af != null);
252 assertTrue("Didn't gather the views in the example file.",
253 Desktop.getAlignFrames().length == 1 + origCount);
257 @Test(groups = { "Functional" })
258 public void viewRefPdbAnnotation() throws Exception
260 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
261 Boolean.TRUE.toString());
262 Cache.applicationProperties.setProperty("ADD_SS_ANN",
263 Boolean.TRUE.toString());
264 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
265 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
266 assertTrue("Didn't read in the example file correctly.", af != null);
267 AlignmentViewPanel sps = null;
268 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
270 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
276 assertTrue("Couldn't find the structure view", sps != null);
277 SequenceI sq = sps.getAlignment().findName("1A70|");
278 AlignmentAnnotation refan = null;
279 for (AlignmentAnnotation ra : sps.getAlignment()
280 .getAlignmentAnnotation())
288 assertTrue("Annotation secondary structure not found.", refan != null);
289 assertTrue("Couldn't find 1a70 null chain", sq != null);
290 // compare the manually added temperature factor annotation
291 // to the track automatically transferred from the pdb structure on load
292 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
294 AlignmentAnnotation alaa;
295 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
296 alaa.adjustForAlignment();
297 if (ala.graph == refan.graph)
299 for (int p = 0; p < ala.annotations.length; p++)
305 "Mismatch at alignment position " + p,
306 (alaa.annotations[p] == null && refan.annotations[p] == null)
307 || alaa.annotations[p].value == refan.annotations[p].value);
308 } catch (NullPointerException q)
310 Assert.fail("Mismatch of alignment annotations at position "
311 + p + " Ref seq ann: " + refan.annotations[p]
312 + " alignment " + alaa.annotations[p]);
320 @Test(groups = { "Functional" })
321 public void testCopyViewSettings() throws Exception
323 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
324 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
325 assertTrue("Didn't read in the example file correctly.", af != null);
326 AlignmentViewPanel sps = null, groups = null;
327 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
329 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
333 if (ap.getViewName().contains("MAFFT"))
338 assertTrue("Couldn't find the structure view", sps != null);
339 assertTrue("Couldn't find the MAFFT view", groups != null);
341 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
342 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
343 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
345 groups.getAlignViewport().setViewStyle(structureStyle);
346 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
348 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
354 * test store and recovery of expanded views - currently this is disabled
355 * since the Desktop.explodeViews method doesn't seem to result in the views
356 * being expanded to distinct align frames when executed programmatically.
360 @Test(groups = { "Functional" }, enabled = false)
361 public void testStoreAndRecoverExpandedviews() throws Exception
363 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
364 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
365 assertTrue("Didn't read in the example file correctly.", af != null);
366 String afid = af.getViewport().getSequenceSetId();
368 final AlignFrame xaf = af;
370 new Thread(new Runnable()
375 Desktop.instance.explodeViews(xaf);
381 // while (++times < 5 && Desktop.getAlignFrames().length < )
383 // Thread.sleep(300);
385 int oldviews = Desktop.getAlignFrames().length;
386 Assert.assertEquals(Desktop.getAlignFrames().length,
387 Desktop.getAlignmentPanels(afid).length);
388 File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
391 new Jalview2XML(false).saveState(tfile);
394 Assert.fail("Didn't save the expanded view state", e);
395 } catch (Exception e)
397 Assert.fail("Didn't save the expanded view state", e);
399 Desktop.instance.closeAll_actionPerformed(null);
400 if (Desktop.getAlignFrames() != null)
402 Assert.assertEquals(Desktop.getAlignFrames().length, 0);
404 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
405 tfile.getAbsolutePath(), FormatAdapter.FILE);
406 Assert.assertNotNull(af);
408 Desktop.getAlignFrames().length,
409 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
412 Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);