merge from 2_4_Release branch
[jalview.git] / src / jalview / datamodel / SequenceI.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3  * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.datamodel;
20
21 import java.util.*;
22
23 /**
24  * DOCUMENT ME!
25  * 
26  * @author $author$
27  * @version $Revision$
28  */
29 public interface SequenceI
30 {
31   /**
32    * Set the display name for the sequence
33    * 
34    * @param name
35    */
36   public void setName(String name);
37
38   /**
39    * Get the display name
40    */
41   public String getName();
42
43   /**
44    * Set start position of first non-gapped symbol in sequence
45    * 
46    * @param start
47    *                new start position
48    */
49   public void setStart(int start);
50
51   /**
52    * get start position of first non-gapped residue in sequence
53    * 
54    * @return
55    */
56   public int getStart();
57
58   /**
59    * get the displayed id of the sequence
60    * 
61    * @return true means the id will be returned in the form
62    *         DisplayName/Start-End
63    */
64   public String getDisplayId(boolean jvsuffix);
65
66   /**
67    * set end position for last residue in sequence
68    * 
69    * @param end
70    */
71   public void setEnd(int end);
72
73   /**
74    * get end position for last residue in sequence getEnd()>getStart() unless
75    * sequence only consists of gap characters
76    * 
77    * @return
78    */
79   public int getEnd();
80
81   /**
82    * @return length of sequence including gaps
83    * 
84    */
85   public int getLength();
86
87   /**
88    * Replace the sequence with the given string
89    * 
90    * @param sequence
91    *                new sequence string
92    */
93   public void setSequence(String sequence);
94
95   /**
96    * @return sequence as string
97    */
98   public String getSequenceAsString();
99
100   /**
101    * get a range on the seuqence as a string
102    * 
103    * @param start
104    *                DOCUMENT ME!
105    * @param end
106    *                DOCUMENT ME!
107    * 
108    * @return DOCUMENT ME!
109    */
110   public String getSequenceAsString(int start, int end);
111
112   /**
113    * DOCUMENT ME!
114    * 
115    * @return DOCUMENT ME!
116    */
117   public char[] getSequence();
118
119   /**
120    * get stretch of sequence characters in an array
121    * 
122    * @param start
123    *                absolute index into getSequence()
124    * @param end
125    *                exclusive index of last position in segment to be returned.
126    * 
127    * @return char[max(0,end-start)];
128    */
129   public char[] getSequence(int start, int end);
130
131   /**
132    * create a new sequence object from start to end of this sequence
133    * 
134    * @param start
135    *                int
136    * @param end
137    *                int
138    * @return SequenceI
139    */
140   public SequenceI getSubSequence(int start, int end);
141
142   /**
143    * DOCUMENT ME!
144    * 
145    * @param i
146    *                DOCUMENT ME!
147    * 
148    * @return DOCUMENT ME!
149    */
150   public char getCharAt(int i);
151
152   /**
153    * DOCUMENT ME!
154    * 
155    * @param desc
156    *                DOCUMENT ME!
157    */
158   public void setDescription(String desc);
159
160   /**
161    * DOCUMENT ME!
162    * 
163    * @return DOCUMENT ME!
164    */
165   public String getDescription();
166
167   /**
168    * DOCUMENT ME!
169    * 
170    * @param pos
171    *                DOCUMENT ME!
172    * 
173    * @return DOCUMENT ME!
174    */
175   public int findIndex(int pos);
176
177   /**
178    * Returns the sequence position for an alignment position
179    * 
180    * @param i
181    *                column index in alignment (from 1)
182    * 
183    * @return residue number for residue (left of and) nearest ith column
184    */
185   public int findPosition(int i);
186
187   /**
188    * Returns an int array where indices correspond to each residue in the
189    * sequence and the element value gives its position in the alignment
190    * 
191    * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
192    *         residues in SequenceI object
193    */
194   public int[] gapMap();
195
196   /**
197    * Returns an int array where indices correspond to each position in sequence
198    * char array and the element value gives the result of findPosition for that
199    * index in the sequence.
200    * 
201    * @return int[SequenceI.getLength()]
202    */
203   public int[] findPositionMap();
204
205   /**
206    * Delete a range of aligned sequence columns, creating a new dataset sequence
207    * if necessary and adjusting start and end positions accordingly.
208    * 
209    * @param i
210    *                first column in range to delete
211    * @param j
212    *                last column in range to delete
213    */
214   public void deleteChars(int i, int j);
215
216   /**
217    * DOCUMENT ME!
218    * 
219    * @param i
220    *                DOCUMENT ME!
221    * @param c
222    *                DOCUMENT ME!
223    */
224   public void insertCharAt(int i, char c);
225
226   /**
227    * DOCUMENT ME!
228    * 
229    * @param i
230    *                DOCUMENT ME!
231    * @param c
232    *                DOCUMENT ME!
233    */
234   public void insertCharAt(int i, int length, char c);
235
236   /**
237    * DOCUMENT ME!
238    * 
239    * @return DOCUMENT ME!
240    */
241   public SequenceFeature[] getSequenceFeatures();
242
243   /**
244    * DOCUMENT ME!
245    * 
246    * @param v
247    *                DOCUMENT ME!
248    */
249   public void setSequenceFeatures(SequenceFeature[] features);
250
251   /**
252    * DOCUMENT ME!
253    * 
254    * @param id
255    *                DOCUMENT ME!
256    */
257   public void setPDBId(Vector ids);
258
259   /**
260    * DOCUMENT ME!
261    * 
262    * @return DOCUMENT ME!
263    */
264   public Vector getPDBId();
265
266   /**
267    * add entry to the vector of PDBIds, if it isn't in the list already
268    * 
269    * @param entry
270    */
271   public void addPDBId(PDBEntry entry);
272
273   /**
274    * update the list of PDBEntrys to include any DBRefEntrys citing structural
275    * databases
276    * 
277    * @return true if PDBEntry list was modified
278    */
279   public boolean updatePDBIds();
280
281   public String getVamsasId();
282
283   public void setVamsasId(String id);
284
285   public void setDBRef(DBRefEntry[] dbs);
286
287   public DBRefEntry[] getDBRef();
288
289   /**
290    * add the given entry to the list of DBRefs for this sequence, or replace a
291    * similar one if entry contains a map object and the existing one doesnt.
292    * 
293    * @param entry
294    */
295   public void addDBRef(DBRefEntry entry);
296
297   public void addSequenceFeature(SequenceFeature sf);
298
299   public void deleteFeature(SequenceFeature sf);
300
301   public void setDatasetSequence(SequenceI seq);
302
303   public SequenceI getDatasetSequence();
304
305   public AlignmentAnnotation[] getAnnotation();
306
307   public void addAlignmentAnnotation(AlignmentAnnotation annotation);
308
309   public void removeAlignmentAnnotation(AlignmentAnnotation annotation);
310
311   /**
312    * Derive a sequence (using this one's dataset or as the dataset)
313    * 
314    * @return duplicate sequence with valid dataset sequence
315    */
316   public SequenceI deriveSequence();
317
318   /**
319    * set the array of associated AlignmentAnnotation for this sequenceI
320    * 
321    * @param revealed
322    */
323   public void setAlignmentAnnotation(AlignmentAnnotation[] annotation);
324
325   /**
326    * Get one or more alignment annotations with a particular label.
327    * 
328    * @param label
329    *                string which each returned annotation must have as a label.
330    * @return null or array of annotations.
331    */
332   public AlignmentAnnotation[] getAnnotation(String label);
333
334   /**
335    * create a new dataset sequence (if necessary) for this sequence and sets
336    * this sequence to refer to it. This call will move any features or
337    * references on the sequence onto the dataset.
338    * 
339    * @return dataset sequence for this sequence
340    */
341   public SequenceI createDatasetSequence();
342
343   /**
344    * Transfer any database references or annotation from entry under a sequence
345    * mapping.
346    * 
347    * @param entry
348    * @param mp
349    *                null or mapping from entry's numbering to local start/end
350    */
351   public void transferAnnotation(SequenceI entry, Mapping mp);
352
353 }