1 package jalview.datamodel;
\r
3 import jalview.analysis.*;
\r
9 public class Sequence implements SequenceI
\r
11 protected String name;
\r
12 protected String sequence;
\r
13 protected String description;
\r
14 protected int start;
\r
16 protected String displayId;
\r
17 protected Color color = Color.white;
\r
20 public Vector sequenceFeatures = new Vector();
\r
21 public void setSequenceFeatures(Vector v)
\r
23 sequenceFeatures = v;
\r
26 public Vector getSequenceFeatures()
\r
27 {return sequenceFeatures; }
\r
29 public void setPDBId(String id)
\r
33 public String getPDBId()
\r
39 public Sequence(String name, String sequence, int start, int end)
\r
43 this.sequence = sequence;
\r
51 public Sequence(String name,String sequence) {
\r
52 this(name,sequence,1,sequence.length());
\r
54 public Sequence(SequenceI seq) {
\r
55 this(seq.getName(),seq.getSequence(),seq.getStart(),seq.getEnd());
\r
57 public String getDisplayId() {
\r
60 public void setDisplayId() {
\r
61 displayId = name + "/" + start + "-" + end;
\r
63 public void setName(String name) {
\r
67 public String getName() {
\r
70 public void setStart(int start) {
\r
74 public int getStart() {
\r
77 public void setEnd(int end) {
\r
81 public int getEnd() {
\r
84 public int getLength() {
\r
85 return this.sequence.length();
\r
87 public void setSequence(String seq) {
\r
88 this.sequence = seq;
\r
90 public String getSequence() {
\r
91 return this.sequence;
\r
93 public String getSequence(int start,int end) {
\r
94 // JBPNote - left to user to pad the result here (TODO:Decide on this policy)
\r
95 if(start>=sequence.length())
\r
98 if(end>=sequence.length())
\r
99 end = sequence.length();
\r
101 return this.sequence.substring(start,end);
\r
104 public char getCharAt(int i) {
\r
105 if (i < sequence.length()) {
\r
106 return sequence.charAt(i);
\r
111 public void setDescription(String desc) {
\r
112 this.description = desc;
\r
114 public String getDescription() {
\r
115 return this.description;
\r
118 public int findIndex(int pos) {
\r
119 // returns the alignment position for a residue
\r
123 while (i< sequence.length() && j <= end && j <= pos) {
\r
125 char c = sequence.charAt(i);
\r
127 if (!jalview.util.Comparison.isGap((c)))
\r
132 if (j == end && j < pos)
\r
139 public int findPosition(int i) {
\r
140 // Returns the sequence position for an alignment position
\r
144 while (j < i && j<sequence.length())
\r
146 char c = sequence.charAt(j);
\r
147 if (!jalview.util.Comparison.isGap((c)))
\r
155 public int[] gapMap() {
\r
156 // Returns an int array giving the position of each residue in the sequence in the alignment
\r
157 String seq = jalview.analysis.AlignSeq.extractGaps("-. ",sequence);
\r
158 int[] map = new int[seq.length()];
\r
161 while (j<sequence.length()) {
\r
162 if (!jalview.util.Comparison.isGap(sequence.charAt(j))) {
\r
170 public void deleteCharAt(int i)
\r
172 if (i>=sequence.length())
\r
174 sequence = sequence.substring(0,i) + sequence.substring(i+1);
\r
177 public void deleteChars(int i, int j)
\r
179 if (i>=sequence.length())
\r
181 if (j>=sequence.length())
\r
182 sequence = sequence.substring(0,i);
\r
184 sequence = sequence.substring(0,i) + sequence.substring(j);
\r
187 public void insertCharAt(int i, char c)
\r
189 insertCharAt(i,c,true);
\r
192 public void insertCharAt(int i,char c,boolean chop) {
\r
194 String tmp = new String(sequence);
\r
196 if (i < sequence.length()) {
\r
197 sequence = tmp.substring(0,i) + String.valueOf(c) + tmp.substring(i);
\r
199 // JBPNote : padding char at end of sequence. We'll not get away with this when we insert residues, I bet!
\r
200 char[] ch = new char[1+i-sequence.length()];
\r
201 for (int j=0, k=ch.length; j<k; j++)
\r
203 sequence = tmp + String.valueOf(ch);
\r
208 public void setColor(Color c) {
\r
212 public Color getColor() {
\r