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;
43 import jalview.util.Platform;
45 public class AnnotationLabelsTest2
47 private static double scaling;
49 @BeforeClass(alwaysRun = true)
50 public static void setUpBeforeClass() throws Exception
52 if (Desktop.instance != null)
53 Desktop.instance.closeAll_actionPerformed(null);
57 * use read-only test properties file
59 Cache.loadProperties("test/jalview/io/testProps.jvprops");
60 Jalview.main(new String[] { "--nonews", "--nosplash", });
62 scaling = JvSwingUtilsTest.getScaling(Desktop.instance);
65 @AfterMethod(alwaysRun = true)
66 public void tearDown()
68 if (Desktop.instance != null)
69 Desktop.instance.closeAll_actionPerformed(null);
73 * configure (read-only) properties for test to ensure Consensus is computed
74 * for colour Above PID testing
76 @BeforeMethod(alwaysRun = true)
79 Cache.loadProperties("test/jalview/io/testProps.jvprops");
80 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
81 Boolean.TRUE.toString());
85 public static void setUpJvOptionPane()
87 JvOptionPane.setInteractiveMode(false);
88 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
93 { "Functional", "testTask1" },
94 dataProvider = "openFilesWithIdWidthChanges")
95 public void testIdWidthChanges(String alignmentFilename, boolean wrap,
96 int idWidth1min, int idWidth1max, int manualWidth,
97 String structureFilename, String paeFilename,
98 boolean secondaryStructureView, TFType temperatureFactorType,
99 ViewerType viewerType, int idWidth2min, int idWidth2max)
101 AlignFrame af = new FileLoader()
102 .LoadFileWaitTillLoaded(alignmentFilename, DataSourceType.FILE);
106 Thread.sleep(200); // to allow alignment annotations to open
107 } catch (InterruptedException e)
109 // TODO Auto-generated catch block
112 AlignViewport av = af.getCurrentView();
116 idWidth = av.getIdWidth();
117 assertTrue(idWidth > idWidth1min,
118 "idWidth (" + idWidth + ") is not greater than " + idWidth1min);
119 assertTrue(idWidth < idWidth1max, "idWidth (" + idWidth
120 + ") is not narrower than " + idWidth1max);
125 af.setWrapFormat(true, false);
126 idWidth = av.getIdWidth();
127 assertTrue(idWidth > idWidth1min, "After wrap idWidth (" + idWidth
128 + ") is not greater than " + idWidth1min);
129 assertTrue(idWidth < idWidth1max, "After wrap idWidth (" + idWidth
130 + ") is not narrower than" + idWidth1max);
133 AlignmentI al = av.getAlignment();
134 SequenceI s = al.getSequenceAt(0);
135 AlignmentPanel ap = af.alignPanel;
137 File structureFile = new File(structureFilename);
138 File paeFile = new File(paeFilename);
140 StructureViewer sv = StructureChooser.openStructureFileForSequence(null,
141 null, ap, s, false, structureFile.getAbsolutePath(),
142 temperatureFactorType, paeFile.getAbsolutePath(), true,
143 secondaryStructureView, false, viewerType);
144 // give time for annotations to open
147 Thread.sleep(200); // to allow alignment annotations to open
148 } catch (InterruptedException e)
150 // TODO Auto-generated catch block
154 // idWidth = ap.getIdPanel().getWidth();
155 idWidth = av.getIdWidth();
156 assertTrue(idWidth >= idWidth2min,
157 "idWidth (" + idWidth + ") is not greater than " + idWidth2min);
158 assertTrue(idWidth <= idWidth2max, "idWidth (" + idWidth
159 + ") is not narrower than " + idWidth2max);
164 { "Functional", "testTask1" },
165 dataProvider = "openFilesWithIdWidthChanges")
166 public void testIdWidthNoChanges(String alignmentFilename, boolean wrap,
167 int idWidth1min, int idWidth1max, int manualWidth,
168 String structureFilename, String paeFilename,
169 boolean secondaryStructureView, TFType temperatureFactorType,
170 ViewerType viewerType, int idWidth2min, int idWidth2max)
172 AlignFrame af = new FileLoader()
173 .LoadFileWaitTillLoaded(alignmentFilename, DataSourceType.FILE);
176 Thread.sleep(200); // to allow alignment annotations to open
177 } catch (InterruptedException e)
179 // TODO Auto-generated catch block
182 AlignViewport av = af.getCurrentView();
185 idWidth = av.getIdWidth();
186 assertTrue(idWidth > idWidth1min,
187 "idWidth (" + idWidth + ") is not greater than " + idWidth1min);
188 assertTrue(idWidth < idWidth1max,
189 "idWidth (" + idWidth + ") is not narrower than" + idWidth1max);
191 AlignmentI al = av.getAlignment();
192 SequenceI s = al.getSequenceAt(0);
193 AlignmentPanel ap = af.alignPanel;
195 // set width manually
196 av.setIdWidth(manualWidth);
197 ap.validateAnnotationDimensions(false);
198 ap.paintAlignment(true, false);
199 ap.getIdPanel().getIdCanvas().setManuallyAdjusted(true);
201 idWidth = av.getIdWidth();
202 assertEquals(idWidth, manualWidth,
203 "idWidth is not set to the manually set width " + manualWidth);
205 File structureFile = new File(structureFilename);
206 File paeFile = new File(paeFilename);
208 StructureViewer sv = StructureChooser.openStructureFileForSequence(null,
209 null, ap, s, false, structureFile.getAbsolutePath(),
210 temperatureFactorType, paeFile.getAbsolutePath(), false,
211 secondaryStructureView, false, viewerType);
213 idWidth = ap.getIdPanel().getWidth();// av.getIdWidth();
214 idWidth = av.getIdWidth();
215 assertEquals(idWidth, manualWidth,
216 "idWidth is not set to the manually set width " + manualWidth
217 + " after adding structure annotations");
218 assertFalse(idWidth > idWidth2min,
219 "idWidth (" + idWidth + ") is greater than " + idWidth2min);
222 @DataProvider(name = "openFilesWithIdWidthChanges")
223 public Object[][] openFilesWithIdWidthChanges()
226 String alignmentFilename,
230 int manualWidth, // ignored by testIdWidthChanges()
231 String structureFilename,
233 boolean secondaryStructureView,
234 TFType temperatureFactorType,
235 ViewerType viewerType,
239 int idWidth2min = scaling == 1.0 ? 114 : 108;
240 int idWidth2max = scaling == 1.0 ? 117 : 114; // was 130
241 if (Platform.isMac())
246 return new Object[][] {
250 { "./test/files/annotation_label_width/sample.a2m", false, 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 },
255 { "./test/files/annotation_label_width/sample.a2m", true, 50, 70,
257 "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb",
258 "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3_scores.json",
259 true, TFType.PLDDT, null, idWidth2min, idWidth2max },