JAL-2333 test beefed up with gaps
[jalview.git] / test / jalview / controller / AlignViewControllerTest.java
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 jalview.datamodel.Sequence;
27 import jalview.datamodel.SequenceFeature;
28 import jalview.datamodel.SequenceGroup;
29 import jalview.datamodel.SequenceI;
30
31 import java.util.BitSet;
32
33 import org.testng.annotations.Test;
34
35 public class AlignViewControllerTest
36 {
37   @Test(groups = "Functional")
38   public void testFindColumnsWithFeature()
39   {
40     SequenceI seq1 = new Sequence("seq1", "-a-MMMaaaaaaaaaaaaaaaa");
41     SequenceI seq2 = new Sequence("seq2", "aa--aMM-MMMMMaaaaaaaaaa");
42     SequenceI seq3 = new Sequence("seq3", "abcab-caD-aaMMMMMaaaaa");
43     SequenceI seq4 = new Sequence("seq4", "abc--abcaaaaaaaaaaaaaa");
44
45     /*
46      * features start/end are base 1
47      */
48     seq1.addSequenceFeature(new SequenceFeature("Metal", "desc", 2, 4, 0f,
49             null));
50     seq1.addSequenceFeature(new SequenceFeature("Helix", "desc", 1, 15, 0f,
51             null));
52     seq2.addSequenceFeature(new SequenceFeature("Metal", "desc", 4, 10, 0f,
53             null));
54     seq3.addSequenceFeature(new SequenceFeature("Metal", "desc", 11, 15,
55             0f, null));
56     // disulfide bond is a 'contact feature' - only select its 'start' and 'end'
57     seq3.addSequenceFeature(new SequenceFeature("disulfide bond", "desc", 8, 12,
58             0f, null));
59
60     /*
61      * select the first five columns --> Metal in seq1 cols 4-5
62      */
63     SequenceGroup sg = new SequenceGroup();
64     sg.setStartRes(0); // base 0
65     sg.setEndRes(4);
66     sg.addSequence(seq1, false);
67     sg.addSequence(seq2, false);
68     sg.addSequence(seq3, false);
69     sg.addSequence(seq4, false);
70
71     BitSet bs = new BitSet();
72     int seqCount = AlignViewController.findColumnsWithFeature("Metal", sg,
73             bs);
74     assertEquals(1, seqCount);
75     assertEquals(2, bs.cardinality());
76     assertTrue(bs.get(3)); // base 0
77     assertTrue(bs.get(4));
78
79     /*
80      * select the first seven columns: Metal in seq1 cols 4-6, seq2 cols 6-7 
81      */
82     sg.setEndRes(6);
83     bs.clear();
84     seqCount = AlignViewController.findColumnsWithFeature("Metal", sg, bs);
85     assertEquals(2, seqCount);
86     assertEquals(4, bs.cardinality());
87     assertTrue(bs.get(3));
88     assertTrue(bs.get(4));
89     assertTrue(bs.get(5));
90     assertTrue(bs.get(6));
91
92     /*
93      * select column 14: Metal in seq3 only
94      */
95     sg.setStartRes(13);
96     sg.setEndRes(13);
97     bs.clear();
98     seqCount = AlignViewController.findColumnsWithFeature("Metal", sg, bs);
99     assertEquals(1, seqCount);
100     assertEquals(1, bs.cardinality());
101     assertTrue(bs.get(13));
102
103     /*
104      * select columns 18-20: no Metal feature
105      */
106     sg.setStartRes(17);
107     sg.setEndRes(19);
108     bs.clear();
109     seqCount = AlignViewController.findColumnsWithFeature("Metal", sg, bs);
110     assertEquals(0, seqCount);
111     assertEquals(0, bs.cardinality());
112
113     /*
114      * columns 11-13 should not match disulfide bond at 8/12
115      */
116     sg.setStartRes(10);
117     sg.setEndRes(12);
118     bs.clear();
119     seqCount = AlignViewController.findColumnsWithFeature("disulfide bond",
120             sg, bs);
121     assertEquals(0, seqCount);
122     assertEquals(0, bs.cardinality());
123
124     /*
125      * columns 6-18 should match disulfide bond at columns 9, 14
126      */
127     sg.setStartRes(5);
128     sg.setEndRes(17);
129     bs.clear();
130     seqCount = AlignViewController.findColumnsWithFeature("disulfide bond",
131             sg, bs);
132     assertEquals(1, seqCount);
133     assertEquals(2, bs.cardinality());
134     assertTrue(bs.get(8));
135     assertTrue(bs.get(13));
136
137     /*
138      * look for a feature that isn't there
139      */
140     sg.setStartRes(0);
141     sg.setEndRes(19);
142     bs.clear();
143     seqCount = AlignViewController.findColumnsWithFeature("Pfam", sg, bs);
144     assertEquals(0, seqCount);
145     assertEquals(0, bs.cardinality());
146   }
147 }