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.Assert.assertEquals;
24 import static org.testng.Assert.assertFalse;
25 import static org.testng.Assert.assertTrue;
29 import org.testng.annotations.AfterMethod;
30 import org.testng.annotations.BeforeClass;
31 import org.testng.annotations.BeforeMethod;
32 import org.testng.annotations.DataProvider;
33 import org.testng.annotations.Test;
35 import jalview.bin.Cache;
36 import jalview.bin.Jalview;
37 import jalview.datamodel.AlignmentI;
38 import jalview.datamodel.SequenceI;
39 import jalview.gui.StructureViewer.ViewerType;
40 import jalview.io.DataSourceType;
41 import jalview.io.FileLoader;
42 import jalview.structure.StructureImportSettings.TFType;
44 public class AnnotationLabelsTest2
46 private static double scaling;
48 @BeforeClass(alwaysRun = true)
49 public static void setUpBeforeClass() throws Exception
51 if (Desktop.instance != null)
52 Desktop.instance.closeAll_actionPerformed(null);
56 * use read-only test properties file
58 Cache.loadProperties("test/jalview/io/testProps.jvprops");
59 Jalview.main(new String[] { "--nonews", "--nosplash", });
61 scaling = JvSwingUtilsTest.getScaling(Desktop.instance);
64 @AfterMethod(alwaysRun = true)
65 public void tearDown()
67 if (Desktop.instance != null)
68 Desktop.instance.closeAll_actionPerformed(null);
72 * configure (read-only) properties for test to ensure Consensus is computed
73 * for colour Above PID testing
75 @BeforeMethod(alwaysRun = true)
78 Cache.loadProperties("test/jalview/io/testProps.jvprops");
79 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
80 Boolean.TRUE.toString());
84 public static void setUpJvOptionPane()
86 JvOptionPane.setInteractiveMode(false);
87 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
92 { "Functional", "testTask1" },
93 dataProvider = "openFilesWithIdWidthChanges")
94 public void testIdWidthChanges(String alignmentFilename, boolean wrap,
95 int idWidth1min, int idWidth1max, int manualWidth,
96 String structureFilename, String paeFilename,
97 boolean secondaryStructureView, TFType temperatureFactorType,
98 ViewerType viewerType, int idWidth2min, int idWidth2max)
100 AlignFrame af = new FileLoader()
101 .LoadFileWaitTillLoaded(alignmentFilename, DataSourceType.FILE);
105 Thread.sleep(200); // to allow alignment annotations to open
106 } catch (InterruptedException e)
108 // TODO Auto-generated catch block
111 AlignViewport av = af.getCurrentView();
115 idWidth = av.getIdWidth();
116 assertTrue(idWidth > idWidth1min,
117 "idWidth (" + idWidth + ") is not greater than " + idWidth1min);
118 assertTrue(idWidth < idWidth1max,
119 "idWidth (" + idWidth + ") is not narrower than" + idWidth1max);
124 af.setWrapFormat(true, false);
125 idWidth = av.getIdWidth();
126 assertTrue(idWidth > idWidth1min, "After wrap idWidth (" + idWidth
127 + ") is not greater than " + idWidth1min);
128 assertTrue(idWidth < idWidth1max, "After wrap idWidth (" + idWidth
129 + ") is not narrower than" + idWidth1max);
132 AlignmentI al = av.getAlignment();
133 SequenceI s = al.getSequenceAt(0);
134 AlignmentPanel ap = af.alignPanel;
136 File structureFile = new File(structureFilename);
137 File paeFile = new File(paeFilename);
139 StructureViewer sv = StructureChooser.openStructureFileForSequence(null,
140 null, ap, s, false, structureFile.getAbsolutePath(),
141 temperatureFactorType, paeFile.getAbsolutePath(), true,
142 secondaryStructureView, false, viewerType);
143 // give time for annotations to open
146 Thread.sleep(200); // to allow alignment annotations to open
147 } catch (InterruptedException e)
149 // TODO Auto-generated catch block
153 // idWidth = ap.getIdPanel().getWidth();
154 idWidth = av.getIdWidth();
155 assertTrue(idWidth >= idWidth2min,
156 "idWidth (" + idWidth + ") is not greater than " + idWidth2min);
157 assertTrue(idWidth <= idWidth2max,
158 "idWidth (" + idWidth + ") is not narrower than" + idWidth2max);
163 { "Functional", "testTask1" },
164 dataProvider = "openFilesWithIdWidthChanges")
165 public void testIdWidthNoChanges(String alignmentFilename, boolean wrap,
166 int idWidth1min, int idWidth1max, int manualWidth,
167 String structureFilename, String paeFilename,
168 boolean secondaryStructureView, TFType temperatureFactorType,
169 ViewerType viewerType, int idWidth2min, int idWidth2max)
171 AlignFrame af = new FileLoader()
172 .LoadFileWaitTillLoaded(alignmentFilename, DataSourceType.FILE);
175 Thread.sleep(200); // to allow alignment annotations to open
176 } catch (InterruptedException e)
178 // TODO Auto-generated catch block
181 AlignViewport av = af.getCurrentView();
184 idWidth = av.getIdWidth();
185 assertTrue(idWidth > idWidth1min,
186 "idWidth (" + idWidth + ") is not greater than " + idWidth1min);
187 assertTrue(idWidth < idWidth1max,
188 "idWidth (" + idWidth + ") is not narrower than" + idWidth1max);
190 AlignmentI al = av.getAlignment();
191 SequenceI s = al.getSequenceAt(0);
192 AlignmentPanel ap = af.alignPanel;
194 // set width manually
195 av.setIdWidth(manualWidth);
196 ap.validateAnnotationDimensions(false);
197 ap.paintAlignment(true, false);
198 ap.getIdPanel().getIdCanvas().setManuallyAdjusted(true);
200 idWidth = av.getIdWidth();
201 assertEquals(idWidth, manualWidth,
202 "idWidth is not set to the manually set width " + manualWidth);
204 File structureFile = new File(structureFilename);
205 File paeFile = new File(paeFilename);
207 StructureViewer sv = StructureChooser.openStructureFileForSequence(null,
208 null, ap, s, false, structureFile.getAbsolutePath(),
209 temperatureFactorType, paeFile.getAbsolutePath(), false,
210 secondaryStructureView, false, viewerType);
212 idWidth = ap.getIdPanel().getWidth();// av.getIdWidth();
213 idWidth = av.getIdWidth();
214 assertEquals(idWidth, manualWidth,
215 "idWidth is not set to the manually set width " + manualWidth
216 + " after adding structure annotations");
217 assertFalse(idWidth > idWidth2min,
218 "idWidth (" + idWidth + ") is greater than " + idWidth2min);
221 @DataProvider(name = "openFilesWithIdWidthChanges")
222 public Object[][] openFilesWithIdWidthChanges()
225 String alignmentFilename,
229 int manualWidth, // ignored by testIdWidthChanges()
230 String structureFilename,
232 boolean secondaryStructureView,
233 TFType temperatureFactorType,
234 ViewerType viewerType,
238 int idWidth2min = scaling == 1.0 ? 114 : 108;
239 int idWidth2max = scaling == 1.0 ? 114 : 114; // was 130
241 return new Object[][] {
245 { "./test/files/annotation_label_width/sample.a2m", false, 50, 70,
247 "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb",
248 "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3_scores.json",
249 true, TFType.PLDDT, null, idWidth2min, idWidth2max },
250 { "./test/files/annotation_label_width/sample.a2m", true, 50, 70,
252 "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb",
253 "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3_scores.json",
254 true, TFType.PLDDT, null, idWidth2min, idWidth2max },