Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 16:12:26 GMT
  2. Package jalview.util

File DnaUtilsTest.java

 

Code metrics

0
59
3
1
182
94
5
0.08
19.67
3
1.67

Classes

Class Line # Actions
DnaUtilsTest 35 59 5
0.967741996.8%
 

Contributing tests

This file is covered by 1 test. .

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.util;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertNull;
25    import static org.testng.AssertJUnit.fail;
26   
27    import jalview.gui.JvOptionPane;
28   
29    import java.text.ParseException;
30    import java.util.List;
31   
32    import org.testng.annotations.BeforeClass;
33    import org.testng.annotations.Test;
34   
 
35    public class DnaUtilsTest
36    {
37   
 
38  1 toggle @BeforeClass(alwaysRun = true)
39    public void setUpJvOptionPane()
40    {
41  1 JvOptionPane.setInteractiveMode(false);
42  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
43    }
44   
45    /**
46    * Tests for parsing an ENA/GenBank location specifier
47    *
48    * @throws ParseException
49    *
50    * @see http://www.insdc.org/files/feature_table.html#3.4
51    */
 
52  1 toggle @Test(groups = { "Functional" })
53    public void testParseLocation() throws ParseException
54    {
55    /*
56    * single locus
57    */
58  1 List<int[]> ranges = DnaUtils.parseLocation("467");
59  1 assertEquals(1, ranges.size());
60  1 assertEquals(467, ranges.get(0)[0]);
61  1 assertEquals(467, ranges.get(0)[1]);
62   
63    /*
64    * simple range
65    */
66  1 ranges = DnaUtils.parseLocation("12..78");
67  1 assertEquals(1, ranges.size());
68  1 assertEquals(12, ranges.get(0)[0]);
69  1 assertEquals(78, ranges.get(0)[1]);
70   
71    /*
72    * join of simple ranges
73    */
74  1 ranges = DnaUtils.parseLocation("join(12..78,134..202,322..345)");
75  1 assertEquals(3, ranges.size());
76  1 assertEquals(12, ranges.get(0)[0]);
77  1 assertEquals(78, ranges.get(0)[1]);
78  1 assertEquals(134, ranges.get(1)[0]);
79  1 assertEquals(202, ranges.get(1)[1]);
80  1 assertEquals(322, ranges.get(2)[0]);
81  1 assertEquals(345, ranges.get(2)[1]);
82   
83    /*
84    * complement of a simple range
85    */
86  1 ranges = DnaUtils.parseLocation("complement(34..126)");
87  1 assertEquals(1, ranges.size());
88  1 assertEquals(126, ranges.get(0)[0]);
89  1 assertEquals(34, ranges.get(0)[1]);
90   
91    /*
92    * complement of a join
93    */
94  1 ranges = DnaUtils
95    .parseLocation("complement(join(2691..4571,4918..5163))");
96  1 assertEquals(2, ranges.size());
97  1 assertEquals(5163, ranges.get(0)[0]);
98  1 assertEquals(4918, ranges.get(0)[1]);
99  1 assertEquals(4571, ranges.get(1)[0]);
100  1 assertEquals(2691, ranges.get(1)[1]);
101   
102    /*
103    * join of two complements
104    */
105  1 ranges = DnaUtils.parseLocation(
106    "join(complement(4918..5163),complement(2691..4571))");
107  1 assertEquals(2, ranges.size());
108  1 assertEquals(5163, ranges.get(0)[0]);
109  1 assertEquals(4918, ranges.get(0)[1]);
110  1 assertEquals(4571, ranges.get(1)[0]);
111  1 assertEquals(2691, ranges.get(1)[1]);
112   
113    /*
114    * join complement to non-complement
115    * @see http://www.ncbi.nlm.nih.gov/genbank/genomesubmit_annotation/ Transpliced Genes
116    */
117  1 ranges = DnaUtils
118    .parseLocation("join(complement(36618..36700),86988..87064)");
119  1 assertEquals(2, ranges.size());
120  1 assertEquals(36700, ranges.get(0)[0]);
121  1 assertEquals(36618, ranges.get(0)[1]);
122  1 assertEquals(86988, ranges.get(1)[0]);
123  1 assertEquals(87064, ranges.get(1)[1]);
124   
125    /*
126    * valid things we don't yet handle
127    */
128  1 checkForParseException("<34..126");
129  1 checkForParseException("35..>126");
130  1 checkForParseException("34.126");
131  1 checkForParseException("34^126");
132  1 checkForParseException("order(34..126,130..180)");
133   
134    /*
135    * invalid things
136    */
137  1 checkForParseException("");
138  1 checkForParseException("JOIN(1..2)");
139  1 checkForParseException("join(1..2");
140  1 checkForParseException("join(1..2(");
141  1 checkForParseException("complement(1..2");
142  1 checkForParseException("complement(1..2(");
143  1 try
144    {
145  1 assertNull(DnaUtils.parseLocation(null));
146  0 fail("Expected exception");
147    } catch (NullPointerException e)
148    {
149    // expected
150    }
151   
152    /*
153    * nested joins are not allowed; just as well since this fails to parse
154    * (splitting tokens by comma fragments the inner join expression)
155    */
156  1 checkForParseException("join(1..2,join(4..5,10..12),18..22)");
157    /*
158    * complement may not enclose multiple ranges
159    * parsing fails for the same reason
160    */
161  1 checkForParseException(
162    "join(complement(36618..36700,4000..4200),86988..87064)");
163    }
164   
165    /**
166    * Verifies that a ParseException is thrown when the given location is parsed
167    *
168    * @param location
169    */
 
170  13 toggle void checkForParseException(String location)
171    {
172  13 try
173    {
174  13 DnaUtils.parseLocation(location);
175  0 fail("Expected exception");
176    } catch (ParseException e)
177    {
178    // expected;
179    }
180    }
181   
182    }