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