2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.datamodel;
\r
22 import jalview.analysis.*;
\r
28 public class Sequence implements SequenceI
\r
30 protected String name;
\r
31 protected String sequence;
\r
32 protected String description;
\r
33 protected int start;
\r
35 protected String displayId;
\r
36 protected Color color = Color.white;
\r
39 public Vector sequenceFeatures = new Vector();
\r
40 public void setSequenceFeatures(Vector v)
\r
42 sequenceFeatures = v;
\r
45 public Vector getSequenceFeatures()
\r
46 {return sequenceFeatures; }
\r
48 public void setPDBId(String id)
\r
52 public String getPDBId()
\r
58 public Sequence(String name, String sequence, int start, int end)
\r
62 this.sequence = sequence;
\r
70 public Sequence(String name,String sequence) {
\r
71 this(name,sequence,1,sequence.length());
\r
73 public Sequence(SequenceI seq) {
\r
74 this(seq.getName(),seq.getSequence(),seq.getStart(),seq.getEnd());
\r
76 public String getDisplayId() {
\r
79 public void setDisplayId() {
\r
80 displayId = name + "/" + start + "-" + end;
\r
82 public void setName(String name) {
\r
86 public String getName() {
\r
89 public void setStart(int start) {
\r
93 public int getStart() {
\r
96 public void setEnd(int end) {
\r
100 public int getEnd() {
\r
103 public int getLength() {
\r
104 return this.sequence.length();
\r
106 public void setSequence(String seq) {
\r
107 this.sequence = seq;
\r
109 public String getSequence() {
\r
110 return this.sequence;
\r
112 public String getSequence(int start,int end) {
\r
113 // JBPNote - left to user to pad the result here (TODO:Decide on this policy)
\r
114 if(start>=sequence.length())
\r
117 if(end>=sequence.length())
\r
118 end = sequence.length();
\r
120 return this.sequence.substring(start,end);
\r
123 public char getCharAt(int i) {
\r
124 if (i < sequence.length()) {
\r
125 return sequence.charAt(i);
\r
130 public void setDescription(String desc) {
\r
131 this.description = desc;
\r
133 public String getDescription() {
\r
134 return this.description;
\r
137 public int findIndex(int pos) {
\r
138 // returns the alignment position for a residue
\r
142 while (i< sequence.length() && j <= end && j <= pos) {
\r
144 char c = sequence.charAt(i);
\r
146 if (!jalview.util.Comparison.isGap((c)))
\r
151 if (j == end && j < pos)
\r
158 public int findPosition(int i) {
\r
159 // Returns the sequence position for an alignment position
\r
163 while (j < i && j<sequence.length())
\r
165 char c = sequence.charAt(j);
\r
166 if (!jalview.util.Comparison.isGap((c)))
\r
174 public int[] gapMap() {
\r
175 // Returns an int array giving the position of each residue in the sequence in the alignment
\r
176 String seq = jalview.analysis.AlignSeq.extractGaps("-. ",sequence);
\r
177 int[] map = new int[seq.length()];
\r
180 while (j<sequence.length()) {
\r
181 if (!jalview.util.Comparison.isGap(sequence.charAt(j))) {
\r
189 public void deleteCharAt(int i)
\r
191 if (i>=sequence.length())
\r
193 sequence = sequence.substring(0,i) + sequence.substring(i+1);
\r
196 public void deleteChars(int i, int j)
\r
198 if (i>=sequence.length())
\r
200 if (j>=sequence.length())
\r
201 sequence = sequence.substring(0,i);
\r
203 sequence = sequence.substring(0,i) + sequence.substring(j);
\r
206 public void insertCharAt(int i, char c)
\r
208 insertCharAt(i,c,true);
\r
211 public void insertCharAt(int i,char c,boolean chop) {
\r
213 String tmp = new String(sequence);
\r
215 if (i < sequence.length()) {
\r
216 sequence = tmp.substring(0,i) + String.valueOf(c) + tmp.substring(i);
\r
218 // JBPNote : padding char at end of sequence. We'll not get away with this when we insert residues, I bet!
\r
219 char[] ch = new char[1+i-sequence.length()];
\r
220 for (int j=0, k=ch.length; j<k; j++)
\r
222 sequence = tmp + String.valueOf(ch);
\r
227 public void setColor(Color c) {
\r
231 public Color getColor() {
\r