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[] {"-props","test/src/jalview/io/testProps.jvprops"});
51 * @throws java.lang.Exception
54 public static void tearDownAfterClass() throws Exception
56 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
59 public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
62 for (SequenceI sq: avp.getAlignment().getDataset().getSequences()) {
63 if (sq.getAnnotation() != null)
65 for (AlignmentAnnotation dssa : sq.getAnnotation())
67 if (dssa.isValidStruc())
77 public void testRNAStructureRecovery() throws Exception
79 String inFile = "examples/RF00031_folded.stk";
80 String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
81 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
82 assertTrue("Didn't read input file "+inFile, af!=null);
83 int olddsann=countDsAnn(af.getViewport());
84 assertTrue("Didn't find any dataset annotations",olddsann>0);
85 af.rnahelicesColour_actionPerformed(null);
86 assertTrue("Couldn't apply RNA helices colourscheme",af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
87 assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
88 af.closeMenuItem_actionPerformed(true);
90 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
91 assertTrue("Failed to import new project", af!=null);
92 int newdsann=countDsAnn(af.getViewport());
93 assertTrue("Differing numbers of dataset sequence annotation\nOriginally "+olddsann+" and now "+newdsann,olddsann==newdsann);
94 System.out.println("Read in same number of annotations as originally present ("+olddsann+")");
95 assertTrue("RNA helices colourscheme was not applied on import.",af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
98 public void testTCoffeeScores() throws Exception
100 String inFile = "examples/uniref50.fa",inAnnot="examples/uniref50.score_ascii";
101 String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
102 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
103 assertTrue("Didn't read input file "+inFile, af!=null);
104 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null,null);
106 "Didn't set T-coffee colourscheme",
107 af.getViewport().getGlobalColourScheme().getClass()
108 .equals(jalview.schemes.TCoffeeColourScheme.class));
110 "Recognise T-Coffee score from string",
111 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
113 jalview.schemes.ColourSchemeProperty.getColourName(af
114 .getViewport().getGlobalColourScheme())) != null);
116 assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
117 af.closeMenuItem_actionPerformed(true);
119 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
120 assertTrue("Failed to import new project", af!=null);
121 assertTrue("Didn't set T-coffee colourscheme for imported project.",af.getViewport().getGlobalColourScheme().getClass().equals(jalview.schemes.TCoffeeColourScheme.class));
122 System.out.println("T-Coffee score shading successfully recovered from project.");
125 public void testColourByAnnotScores() throws Exception
127 String inFile = "examples/uniref50.fa",inAnnot="examples/testdata/uniref50_iupred.jva";
128 String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
129 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
130 assertTrue("Didn't read input file "+inFile, af!=null);
131 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null,null);
132 AlignmentAnnotation[] aa = af.getViewport().getAlignment().getSequenceAt(0).getAnnotation("IUPredWS (Short)");
133 assertTrue("Didn't find any IUPred annotation to use to shade alignment.",aa!=null && aa.length>0);
134 AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient(aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD);
135 AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient(aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD);
136 cs.setSeqAssociated(true);
137 gcs.setSeqAssociated(true);
139 SequenceGroup sg = new SequenceGroup();
143 af.getViewport().getAlignment().addGroup(sg);
144 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
145 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
146 af.alignPanel.alignmentChanged();
147 assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
148 af.closeMenuItem_actionPerformed(true);
150 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
151 assertTrue("Failed to import new project", af!=null);
153 // check for group and alignment colourschemes
155 ColourSchemeI _rcs=af.getViewport().getGlobalColourScheme();
156 ColourSchemeI _rgcs=af.getViewport().getAlignment().getGroups().get(0).cs;
157 assertTrue("Didn't recover global colourscheme",_rcs!=null);
158 assertTrue("Didn't recover annotation colour global scheme",_rcs instanceof AnnotationColourGradient);
159 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
160 assertTrue("Annotation colourscheme wasn't sequence associated",__rcs.isSeqAssociated());
163 boolean diffseqcols=false,diffgseqcols=false;
164 SequenceI[] sqs=af.getViewport().getAlignment().getSequencesArray();
165 for (int p=0,pSize=af.getViewport().getAlignment().getWidth();p<pSize && (!diffseqcols || !diffgseqcols);p++)
167 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0])!=_rcs.findColour(sqs[5].getCharAt(p), p, sqs[5]))
172 assertTrue("Got Different sequence colours", diffseqcols);
173 System.out.println("Per sequence colourscheme (Background) successfully applied and recovered.");
175 assertTrue("Didn't recover group colourscheme",_rgcs!=null);
176 assertTrue("Didn't recover annotation colour group colourscheme",_rgcs instanceof AnnotationColourGradient);
177 __rcs = (AnnotationColourGradient) _rgcs;
178 assertTrue("Group Annotation colourscheme wasn't sequence associated",__rcs.isSeqAssociated());
180 for (int p=0,pSize=af.getViewport().getAlignment().getWidth();p<pSize && (!diffseqcols || !diffgseqcols);p++)
182 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1])!=_rgcs.findColour(sqs[2].getCharAt(p), p, sqs[2]))
187 assertTrue("Got Different group sequence colours", diffgseqcols);
188 System.out.println("Per sequence (Group) colourscheme successfully applied and recovered.");
191 public void gatherViewsHere() throws Exception
193 int origCount = Desktop.getAlignframes().length;
194 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded("examples/exampleFile_2_7.jar", FormatAdapter.FILE);
195 assertTrue("Didn't read in the example file correctly.",af!=null);
196 assertTrue("Didn't gather the views in the example file.", Desktop.getAlignframes().length==1+origCount);