Use regex on seq names
authoramwaterhouse <Andrew Waterhouse>
Mon, 5 Dec 2005 13:38:26 +0000 (13:38 +0000)
committeramwaterhouse <Andrew Waterhouse>
Mon, 5 Dec 2005 13:38:26 +0000 (13:38 +0000)
src/jalview/datamodel/Sequence.java

index 05a2b73..80dfda5 100755 (executable)
@@ -66,24 +66,20 @@ public class Sequence implements SequenceI
       checkValidRange();\r
     }\r
 \r
+    static com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(\r
+                        "[/][0-9]{1,}[-][0-9]{1,}$");\r
+    static com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex(\r
+                        "[0-9]{1,}$");\r
+\r
     void parseId()\r
     {\r
-         // Remove /start-end from sequence\r
-         if (name.indexOf("/") > 0)\r
+        // Does sequence have the /start-end signiature?\r
+         if(limitrx.search(name))\r
          {\r
-           String limits = name.substring(name.lastIndexOf("/")+1);\r
-           try\r
-           {\r
-             StringTokenizer st = new StringTokenizer(limits, "-");\r
-             setStart(Integer.valueOf(st.nextToken()).intValue());\r
-             setEnd(Integer.valueOf(st.nextToken()).intValue());\r
-\r
-             // If we're still in this loop, parsing of start and end was ok\r
-             // Therefore remove it from the sequence name\r
-             name = name.substring(0, name.lastIndexOf("/"));\r
-           }\r
-           catch (NumberFormatException ex)\r
-           {      }\r
+            name = limitrx.left();\r
+            endrx.search(limitrx.stringMatched());\r
+            setStart( Integer.parseInt( limitrx.stringMatched().substring(1,endrx.matchedFrom()-1 )));\r
+            setEnd(   Integer.parseInt( endrx.stringMatched() ));\r
          }\r
     }\r
 \r