new method to get map of sequence positions corresponding to alignment columns
[jalview.git] / src / jalview / datamodel / SequenceI.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2007 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 new start position
47    */
48   public void setStart(int start);
49
50   /**
51    * get start position of first non-gapped residue in sequence
52    * @return 
53    */
54   public int getStart();
55
56   /**
57    * get the displayed id of the sequence
58    * @return true means the id will be returned in the form DisplayName/Start-End
59    */
60   public String getDisplayId(boolean jvsuffix);
61
62   /**
63    * set end position for last residue in sequence
64    * @param end 
65    */
66   public void setEnd(int end);
67
68   /**
69    * get end position for last residue in sequence
70    * getEnd()>getStart() unless sequence only consists of gap characters
71    *
72    * @return 
73    */
74   public int getEnd();
75
76   /**
77    * @return length of sequence including gaps
78
79    */
80   public int getLength();
81
82   /**
83    * Replace the sequence with the given string
84    *
85    * @param sequence new sequence string
86    */
87   public void setSequence(String sequence);
88
89   /**
90    * @return sequence as string
91    */
92   public String getSequenceAsString();
93
94   /**
95    * get a range on the seuqence as a string
96    * @param start DOCUMENT ME!
97    * @param end DOCUMENT ME!
98    *
99    * @return DOCUMENT ME!
100    */
101   public String getSequenceAsString(int start, int end);
102
103   /**
104    * DOCUMENT ME!
105    *
106    * @return DOCUMENT ME!
107    */
108   public char[] getSequence();
109
110   /**
111    * get stretch of sequence characters in an array
112    *
113    * @param start absolute index into getSequence()
114    * @param end exclusive index of last position in segment to be returned.
115    *
116    * @return char[max(0,end-start)];
117    */
118   public char[] getSequence(int start, int end);
119
120   /**
121    * create a new sequence object from start to end of this sequence
122    * @param start int
123    * @param end int
124    * @return SequenceI
125    */
126   public SequenceI getSubSequence(int start, int end);
127
128   /**
129    * DOCUMENT ME!
130    *
131    * @param i DOCUMENT ME!
132    *
133    * @return DOCUMENT ME!
134    */
135   public char getCharAt(int i);
136
137   /**
138    * DOCUMENT ME!
139    *
140    * @param desc DOCUMENT ME!
141    */
142   public void setDescription(String desc);
143
144   /**
145    * DOCUMENT ME!
146    *
147    * @return DOCUMENT ME!
148    */
149   public String getDescription();
150
151   /**
152    * DOCUMENT ME!
153    *
154    * @param pos DOCUMENT ME!
155    *
156    * @return DOCUMENT ME!
157    */
158   public int findIndex(int pos);
159
160   /**
161    * Returns the sequence position for an alignment position
162    *
163    * @param i column index in alignment (from 1)
164    *
165    * @return residue number for residue (left of and) nearest ith column
166    */
167   public int findPosition(int i);
168
169   /**
170    * Returns an int array where indices correspond to each residue in the sequence and the element value gives its position in the alignment
171    *
172    * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no residues in SequenceI object
173    */
174   public int[] gapMap();
175
176   /**
177    * Returns an int array where indices correspond to each position in
178    * sequence char array and the element value gives the result of findPosition
179    * for that index in the sequence.
180    * 
181    * @return int[SequenceI.getLength()] 
182    */
183   public int[] findPositionMap();
184   /**
185    * Delete a range of aligned sequence columns, creating a new dataset sequence if necessary
186    * and adjusting start and end positions accordingly.
187    *
188    * @param i first column in range to delete
189    * @param j last column in range to delete
190    */
191   public void deleteChars(int i, int j);
192
193   /**
194    * DOCUMENT ME!
195    *
196    * @param i DOCUMENT ME!
197    * @param c DOCUMENT ME!
198    */
199   public void insertCharAt(int i, char c);
200
201   /**
202    * DOCUMENT ME!
203    *
204    * @param i DOCUMENT ME!
205    * @param c DOCUMENT ME!
206    */
207   public void insertCharAt(int i, int length, char c);
208
209   /**
210    * DOCUMENT ME!
211    *
212    * @return DOCUMENT ME!
213    */
214   public SequenceFeature[] getSequenceFeatures();
215
216   /**
217    * DOCUMENT ME!
218    *
219    * @param v DOCUMENT ME!
220    */
221   public void setSequenceFeatures(SequenceFeature[] features);
222
223   /**
224    * DOCUMENT ME!
225    *
226    * @param id DOCUMENT ME!
227    */
228   public void setPDBId(Vector ids);
229
230   /**
231    * DOCUMENT ME!
232    *
233    * @return DOCUMENT ME!
234    */
235   public Vector getPDBId();
236
237   /**
238    * add entry to the vector of PDBIds, if it isn't in the list already
239    * @param entry
240    */
241   public void addPDBId(PDBEntry entry);
242   /**
243    * update the list of PDBEntrys to include any DBRefEntrys citing structural databases 
244    * @return true if PDBEntry list was modified
245    */
246   public boolean updatePDBIds();
247
248   public String getVamsasId();
249
250   public void setVamsasId(String id);
251
252   public void setDBRef(DBRefEntry[] dbs);
253
254   public DBRefEntry[] getDBRef();
255
256   /**
257    * add the given entry to the list of DBRefs for this sequence, 
258    * or replace a similar one if entry contains a map object 
259    * and the existing one doesnt. 
260    * @param entry
261    */
262   public void addDBRef(DBRefEntry entry);
263
264   public void addSequenceFeature(SequenceFeature sf);
265
266   public void deleteFeature(SequenceFeature sf);
267
268   public void setDatasetSequence(SequenceI seq);
269
270   public SequenceI getDatasetSequence();
271
272   public AlignmentAnnotation[] getAnnotation();
273
274   public void addAlignmentAnnotation(AlignmentAnnotation annotation);
275
276   public void removeAlignmentAnnotation(AlignmentAnnotation annotation);
277
278   /**
279    * Derive a sequence (using this one's dataset or as the dataset)
280    * @return duplicate sequence with valid dataset sequence
281    */
282   public SequenceI deriveSequence();
283   /**
284    * set the array of associated AlignmentAnnotation for this sequenceI
285    * @param revealed
286    */
287   public void setAlignmentAnnotation(AlignmentAnnotation[] annotation);
288   /**
289    * Get one or more alignment annotations with a particular label.  
290    * @param label string which each returned annotation must have as a label.
291    * @return null or array of annotations.
292    */
293   public AlignmentAnnotation[] getAnnotation(String label);
294   /**
295    * create a new dataset sequence (if necessary) 
296    * for this sequence and sets this sequence to refer to it.
297    * This call will move any features or references on the sequence onto the dataset.
298    * @return dataset sequence for this sequence
299    */
300   public SequenceI createDatasetSequence();
301   
302   /**
303    * Transfer any database references or annotation from entry
304    * under a sequence mapping.
305    * @param entry
306    * @param mp null or mapping from entry's numbering to local start/end
307    */
308   public void transferAnnotation(SequenceI entry, Mapping mp);
309
310 }