Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 17:27:16 GMT
  2. Package jalview.controller

File AlignViewControllerTest.java

 

Code metrics

0
98
3
1
246
155
3
0.03
32.67
3
1

Classes

Class Line # Actions
AlignViewControllerTest 50 98 3
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

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.controller;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertTrue;
25   
26    import java.awt.Color;
27    import java.util.Arrays;
28    import java.util.BitSet;
29   
30    import org.testng.annotations.BeforeClass;
31    import org.testng.annotations.Test;
32   
33    import jalview.analysis.Finder;
34    import jalview.api.AlignViewControllerI;
35    import jalview.api.FeatureColourI;
36    import jalview.api.FinderI;
37    import jalview.datamodel.Alignment;
38    import jalview.datamodel.SearchResults;
39    import jalview.datamodel.SearchResultsI;
40    import jalview.datamodel.Sequence;
41    import jalview.datamodel.SequenceFeature;
42    import jalview.datamodel.SequenceGroup;
43    import jalview.datamodel.SequenceI;
44    import jalview.gui.AlignFrame;
45    import jalview.gui.JvOptionPane;
46    import jalview.io.DataSourceType;
47    import jalview.io.FileLoader;
48    import jalview.schemes.FeatureColour;
49   
 
50    public class AlignViewControllerTest
51    {
52   
 
53  1 toggle @BeforeClass(alwaysRun = true)
54    public void setUpJvOptionPane()
55    {
56  1 JvOptionPane.setInteractiveMode(false);
57  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
58    }
59   
 
60  1 toggle @Test(groups = "Functional")
61    public void testFindColumnsWithFeature()
62    {
63  1 SequenceI seq1 = new Sequence("seq1", "-a-MMMaaaaaaaaaaaaaaaa");
64  1 SequenceI seq2 = new Sequence("seq2", "aa--aMM-MMMMMaaaaaaaaaa");
65  1 SequenceI seq3 = new Sequence("seq3", "abcab-caD-aaMMMMMaaaaa");
66  1 SequenceI seq4 = new Sequence("seq4", "abc--abcaaaaaaaaaaaaaa");
67   
68    /*
69    * features start/end are base 1
70    */
71  1 seq1.addSequenceFeature(
72    new SequenceFeature("Metal", "desc", 2, 4, 0f, null));
73  1 seq1.addSequenceFeature(
74    new SequenceFeature("Helix", "desc", 1, 15, 0f, null));
75  1 seq2.addSequenceFeature(
76    new SequenceFeature("Metal", "desc", 4, 10, 10f, null));
77  1 seq3.addSequenceFeature(
78    new SequenceFeature("Metal", "desc", 11, 15, 10f, null));
79    // disulfide bond is a 'contact feature' - only select its 'start' and 'end'
80  1 seq3.addSequenceFeature(
81    new SequenceFeature("disulfide bond", "desc", 8, 12, 0f, null));
82   
83    /*
84    * select the first five columns --> Metal in seq1 cols 4-5
85    */
86  1 SequenceGroup sg = new SequenceGroup();
87  1 sg.setStartRes(0); // base 0
88  1 sg.setEndRes(4);
89  1 sg.addSequence(seq1, false);
90  1 sg.addSequence(seq2, false);
91  1 sg.addSequence(seq3, false);
92  1 sg.addSequence(seq4, false);
93   
94    /*
95    * set features visible on a viewport as only visible features are selected
96    */
97  1 AlignFrame af = new AlignFrame(
98    new Alignment(new SequenceI[]
99    { seq1, seq2, seq3, seq4 }), 100, 100);
100  1 af.getFeatureRenderer().findAllFeatures(true);
101   
102  1 AlignViewController avc = new AlignViewController(af, af.getViewport(),
103    af.alignPanel);
104   
105  1 BitSet bs = new BitSet();
106  1 int seqCount = avc.findColumnsWithFeature("Metal", sg, bs);
107  1 assertEquals(1, seqCount);
108  1 assertEquals(2, bs.cardinality());
109  1 assertTrue(bs.get(3)); // base 0
110  1 assertTrue(bs.get(4));
111   
112    /*
113    * select the first seven columns: Metal in seq1 cols 4-6, seq2 cols 6-7
114    */
115  1 sg.setEndRes(6);
116  1 bs.clear();
117  1 seqCount = avc.findColumnsWithFeature("Metal", sg, bs);
118  1 assertEquals(2, seqCount);
119  1 assertEquals(4, bs.cardinality());
120  1 assertTrue(bs.get(3));
121  1 assertTrue(bs.get(4));
122  1 assertTrue(bs.get(5));
123  1 assertTrue(bs.get(6));
124   
125    /*
126    * select column 14: Metal in seq3 only
127    */
128  1 sg.setStartRes(13);
129  1 sg.setEndRes(13);
130  1 bs.clear();
131  1 seqCount = avc.findColumnsWithFeature("Metal", sg, bs);
132  1 assertEquals(1, seqCount);
133  1 assertEquals(1, bs.cardinality());
134  1 assertTrue(bs.get(13));
135   
136    /*
137    * select columns 18-20: no Metal feature
138    */
139  1 sg.setStartRes(17);
140  1 sg.setEndRes(19);
141  1 bs.clear();
142  1 seqCount = avc.findColumnsWithFeature("Metal", sg, bs);
143  1 assertEquals(0, seqCount);
144  1 assertEquals(0, bs.cardinality());
145   
146    /*
147    * threshold Metal to hide where score < 5
148    * seq1 feature in columns 4-6 is hidden
149    * seq2 feature in columns 6-7 is shown
150    */
151  1 FeatureColourI fc = new FeatureColour(null, Color.red, Color.blue, null,
152    0f, 10f);
153  1 fc.setAboveThreshold(true);
154  1 fc.setThreshold(5f);
155  1 af.getFeatureRenderer().setColour("Metal", fc);
156  1 sg.setStartRes(0);
157  1 sg.setEndRes(6);
158  1 bs.clear();
159  1 seqCount = avc.findColumnsWithFeature("Metal", sg, bs);
160  1 assertEquals(1, seqCount);
161  1 assertEquals(2, bs.cardinality());
162  1 assertTrue(bs.get(5));
163  1 assertTrue(bs.get(6));
164   
165    /*
166    * columns 11-13 should not match disulfide bond at 8/12
167    */
168  1 sg.setStartRes(10);
169  1 sg.setEndRes(12);
170  1 bs.clear();
171  1 seqCount = avc.findColumnsWithFeature("disulfide bond", sg, bs);
172  1 assertEquals(0, seqCount);
173  1 assertEquals(0, bs.cardinality());
174   
175    /*
176    * columns 6-18 should match disulfide bond at columns 9, 14
177    */
178  1 sg.setStartRes(5);
179  1 sg.setEndRes(17);
180  1 bs.clear();
181  1 seqCount = avc.findColumnsWithFeature("disulfide bond", sg, bs);
182  1 assertEquals(1, seqCount);
183  1 assertEquals(2, bs.cardinality());
184  1 assertTrue(bs.get(8));
185  1 assertTrue(bs.get(13));
186   
187    /*
188    * look for a feature that isn't there
189    */
190  1 sg.setStartRes(0);
191  1 sg.setEndRes(19);
192  1 bs.clear();
193  1 seqCount = avc.findColumnsWithFeature("Pfam", sg, bs);
194  1 assertEquals(0, seqCount);
195  1 assertEquals(0, bs.cardinality());
196    }
197   
198    /**
199    * shameless copy of test data from findFeature for testing mark columns from
200    * highlight
201    */
 
202  1 toggle @Test(groups = "Functional")
203    public void testSelectColumnsWithHighlight()
204    {
205  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
206    "seq1 aMMMaaaaaaaaaaaaaaaa\n" + "seq2 aaaMMMMMMMaaaaaaaaaa\n"
207    + "seq3 aaaaaaaaaaMMMMMaaaaa\n"
208    + "seq4 aaaaaaaaaaaaaaaaaaaa\n",
209    DataSourceType.PASTE);
210   
211  1 SearchResultsI sr = new SearchResults();
212  1 SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
213  1 SequenceI seq1 = sqs[0];
214  1 SequenceI seq2 = sqs[1];
215  1 SequenceI seq3 = sqs[2];
216  1 SequenceI seq4 = sqs[3];
217   
218    /*
219    * features start/end are base 1
220    */
221  1 sr.addResult(seq1, 2, 4);
222  1 sr.addResult(seq2, 4, 10);
223  1 sr.addResult(seq3, 11, 15);
224   
225    /*
226    * test Match/Find works first
227    */
228  1 FinderI f = new Finder(af.getViewport());
229  1 f.findAll("M+", true, false, false, false);
230  1 assertEquals(
231    "Finder found different set of results to manually created SearchResults",
232    sr, f.getSearchResults());
233   
234    /*
235    * now check simple mark columns from find operation
236    */
237  1 af.getViewport().setSearchResults(sr);
238  1 AlignViewControllerI avc = af.avc;
239   
240  1 avc.markHighlightedColumns(false, false, false);
241  1 assertTrue("Didn't select highlighted columns",
242    Arrays.deepEquals(af.getViewport().getColumnSelection()
243    .getSelectedRanges().toArray(), new int[][]
244    { { 1, 14 } }));
245    }
246    }