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.assertFalse;
24 import static org.testng.AssertJUnit.assertEquals;
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;
37 import java.io.IOException;
38 import java.util.List;
40 import org.testng.annotations.BeforeClass;
41 import org.testng.annotations.BeforeMethod;
42 import org.testng.annotations.Test;
45 * Unit tests for AnnotationChooser
50 public class AnnotationColumnChooserTest
52 @BeforeClass(alwaysRun = true)
53 public void setUpJvOptionPane()
55 JvOptionPane.setInteractiveMode(false);
56 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
59 // 4 sequences x 13 positions
60 final static String TEST_DATA = ">FER_CAPAA Ferredoxin\n"
62 + ">FER_CAPAN Ferredoxin, chloroplast precursor\n"
64 + ">FER1_SOLLC Ferredoxin-1, chloroplast precursor\n"
65 + "TIETHKEEELTA-\n" + ">Q93XJ9_SOLTU Ferredoxin I precursor\n"
68 AnnotationChooser testee;
70 AlignmentPanel parentPanel;
74 @BeforeMethod(alwaysRun = true)
75 public void setUp() throws IOException
77 Cache.loadProperties("test/jalview/io/testProps.jvprops");
78 // pin down annotation sort order for test
79 Cache.applicationProperties.setProperty(Preferences.SORT_ANNOTATIONS,
80 SequenceAnnotationOrder.NONE.name());
81 final String TRUE = Boolean.TRUE.toString();
82 Cache.applicationProperties.setProperty(Preferences.SHOW_AUTOCALC_ABOVE,
84 Cache.applicationProperties.setProperty("SHOW_QUALITY", TRUE);
85 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", TRUE);
86 Cache.applicationProperties.setProperty("SHOW_IDENTITY", TRUE);
88 AlignmentI al = new FormatAdapter().readFile(TEST_DATA,
89 DataSourceType.PASTE, FileFormat.Fasta);
90 af = new AlignFrame(al, 700, 500);
91 parentPanel = new AlignmentPanel(af, af.getViewport());
96 * Add 4 annotations, 3 of them sequence-specific.
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'
103 private void addAnnotations()
105 Annotation an = new Annotation(2f);
106 Annotation[] anns = new Annotation[] { an, an, an };
107 AlignmentAnnotation ann0 = new AlignmentAnnotation("IUPRED", "", anns);
108 AlignmentAnnotation ann1 = new AlignmentAnnotation("Beauty", "", anns);
109 AlignmentAnnotation ann2 = new AlignmentAnnotation("JMol", "", anns);
110 AlignmentAnnotation ann3 = new AlignmentAnnotation("IUPRED", "", anns);
111 AlignmentAnnotation ann4 = new AlignmentAnnotation("JMol", "", anns);
112 SequenceI[] seqs = parentPanel.getAlignment().getSequencesArray();
113 ann0.setSequenceRef(seqs[0]);
114 ann2.setSequenceRef(seqs[3]);
115 ann3.setSequenceRef(seqs[2]);
116 ann4.setSequenceRef(seqs[1]);
117 parentPanel.getAlignment().addAnnotation(ann0);
118 parentPanel.getAlignment().addAnnotation(ann1);
119 parentPanel.getAlignment().addAnnotation(ann2);
120 parentPanel.getAlignment().addAnnotation(ann3);
121 parentPanel.getAlignment().addAnnotation(ann4);
127 @Test(groups = { "Functional" })
128 public void testReset()
130 AnnotationColumnChooser acc = new AnnotationColumnChooser(
131 af.getViewport(), af.alignPanel);
133 HiddenColumns oldhidden = new HiddenColumns();
134 oldhidden.hideColumns(10, 20);
135 acc.setOldHiddenColumns(oldhidden);
137 HiddenColumns newHidden = new HiddenColumns();
138 newHidden.hideColumns(0, 3);
139 newHidden.hideColumns(22, 25);
140 af.getViewport().setHiddenColumns(newHidden);
142 HiddenColumns currentHidden = af.getViewport().getAlignment()
144 List<int[]> regions = currentHidden.getHiddenColumnsCopy();
145 assertEquals(regions.get(0)[0], 0);
146 assertEquals(regions.get(0)[1], 3);
147 assertEquals(regions.get(1)[0], 22);
148 assertEquals(regions.get(1)[1], 25);
150 // now reset hidden columns
152 currentHidden = af.getViewport().getAlignment().getHiddenColumns();
153 regions = currentHidden.getHiddenColumnsCopy();
154 assertEquals(regions.get(0)[0], 10);
155 assertEquals(regions.get(0)[1], 20);
157 // check works with empty hidden columns as old columns
158 oldhidden = new HiddenColumns();
159 acc.setOldHiddenColumns(oldhidden);
161 currentHidden = af.getViewport().getAlignment().getHiddenColumns();
162 assertFalse(currentHidden.hasHiddenColumns());
164 // check works with empty hidden columns as new columns
165 oldhidden.hideColumns(10, 20);
166 acc.setOldHiddenColumns(oldhidden);
167 currentHidden = af.getViewport().getAlignment().getHiddenColumns();
168 assertFalse(currentHidden.hasHiddenColumns());
171 currentHidden = af.getViewport().getAlignment().getHiddenColumns();
172 regions = currentHidden.getHiddenColumnsCopy();
173 assertEquals(regions.get(0)[0], 10);
174 assertEquals(regions.get(0)[1], 20);