package jalview.datamodel;\r
\r
-\r
+import jalview.analysis.*;\r
import java.awt.*;\r
+import java.util.*;\r
+import MCview.*;\r
+\r
\r
public class Sequence implements SequenceI\r
{\r
- protected String name;\r
- protected String sequence;\r
- protected int start;\r
- protected int end;\r
- protected String description;\r
- protected int charHeight;\r
- protected String displayId;\r
- protected Color color = Color.white;\r
+ protected String name;\r
+ protected String sequence;\r
+ protected String description;\r
+ protected int start;\r
+ protected int end;\r
+ protected String displayId;\r
+ protected Color color = Color.white;\r
+ String pdbId;\r
+\r
+ public Vector sequenceFeatures = new Vector();\r
+ public void setSequenceFeatures(Vector v)\r
+ {\r
+ sequenceFeatures = v;\r
+ }\r
+\r
+ public Vector getSequenceFeatures()\r
+ {return sequenceFeatures; }\r
+\r
+ public void setPDBId(String id)\r
+ {\r
+ pdbId = id;\r
+ }\r
+ public String getPDBId()\r
+ {\r
+ return pdbId;\r
+ }\r
+\r
\r
public Sequence(String name, String sequence, int start, int end)\r
{\r
return this.sequence;\r
}\r
public String getSequence(int start,int end) {\r
+ // JBPNote - left to user to pad the result here (TODO:Decide on this policy)\r
+ if(start>=sequence.length())\r
+ return "";\r
+\r
+ if(end>=sequence.length())\r
+ end = sequence.length();\r
+\r
return this.sequence.substring(start,end);\r
}\r
\r
\r
while (i< sequence.length() && j <= end && j <= pos) {\r
\r
- String s = sequence.substring(i,i+1);\r
+ char c = sequence.charAt(i);\r
\r
- if (!(s.equals(".") || s.equals("-") || s.equals(" "))) {\r
+ if (!jalview.util.Comparison.isGap((c)))\r
j++;\r
- }\r
+\r
i++;\r
}\r
- if (j == end && j < pos) {\r
+ if (j == end && j < pos)\r
return end+1;\r
- } else {\r
-\r
+ else\r
return i;\r
- }\r
+\r
}\r
\r
public int findPosition(int i) {\r
int j = 0;\r
int pos = start;\r
\r
- while (j < i) {\r
- String s = sequence.substring(j,j+1);\r
-\r
- if (!(s.equals(".") || s.equals("-") || s.equals(" "))) {\r
+ while (j < i && j<sequence.length())\r
+ {\r
+ char c = sequence.charAt(j);\r
+ if (!jalview.util.Comparison.isGap((c)))\r
pos++;\r
- }\r
+\r
j++;\r
}\r
return pos;\r
}\r
+\r
+ public int[] gapMap() {\r
+ // Returns an int array giving the position of each residue in the sequence in the alignment\r
+ String seq = jalview.analysis.AlignSeq.extractGaps("-. ",sequence);\r
+ int[] map = new int[seq.length()];\r
+ int j=0;\r
+ int p=0;\r
+ while (j<sequence.length()) {\r
+ if (!jalview.util.Comparison.isGap(sequence.charAt(j))) {\r
+ map[p++]=j;\r
+ }\r
+ j++;\r
+ }\r
+ return map;\r
+ }\r
+\r
public void deleteCharAt(int i)\r
{\r
- StringBuffer sbuffer = new StringBuffer(sequence);\r
- sbuffer.deleteCharAt(i);\r
- sequence = sbuffer.toString();\r
+ if (i>=sequence.length())\r
+ return;\r
+ sequence = sequence.substring(0,i) + sequence.substring(i+1);\r
+ }\r
+\r
+ public void deleteChars(int i, int j)\r
+ {\r
+ if (i>=sequence.length())\r
+ return;\r
+ if (j>=sequence.length())\r
+ sequence = sequence.substring(0,i);\r
+ else\r
+ sequence = sequence.substring(0,i) + sequence.substring(j);\r
}\r
\r
public void insertCharAt(int i, char c)\r
if (i < sequence.length()) {\r
sequence = tmp.substring(0,i) + String.valueOf(c) + tmp.substring(i);\r
} else {\r
- sequence = tmp + String.valueOf(c);\r
+ // JBPNote : padding char at end of sequence. We'll not get away with this when we insert residues, I bet!\r
+ char[] ch = new char[1+i-sequence.length()];\r
+ for (int j=0, k=ch.length; j<k; j++)\r
+ ch[j] = c;\r
+ sequence = tmp + String.valueOf(ch);\r
}\r
\r
}\r