System.err.println(errorMessage);
return null;
}
+
+ /*
+ * try to parse m..n (or simply m)
+ */
String[] range = location.split("\\.\\.");
- if (range.length == 2)
+ if (range.length == 1 || range.length == 2)
{
try
{
int start = Integer.valueOf(range[0]);
- int end = Integer.valueOf(range[1]);
+ int end = range.length == 1 ? start : Integer.valueOf(range[1]);
return Collections.singletonList(new int[] { start, end });
} catch (NumberFormatException e)
{
/*
* take what is inside complement()
*/
+ if (!location.endsWith(")"))
+ {
+ return null;
+ }
String toComplement = location.substring("complement(".length(),
location.length() - 1);
List<int[]> ranges = parseLocation(toComplement);
/*
* take what is inside join()
*/
+ if (!location.endsWith(")"))
+ {
+ return null;
+ }
String joinedLocs = location.substring("join(".length(),
location.length() - 1);
String[] locations = joinedLocs.split(",");
public void testParseLocation()
{
/*
+ * single locus
+ */
+ List<int[]> ranges = DnaUtils.parseLocation("467");
+ assertEquals(1, ranges.size());
+ assertEquals(467, ranges.get(0)[0]);
+ assertEquals(467, ranges.get(0)[1]);
+
+ /*
* simple range
*/
- List<int[]> ranges = DnaUtils.parseLocation("12..78");
+ ranges = DnaUtils.parseLocation("12..78");
assertEquals(1, ranges.size());
assertEquals(12, ranges.get(0)[0]);
assertEquals(78, ranges.get(0)[1]);
assertNull(DnaUtils.parseLocation("34..>126"));
assertNull(DnaUtils.parseLocation("34.126"));
assertNull(DnaUtils.parseLocation("34^126"));
+ assertNull(DnaUtils.parseLocation("order(34..126,130..180)"));
/*
* invalid things
assertNull(DnaUtils.parseLocation(""));
assertNull(DnaUtils.parseLocation("JOIN(1..2)"));
assertNull(DnaUtils.parseLocation("join(1..2"));
+ assertNull(DnaUtils.parseLocation("join(1..2("));
+ assertNull(DnaUtils.parseLocation("complement(1..2"));
+ assertNull(DnaUtils.parseLocation("complement(1..2("));
try
{
assertNull(DnaUtils.parseLocation(null));