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 jalview.gui.JvOptionPane;
29 import java.text.ParseException;
30 import java.util.List;
32 import org.testng.annotations.BeforeClass;
33 import org.testng.annotations.Test;
35 public class DnaUtilsTest
38 @BeforeClass(alwaysRun = true)
39 public void setUpJvOptionPane()
41 JvOptionPane.setInteractiveMode(false);
42 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
46 * Tests for parsing an ENA/GenBank location specifier
48 * @throws ParseException
50 * @see http://www.insdc.org/files/feature_table.html#3.4
52 @Test(groups = { "Functional" })
53 public void testParseLocation() throws ParseException
58 List<int[]> ranges = DnaUtils.parseLocation("467");
59 assertEquals(1, ranges.size());
60 assertEquals(467, ranges.get(0)[0]);
61 assertEquals(467, ranges.get(0)[1]);
66 ranges = DnaUtils.parseLocation("12..78");
67 assertEquals(1, ranges.size());
68 assertEquals(12, ranges.get(0)[0]);
69 assertEquals(78, ranges.get(0)[1]);
72 * join of simple ranges
74 ranges = DnaUtils.parseLocation("join(12..78,134..202,322..345)");
75 assertEquals(3, ranges.size());
76 assertEquals(12, ranges.get(0)[0]);
77 assertEquals(78, ranges.get(0)[1]);
78 assertEquals(134, ranges.get(1)[0]);
79 assertEquals(202, ranges.get(1)[1]);
80 assertEquals(322, ranges.get(2)[0]);
81 assertEquals(345, ranges.get(2)[1]);
84 * complement of a simple range
86 ranges = DnaUtils.parseLocation("complement(34..126)");
87 assertEquals(1, ranges.size());
88 assertEquals(126, ranges.get(0)[0]);
89 assertEquals(34, ranges.get(0)[1]);
92 * complement of a join
95 .parseLocation("complement(join(2691..4571,4918..5163))");
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 of two complements
106 .parseLocation("join(complement(4918..5163),complement(2691..4571))");
107 assertEquals(2, ranges.size());
108 assertEquals(5163, ranges.get(0)[0]);
109 assertEquals(4918, ranges.get(0)[1]);
110 assertEquals(4571, ranges.get(1)[0]);
111 assertEquals(2691, ranges.get(1)[1]);
114 * join complement to non-complement
115 * @see http://www.ncbi.nlm.nih.gov/genbank/genomesubmit_annotation/ Transpliced Genes
118 .parseLocation("join(complement(36618..36700),86988..87064)");
119 assertEquals(2, ranges.size());
120 assertEquals(36700, ranges.get(0)[0]);
121 assertEquals(36618, ranges.get(0)[1]);
122 assertEquals(86988, ranges.get(1)[0]);
123 assertEquals(87064, ranges.get(1)[1]);
126 * valid things we don't yet handle
128 checkForParseException("<34..126");
129 checkForParseException("35..>126");
130 checkForParseException("34.126");
131 checkForParseException("34^126");
132 checkForParseException("order(34..126,130..180)");
137 checkForParseException("");
138 checkForParseException("JOIN(1..2)");
139 checkForParseException("join(1..2");
140 checkForParseException("join(1..2(");
141 checkForParseException("complement(1..2");
142 checkForParseException("complement(1..2(");
145 assertNull(DnaUtils.parseLocation(null));
146 fail("Expected exception");
147 } catch (NullPointerException e)
153 * nested joins are not allowed; just as well since this fails to parse
154 * (splitting tokens by comma fragments the inner join expression)
156 checkForParseException("join(1..2,join(4..5,10..12),18..22)");
158 * complement may not enclose multiple ranges
159 * parsing fails for the same reason
161 checkForParseException("join(complement(36618..36700,4000..4200),86988..87064)");
165 * Verifies that a ParseException is thrown when the given location is parsed
169 void checkForParseException(String location)
173 DnaUtils.parseLocation(location);
174 fail("Expected exception");
175 } catch (ParseException e)