JAL-2189 apply license
[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", "aMMMaaaaaaaaaaaaaaaa");
41     SequenceI seq2 = new Sequence("seq2", "aaaMMMMMMMaaaaaaaaaa");
42     SequenceI seq3 = new Sequence("seq3", "aaaaaaaaaaMMMMMaaaaa");
43     SequenceI seq4 = new Sequence("seq3", "aaaaaaaaaaaaaaaaaaaa");
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
57     /*
58      * select the first three columns --> Metal in seq1 2-3
59      */
60     SequenceGroup sg = new SequenceGroup();
61     sg.setStartRes(0); // base 0
62     sg.setEndRes(2);
63     sg.addSequence(seq1, false);
64     sg.addSequence(seq2, false);
65     sg.addSequence(seq3, false);
66     sg.addSequence(seq4, false);
67
68     BitSet bs = new BitSet();
69     int seqCount = AlignViewController.findColumnsWithFeature("Metal", sg,
70             bs);
71     assertEquals(1, seqCount);
72     assertEquals(2, bs.cardinality());
73     assertTrue(bs.get(1));
74     assertTrue(bs.get(2));
75
76     /*
77      * select the first four columns: Metal in seq1 2:4, seq2 4:4
78      */
79     sg.setEndRes(3);
80     bs.clear();
81     seqCount = AlignViewController.findColumnsWithFeature("Metal", sg, bs);
82     assertEquals(2, seqCount);
83     assertEquals(3, bs.cardinality());
84     assertTrue(bs.get(1));
85     assertTrue(bs.get(2));
86     assertTrue(bs.get(3));
87
88     /*
89      * select column 11: Metal in seq3 only
90      */
91     sg.setStartRes(10);
92     sg.setEndRes(10);
93     bs.clear();
94     seqCount = AlignViewController.findColumnsWithFeature("Metal", sg, bs);
95     assertEquals(1, seqCount);
96     assertEquals(1, bs.cardinality());
97     assertTrue(bs.get(10));
98
99     /*
100      * select columns 16-20: no Metal feature
101      */
102     sg.setStartRes(15);
103     sg.setEndRes(19);
104     bs.clear();
105     seqCount = AlignViewController.findColumnsWithFeature("Metal", sg, bs);
106     assertEquals(0, seqCount);
107     assertEquals(0, bs.cardinality());
108
109     /*
110      * look for a feature that isn't there
111      */
112     sg.setStartRes(0);
113     sg.setEndRes(19);
114     bs.clear();
115     seqCount = AlignViewController.findColumnsWithFeature("Pfam", sg, bs);
116     assertEquals(0, seqCount);
117     assertEquals(0, bs.cardinality());
118   }
119 }