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.*;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.SequenceGroup;
26 import jalview.datamodel.SequenceI;
27 import jalview.gui.AlignFrame;
28 import jalview.gui.Desktop;
29 import jalview.schemes.AnnotationColourGradient;
30 import jalview.schemes.ColourSchemeI;
34 import org.junit.AfterClass;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
38 public class Jalview2xmlTests
42 * @throws java.lang.Exception
45 public static void setUpBeforeClass() throws Exception
47 jalview.bin.Jalview.main(new String[]
48 { "-props", "test/src/jalview/io/testProps.jvprops" });
52 * @throws java.lang.Exception
55 public static void tearDownAfterClass() throws Exception
57 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
61 public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
64 for (SequenceI sq : avp.getAlignment().getDataset().getSequences())
66 if (sq.getAnnotation() != null)
68 for (AlignmentAnnotation dssa : sq.getAnnotation())
70 if (dssa.isValidStruc())
81 public void testRNAStructureRecovery() throws Exception
83 String inFile = "examples/RF00031_folded.stk";
84 String tfile = File.createTempFile("JalviewTest", ".jvp")
86 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
87 inFile, FormatAdapter.FILE);
88 assertTrue("Didn't read input file " + inFile, af != null);
89 int olddsann = countDsAnn(af.getViewport());
90 assertTrue("Didn't find any dataset annotations", olddsann > 0);
91 af.rnahelicesColour_actionPerformed(null);
93 "Couldn't apply RNA helices colourscheme",
94 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
95 assertTrue("Failed to store as a project.",
96 af.saveAlignment(tfile, "Jalview"));
97 af.closeMenuItem_actionPerformed(true);
99 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
101 assertTrue("Failed to import new project", af != null);
102 int newdsann = countDsAnn(af.getViewport());
104 "Differing numbers of dataset sequence annotation\nOriginally "
105 + olddsann + " and now " + newdsann,
106 olddsann == newdsann);
108 .println("Read in same number of annotations as originally present ("
111 "RNA helices colourscheme was not applied on import.",
112 af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
116 public void testTCoffeeScores() throws Exception
118 String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
119 String tfile = File.createTempFile("JalviewTest", ".jvp")
121 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
122 inFile, FormatAdapter.FILE);
123 assertTrue("Didn't read input file " + inFile, af != null);
124 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
126 "Didn't set T-coffee colourscheme",
127 af.getViewport().getGlobalColourScheme().getClass()
128 .equals(jalview.schemes.TCoffeeColourScheme.class));
130 "Recognise T-Coffee score from string",
131 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
133 jalview.schemes.ColourSchemeProperty.getColourName(af
134 .getViewport().getGlobalColourScheme())) != null);
136 assertTrue("Failed to store as a project.",
137 af.saveAlignment(tfile, "Jalview"));
138 af.closeMenuItem_actionPerformed(true);
140 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
142 assertTrue("Failed to import new project", af != null);
144 "Didn't set T-coffee colourscheme for imported project.",
145 af.getViewport().getGlobalColourScheme().getClass()
146 .equals(jalview.schemes.TCoffeeColourScheme.class));
148 .println("T-Coffee score shading successfully recovered from project.");
152 public void testColourByAnnotScores() throws Exception
154 String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
155 String tfile = File.createTempFile("JalviewTest", ".jvp")
157 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
158 inFile, FormatAdapter.FILE);
159 assertTrue("Didn't read input file " + inFile, af != null);
160 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null);
161 AlignmentAnnotation[] aa = af.getViewport().getAlignment()
162 .getSequenceAt(0).getAnnotation("IUPredWS (Short)");
164 "Didn't find any IUPred annotation to use to shade alignment.",
165 aa != null && aa.length > 0);
166 AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient(
167 aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD);
168 AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient(
169 aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD);
170 cs.setSeqAssociated(true);
171 gcs.setSeqAssociated(true);
173 SequenceGroup sg = new SequenceGroup();
177 af.getViewport().getAlignment().addGroup(sg);
178 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
179 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
180 af.alignPanel.alignmentChanged();
181 assertTrue("Failed to store as a project.",
182 af.saveAlignment(tfile, "Jalview"));
183 af.closeMenuItem_actionPerformed(true);
185 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
187 assertTrue("Failed to import new project", af != null);
189 // check for group and alignment colourschemes
191 ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
192 ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
194 assertTrue("Didn't recover global colourscheme", _rcs != null);
195 assertTrue("Didn't recover annotation colour global scheme",
196 _rcs instanceof AnnotationColourGradient);
197 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
198 assertTrue("Annotation colourscheme wasn't sequence associated",
199 __rcs.isSeqAssociated());
201 boolean diffseqcols = false, diffgseqcols = false;
202 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
203 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
204 && (!diffseqcols || !diffgseqcols); p++)
206 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0]) != _rcs
207 .findColour(sqs[5].getCharAt(p), p, sqs[5]))
212 assertTrue("Got Different sequence colours", diffseqcols);
214 .println("Per sequence colourscheme (Background) successfully applied and recovered.");
216 assertTrue("Didn't recover group colourscheme", _rgcs != null);
217 assertTrue("Didn't recover annotation colour group colourscheme",
218 _rgcs instanceof AnnotationColourGradient);
219 __rcs = (AnnotationColourGradient) _rgcs;
220 assertTrue("Group Annotation colourscheme wasn't sequence associated",
221 __rcs.isSeqAssociated());
223 for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
224 && (!diffseqcols || !diffgseqcols); p++)
226 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1]) != _rgcs
227 .findColour(sqs[2].getCharAt(p), p, sqs[2]))
232 assertTrue("Got Different group sequence colours", diffgseqcols);
234 .println("Per sequence (Group) colourscheme successfully applied and recovered.");
238 public void gatherViewsHere() throws Exception
240 int origCount = Desktop.getAlignframes().length;
241 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
242 "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
243 assertTrue("Didn't read in the example file correctly.", af != null);
244 assertTrue("Didn't gather the views in the example file.",
245 Desktop.getAlignframes().length == 1 + origCount);