From: amwaterhouse Date: Fri, 4 Nov 2005 10:56:54 +0000 (+0000) Subject: Id parsing moved to Sequence X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=820ae6f18432291d846be13bb776de9767b7a8ec;p=jalview.git Id parsing moved to Sequence --- diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index c24dc02..8e821a2 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -33,11 +33,11 @@ public class Sequence implements SequenceI { SequenceI datasetSequence; String name; + String shortName; String sequence; String description; int start; int end; - String displayId; Color color = Color.white; String pdbId; String vamsasId; @@ -58,6 +58,8 @@ public class Sequence implements SequenceI public Sequence(String name, String sequence, int start, int end) { this.name = name; + parseId(); + this.sequence = sequence; this.start = start; this.end = end; @@ -65,6 +67,57 @@ public class Sequence implements SequenceI checkValidRange(); } + void parseId() + { + // Read in any DB refs first + StringTokenizer st = new StringTokenizer(name, "|"); + if(st.countTokens()<1) + { + shortName = name; + return; + } + + while (st.countTokens() > 1) + { + String a = st.nextToken(); + String b = st.nextToken(); + addDBRef(new DBRefEntry(a, "0", b)); + } + + if (st.hasMoreTokens()) + shortName = st.nextToken(); + + // Remove /start-end from sequence + if (shortName.indexOf("/") > 0) + { + st = new StringTokenizer(shortName, "/"); + String limits = null; + try + { + if (st.countTokens() == 2) + { + shortName = st.nextToken(); + + limits = st.nextToken(); + + st = new StringTokenizer(limits, "-"); + + if (st.countTokens() == 2) + { + setStart(Integer.valueOf(st.nextToken()).intValue()); + setEnd(Integer.valueOf(st.nextToken()).intValue()); + } + } + } + catch (NumberFormatException ex) + { + // Problem parsing sequence limits. Just add it back to the + // Id so we dont lose this info + shortName += "/" + limits; + } + } + } + void checkValidRange() { if (end < 1) @@ -97,7 +150,7 @@ public class Sequence implements SequenceI */ public Sequence(String name, String sequence) { - this(name, sequence, 1, sequence.length()); + this(name, sequence, 1, -1); } /** @@ -175,7 +228,7 @@ public class Sequence implements SequenceI } } - result.append(name); + result.append(shortName); if (jvsuffix) { @@ -192,7 +245,8 @@ public class Sequence implements SequenceI */ public void setName(String name) { - this.name = name; + this.name = name; + this.parseId(); } /** @@ -202,7 +256,7 @@ public class Sequence implements SequenceI */ public String getName() { - return this.name; + return this.name; } /** diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 1377de2..6055230 100755 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -795,7 +795,7 @@ public class PopupMenu extends JPopupMenu */ void sequenceName_actionPerformed(ActionEvent e) { - String id = sequence.getName(); + String id = sequence.getDisplayId(false, false); String s = (String) JOptionPane.showInternalInputDialog(ap, "Edit sequence name", "Edit sequence name (" + sequence.getName() + ")", diff --git a/src/jalview/io/AlignFile.java b/src/jalview/io/AlignFile.java index 842f2fc..1ec2805 100755 --- a/src/jalview/io/AlignFile.java +++ b/src/jalview/io/AlignFile.java @@ -171,58 +171,20 @@ public abstract class AlignFile extends FileParse */ Sequence parseId(String id) { + Sequence seq = null; id = id.trim(); - Sequence seq = new Sequence("",""); int space = id.indexOf(" "); if(space>-1) { + seq = new Sequence(id.substring(0, space),""); seq.setDescription(id.substring(space+1)); - id = id.substring(0, space); } - - // Read in any DB refs first - StringTokenizer st; - st = new StringTokenizer(id, "|"); - - while (st.countTokens()>1) + else { - String a = st.nextToken(); - String b = st.nextToken(); - seq.addDBRef( new DBRefEntry( a, "0", b)); + seq = new Sequence(id, ""); } - if(st.hasMoreTokens()) - id = st.nextToken(); - - - // Remove /start-end from sequence - if (id.indexOf("/") > 0) - { - st = new StringTokenizer(id, "/"); - String limits=null; - try{ - if (st.countTokens() == 2) - { - id = st.nextToken(); - - limits = st.nextToken(); - st = new StringTokenizer(limits, "-"); - - if (st.countTokens() == 2) - { - seq.setStart(Integer.valueOf(st.nextToken()).intValue()); - seq.setEnd(Integer.valueOf(st.nextToken()).intValue()); - } - } - }catch(NumberFormatException ex) - { - // Problem parsing sequence limits. Just add it back to the - // Id so we dont lose this info - id += "/" + limits; - } - } - seq.setName(id); return seq; } @@ -235,25 +197,7 @@ public abstract class AlignFile extends FileParse */ String printId(SequenceI seq) { - StringBuffer result = new StringBuffer(); - if(dbPrefix && seq.getDBRef()!=null) - { - Vector dbrefs = seq.getDBRef(); - for(int i=0; i