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
30 * @version $Revision$
\r
32 public class Sequence implements SequenceI
\r
34 SequenceI datasetSequence;
\r
40 Color color = Color.white;
\r
46 /** DOCUMENT ME!! */
\r
47 public Vector sequenceFeatures = new Vector();
\r
50 * Creates a new Sequence object.
\r
52 * @param name DOCUMENT ME!
\r
53 * @param sequence DOCUMENT ME!
\r
54 * @param start DOCUMENT ME!
\r
55 * @param end DOCUMENT ME!
\r
57 public Sequence(String name, String sequence, int start, int end)
\r
60 this.sequence = sequence;
\r
71 // Remove /start-end from sequence
\r
72 if (name.indexOf("/") > 0)
\r
74 String limits = name.substring(name.lastIndexOf("/")+1);
\r
77 StringTokenizer st = new StringTokenizer(limits, "-");
\r
78 setStart(Integer.valueOf(st.nextToken()).intValue());
\r
79 setEnd(Integer.valueOf(st.nextToken()).intValue());
\r
81 // If we're still in this loop, parsing of start and end was ok
\r
82 // Therefore remove it from the sequence name
\r
83 name = name.substring(0, name.lastIndexOf("/"));
\r
85 catch (NumberFormatException ex)
\r
90 void checkValidRange()
\r
96 for (int j = 0; j < sequence.length(); j++)
\r
98 ch = sequence.charAt(j);
\r
99 if (!jalview.util.Comparison.isGap( (ch)))
\r
106 endRes += start - 1;
\r
115 * Creates a new Sequence object.
\r
117 * @param name DOCUMENT ME!
\r
118 * @param sequence DOCUMENT ME!
\r
120 public Sequence(String name, String sequence)
\r
122 this(name, sequence, 1, -1);
\r
126 * Creates a new Sequence object.
\r
128 * @param seq DOCUMENT ME!
\r
130 public Sequence(SequenceI seq)
\r
132 this(seq.getName(), seq.getSequence(), seq.getStart(), seq.getEnd());
\r
138 * @param v DOCUMENT ME!
\r
140 public void setSequenceFeatures(Vector v)
\r
142 sequenceFeatures = v;
\r
145 public void addSequenceFeature(SequenceFeature sf)
\r
147 if(sequenceFeatures==null)
\r
148 sequenceFeatures = new Vector();
\r
150 sequenceFeatures.addElement(sf);
\r
156 * @return DOCUMENT ME!
\r
158 public Vector getSequenceFeatures()
\r
160 return sequenceFeatures;
\r
163 public void addPDBId(PDBEntry entry)
\r
166 pdbIds = new Vector();
\r
168 pdbIds.addElement(entry);
\r
174 * @param id DOCUMENT ME!
\r
176 public void setPDBId(Vector id)
\r
184 * @return DOCUMENT ME!
\r
186 public Vector getPDBId()
\r
194 * @return DOCUMENT ME!
\r
196 public String getDisplayId(boolean jvsuffix)
\r
198 StringBuffer result = new StringBuffer(name);
\r
201 result.append("/" + start + "-" + end);
\r
204 return result.toString();
\r
210 * @param name DOCUMENT ME!
\r
212 public void setName(String name)
\r
221 * @return DOCUMENT ME!
\r
223 public String getName()
\r
231 * @param start DOCUMENT ME!
\r
233 public void setStart(int start)
\r
235 this.start = start;
\r
241 * @return DOCUMENT ME!
\r
243 public int getStart()
\r
251 * @param end DOCUMENT ME!
\r
253 public void setEnd(int end)
\r
261 * @return DOCUMENT ME!
\r
263 public int getEnd()
\r
271 * @return DOCUMENT ME!
\r
273 public int getLength()
\r
275 return this.sequence.length();
\r
281 * @param seq DOCUMENT ME!
\r
283 public void setSequence(String seq)
\r
285 this.sequence = seq;
\r
292 * @return DOCUMENT ME!
\r
294 public String getSequence()
\r
296 return this.sequence;
\r
302 * @param start DOCUMENT ME!
\r
303 * @param end DOCUMENT ME!
\r
305 * @return DOCUMENT ME!
\r
307 public String getSequence(int start, int end)
\r
309 // JBPNote - left to user to pad the result here (TODO:Decide on this policy)
\r
310 if (start >= sequence.length())
\r
315 if (end >= sequence.length())
\r
317 end = sequence.length();
\r
320 return this.sequence.substring(start, end);
\r
326 * @param i DOCUMENT ME!
\r
328 * @return DOCUMENT ME!
\r
330 public char getCharAt(int i)
\r
332 if (i < sequence.length())
\r
334 return sequence.charAt(i);
\r
345 * @param desc DOCUMENT ME!
\r
347 public void setDescription(String desc)
\r
349 this.description = desc;
\r
355 * @return DOCUMENT ME!
\r
357 public String getDescription()
\r
359 return this.description;
\r
365 * @param pos DOCUMENT ME!
\r
367 * @return DOCUMENT ME!
\r
369 public int findIndex(int pos)
\r
371 // returns the alignment position for a residue
\r
375 while ((i < sequence.length()) && (j <= end) && (j <= pos))
\r
377 if (!jalview.util.Comparison.isGap(sequence.charAt(i)))
\r
385 if ((j == end) && (j < pos))
\r
398 * @param i DOCUMENT ME!
\r
400 * @return DOCUMENT ME!
\r
402 public int findPosition(int i)
\r
404 // Returns the sequence position for an alignment position
\r
408 while ((j < i) && (j < sequence.length()))
\r
410 if (!jalview.util.Comparison.isGap((sequence.charAt(j))))
\r
424 * @return DOCUMENT ME!
\r
426 public int[] gapMap()
\r
428 // Returns an int array giving the position of each residue in the sequence in the alignment
\r
429 String seq = jalview.analysis.AlignSeq.extractGaps("-. ", sequence);
\r
430 int[] map = new int[seq.length()];
\r
434 while (j < sequence.length())
\r
436 if (!jalview.util.Comparison.isGap(sequence.charAt(j)))
\r
450 * @param i DOCUMENT ME!
\r
452 public void deleteCharAt(int i)
\r
454 if (i >= sequence.length())
\r
459 sequence = sequence.substring(0, i) + sequence.substring(i + 1);
\r
465 * @param i DOCUMENT ME!
\r
466 * @param j DOCUMENT ME!
\r
468 public void deleteChars(int i, int j)
\r
470 if (i >= sequence.length())
\r
475 if (j >= sequence.length())
\r
477 sequence = sequence.substring(0, i);
\r
481 sequence = sequence.substring(0, i) + sequence.substring(j);
\r
488 * @param i DOCUMENT ME!
\r
489 * @param c DOCUMENT ME!
\r
491 public void insertCharAt(int i, char c)
\r
493 insertCharAt(i, c, true);
\r
499 * @param i DOCUMENT ME!
\r
500 * @param c DOCUMENT ME!
\r
501 * @param chop DOCUMENT ME!
\r
503 public void insertCharAt(int i, char c, boolean chop)
\r
505 String tmp = new String(sequence);
\r
507 if (i < sequence.length())
\r
509 sequence = tmp.substring(0, i) + String.valueOf(c) +
\r
514 // JBPNote : padding char at end of sequence. We'll not get away with this when we insert residues, I bet!
\r
515 char[] ch = new char[(1 + i) - sequence.length()];
\r
517 for (int j = 0, k = ch.length; j < k; j++)
\r
520 sequence = tmp + String.valueOf(ch);
\r
527 * @param c DOCUMENT ME!
\r
529 public void setColor(Color c)
\r
537 * @return DOCUMENT ME!
\r
539 public Color getColor()
\r
544 public String getVamsasId()
\r
549 public void setVamsasId(String id)
\r
554 public void setDBRef(Vector dbref)
\r
558 public Vector getDBRef()
\r
563 public void addDBRef(DBRefEntry entry)
\r
566 dbrefs = new Vector();
\r
568 dbrefs.addElement(entry);
\r
571 public void setDatasetSequence(SequenceI seq)
\r
573 datasetSequence = seq;
\r
576 public SequenceI getDatasetSequence()
\r
578 return datasetSequence;
\r