2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNull;
25 import static org.testng.AssertJUnit.fail;
27 import java.text.ParseException;
28 import java.util.List;
30 import org.testng.annotations.Test;
32 public class DnaUtilsTest
35 * Tests for parsing an ENA/GenBank location specifier
37 * @throws ParseException
39 * @see http://www.insdc.org/files/feature_table.html#3.4
41 @Test(groups = { "Functional" })
42 public void testParseLocation() throws ParseException
47 List<int[]> ranges = DnaUtils.parseLocation("467");
48 assertEquals(1, ranges.size());
49 assertEquals(467, ranges.get(0)[0]);
50 assertEquals(467, ranges.get(0)[1]);
55 ranges = DnaUtils.parseLocation("12..78");
56 assertEquals(1, ranges.size());
57 assertEquals(12, ranges.get(0)[0]);
58 assertEquals(78, ranges.get(0)[1]);
61 * join of simple ranges
63 ranges = DnaUtils.parseLocation("join(12..78,134..202,322..345)");
64 assertEquals(3, ranges.size());
65 assertEquals(12, ranges.get(0)[0]);
66 assertEquals(78, ranges.get(0)[1]);
67 assertEquals(134, ranges.get(1)[0]);
68 assertEquals(202, ranges.get(1)[1]);
69 assertEquals(322, ranges.get(2)[0]);
70 assertEquals(345, ranges.get(2)[1]);
73 * complement of a simple range
75 ranges = DnaUtils.parseLocation("complement(34..126)");
76 assertEquals(1, ranges.size());
77 assertEquals(126, ranges.get(0)[0]);
78 assertEquals(34, ranges.get(0)[1]);
81 * complement of a join
84 .parseLocation("complement(join(2691..4571,4918..5163))");
85 assertEquals(2, ranges.size());
86 assertEquals(5163, ranges.get(0)[0]);
87 assertEquals(4918, ranges.get(0)[1]);
88 assertEquals(4571, ranges.get(1)[0]);
89 assertEquals(2691, ranges.get(1)[1]);
92 * join of two complements
95 .parseLocation("join(complement(4918..5163),complement(2691..4571))");
96 assertEquals(2, ranges.size());
97 assertEquals(5163, ranges.get(0)[0]);
98 assertEquals(4918, ranges.get(0)[1]);
99 assertEquals(4571, ranges.get(1)[0]);
100 assertEquals(2691, ranges.get(1)[1]);
103 * join complement to non-complement
104 * @see http://www.ncbi.nlm.nih.gov/genbank/genomesubmit_annotation/ Transpliced Genes
107 .parseLocation("join(complement(36618..36700),86988..87064)");
108 assertEquals(2, ranges.size());
109 assertEquals(36700, ranges.get(0)[0]);
110 assertEquals(36618, ranges.get(0)[1]);
111 assertEquals(86988, ranges.get(1)[0]);
112 assertEquals(87064, ranges.get(1)[1]);
115 * valid things we don't yet handle
117 checkForParseException("<34..126");
118 checkForParseException("35..>126");
119 checkForParseException("34.126");
120 checkForParseException("34^126");
121 checkForParseException("order(34..126,130..180)");
126 checkForParseException("");
127 checkForParseException("JOIN(1..2)");
128 checkForParseException("join(1..2");
129 checkForParseException("join(1..2(");
130 checkForParseException("complement(1..2");
131 checkForParseException("complement(1..2(");
134 assertNull(DnaUtils.parseLocation(null));
135 fail("Expected exception");
136 } catch (NullPointerException e)
142 * nested joins are not allowed; just as well since this fails to parse
143 * (splitting tokens by comma fragments the inner join expression)
145 checkForParseException("join(1..2,join(4..5,10..12),18..22)");
147 * complement may not enclose multiple ranges
148 * parsing fails for the same reason
150 checkForParseException("join(complement(36618..36700,4000..4200),86988..87064)");
154 * Verifies that a ParseException is thrown when the given location is parsed
158 void checkForParseException(String location)
162 DnaUtils.parseLocation(location);
163 fail("Expected exception");
164 } catch (ParseException e)