Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.io.gff

File GffHelperBaseTest.java

 

Code metrics

0
92
3
1
198
124
3
0.03
30.67
3
1

Classes

Class Line # Actions
GffHelperBaseTest 36 92 3 0
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.io.gff;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertFalse;
25    import static org.testng.AssertJUnit.assertTrue;
26   
27    import jalview.gui.JvOptionPane;
28   
29    import java.util.Arrays;
30    import java.util.List;
31    import java.util.Map;
32   
33    import org.testng.annotations.BeforeClass;
34    import org.testng.annotations.Test;
35   
 
36    public class GffHelperBaseTest
37    {
38   
 
39  1 toggle @BeforeClass(alwaysRun = true)
40    public void setUpJvOptionPane()
41    {
42  1 JvOptionPane.setInteractiveMode(false);
43  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
44    }
45   
46    /**
47    * Test the method that parses lines like <br>
48    * ID=2345;Name=Something,Another thing;Notes=Hello;Notes=World
49    */
 
50  1 toggle @Test(groups = { "Functional" })
51    public void testParseNameValuePairs()
52    {
53  1 assertTrue(GffHelperBase.parseNameValuePairs(null, ";", ' ', ",")
54    .isEmpty());
55  1 assertTrue(GffHelperBase.parseNameValuePairs("", ";", ' ', ",")
56    .isEmpty());
57  1 assertTrue(GffHelperBase.parseNameValuePairs("hello=world", ";", ' ',
58    ",").isEmpty());
59   
60  1 Map<String, List<String>> map = GffHelperBase.parseNameValuePairs(
61    "hello world", ";", ' ', ", ");
62  1 assertEquals(1, map.size());
63  1 assertEquals(1, map.get("hello").size());
64  1 assertEquals("world", map.get("hello").get(0));
65   
66  1 map = GffHelperBase
67    .parseNameValuePairs(
68    "Method= manual curation ;nothing; Notes=F2 S ; Notes=Metal,Shiny; Type=",
69    ";", '=', ",");
70   
71    // Type is ignored as no value was supplied
72  1 assertEquals(2, map.size());
73   
74  1 assertEquals(1, map.get("Method").size());
75  1 assertEquals("manual curation", map.get("Method").get(0)); // trimmed
76   
77  1 assertEquals(3, map.get("Notes").size());
78  1 assertEquals("F2 S", map.get("Notes").get(0));
79  1 assertEquals("Metal", map.get("Notes").get(1));
80  1 assertEquals("Shiny", map.get("Notes").get(2));
81    }
82   
83    /**
84    * Test for the method that tries to trim mappings to equivalent lengths
85    */
 
86  1 toggle @Test(groups = "Functional")
87    public void testTrimMapping()
88    {
89  1 int[] from = { 1, 12 };
90  1 int[] to = { 20, 31 };
91  1 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
92  1 assertEquals("[1, 12]", Arrays.toString(from)); // unchanged
93  1 assertEquals("[20, 31]", Arrays.toString(to)); // unchanged
94   
95    // from too long:
96  1 from = new int[] { 1, 13 };
97  1 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
98  1 assertEquals("[1, 12]", Arrays.toString(from)); // trimmed
99  1 assertEquals("[20, 31]", Arrays.toString(to)); // unchanged
100   
101    // to too long:
102  1 to = new int[] { 20, 33 };
103  1 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
104  1 assertEquals("[1, 12]", Arrays.toString(from)); // unchanged
105  1 assertEquals("[20, 31]", Arrays.toString(to)); // trimmed
106   
107    // from reversed:
108  1 from = new int[] { 12, 1 };
109  1 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
110  1 assertEquals("[12, 1]", Arrays.toString(from)); // unchanged
111  1 assertEquals("[20, 31]", Arrays.toString(to)); // unchanged
112   
113    // to reversed:
114  1 to = new int[] { 31, 20 };
115  1 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
116  1 assertEquals("[12, 1]", Arrays.toString(from)); // unchanged
117  1 assertEquals("[31, 20]", Arrays.toString(to)); // unchanged
118   
119    // from reversed and too long:
120  1 from = new int[] { 14, 1 };
121  1 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
122  1 assertEquals("[14, 3]", Arrays.toString(from)); // end trimmed
123  1 assertEquals("[31, 20]", Arrays.toString(to)); // unchanged
124   
125    // to reversed and too long:
126  1 to = new int[] { 31, 10 };
127  1 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
128  1 assertEquals("[14, 3]", Arrays.toString(from)); // unchanged
129  1 assertEquals("[31, 20]", Arrays.toString(to)); // end trimmed
130   
131    // cdna to peptide (matching)
132  1 from = new int[] { 1, 18 };
133  1 to = new int[] { 4, 9 };
134  1 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
135  1 assertEquals("[1, 18]", Arrays.toString(from)); // unchanged
136  1 assertEquals("[4, 9]", Arrays.toString(to)); // unchanged
137   
138    // overlong cdna to peptide
139  1 from = new int[] { 1, 20 };
140  1 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
141  1 assertEquals("[1, 18]", Arrays.toString(from)); // end trimmed
142  1 assertEquals("[4, 9]", Arrays.toString(to)); // unchanged
143   
144    // overlong cdna (reversed) to peptide
145  1 from = new int[] { 20, 1 };
146  1 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
147  1 assertEquals("[20, 3]", Arrays.toString(from)); // end trimmed
148  1 assertEquals("[4, 9]", Arrays.toString(to)); // unchanged
149   
150    // overlong cdna (reversed) to peptide (reversed)
151  1 from = new int[] { 20, 1 };
152  1 to = new int[] { 9, 4 };
153  1 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
154  1 assertEquals("[20, 3]", Arrays.toString(from)); // end trimmed
155  1 assertEquals("[9, 4]", Arrays.toString(to)); // unchanged
156   
157    // peptide to cdna (matching)
158  1 from = new int[] { 4, 9 };
159  1 to = new int[] { 1, 18 };
160  1 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
161  1 assertEquals("[4, 9]", Arrays.toString(from)); // unchanged
162  1 assertEquals("[1, 18]", Arrays.toString(to)); // unchanged
163   
164    // peptide to overlong cdna
165  1 to = new int[] { 1, 20 };
166  1 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
167  1 assertEquals("[4, 9]", Arrays.toString(from)); // unchanged
168  1 assertEquals("[1, 18]", Arrays.toString(to)); // end trimmed
169   
170    // peptide to overlong cdna (reversed)
171  1 to = new int[] { 20, 1 };
172  1 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
173  1 assertEquals("[4, 9]", Arrays.toString(from)); // unchanged
174  1 assertEquals("[20, 3]", Arrays.toString(to)); // end trimmed
175   
176    // peptide (reversed) to overlong cdna (reversed)
177  1 from = new int[] { 9, 4 };
178  1 to = new int[] { 20, 1 };
179  1 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
180  1 assertEquals("[9, 4]", Arrays.toString(from)); // unchanged
181  1 assertEquals("[20, 3]", Arrays.toString(to)); // end trimmed
182   
183    // overlong peptide to word-length cdna
184  1 from = new int[] { 4, 10 };
185  1 to = new int[] { 1, 18 };
186  1 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
187  1 assertEquals("[4, 9]", Arrays.toString(from)); // end trimmed
188  1 assertEquals("[1, 18]", Arrays.toString(to)); // unchanged
189   
190    // overlong peptide to non-word-length cdna
191  1 from = new int[] { 4, 10 };
192  1 to = new int[] { 1, 19 };
193  1 assertFalse(GffHelperBase.trimMapping(from, to, 1, 3));
194  1 assertEquals("[4, 10]", Arrays.toString(from)); // unchanged
195  1 assertEquals("[1, 19]", Arrays.toString(to)); // unchanged
196   
197    }
198    }