3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertNull;
5 import static org.testng.AssertJUnit.fail;
7 import java.text.ParseException;
10 import org.testng.annotations.Test;
12 public class DnaUtilsTest
15 * Tests for parsing an ENA/GenBank location specifier
17 * @throws ParseException
19 * @see http://www.insdc.org/files/feature_table.html#3.4
21 @Test(groups = { "Functional" })
22 public void testParseLocation() throws ParseException
27 List<int[]> ranges = DnaUtils.parseLocation("467");
28 assertEquals(1, ranges.size());
29 assertEquals(467, ranges.get(0)[0]);
30 assertEquals(467, ranges.get(0)[1]);
35 ranges = DnaUtils.parseLocation("12..78");
36 assertEquals(1, ranges.size());
37 assertEquals(12, ranges.get(0)[0]);
38 assertEquals(78, ranges.get(0)[1]);
41 * join of simple ranges
43 ranges = DnaUtils.parseLocation("join(12..78,134..202,322..345)");
44 assertEquals(3, ranges.size());
45 assertEquals(12, ranges.get(0)[0]);
46 assertEquals(78, ranges.get(0)[1]);
47 assertEquals(134, ranges.get(1)[0]);
48 assertEquals(202, ranges.get(1)[1]);
49 assertEquals(322, ranges.get(2)[0]);
50 assertEquals(345, ranges.get(2)[1]);
53 * complement of a simple range
55 ranges = DnaUtils.parseLocation("complement(34..126)");
56 assertEquals(1, ranges.size());
57 assertEquals(126, ranges.get(0)[0]);
58 assertEquals(34, ranges.get(0)[1]);
61 * complement of a join
64 .parseLocation("complement(join(2691..4571,4918..5163))");
65 assertEquals(2, ranges.size());
66 assertEquals(5163, ranges.get(0)[0]);
67 assertEquals(4918, ranges.get(0)[1]);
68 assertEquals(4571, ranges.get(1)[0]);
69 assertEquals(2691, ranges.get(1)[1]);
72 * join of two complements
75 .parseLocation("join(complement(4918..5163),complement(2691..4571))");
76 assertEquals(2, ranges.size());
77 assertEquals(5163, ranges.get(0)[0]);
78 assertEquals(4918, ranges.get(0)[1]);
79 assertEquals(4571, ranges.get(1)[0]);
80 assertEquals(2691, ranges.get(1)[1]);
83 * join complement to non-complement
84 * @see http://www.ncbi.nlm.nih.gov/genbank/genomesubmit_annotation/ Transpliced Genes
87 .parseLocation("join(complement(36618..36700),86988..87064)");
88 assertEquals(2, ranges.size());
89 assertEquals(36700, ranges.get(0)[0]);
90 assertEquals(36618, ranges.get(0)[1]);
91 assertEquals(86988, ranges.get(1)[0]);
92 assertEquals(87064, ranges.get(1)[1]);
95 * valid things we don't yet handle
97 checkForParseException("<34..126");
98 checkForParseException("35..>126");
99 checkForParseException("34.126");
100 checkForParseException("34^126");
101 checkForParseException("order(34..126,130..180)");
106 checkForParseException("");
107 checkForParseException("JOIN(1..2)");
108 checkForParseException("join(1..2");
109 checkForParseException("join(1..2(");
110 checkForParseException("complement(1..2");
111 checkForParseException("complement(1..2(");
114 assertNull(DnaUtils.parseLocation(null));
115 fail("Expected exception");
116 } catch (NullPointerException e)
122 * nested joins are not allowed; just as well since this fails to parse
123 * (splitting tokens by comma fragments the inner join expression)
125 checkForParseException("join(1..2,join(4..5,10..12),18..22)");
127 * complement may not enclose multiple ranges
128 * parsing fails for the same reason
130 checkForParseException("join(complement(36618..36700,4000..4200),86988..87064)");
134 * Verifies that a ParseException is thrown when the given location is parsed
138 void checkForParseException(String location)
142 DnaUtils.parseLocation(location);
143 fail("Expected exception");
144 } catch (ParseException e)