JAL-1517 source formatting
[jalview.git] / src / jalview / datamodel / AlignmentI.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3  * Copyright (C) 2014 The Jalview Authors
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
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.datamodel;
22
23 import java.util.*;
24
25 /**
26  * Data structure to hold and manipulate a multiple sequence alignment
27  */
28 public interface AlignmentI extends AnnotatedCollectionI
29 {
30   /**
31    * Calculates the number of sequences in an alignment
32    * 
33    * @return Number of sequences in alignment
34    */
35   public int getHeight();
36
37   /**
38    * Calculates the maximum width of the alignment, including gaps.
39    * 
40    * @return Greatest sequence length within alignment.
41    */
42   @Override
43   public int getWidth();
44
45   /**
46    * Calculates if this set of sequences (visible and invisible) are all the
47    * same length
48    * 
49    * @return true if all sequences in alignment are the same length
50    */
51   public boolean isAligned();
52
53   /**
54    * Calculates if this set of sequences is all the same length
55    * 
56    * @param includeHidden
57    *          optionally exclude hidden sequences from test
58    * @return true if all (or just visible) sequences are the same length
59    */
60   public boolean isAligned(boolean includeHidden);
61
62   /**
63    * Gets sequences as a Synchronized collection
64    * 
65    * @return All sequences in alignment.
66    */
67   @Override
68   public List<SequenceI> getSequences();
69
70   /**
71    * Gets sequences as a SequenceI[]
72    * 
73    * @return All sequences in alignment.
74    */
75   public SequenceI[] getSequencesArray();
76
77   /**
78    * Find a specific sequence in this alignment.
79    * 
80    * @param i
81    *          Index of required sequence.
82    * 
83    * @return SequenceI at given index.
84    */
85   public SequenceI getSequenceAt(int i);
86
87   /**
88    * Add a new sequence to this alignment.
89    * 
90    * @param seq
91    *          New sequence will be added at end of alignment.
92    */
93   public void addSequence(SequenceI seq);
94
95   /**
96    * Used to set a particular index of the alignment with the given sequence.
97    * 
98    * @param i
99    *          Index of sequence to be updated.
100    * @param seq
101    *          New sequence to be inserted.
102    */
103   public void setSequenceAt(int i, SequenceI seq);
104
105   /**
106    * Deletes a sequence from the alignment
107    * 
108    * @param s
109    *          Sequence to be deleted.
110    */
111   public void deleteSequence(SequenceI s);
112
113   /**
114    * Deletes a sequence from the alignment.
115    * 
116    * @param i
117    *          Index of sequence to be deleted.
118    */
119   public void deleteSequence(int i);
120
121   /**
122    * Finds sequence in alignment using sequence name as query.
123    * 
124    * @param name
125    *          Id of sequence to search for.
126    * 
127    * @return Sequence matching query, if found. If not found returns null.
128    */
129   public SequenceI findName(String name);
130
131   public SequenceI[] findSequenceMatch(String name);
132
133   /**
134    * Finds index of a given sequence in the alignment.
135    * 
136    * @param s
137    *          Sequence to look for.
138    * 
139    * @return Index of sequence within the alignment or -1 if not found
140    */
141   public int findIndex(SequenceI s);
142
143   /**
144    * Finds group that given sequence is part of.
145    * 
146    * @param s
147    *          Sequence in alignment.
148    * 
149    * @return First group found for sequence. WARNING : Sequences may be members
150    *         of several groups. This method is incomplete.
151    */
152   public SequenceGroup findGroup(SequenceI s);
153
154   /**
155    * Finds all groups that a given sequence is part of.
156    * 
157    * @param s
158    *          Sequence in alignment.
159    * 
160    * @return All groups containing given sequence.
161    */
162   public SequenceGroup[] findAllGroups(SequenceI s);
163
164   /**
165    * Adds a new SequenceGroup to this alignment.
166    * 
167    * @param sg
168    *          New group to be added.
169    */
170   public void addGroup(SequenceGroup sg);
171
172   /**
173    * Deletes a specific SequenceGroup
174    * 
175    * @param g
176    *          Group will be deleted from alignment.
177    */
178   public void deleteGroup(SequenceGroup g);
179
180   /**
181    * Get all the groups associated with this alignment.
182    * 
183    * @return All groups as a list.
184    */
185   public List<SequenceGroup> getGroups();
186
187   /**
188    * Deletes all groups from this alignment.
189    */
190   public void deleteAllGroups();
191
192   /**
193    * Adds a new AlignmentAnnotation to this alignment
194    * 
195    * @note Care should be taken to ensure that annotation is at least as wide as
196    *       the longest sequence in the alignment for rendering purposes.
197    */
198   public void addAnnotation(AlignmentAnnotation aa);
199
200   /**
201    * moves annotation to a specified index in alignment annotation display stack
202    * 
203    * @param aa
204    *          the annotation object to be moved
205    * @param index
206    *          the destination position
207    */
208   public void setAnnotationIndex(AlignmentAnnotation aa, int index);
209
210   /**
211    * Deletes a specific AlignmentAnnotation from the alignment, and removes its
212    * reference from any SequenceI or SequenceGroup object's annotation if and
213    * only if aa is contained within the alignment's annotation vector.
214    * Otherwise, it will do nothing.
215    * 
216    * @param aa
217    *          the annotation to delete
218    * @return true if annotation was deleted from this alignment.
219    */
220   public boolean deleteAnnotation(AlignmentAnnotation aa);
221
222   /**
223    * Deletes a specific AlignmentAnnotation from the alignment, and optionally
224    * removes any reference from any SequenceI or SequenceGroup object's
225    * annotation if and only if aa is contained within the alignment's annotation
226    * vector. Otherwise, it will do nothing.
227    * 
228    * @param aa
229    *          the annotation to delete
230    * @param unhook
231    *          flag indicating if any references should be removed from
232    *          annotation - use this if you intend to add the annotation back
233    *          into the alignment
234    * @return true if annotation was deleted from this alignment.
235    */
236   public boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
237
238   /**
239    * Get the annotation associated with this alignment (this can be null if no
240    * annotation has ever been created on the alignment)
241    * 
242    * @return array of AlignmentAnnotation objects
243    */
244   @Override
245   public AlignmentAnnotation[] getAlignmentAnnotation();
246
247   /**
248    * Change the gap character used in this alignment to 'gc'
249    * 
250    * @param gc
251    *          the new gap character.
252    */
253   public void setGapCharacter(char gc);
254
255   /**
256    * Get the gap character used in this alignment
257    * 
258    * @return gap character
259    */
260   public char getGapCharacter();
261
262   /**
263    * Test for all nucleotide alignment
264    * 
265    * @return true if alignment is nucleotide sequence
266    */
267   public boolean isNucleotide();
268
269   /**
270    * Test if alignment contains RNA structure
271    * 
272    * @return true if RNA structure AligmnentAnnotation was added to alignment
273    */
274   public boolean hasRNAStructure();
275
276   /**
277    * Set alignment to be a nucleotide sequence
278    * 
279    */
280   public void setNucleotide(boolean b);
281
282   /**
283    * Get the associated dataset for the alignment.
284    * 
285    * @return Alignment containing dataset sequences or null of this is a
286    *         dataset.
287    */
288   public Alignment getDataset();
289
290   /**
291    * Set the associated dataset for the alignment, or create one.
292    * 
293    * @param dataset
294    *          The dataset alignment or null to construct one.
295    */
296   public void setDataset(Alignment dataset);
297
298   /**
299    * pads sequences with gaps (to ensure the set looks like an alignment)
300    * 
301    * @return boolean true if alignment was modified
302    */
303   public boolean padGaps();
304
305   public HiddenSequences getHiddenSequences();
306
307   /**
308    * Compact representation of alignment
309    * 
310    * @return CigarArray
311    */
312   public CigarArray getCompactAlignment();
313
314   /**
315    * Set an arbitrary key value pair for an alignment. Note: both key and value
316    * objects should return a meaningful, human readable response to .toString()
317    * 
318    * @param key
319    * @param value
320    */
321   public void setProperty(Object key, Object value);
322
323   /**
324    * Get a named property from the alignment.
325    * 
326    * @param key
327    * @return value of property
328    */
329   public Object getProperty(Object key);
330
331   /**
332    * Get the property hashtable.
333    * 
334    * @return hashtable of alignment properties (or null if none are defined)
335    */
336   public Hashtable getProperties();
337
338   /**
339    * add a reference to a frame of aligned codons for this alignment
340    * 
341    * @param codons
342    */
343   public void addCodonFrame(AlignedCodonFrame codons);
344
345   /**
346    * remove a particular codon frame reference from this alignment
347    * 
348    * @param codons
349    * @return true if codon frame was removed.
350    */
351   public boolean removeCodonFrame(AlignedCodonFrame codons);
352
353   /**
354    * get all codon frames associated with this alignment
355    * 
356    * @return
357    */
358   public AlignedCodonFrame[] getCodonFrames();
359
360   /**
361    * get a particular codon frame
362    * 
363    * @param index
364    * @return
365    */
366   public AlignedCodonFrame getCodonFrame(int index);
367
368   /**
369    * get codon frames involving sequenceI
370    */
371   public AlignedCodonFrame[] getCodonFrame(SequenceI seq);
372
373   /**
374    * find sequence with given name in alignment
375    * 
376    * @param token
377    *          name to find
378    * @param b
379    *          true implies that case insensitive matching will <em>also</em> be
380    *          tried
381    * @return matched sequence or null
382    */
383   public SequenceI findName(String token, boolean b);
384
385   /**
386    * find next sequence with given name in alignment starting after a given
387    * sequence
388    * 
389    * @param startAfter
390    *          the sequence after which the search will be started (usually the
391    *          result of the last call to findName)
392    * @param token
393    *          name to find
394    * @param b
395    *          true implies that case insensitive matching will <em>also</em> be
396    *          tried
397    * @return matched sequence or null
398    */
399   public SequenceI findName(SequenceI startAfter, String token, boolean b);
400
401   /**
402    * find first sequence in alignment which is involved in the given search
403    * result object
404    * 
405    * @param results
406    * @return -1 or index of sequence in alignment
407    */
408   public int findIndex(SearchResults results);
409
410   /**
411    * append sequences and annotation from another alignment object to this one.
412    * Note: this is a straight transfer of object references, and may result in
413    * toappend's dependent data being transformed to fit the alignment (changing
414    * gap characters, etc...). If you are uncertain, use the copy Alignment copy
415    * constructor to create a new version which can be appended without side
416    * effect.
417    * 
418    * @param toappend
419    *          - the alignment to be appended.
420    */
421   public void append(AlignmentI toappend);
422
423   /**
424    * Justify the sequences to the left or right by deleting and inserting gaps
425    * before the initial residue or after the terminal residue
426    * 
427    * @param right
428    *          true if alignment padded to right, false to justify to left
429    * @return true if alignment was changed TODO: return undo object
430    */
431   public boolean justify(boolean right);
432
433   /**
434    * add given annotation row at given position (0 is start, -1 is end)
435    * 
436    * @param consensus
437    * @param i
438    */
439   public void addAnnotation(AlignmentAnnotation consensus, int i);
440
441   /**
442    * search for or create a specific annotation row on the alignment
443    * 
444    * @param name
445    *          name for annotation (must match)
446    * @param calcId
447    *          calcId for the annotation (null or must match)
448    * @param autoCalc
449    *          - value of autocalc flag for the annotation
450    * @param seqRef
451    *          - null or specific sequence reference
452    * @param groupRef
453    *          - null or specific group reference
454    * @param method
455    *          - CalcId for the annotation (must match)
456    * 
457    * @return existing annotation matching the given attributes
458    */
459   public AlignmentAnnotation findOrCreateAnnotation(String name,
460           String calcId, boolean autoCalc, SequenceI seqRef,
461           SequenceGroup groupRef);
462
463   /**
464    * move the given group up or down in the alignment by the given number of
465    * rows. Implementor assumes given group is already present on alignment - no
466    * recalculations are triggered.
467    * 
468    * @param sg
469    * @param map
470    * @param up
471    * @param i
472    */
473   public void moveSelectedSequencesByOne(SequenceGroup sg,
474           Map<SequenceI, SequenceCollectionI> map, boolean up);
475
476   /**
477    * validate annotation after an edit and update any alignment state flags
478    * accordingly
479    * 
480    * @param alignmentAnnotation
481    */
482   public void validateAnnotation(AlignmentAnnotation alignmentAnnotation);
483 }