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.schemes.AnnotationColourGradient;
34 import jalview.schemes.ColourSchemeI;
38 import org.testng.Assert;
39 import org.testng.AssertJUnit;
40 import org.testng.annotations.AfterClass;
41 import org.testng.annotations.BeforeClass;
42 import org.testng.annotations.Test;
44 public class Jalview2xmlTests
48 * @throws java.lang.Exception
51 public static void setUpBeforeClass() throws Exception
53 jalview.bin.Jalview.main(new String[]
54 { "-props", "test/jalview/io/testProps.jvprops" });
58 * @throws java.lang.Exception
61 public static void tearDownAfterClass() throws Exception
63 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
67 public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
70 for (SequenceI sq : avp.getAlignment().getDataset().getSequences())
72 if (sq.getAnnotation() != null)
74 for (AlignmentAnnotation dssa : sq.getAnnotation())
76 if (dssa.isValidStruc())
87 public void testRNAStructureRecovery() throws Exception
89 String inFile = "examples/RF00031_folded.stk";
90 String tfile = File.createTempFile("JalviewTest", ".jvp")
92 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
93 inFile, FormatAdapter.FILE);
94 assertTrue("Didn't read input file " + inFile, af != null);
95 int olddsann = countDsAnn(af.getViewport());
96 assertTrue("Didn't find any dataset annotations", olddsann > 0);
97 af.rnahelicesColour_actionPerformed(null);
99 "Couldn't apply RNA helices colourscheme",
100 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
101 assertTrue("Failed to store as a project.",
102 af.saveAlignment(tfile, "Jalview"));
103 af.closeMenuItem_actionPerformed(true);
105 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
107 assertTrue("Failed to import new project", af != null);
108 int newdsann = countDsAnn(af.getViewport());
110 "Differing numbers of dataset sequence annotation\nOriginally "
111 + olddsann + " and now " + newdsann,
112 olddsann == newdsann);
114 .println("Read in same number of annotations as originally present ("
117 "RNA helices colourscheme was not applied on import.",
118 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
122 public void testTCoffeeScores() throws Exception
124 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
125 String tfile = File.createTempFile("JalviewTest", ".jvp")
127 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
128 inFile, FormatAdapter.FILE);
129 assertTrue("Didn't read input file " + inFile, af != null);
130 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
132 "Didn't set T-coffee colourscheme",
133 af.getViewport().getGlobalColourScheme().getClass()
134 .equals(jalview.schemes.TCoffeeColourScheme.class));
136 "Recognise T-Coffee score from string",
137 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
139 jalview.schemes.ColourSchemeProperty.getColourName(af
140 .getViewport().getGlobalColourScheme())) != null);
142 assertTrue("Failed to store as a project.",
143 af.saveAlignment(tfile, "Jalview"));
144 af.closeMenuItem_actionPerformed(true);
146 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
148 assertTrue("Failed to import new project", af != null);
150 "Didn't set T-coffee colourscheme for imported project.",
151 af.getViewport().getGlobalColourScheme().getClass()
152 .equals(jalview.schemes.TCoffeeColourScheme.class));
154 .println("T-Coffee score shading successfully recovered from project.");
158 public void testColourByAnnotScores() throws Exception
160 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
161 String tfile = File.createTempFile("JalviewTest", ".jvp")
163 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
164 inFile, FormatAdapter.FILE);
165 assertTrue("Didn't read input file " + inFile, af != null);
166 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
167 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
168 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
170 "Didn't find any IUPred annotation to use to shade alignment.",
171 aa != null && aa.length > 0);
172 AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient(
173 aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD);
174 AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient(
175 aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD);
176 cs.setSeqAssociated(true);
177 gcs.setSeqAssociated(true);
179 SequenceGroup sg = new SequenceGroup();
183 af.getViewport().getAlignment().addGroup(sg);
184 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
185 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
186 af.alignPanel.alignmentChanged();
187 assertTrue("Failed to store as a project.",
188 af.saveAlignment(tfile, "Jalview"));
189 af.closeMenuItem_actionPerformed(true);
191 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
193 assertTrue("Failed to import new project", af != null);
195 // check for group and alignment colourschemes
197 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
198 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
200 assertTrue("Didn't recover global colourscheme", _rcs != null);
201 assertTrue("Didn't recover annotation colour global scheme",
202 _rcs instanceof AnnotationColourGradient);
203 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
204 assertTrue("Annotation colourscheme wasn't sequence associated",
205 __rcs.isSeqAssociated());
207 boolean diffseqcols = false, diffgseqcols = false;
208 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
209 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
210 && (!diffseqcols || !diffgseqcols); p++)
212 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0]) != _rcs
213 .findColour(sqs[5].getCharAt(p), p, sqs[5]))
218 assertTrue("Got Different sequence colours", diffseqcols);
220 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
222 assertTrue("Didn't recover group colourscheme", _rgcs != null);
223 assertTrue("Didn't recover annotation colour group colourscheme",
224 _rgcs instanceof AnnotationColourGradient);
225 __rcs = (AnnotationColourGradient) _rgcs;
226 assertTrue("Group Annotation colourscheme wasn't sequence associated",
227 __rcs.isSeqAssociated());
229 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
230 && (!diffseqcols || !diffgseqcols); p++)
232 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1]) != _rgcs
233 .findColour(sqs[2].getCharAt(p), p, sqs[2]))
238 assertTrue("Got Different group sequence colours", diffgseqcols);
240 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
244 public void gatherViewsHere() throws Exception
246 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
247 .getAlignFrames().length;
248 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
249 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
250 assertTrue("Didn't read in the example file correctly.", af != null);
251 assertTrue("Didn't gather the views in the example file.",
252 Desktop.getAlignFrames().length == 1 + origCount);
257 public void viewRefPdbAnnotation() throws Exception
259 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
260 Boolean.TRUE.toString());
261 Cache.applicationProperties.setProperty("ADD_SS_ANN",
262 Boolean.TRUE.toString());
263 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
264 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
265 assertTrue("Didn't read in the example file correctly.", af != null);
266 AlignmentViewPanel sps = null;
267 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
269 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
275 assertTrue("Couldn't find the structure view", sps != null);
276 SequenceI sq = sps.getAlignment().findName("1A70|");
277 AlignmentAnnotation refan = null;
278 for (AlignmentAnnotation ra:sps.getAlignment().getAlignmentAnnotation())
286 assertTrue("Annotation secondary structure not found.",refan!=null);
287 assertTrue("Couldn't find 1a70 null chain", sq != null);
288 // compare the manually added temperature factor annotation
289 // to the track automatically transferred from the pdb structure on load
290 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
292 AlignmentAnnotation alaa;
293 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
294 alaa.adjustForAlignment();
295 if (ala.graph == refan.graph)
297 for (int p = 0; p < ala.annotations.length; p++)
302 "Mismatch at alignment position " + p,
303 (alaa.annotations[p] == null && refan.annotations[p] == null)
304 || alaa.annotations[p].value == refan.annotations[p].value);
306 catch (NullPointerException q)
308 Assert.fail("Mismatch of alignment annotations at position " + p
309 + " Ref seq ann: " + refan.annotations[p]
310 + " alignment " + alaa.annotations[p]);
319 public void testCopyViewSettings() throws Exception
321 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
322 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
323 assertTrue("Didn't read in the example file correctly.", af != null);
324 AlignmentViewPanel sps = null, groups = null;
325 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
327 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
331 if (ap.getViewName().contains("MAFFT"))
336 assertTrue("Couldn't find the structure view", sps != null);
337 assertTrue("Couldn't find the MAFFT view", groups != null);
339 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
340 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
341 AssertJUnit.assertFalse(structureStyle.sameStyle(groupStyle));
343 groups.getAlignViewport().setViewStyle(structureStyle);
344 AssertJUnit.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
346 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()