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.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.SequenceGroup;
28 import jalview.datamodel.SequenceI;
29 import jalview.gui.AlignFrame;
30 import jalview.gui.Desktop;
31 import jalview.schemes.AnnotationColourGradient;
32 import jalview.schemes.ColourSchemeI;
36 import org.junit.AfterClass;
37 import org.junit.BeforeClass;
38 import org.junit.Test;
40 public class Jalview2xmlTests
44 * @throws java.lang.Exception
47 public static void setUpBeforeClass() throws Exception
49 jalview.bin.Jalview.main(new String[]
50 { "-props", "test/jalview/io/testProps.jvprops" });
54 * @throws java.lang.Exception
57 public static void tearDownAfterClass() throws Exception
59 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
63 public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
66 for (SequenceI sq : avp.getAlignment().getDataset().getSequences())
68 if (sq.getAnnotation() != null)
70 for (AlignmentAnnotation dssa : sq.getAnnotation())
72 if (dssa.isValidStruc())
83 public void testRNAStructureRecovery() throws Exception
85 String inFile = "examples/RF00031_folded.stk";
86 String tfile = File.createTempFile("JalviewTest", ".jvp")
88 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
89 inFile, FormatAdapter.FILE);
90 assertTrue("Didn't read input file " + inFile, af != null);
91 int olddsann = countDsAnn(af.getViewport());
92 assertTrue("Didn't find any dataset annotations", olddsann > 0);
93 af.rnahelicesColour_actionPerformed(null);
95 "Couldn't apply RNA helices colourscheme",
96 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
97 assertTrue("Failed to store as a project.",
98 af.saveAlignment(tfile, "Jalview"));
99 af.closeMenuItem_actionPerformed(true);
101 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
103 assertTrue("Failed to import new project", af != null);
104 int newdsann = countDsAnn(af.getViewport());
106 "Differing numbers of dataset sequence annotation\nOriginally "
107 + olddsann + " and now " + newdsann,
108 olddsann == newdsann);
110 .println("Read in same number of annotations as originally present ("
113 "RNA helices colourscheme was not applied on import.",
114 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
118 public void testTCoffeeScores() throws Exception
120 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
121 String tfile = File.createTempFile("JalviewTest", ".jvp")
123 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
124 inFile, FormatAdapter.FILE);
125 assertTrue("Didn't read input file " + inFile, af != null);
126 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
128 "Didn't set T-coffee colourscheme",
129 af.getViewport().getGlobalColourScheme().getClass()
130 .equals(jalview.schemes.TCoffeeColourScheme.class));
132 "Recognise T-Coffee score from string",
133 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
135 jalview.schemes.ColourSchemeProperty.getColourName(af
136 .getViewport().getGlobalColourScheme())) != null);
138 assertTrue("Failed to store as a project.",
139 af.saveAlignment(tfile, "Jalview"));
140 af.closeMenuItem_actionPerformed(true);
142 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
144 assertTrue("Failed to import new project", af != null);
146 "Didn't set T-coffee colourscheme for imported project.",
147 af.getViewport().getGlobalColourScheme().getClass()
148 .equals(jalview.schemes.TCoffeeColourScheme.class));
150 .println("T-Coffee score shading successfully recovered from project.");
154 public void testColourByAnnotScores() throws Exception
156 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
157 String tfile = File.createTempFile("JalviewTest", ".jvp")
159 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
160 inFile, FormatAdapter.FILE);
161 assertTrue("Didn't read input file " + inFile, af != null);
162 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
163 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
164 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
166 "Didn't find any IUPred annotation to use to shade alignment.",
167 aa != null && aa.length > 0);
168 AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient(
169 aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD);
170 AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient(
171 aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD);
172 cs.setSeqAssociated(true);
173 gcs.setSeqAssociated(true);
175 SequenceGroup sg = new SequenceGroup();
179 af.getViewport().getAlignment().addGroup(sg);
180 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
181 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
182 af.alignPanel.alignmentChanged();
183 assertTrue("Failed to store as a project.",
184 af.saveAlignment(tfile, "Jalview"));
185 af.closeMenuItem_actionPerformed(true);
187 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
189 assertTrue("Failed to import new project", af != null);
191 // check for group and alignment colourschemes
193 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
194 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
196 assertTrue("Didn't recover global colourscheme", _rcs != null);
197 assertTrue("Didn't recover annotation colour global scheme",
198 _rcs instanceof AnnotationColourGradient);
199 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
200 assertTrue("Annotation colourscheme wasn't sequence associated",
201 __rcs.isSeqAssociated());
203 boolean diffseqcols = false, diffgseqcols = false;
204 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
205 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
206 && (!diffseqcols || !diffgseqcols); p++)
208 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0]) != _rcs
209 .findColour(sqs[5].getCharAt(p), p, sqs[5]))
214 assertTrue("Got Different sequence colours", diffseqcols);
216 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
218 assertTrue("Didn't recover group colourscheme", _rgcs != null);
219 assertTrue("Didn't recover annotation colour group colourscheme",
220 _rgcs instanceof AnnotationColourGradient);
221 __rcs = (AnnotationColourGradient) _rgcs;
222 assertTrue("Group Annotation colourscheme wasn't sequence associated",
223 __rcs.isSeqAssociated());
225 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
226 && (!diffseqcols || !diffgseqcols); p++)
228 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1]) != _rgcs
229 .findColour(sqs[2].getCharAt(p), p, sqs[2]))
234 assertTrue("Got Different group sequence colours", diffgseqcols);
236 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
240 public void gatherViewsHere() throws Exception
242 int origCount = Desktop.getAlignFrames() == null ? 0 : Desktop
243 .getAlignFrames().length;
244 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
245 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
246 assertTrue("Didn't read in the example file correctly.", af != null);
247 assertTrue("Didn't gather the views in the example file.",
248 Desktop.getAlignFrames().length == 1 + origCount);
253 public void viewRefPdbAnnotation() throws Exception
255 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
256 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
257 assertTrue("Didn't read in the example file correctly.", af != null);
258 AlignmentViewPanel sps = null;
259 for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
261 if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
267 assertTrue("Couldn't find the structure view", sps != null);
268 SequenceI sq = sps.getAlignment().findName("1A70|");
269 AlignmentAnnotation refan = null;
270 for (AlignmentAnnotation ra:sps.getAlignment().getAlignmentAnnotation())
278 assertTrue("Annotation secondary structure not found.",refan!=null);
279 assertTrue("Couldn't find 1a70 null chain", sq != null);
280 // compare the manually added temperature factor annotation
281 // to the track automatically transferred from the pdb structure on load
282 for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
284 AlignmentAnnotation alaa;
285 sq.addAlignmentAnnotation(alaa = new AlignmentAnnotation(ala));
286 alaa.adjustForAlignment();
287 if (ala.graph == refan.graph)
289 for (int p = 0; p < ala.annotations.length; p++)
294 "Mismatch at alignment position " + p,
295 (alaa.annotations[p] == null && refan.annotations[p] == null)
296 || alaa.annotations[p].value == refan.annotations[p].value);
298 catch (NullPointerException q)
300 fail("Mismatch of alignment annotations at position " + p
301 + " Ref seq ann: " + refan.annotations[p]
302 + " alignment " + alaa.annotations[p]);