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.
21 package jalview.controller;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
26 import jalview.analysis.Finder;
27 import jalview.api.AlignViewControllerI;
28 import jalview.datamodel.SearchResults;
29 import jalview.datamodel.SearchResultsI;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceFeature;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
34 import jalview.gui.AlignFrame;
35 import jalview.gui.JvOptionPane;
36 import jalview.io.DataSourceType;
37 import jalview.io.FileLoader;
39 import java.util.Arrays;
40 import java.util.BitSet;
42 import org.testng.annotations.BeforeClass;
43 import org.testng.annotations.Test;
45 public class AlignViewControllerTest
48 @BeforeClass(alwaysRun = true)
49 public void setUpJvOptionPane()
51 JvOptionPane.setInteractiveMode(false);
52 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
55 @Test(groups = "Functional")
56 public void testFindColumnsWithFeature()
58 SequenceI seq1 = new Sequence("seq1", "-a-MMMaaaaaaaaaaaaaaaa");
59 SequenceI seq2 = new Sequence("seq2", "aa--aMM-MMMMMaaaaaaaaaa");
60 SequenceI seq3 = new Sequence("seq3", "abcab-caD-aaMMMMMaaaaa");
61 SequenceI seq4 = new Sequence("seq4", "abc--abcaaaaaaaaaaaaaa");
64 * features start/end are base 1
66 seq1.addSequenceFeature(new SequenceFeature("Metal", "desc", 2, 4, 0f,
68 seq1.addSequenceFeature(new SequenceFeature("Helix", "desc", 1, 15, 0f,
70 seq2.addSequenceFeature(new SequenceFeature("Metal", "desc", 4, 10, 0f,
72 seq3.addSequenceFeature(new SequenceFeature("Metal", "desc", 11, 15,
74 // disulfide bond is a 'contact feature' - only select its 'start' and 'end'
75 seq3.addSequenceFeature(new SequenceFeature("disulfide bond", "desc", 8, 12,
79 * select the first five columns --> Metal in seq1 cols 4-5
81 SequenceGroup sg = new SequenceGroup();
82 sg.setStartRes(0); // base 0
84 sg.addSequence(seq1, false);
85 sg.addSequence(seq2, false);
86 sg.addSequence(seq3, false);
87 sg.addSequence(seq4, false);
89 BitSet bs = new BitSet();
90 int seqCount = AlignViewController.findColumnsWithFeature("Metal", sg,
92 assertEquals(1, seqCount);
93 assertEquals(2, bs.cardinality());
94 assertTrue(bs.get(3)); // base 0
95 assertTrue(bs.get(4));
98 * select the first seven columns: Metal in seq1 cols 4-6, seq2 cols 6-7
102 seqCount = AlignViewController.findColumnsWithFeature("Metal", sg, bs);
103 assertEquals(2, seqCount);
104 assertEquals(4, bs.cardinality());
105 assertTrue(bs.get(3));
106 assertTrue(bs.get(4));
107 assertTrue(bs.get(5));
108 assertTrue(bs.get(6));
111 * select column 14: Metal in seq3 only
116 seqCount = AlignViewController.findColumnsWithFeature("Metal", sg, bs);
117 assertEquals(1, seqCount);
118 assertEquals(1, bs.cardinality());
119 assertTrue(bs.get(13));
122 * select columns 18-20: no Metal feature
127 seqCount = AlignViewController.findColumnsWithFeature("Metal", sg, bs);
128 assertEquals(0, seqCount);
129 assertEquals(0, bs.cardinality());
132 * columns 11-13 should not match disulfide bond at 8/12
137 seqCount = AlignViewController.findColumnsWithFeature("disulfide bond",
139 assertEquals(0, seqCount);
140 assertEquals(0, bs.cardinality());
143 * columns 6-18 should match disulfide bond at columns 9, 14
148 seqCount = AlignViewController.findColumnsWithFeature("disulfide bond",
150 assertEquals(1, seqCount);
151 assertEquals(2, bs.cardinality());
152 assertTrue(bs.get(8));
153 assertTrue(bs.get(13));
156 * look for a feature that isn't there
161 seqCount = AlignViewController.findColumnsWithFeature("Pfam", sg, bs);
162 assertEquals(0, seqCount);
163 assertEquals(0, bs.cardinality());
167 * shameless copy of test data from findFeature for testing mark columns from
170 @Test(groups = "Functional")
171 public void testSelectColumnsWithHighlight()
173 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
174 "seq1 aMMMaaaaaaaaaaaaaaaa\n" + "seq2 aaaMMMMMMMaaaaaaaaaa\n"
175 + "seq3 aaaaaaaaaaMMMMMaaaaa\n"
176 + "seq4 aaaaaaaaaaaaaaaaaaaa\n", DataSourceType.PASTE);
178 SearchResultsI sr = new SearchResults();
179 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
180 SequenceI seq1 = sqs[0];
181 SequenceI seq2 = sqs[1];
182 SequenceI seq3 = sqs[2];
183 SequenceI seq4 = sqs[3];
186 * features start/end are base 1
188 sr.addResult(seq1, 2, 4);
189 sr.addResult(seq2, 4, 10);
190 sr.addResult(seq3, 11, 15);
193 * test Match/Find works first
195 Finder f = new Finder(af.getViewport().getAlignment(), null);
197 f.setCaseSensitive(true);
200 "Finder found different set of results to manually created SearchResults",
201 sr, f.getSearchResults());
204 * now check simple mark columns from find operation
206 af.getViewport().setSearchResults(sr);
207 AlignViewControllerI avc = af.avc;
209 avc.markHighlightedColumns(false, false, false);
210 assertTrue("Didn't select highlighted columns", Arrays.deepEquals(af
211 .getViewport().getColumnSelection().getSelectedRanges()
212 .toArray(), new int[][] { { 1, 14 } }));