From a497d3031bbc2ae601295bdd03e240c38261e15c Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Mon, 5 Dec 2005 13:38:26 +0000 Subject: [PATCH] Use regex on seq names --- src/jalview/datamodel/Sequence.java | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 05a2b73..80dfda5 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -66,24 +66,20 @@ public class Sequence implements SequenceI checkValidRange(); } + static com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex( + "[/][0-9]{1,}[-][0-9]{1,}$"); + static com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex( + "[0-9]{1,}$"); + void parseId() { - // Remove /start-end from sequence - if (name.indexOf("/") > 0) + // Does sequence have the /start-end signiature? + if(limitrx.search(name)) { - String limits = name.substring(name.lastIndexOf("/")+1); - try - { - StringTokenizer st = new StringTokenizer(limits, "-"); - setStart(Integer.valueOf(st.nextToken()).intValue()); - setEnd(Integer.valueOf(st.nextToken()).intValue()); - - // If we're still in this loop, parsing of start and end was ok - // Therefore remove it from the sequence name - name = name.substring(0, name.lastIndexOf("/")); - } - catch (NumberFormatException ex) - { } + name = limitrx.left(); + endrx.search(limitrx.stringMatched()); + setStart( Integer.parseInt( limitrx.stringMatched().substring(1,endrx.matchedFrom()-1 ))); + setEnd( Integer.parseInt( endrx.stringMatched() )); } } -- 1.7.10.2