JAL-2114 added single-locus case and more error tests
[jalview.git] / src / jalview / util / DnaUtils.java
index 639eb8e..9ab4fda 100644 (file)
@@ -32,13 +32,17 @@ public class DnaUtils
       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)
       {
@@ -70,6 +74,10 @@ public class DnaUtils
     /*
      * take what is inside complement()
      */
+    if (!location.endsWith(")"))
+    {
+      return null;
+    }
     String toComplement = location.substring("complement(".length(),
             location.length() - 1);
     List<int[]> ranges = parseLocation(toComplement);
@@ -107,6 +115,10 @@ public class DnaUtils
     /*
      * take what is inside join()
      */
+    if (!location.endsWith(")"))
+    {
+      return null;
+    }
     String joinedLocs = location.substring("join(".length(),
             location.length() - 1);
     String[] locations = joinedLocs.split(",");