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
19 package jalview.datamodel;
\r
23 import jalview.analysis.*;
\r
30 public class Sequence implements SequenceI {
\r
31 protected String name;
\r
32 protected String sequence;
\r
33 protected String description;
\r
34 protected int start;
\r
36 protected String displayId;
\r
37 protected Color color = Color.white;
\r
39 public Vector sequenceFeatures = new Vector();
\r
41 public Sequence(String name, String sequence, int start, int end) {
\r
43 this.sequence = sequence;
\r
50 public Sequence(String name, String sequence) {
\r
51 this(name, sequence, 1, sequence.length());
\r
54 public Sequence(SequenceI seq) {
\r
55 this(seq.getName(), seq.getSequence(), seq.getStart(), seq.getEnd());
\r
58 public void setSequenceFeatures(Vector v) {
\r
59 sequenceFeatures = v;
\r
62 public Vector getSequenceFeatures() {
\r
63 return sequenceFeatures;
\r
66 public void setPDBId(String id) {
\r
70 public String getPDBId() {
\r
74 public String getDisplayId() {
\r
78 public void setDisplayId() {
\r
79 displayId = name + "/" + start + "-" + end;
\r
82 public void setName(String name) {
\r
87 public String getName() {
\r
91 public void setStart(int start) {
\r
96 public int getStart() {
\r
100 public void setEnd(int end) {
\r
105 public int getEnd() {
\r
109 public int getLength() {
\r
110 return this.sequence.length();
\r
113 public void setSequence(String seq) {
\r
114 this.sequence = seq;
\r
117 public String getSequence() {
\r
118 return this.sequence;
\r
121 public String getSequence(int start, int end) {
\r
122 // JBPNote - left to user to pad the result here (TODO:Decide on this policy)
\r
123 if (start >= sequence.length()) {
\r
127 if (end >= sequence.length()) {
\r
128 end = sequence.length();
\r
131 return this.sequence.substring(start, end);
\r
134 public char getCharAt(int i) {
\r
135 if (i < sequence.length()) {
\r
136 return sequence.charAt(i);
\r
142 public void setDescription(String desc) {
\r
143 this.description = desc;
\r
146 public String getDescription() {
\r
147 return this.description;
\r
150 public int findIndex(int pos) {
\r
151 // returns the alignment position for a residue
\r
155 while ((i < sequence.length()) && (j <= end) && (j <= pos)) {
\r
156 char c = sequence.charAt(i);
\r
158 if (!jalview.util.Comparison.isGap((c))) {
\r
165 if ((j == end) && (j < pos)) {
\r
172 public int findPosition(int i) {
\r
173 // Returns the sequence position for an alignment position
\r
177 while ((j < i) && (j < sequence.length())) {
\r
178 char c = sequence.charAt(j);
\r
180 if (!jalview.util.Comparison.isGap((c))) {
\r
190 public int[] gapMap() {
\r
191 // Returns an int array giving the position of each residue in the sequence in the alignment
\r
192 String seq = jalview.analysis.AlignSeq.extractGaps("-. ", sequence);
\r
193 int[] map = new int[seq.length()];
\r
197 while (j < sequence.length()) {
\r
198 if (!jalview.util.Comparison.isGap(sequence.charAt(j))) {
\r
208 public void deleteCharAt(int i) {
\r
209 if (i >= sequence.length()) {
\r
213 sequence = sequence.substring(0, i) + sequence.substring(i + 1);
\r
216 public void deleteChars(int i, int j) {
\r
217 if (i >= sequence.length()) {
\r
221 if (j >= sequence.length()) {
\r
222 sequence = sequence.substring(0, i);
\r
224 sequence = sequence.substring(0, i) + sequence.substring(j);
\r
228 public void insertCharAt(int i, char c) {
\r
229 insertCharAt(i, c, true);
\r
232 public void insertCharAt(int i, char c, boolean chop) {
\r
233 String tmp = new String(sequence);
\r
235 if (i < sequence.length()) {
\r
236 sequence = tmp.substring(0, i) + String.valueOf(c) +
\r
239 // JBPNote : padding char at end of sequence. We'll not get away with this when we insert residues, I bet!
\r
240 char[] ch = new char[(1 + i) - sequence.length()];
\r
242 for (int j = 0, k = ch.length; j < k; j++)
\r
245 sequence = tmp + String.valueOf(ch);
\r
249 public void setColor(Color c) {
\r
253 public Color getColor() {
\r