X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequence.java;h=d35a05bb7cc6df87e94c5f7e949e11c7e6e71357;hb=9480f18113c0d16dfb157eb3fff60a1e29c33d39;hp=34c1cd917f6f0fb252de743de48435710db7bfae;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 34c1cd9..d35a05b 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -18,10 +18,6 @@ */ package jalview.datamodel; -import MCview.*; - -import jalview.analysis.*; - import java.awt.*; import java.util.*; @@ -35,17 +31,23 @@ import java.util.*; */ public class Sequence implements SequenceI { - protected String name; - protected String sequence; - protected String description; - protected int start; - protected int end; - protected String displayId; - protected Color color = Color.white; - String pdbId; + SequenceI datasetSequence; + String name; + String sequence; + String description; + int start; + int end; + Color color = Color.white; + Vector pdbIds; + String vamsasId; + Vector dbrefs; + + /** This annotation is displayed below the alignment but the + * positions are tied to the residues of this sequence */ + Vector annotation; /** DOCUMENT ME!! */ - public Vector sequenceFeatures = new Vector(); + public Vector sequenceFeatures; /** * Creates a new Sequence object. @@ -57,12 +59,55 @@ public class Sequence implements SequenceI */ public Sequence(String name, String sequence, int start, int end) { - this.name = name; - this.sequence = sequence; - this.start = start; - this.end = end; + this.name = name; + this.sequence = sequence; + this.start = start; + this.end = end; + + parseId(); + + checkValidRange(); + } + + com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex( + "[/][0-9]{1,}[-][0-9]{1,}$"); + com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex( + "[0-9]{1,}$"); + + void parseId() + { + // Does sequence have the /start-end signiature? + if(limitrx.search(name)) + { + name = limitrx.left(); + endrx.search(limitrx.stringMatched()); + setStart( Integer.parseInt( limitrx.stringMatched().substring(1,endrx.matchedFrom()-1 ))); + setEnd( Integer.parseInt( endrx.stringMatched() )); + } + } + + void checkValidRange() + { + if (end < 1) + { + int endRes = 0; + char ch; + for (int j = 0; j < sequence.length(); j++) + { + ch = sequence.charAt(j); + if (!jalview.util.Comparison.isGap( (ch))) + { + endRes++; + } + } + if (endRes > 0) + { + endRes += start - 1; + } + + this.end = endRes; + } - setDisplayId(); } /** @@ -73,7 +118,7 @@ public class Sequence implements SequenceI */ public Sequence(String name, String sequence) { - this(name, sequence, 1, sequence.length()); + this(name, sequence, 1, -1); } /** @@ -96,6 +141,14 @@ public class Sequence implements SequenceI sequenceFeatures = v; } + public void addSequenceFeature(SequenceFeature sf) + { + if(sequenceFeatures==null) + sequenceFeatures = new Vector(); + + sequenceFeatures.addElement(sf); + } + /** * DOCUMENT ME! * @@ -106,14 +159,22 @@ public class Sequence implements SequenceI return sequenceFeatures; } + public void addPDBId(PDBEntry entry) + { + if(pdbIds == null) + pdbIds = new Vector(); + + pdbIds.addElement(entry); + } + /** * DOCUMENT ME! * * @param id DOCUMENT ME! */ - public void setPDBId(String id) + public void setPDBId(Vector id) { - pdbId = id; + pdbIds = id; } /** @@ -121,9 +182,9 @@ public class Sequence implements SequenceI * * @return DOCUMENT ME! */ - public String getPDBId() + public Vector getPDBId() { - return pdbId; + return pdbIds; } /** @@ -131,17 +192,15 @@ public class Sequence implements SequenceI * * @return DOCUMENT ME! */ - public String getDisplayId() + public String getDisplayId(boolean jvsuffix) { - return displayId; - } + StringBuffer result = new StringBuffer(name); + if (jvsuffix) + { + result.append("/" + start + "-" + end); + } - /** - * DOCUMENT ME! - */ - public void setDisplayId() - { - displayId = name + "/" + start + "-" + end; + return result.toString(); } /** @@ -151,8 +210,8 @@ public class Sequence implements SequenceI */ public void setName(String name) { - this.name = name; - setDisplayId(); + this.name = name; + this.parseId(); } /** @@ -162,7 +221,7 @@ public class Sequence implements SequenceI */ public String getName() { - return this.name; + return this.name; } /** @@ -173,7 +232,6 @@ public class Sequence implements SequenceI public void setStart(int start) { this.start = start; - setDisplayId(); } /** @@ -194,7 +252,6 @@ public class Sequence implements SequenceI public void setEnd(int end) { this.end = end; - setDisplayId(); } /** @@ -225,6 +282,7 @@ public class Sequence implements SequenceI public void setSequence(String seq) { this.sequence = seq; + checkValidRange(); } /** @@ -315,9 +373,7 @@ public class Sequence implements SequenceI while ((i < sequence.length()) && (j <= end) && (j <= pos)) { - char c = sequence.charAt(i); - - if (!jalview.util.Comparison.isGap((c))) + if (!jalview.util.Comparison.isGap(sequence.charAt(i))) { j++; } @@ -350,9 +406,7 @@ public class Sequence implements SequenceI while ((j < i) && (j < sequence.length())) { - char c = sequence.charAt(j); - - if (!jalview.util.Comparison.isGap((c))) + if (!jalview.util.Comparison.isGap((sequence.charAt(j)))) { pos++; } @@ -485,4 +539,62 @@ public class Sequence implements SequenceI { return color; } + + public String getVamsasId() + { + return vamsasId; + } + + public void setVamsasId(String id) + { + vamsasId = id; + } + + public void setDBRef(Vector dbref) + { + dbrefs = dbref; + } + public Vector getDBRef() + { + return dbrefs; + } + + public void addDBRef(DBRefEntry entry) + { + if(dbrefs == null) + dbrefs = new Vector(); + + dbrefs.addElement(entry); + } + + public void setDatasetSequence(SequenceI seq) + { + datasetSequence = seq; + } + + public SequenceI getDatasetSequence() + { + return datasetSequence; + } + + public AlignmentAnnotation [] getAnnotation() + { + if(annotation==null) + return null; + + AlignmentAnnotation [] ret = new AlignmentAnnotation[annotation.size()]; + for(int r = 0; r