Clover icon

Coverage Report

  1. Project Clover database Mon Nov 18 2024 09:38:20 GMT
  2. Package jalview.io.gff

File GffHelperBaseTest.java

 

Code metrics

0
134
4
1
265
176
5
0.04
33.5
4
1.25

Classes

Class Line # Actions
GffHelperBaseTest 37 134 5
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.Assert.assertEquals;
24    import static org.testng.Assert.assertFalse;
25    import static org.testng.Assert.assertTrue;
26    import static org.testng.Assert.fail;
27   
28    import jalview.gui.JvOptionPane;
29   
30    import java.util.Arrays;
31    import java.util.List;
32    import java.util.Map;
33   
34    import org.testng.annotations.BeforeClass;
35    import org.testng.annotations.Test;
36   
 
37    public class GffHelperBaseTest
38    {
39   
 
40  0 toggle @BeforeClass(alwaysRun = true)
41    public void setUpJvOptionPane()
42    {
43  0 JvOptionPane.setInteractiveMode(false);
44  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
45    }
46   
47    /**
48    * Test the method that parses lines like <br>
49    * ID=2345;Name=Something,Another thing;Notes=Hello;Notes=World
50    */
 
51  0 toggle @Test(groups = { "Functional" })
52    public void testParseNameValuePairs()
53    {
54  0 assertTrue(GffHelperBase.parseNameValuePairs(null, ";", ' ', ",")
55    .isEmpty());
56  0 assertTrue(
57    GffHelperBase.parseNameValuePairs("", ";", ' ', ",").isEmpty());
58  0 assertTrue(GffHelperBase
59    .parseNameValuePairs("hello=world", ";", ' ', ",").isEmpty());
60   
61  0 Map<String, List<String>> map = GffHelperBase
62    .parseNameValuePairs("hello world", ";", ' ', ", ");
63  0 assertEquals(map.size(), 1);
64  0 assertEquals(map.get("hello").size(), 1);
65  0 assertEquals(map.get("hello").get(0), "world");
66   
67  0 map = GffHelperBase.parseNameValuePairs(
68    "Method= manual curation ;nothing; Notes=F2 S ; Notes=Metal,Shiny%2Csmooth; Type=",
69    ";", '=', ",");
70   
71    // Type is ignored as no value was supplied
72  0 assertEquals(map.size(), 2);
73   
74  0 assertEquals(map.get("Method").size(), 1);
75  0 assertEquals(map.get("Method").get(0), "manual curation"); // trimmed
76   
77  0 assertEquals(map.get("Notes").size(), 3);
78  0 assertEquals(map.get("Notes").get(0), "F2 S");
79  0 assertEquals(map.get("Notes").get(1), "Metal");
80  0 assertEquals(map.get("Notes").get(2), "Shiny%2Csmooth"); // not decoded here
81   
82    /*
83    * gff3 style with nested attribute values
84    */
85  0 String csqValue = "POLYPHEN=possibly_damaging,probably_damaging,SIFT=tolerated%2Cdeleterious";
86  0 map = GffHelperBase.parseNameValuePairs("hello=world;CSQ=" + csqValue,
87    ";", '=', ",");
88  0 assertEquals(map.size(), 2); // keys hello, CSQ
89  0 assertEquals(map.get("hello").size(), 1);
90  0 assertEquals(map.get("hello").get(0), "world");
91    // CSQ values is read 'raw' here, and parsed further elsewhere
92  0 assertEquals(map.get("CSQ").size(), 1);
93  0 assertEquals(map.get("CSQ").get(0), csqValue);
94    }
95   
96    /**
97    * Test for the method that tries to trim mappings to equivalent lengths
98    */
 
99  0 toggle @Test(groups = "Functional")
100    public void testTrimMapping()
101    {
102  0 int[] from = { 1, 12 };
103  0 int[] to = { 20, 31 };
104  0 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
105  0 assertEquals(Arrays.toString(from), "[1, 12]"); // unchanged
106  0 assertEquals(Arrays.toString(to), "[20, 31]"); // unchanged
107   
108    // from too long:
109  0 from = new int[] { 1, 13 };
110  0 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
111  0 assertEquals(Arrays.toString(from), "[1, 12]"); // trimmed
112  0 assertEquals(Arrays.toString(to), "[20, 31]"); // unchanged
113   
114    // to too long:
115  0 to = new int[] { 20, 33 };
116  0 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
117  0 assertEquals(Arrays.toString(from), "[1, 12]"); // unchanged
118  0 assertEquals(Arrays.toString(to), "[20, 31]"); // trimmed
119   
120    // from reversed:
121  0 from = new int[] { 12, 1 };
122  0 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
123  0 assertEquals(Arrays.toString(from), "[12, 1]"); // unchanged
124  0 assertEquals(Arrays.toString(to), "[20, 31]"); // unchanged
125   
126    // to reversed:
127  0 to = new int[] { 31, 20 };
128  0 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
129  0 assertEquals(Arrays.toString(from), "[12, 1]"); // unchanged
130  0 assertEquals(Arrays.toString(to), "[31, 20]"); // unchanged
131   
132    // from reversed and too long:
133  0 from = new int[] { 14, 1 };
134  0 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
135  0 assertEquals(Arrays.toString(from), "[14, 3]"); // end trimmed
136  0 assertEquals(Arrays.toString(to), "[31, 20]"); // unchanged
137   
138    // to reversed and too long:
139  0 to = new int[] { 31, 10 };
140  0 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
141  0 assertEquals(Arrays.toString(from), "[14, 3]"); // unchanged
142  0 assertEquals(Arrays.toString(to), "[31, 20]"); // end trimmed
143   
144    // cdna to peptide (matching)
145  0 from = new int[] { 1, 18 };
146  0 to = new int[] { 4, 9 };
147  0 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
148  0 assertEquals(Arrays.toString(from), "[1, 18]"); // unchanged
149  0 assertEquals(Arrays.toString(to), "[4, 9]"); // unchanged
150   
151    // overlong cdna to peptide
152  0 from = new int[] { 1, 20 };
153  0 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
154  0 assertEquals(Arrays.toString(from), "[1, 18]"); // end trimmed
155  0 assertEquals(Arrays.toString(to), "[4, 9]"); // unchanged
156   
157    // overlong cdna (reversed) to peptide
158  0 from = new int[] { 20, 1 };
159  0 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
160  0 assertEquals(Arrays.toString(from), "[20, 3]"); // end trimmed
161  0 assertEquals(Arrays.toString(to), "[4, 9]"); // unchanged
162   
163    // overlong cdna (reversed) to peptide (reversed)
164  0 from = new int[] { 20, 1 };
165  0 to = new int[] { 9, 4 };
166  0 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
167  0 assertEquals(Arrays.toString(from), "[20, 3]"); // end trimmed
168  0 assertEquals(Arrays.toString(to), "[9, 4]"); // unchanged
169   
170    // peptide to cdna (matching)
171  0 from = new int[] { 4, 9 };
172  0 to = new int[] { 1, 18 };
173  0 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
174  0 assertEquals(Arrays.toString(from), "[4, 9]"); // unchanged
175  0 assertEquals(Arrays.toString(to), "[1, 18]"); // unchanged
176   
177    // peptide to overlong cdna
178  0 to = new int[] { 1, 20 };
179  0 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
180  0 assertEquals(Arrays.toString(from), "[4, 9]"); // unchanged
181  0 assertEquals(Arrays.toString(to), "[1, 18]"); // end trimmed
182   
183    // peptide to overlong cdna (reversed)
184  0 to = new int[] { 20, 1 };
185  0 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
186  0 assertEquals(Arrays.toString(from), "[4, 9]"); // unchanged
187  0 assertEquals(Arrays.toString(to), "[20, 3]"); // end trimmed
188   
189    // peptide (reversed) to overlong cdna (reversed)
190  0 from = new int[] { 9, 4 };
191  0 to = new int[] { 20, 1 };
192  0 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
193  0 assertEquals(Arrays.toString(from), "[9, 4]"); // unchanged
194  0 assertEquals(Arrays.toString(to), "[20, 3]"); // end trimmed
195   
196    // overlong peptide to word-length cdna
197  0 from = new int[] { 4, 10 };
198  0 to = new int[] { 1, 18 };
199  0 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
200  0 assertEquals(Arrays.toString(from), "[4, 9]"); // end trimmed
201  0 assertEquals(Arrays.toString(to), "[1, 18]"); // unchanged
202   
203    // overlong peptide to non-word-length cdna
204  0 from = new int[] { 4, 10 };
205  0 to = new int[] { 1, 19 };
206  0 assertFalse(GffHelperBase.trimMapping(from, to, 1, 3));
207  0 assertEquals(Arrays.toString(from), "[4, 10]"); // unchanged
208  0 assertEquals(Arrays.toString(to), "[1, 19]"); // unchanged
209    }
210   
 
211  0 toggle @Test(groups = { "Functional" })
212    public void testParseAttributeMap()
213    {
214  0 Map<String, String> map = GffHelperBase
215    .parseAttributeMap("A=B,C%2C%3D%3B%09%25D,X=Y");
216  0 assertEquals(map.size(), 2);
217    // value of A is everything up to and excluding ,X=
218  0 assertEquals(map.get("A"), "B,C,=;\t%D");
219  0 assertEquals(map.get("X"), "Y");
220   
221    /*
222    * malformed cases should result in an empty map
223    */
224  0 map = GffHelperBase.parseAttributeMap("=B=Y");
225  0 assertTrue(map.isEmpty());
226    // first token should be an attribute name only, no commas
227  0 map = GffHelperBase.parseAttributeMap("A,B=C");
228  0 assertTrue(map.isEmpty());
229    // intermediate tokens need at least one comma (value,name=)
230  0 map = GffHelperBase.parseAttributeMap("A=B=C");
231  0 assertTrue(map.isEmpty());
232    // last token may have a comma or not
233  0 map = GffHelperBase.parseAttributeMap("A=B");
234  0 assertEquals(map.get("A"), "B");
235  0 map = GffHelperBase.parseAttributeMap("A=B,C");
236  0 assertEquals(map.get("A"), "B,C");
237  0 map = GffHelperBase.parseAttributeMap("A");
238  0 assertTrue(map.isEmpty());
239  0 map = GffHelperBase.parseAttributeMap("A=");
240  0 assertTrue(map.isEmpty());
241  0 map = GffHelperBase.parseAttributeMap("A==C");
242  0 assertTrue(map.isEmpty());
243  0 map = GffHelperBase.parseAttributeMap("=A");
244  0 assertTrue(map.isEmpty());
245  0 map = GffHelperBase.parseAttributeMap("=");
246  0 assertTrue(map.isEmpty());
247  0 map = GffHelperBase.parseAttributeMap(",");
248  0 assertTrue(map.isEmpty());
249  0 map = GffHelperBase.parseAttributeMap(" ");
250  0 assertTrue(map.isEmpty());
251  0 map = GffHelperBase.parseAttributeMap("");
252  0 assertTrue(map.isEmpty());
253  0 map = GffHelperBase.parseAttributeMap("A=B, =C");
254  0 assertTrue(map.isEmpty());
255   
256  0 try
257    {
258  0 GffHelperBase.parseAttributeMap(null);
259  0 fail("expected exception");
260    } catch (NullPointerException e)
261    {
262    // expected
263    }
264    }
265    }