Class |
Line # |
Actions |
|||
---|---|---|---|---|---|
AnnotationColumnChooserTest | 50 | 67 | 4 |
1 | /* | |
2 | * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) | |
3 | * Copyright (C) $$Year-Rel$$ The Jalview Authors | |
4 | * | |
5 | * This file is part of Jalview. | |
6 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
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. | |
20 | */ | |
21 | package jalview.gui; | |
22 | ||
23 | import static org.testng.Assert.assertFalse; | |
24 | import static org.testng.AssertJUnit.assertEquals; | |
25 | ||
26 | import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; | |
27 | import jalview.bin.Cache; | |
28 | import jalview.datamodel.AlignmentAnnotation; | |
29 | import jalview.datamodel.AlignmentI; | |
30 | import jalview.datamodel.Annotation; | |
31 | import jalview.datamodel.HiddenColumns; | |
32 | import jalview.datamodel.SequenceI; | |
33 | import jalview.io.DataSourceType; | |
34 | import jalview.io.FileFormat; | |
35 | import jalview.io.FormatAdapter; | |
36 | ||
37 | import java.io.IOException; | |
38 | import java.util.Iterator; | |
39 | ||
40 | import org.testng.annotations.BeforeClass; | |
41 | import org.testng.annotations.BeforeMethod; | |
42 | import org.testng.annotations.Test; | |
43 | ||
44 | /** | |
45 | * Unit tests for AnnotationChooser | |
46 | * | |
47 | * @author kmourao | |
48 | * | |
49 | */ | |
50 | public class AnnotationColumnChooserTest | |
51 | { | |
52 | 1 | @BeforeClass(alwaysRun = true) |
53 | public void setUpJvOptionPane() | |
54 | { | |
55 | 1 | JvOptionPane.setInteractiveMode(false); |
56 | 1 | JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
57 | } | |
58 | ||
59 | // 4 sequences x 13 positions | |
60 | final static String TEST_DATA = ">FER_CAPAA Ferredoxin\n" | |
61 | + "TIETHKEAELVG-\n" | |
62 | + ">FER_CAPAN Ferredoxin, chloroplast precursor\n" | |
63 | + "TIETHKEAELVG-\n" | |
64 | + ">FER1_SOLLC Ferredoxin-1, chloroplast precursor\n" | |
65 | + "TIETHKEEELTA-\n" + ">Q93XJ9_SOLTU Ferredoxin I precursor\n" | |
66 | + "TIETHKEEELTA-\n"; | |
67 | ||
68 | AnnotationChooser testee; | |
69 | ||
70 | AlignmentPanel parentPanel; | |
71 | ||
72 | AlignFrame af; | |
73 | ||
74 | 1 | @BeforeMethod(alwaysRun = true) |
75 | public void setUp() throws IOException | |
76 | { | |
77 | 1 | Cache.loadProperties("test/jalview/io/testProps.jvprops"); |
78 | // pin down annotation sort order for test | |
79 | 1 | Cache.applicationProperties.setProperty(Preferences.SORT_ANNOTATIONS, |
80 | SequenceAnnotationOrder.NONE.name()); | |
81 | 1 | final String TRUE = Boolean.TRUE.toString(); |
82 | 1 | Cache.applicationProperties.setProperty(Preferences.SHOW_AUTOCALC_ABOVE, |
83 | TRUE); | |
84 | 1 | Cache.applicationProperties.setProperty("SHOW_QUALITY", TRUE); |
85 | 1 | Cache.applicationProperties.setProperty("SHOW_CONSERVATION", TRUE); |
86 | 1 | Cache.applicationProperties.setProperty("SHOW_IDENTITY", TRUE); |
87 | ||
88 | 1 | AlignmentI al = new FormatAdapter().readFile(TEST_DATA, |
89 | DataSourceType.PASTE, FileFormat.Fasta); | |
90 | 1 | af = new AlignFrame(al, 700, 500); |
91 | 1 | parentPanel = new AlignmentPanel(af, af.getViewport()); |
92 | 1 | addAnnotations(); |
93 | } | |
94 | ||
95 | /** | |
96 | * Add 4 annotations, 3 of them sequence-specific. | |
97 | * | |
98 | * <PRE> | |
99 | * ann1 - for sequence 0 - label 'IUPRED' ann2 - not sequence related - label | |
100 | * 'Beauty' ann3 - for sequence 3 - label 'JMol' ann4 - for sequence 2 - label | |
101 | * 'IUPRED' ann5 - for sequence 1 - label 'JMol' | |
102 | */ | |
103 | 1 | private void addAnnotations() |
104 | { | |
105 | 1 | Annotation an = new Annotation(2f); |
106 | 1 | Annotation[] anns = new Annotation[] { an, an, an }; |
107 | 1 | AlignmentAnnotation ann0 = new AlignmentAnnotation("IUPRED", "", anns); |
108 | 1 | AlignmentAnnotation ann1 = new AlignmentAnnotation("Beauty", "", anns); |
109 | 1 | AlignmentAnnotation ann2 = new AlignmentAnnotation("JMol", "", anns); |
110 | 1 | AlignmentAnnotation ann3 = new AlignmentAnnotation("IUPRED", "", anns); |
111 | 1 | AlignmentAnnotation ann4 = new AlignmentAnnotation("JMol", "", anns); |
112 | 1 | SequenceI[] seqs = parentPanel.getAlignment().getSequencesArray(); |
113 | 1 | ann0.setSequenceRef(seqs[0]); |
114 | 1 | ann2.setSequenceRef(seqs[3]); |
115 | 1 | ann3.setSequenceRef(seqs[2]); |
116 | 1 | ann4.setSequenceRef(seqs[1]); |
117 | 1 | parentPanel.getAlignment().addAnnotation(ann0); |
118 | 1 | parentPanel.getAlignment().addAnnotation(ann1); |
119 | 1 | parentPanel.getAlignment().addAnnotation(ann2); |
120 | 1 | parentPanel.getAlignment().addAnnotation(ann3); |
121 | 1 | parentPanel.getAlignment().addAnnotation(ann4); |
122 | } | |
123 | ||
124 | /** | |
125 | * Test reset | |
126 | */ | |
127 | 1 | @Test(groups = { "Functional" }) |
128 | public void testReset() | |
129 | { | |
130 | 1 | AnnotationColumnChooser acc = new AnnotationColumnChooser( |
131 | af.getViewport(), af.alignPanel); | |
132 | ||
133 | 1 | HiddenColumns oldhidden = new HiddenColumns(); |
134 | 1 | oldhidden.hideColumns(10, 20); |
135 | 1 | acc.setOldHiddenColumns(oldhidden); |
136 | ||
137 | 1 | HiddenColumns newHidden = new HiddenColumns(); |
138 | 1 | newHidden.hideColumns(0, 3); |
139 | 1 | newHidden.hideColumns(22, 25); |
140 | 1 | af.getViewport().setHiddenColumns(newHidden); |
141 | ||
142 | 1 | HiddenColumns currentHidden = af.getViewport().getAlignment() |
143 | .getHiddenColumns(); | |
144 | 1 | Iterator<int[]> regions = currentHidden.iterator(); |
145 | 1 | int[] next = regions.next(); |
146 | 1 | assertEquals(0, next[0]); |
147 | 1 | assertEquals(3, next[1]); |
148 | 1 | next = regions.next(); |
149 | 1 | assertEquals(22, next[0]); |
150 | 1 | assertEquals(25, next[1]); |
151 | ||
152 | // now reset hidden columns | |
153 | 1 | acc.reset(); |
154 | 1 | currentHidden = af.getViewport().getAlignment().getHiddenColumns(); |
155 | 1 | regions = currentHidden.iterator(); |
156 | 1 | next = regions.next(); |
157 | 1 | assertEquals(10, next[0]); |
158 | 1 | assertEquals(20, next[1]); |
159 | ||
160 | // check works with empty hidden columns as old columns | |
161 | 1 | oldhidden = new HiddenColumns(); |
162 | 1 | acc.setOldHiddenColumns(oldhidden); |
163 | 1 | acc.reset(); |
164 | 1 | currentHidden = af.getViewport().getAlignment().getHiddenColumns(); |
165 | 1 | assertFalse(currentHidden.hasHiddenColumns()); |
166 | ||
167 | // check works with empty hidden columns as new columns | |
168 | 1 | oldhidden.hideColumns(10, 20); |
169 | 1 | acc.setOldHiddenColumns(oldhidden); |
170 | 1 | currentHidden = af.getViewport().getAlignment().getHiddenColumns(); |
171 | 1 | assertFalse(currentHidden.hasHiddenColumns()); |
172 | ||
173 | 1 | acc.reset(); |
174 | 1 | currentHidden = af.getViewport().getAlignment().getHiddenColumns(); |
175 | 1 | regions = currentHidden.iterator(); |
176 | 1 | next = regions.next(); |
177 | 1 | assertEquals(10, next[0]); |
178 | 1 | assertEquals(20, next[1]); |
179 | } | |
180 | } |