2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
25 import jalview.api.AlignmentViewPanel;
26 import jalview.api.ViewStyleI;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.SequenceGroup;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.AlignFrame;
31 import jalview.gui.Desktop;
32 import jalview.schemes.AnnotationColourGradient;
33 import jalview.schemes.ColourSchemeI;
37 import org.junit.AfterClass;
38 import org.junit.Assert;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
42 public class Jalview2xmlTests
46 * @throws java.lang.Exception
49 public static void setUpBeforeClass() throws Exception
51 jalview.bin.Jalview.main(new String[]
52 { "-props", "test/jalview/io/testProps.jvprops" });
56 * @throws java.lang.Exception
59 public static void tearDownAfterClass() throws Exception
61 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
65 public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
68 for (SequenceI sq : avp.getAlignment().getDataset().getSequences())
70 if (sq.getAnnotation() != null)
72 for (AlignmentAnnotation dssa : sq.getAnnotation())
74 if (dssa.isValidStruc())
85 public void testRNAStructureRecovery() throws Exception
87 String inFile = "examples/RF00031_folded.stk";
88 String tfile = File.createTempFile("JalviewTest", ".jvp")
90 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
91 inFile, FormatAdapter.FILE);
92 assertTrue("Didn't read input file " + inFile, af != null);
93 int olddsann = countDsAnn(af.getViewport());
94 assertTrue("Didn't find any dataset annotations", olddsann > 0);
95 af.rnahelicesColour_actionPerformed(null);
97 "Couldn't apply RNA helices colourscheme",
98 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
99 assertTrue("Failed to store as a project.",
100 af.saveAlignment(tfile, "Jalview"));
101 af.closeMenuItem_actionPerformed(true);
103 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
105 assertTrue("Failed to import new project", af != null);
106 int newdsann = countDsAnn(af.getViewport());
108 "Differing numbers of dataset sequence annotation\nOriginally "
109 + olddsann + " and now " + newdsann,
110 olddsann == newdsann);
112 .println("Read in same number of annotations as originally present ("
115 "RNA helices colourscheme was not applied on import.",
116 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
120 public void testTCoffeeScores() throws Exception
122 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
123 String tfile = File.createTempFile("JalviewTest", ".jvp")
125 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
126 inFile, FormatAdapter.FILE);
127 assertTrue("Didn't read input file " + inFile, af != null);
128 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
130 "Didn't set T-coffee colourscheme",
131 af.getViewport().getGlobalColourScheme().getClass()
132 .equals(jalview.schemes.TCoffeeColourScheme.class));
134 "Recognise T-Coffee score from string",
135 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
137 jalview.schemes.ColourSchemeProperty.getColourName(af
138 .getViewport().getGlobalColourScheme())) != null);
140 assertTrue("Failed to store as a project.",
141 af.saveAlignment(tfile, "Jalview"));
142 af.closeMenuItem_actionPerformed(true);
144 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
146 assertTrue("Failed to import new project", af != null);
148 "Didn't set T-coffee colourscheme for imported project.",
149 af.getViewport().getGlobalColourScheme().getClass()
150 .equals(jalview.schemes.TCoffeeColourScheme.class));
152 .println("T-Coffee score shading successfully recovered from project.");
156 public void testColourByAnnotScores() throws Exception
158 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
159 String tfile = File.createTempFile("JalviewTest", ".jvp")
161 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
162 inFile, FormatAdapter.FILE);
163 assertTrue("Didn't read input file " + inFile, af != null);
164 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
165 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
166 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
168 "Didn't find any IUPred annotation to use to shade alignment.",
169 aa != null && aa.length > 0);
170 AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient(
171 aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD);
172 AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient(
173 aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD);
174 cs.setSeqAssociated(true);
175 gcs.setSeqAssociated(true);
177 SequenceGroup sg = new SequenceGroup();
181 af.getViewport().getAlignment().addGroup(sg);
182 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
183 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
184 af.alignPanel.alignmentChanged();
185 assertTrue("Failed to store as a project.",
186 af.saveAlignment(tfile, "Jalview"));
187 af.closeMenuItem_actionPerformed(true);
189 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
191 assertTrue("Failed to import new project", af != null);
193 // check for group and alignment colourschemes
195 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
196 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
198 assertTrue("Didn't recover global colourscheme", _rcs != null);
199 assertTrue("Didn't recover annotation colour global scheme",
200 _rcs instanceof AnnotationColourGradient);
201 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
202 assertTrue("Annotation colourscheme wasn't sequence associated",
203 __rcs.isSeqAssociated());
205 boolean diffseqcols = false, diffgseqcols = false;
206 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
207 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
208 && (!diffseqcols || !diffgseqcols); p++)
210 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0]) != _rcs
211 .findColour(sqs[5].getCharAt(p), p, sqs[5]))
216 assertTrue("Got Different sequence colours", diffseqcols);
218 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
220 assertTrue("Didn't recover group colourscheme", _rgcs != null);
221 assertTrue("Didn't recover annotation colour group colourscheme",
222 _rgcs instanceof AnnotationColourGradient);
223 __rcs = (AnnotationColourGradient) _rgcs;
224 assertTrue("Group Annotation colourscheme wasn't sequence associated",
225 __rcs.isSeqAssociated());
227 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
228 && (!diffseqcols || !diffgseqcols); p++)
230 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1]) != _rgcs
231 .findColour(sqs[2].getCharAt(p), p, sqs[2]))
236 assertTrue("Got Different group sequence colours", diffgseqcols);
238 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
242 public void gatherViewsHere() throws Exception
244 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
245 .getAlignFrames().length;
246 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
247 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
248 assertTrue("Didn't read in the example file correctly.", af != null);
249 assertTrue("Didn't gather the views in the example file.",
250 Desktop.getAlignFrames().length == 1 + origCount);
255 public void viewRefPdbAnnotation() throws Exception
257 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
258 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
259 assertTrue("Didn't read in the example file correctly.", af != null);
260 AlignmentViewPanel sps = null;
261 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
263 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
269 assertTrue("Couldn't find the structure view", sps != null);
270 SequenceI sq = sps.getAlignment().findName("1A70|");
271 AlignmentAnnotation refan = null;
272 for (AlignmentAnnotation ra:sps.getAlignment().getAlignmentAnnotation())
280 assertTrue("Annotation secondary structure not found.",refan!=null);
281 assertTrue("Couldn't find 1a70 null chain", sq != null);
282 // compare the manually added temperature factor annotation
283 // to the track automatically transferred from the pdb structure on load
284 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
286 AlignmentAnnotation alaa;
287 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
288 alaa.adjustForAlignment();
289 if (ala.graph == refan.graph)
291 for (int p = 0; p < ala.annotations.length; p++)
296 "Mismatch at alignment position " + p,
297 (alaa.annotations[p] == null && refan.annotations[p] == null)
298 || alaa.annotations[p].value == refan.annotations[p].value);
300 catch (NullPointerException q)
302 fail("Mismatch of alignment annotations at position " + p
303 + " Ref seq ann: " + refan.annotations[p]
304 + " alignment " + alaa.annotations[p]);
313 public void testCopyViewSettings() throws Exception
315 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
316 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
317 Assert.assertTrue("Didn't read in the example file correctly.", af != null);
318 AlignmentViewPanel sps = null, groups = null;
319 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
321 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
325 if (ap.getViewName().contains("MAFFT"))
330 assertTrue("Couldn't find the structure view", sps != null);
331 assertTrue("Couldn't find the MAFFT view", groups != null);
333 ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
334 ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
335 Assert.assertFalse(structureStyle.sameStyle(groupStyle));
337 groups.getAlignViewport().setViewStyle(structureStyle);
338 Assert.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
340 Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()