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
5 * This file is part of Jalview.
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.
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.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.datamodel;
23 * Data structure to hold and manipulate a multiple sequence alignment
25 public interface AlignmentI extends AnnotatedCollectionI
28 * Calculates the number of sequences in an alignment
30 * @return Number of sequences in alignment
32 public int getHeight();
35 * Calculates the maximum width of the alignment, including gaps.
37 * @return Greatest sequence length within alignment.
40 public int getWidth();
43 * Calculates if this set of sequences (visible and invisible) are all the
46 * @return true if all sequences in alignment are the same length
48 public boolean isAligned();
51 * Calculates if this set of sequences is all the same length
53 * @param includeHidden
54 * optionally exclude hidden sequences from test
55 * @return true if all (or just visible) sequences are the same length
57 public boolean isAligned(boolean includeHidden);
60 * Gets sequences as a Synchronized collection
62 * @return All sequences in alignment.
65 public List<SequenceI> getSequences();
68 * Gets sequences as a SequenceI[]
70 * @return All sequences in alignment.
72 public SequenceI[] getSequencesArray();
75 * Find a specific sequence in this alignment.
78 * Index of required sequence.
80 * @return SequenceI at given index.
82 public SequenceI getSequenceAt(int i);
85 * Add a new sequence to this alignment.
88 * New sequence will be added at end of alignment.
90 public void addSequence(SequenceI seq);
93 * Used to set a particular index of the alignment with the given sequence.
96 * Index of sequence to be updated.
98 * New sequence to be inserted.
100 public void setSequenceAt(int i, SequenceI seq);
103 * Deletes a sequence from the alignment
106 * Sequence to be deleted.
108 public void deleteSequence(SequenceI s);
111 * Deletes a sequence from the alignment.
114 * Index of sequence to be deleted.
116 public void deleteSequence(int i);
119 * Finds sequence in alignment using sequence name as query.
122 * Id of sequence to search for.
124 * @return Sequence matching query, if found. If not found returns null.
126 public SequenceI findName(String name);
128 public SequenceI[] findSequenceMatch(String name);
131 * Finds index of a given sequence in the alignment.
134 * Sequence to look for.
136 * @return Index of sequence within the alignment or -1 if not found
138 public int findIndex(SequenceI s);
141 * Finds group that given sequence is part of.
144 * Sequence in alignment.
146 * @return First group found for sequence. WARNING : Sequences may be members
147 * of several groups. This method is incomplete.
149 public SequenceGroup findGroup(SequenceI s);
152 * Finds all groups that a given sequence is part of.
155 * Sequence in alignment.
157 * @return All groups containing given sequence.
159 public SequenceGroup[] findAllGroups(SequenceI s);
162 * Adds a new SequenceGroup to this alignment.
165 * New group to be added.
167 public void addGroup(SequenceGroup sg);
170 * Deletes a specific SequenceGroup
173 * Group will be deleted from alignment.
175 public void deleteGroup(SequenceGroup g);
178 * Get all the groups associated with this alignment.
180 * @return All groups as a list.
182 public List<SequenceGroup> getGroups();
185 * Deletes all groups from this alignment.
187 public void deleteAllGroups();
190 * Adds a new AlignmentAnnotation to this alignment
192 * @note Care should be taken to ensure that annotation is at least as wide as
193 * the longest sequence in the alignment for rendering purposes.
195 public void addAnnotation(AlignmentAnnotation aa);
198 * moves annotation to a specified index in alignment annotation display stack
201 * the annotation object to be moved
203 * the destination position
205 public void setAnnotationIndex(AlignmentAnnotation aa, int index);
208 * Deletes a specific AlignmentAnnotation from the alignment, and removes its
209 * reference from any SequenceI or SequenceGroup object's annotation if and
210 * only if aa is contained within the alignment's annotation vector.
211 * Otherwise, it will do nothing.
214 * the annotation to delete
215 * @return true if annotation was deleted from this alignment.
217 public boolean deleteAnnotation(AlignmentAnnotation aa);
220 * Deletes a specific AlignmentAnnotation from the alignment, and optionally
221 * removes any reference from any SequenceI or SequenceGroup object's
222 * annotation if and only if aa is contained within the alignment's annotation
223 * vector. Otherwise, it will do nothing.
226 * the annotation to delete
228 * flag indicating if any references should be removed from
229 * annotation - use this if you intend to add the annotation back
231 * @return true if annotation was deleted from this alignment.
233 public boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
236 * Get the annotation associated with this alignment (this can be null if no
237 * annotation has ever been created on the alignment)
239 * @return array of AlignmentAnnotation objects
242 public AlignmentAnnotation[] getAlignmentAnnotation();
245 * Change the gap character used in this alignment to 'gc'
248 * the new gap character.
250 public void setGapCharacter(char gc);
253 * Get the gap character used in this alignment
255 * @return gap character
257 public char getGapCharacter();
260 * Test for all nucleotide alignment
262 * @return true if alignment is nucleotide sequence
264 public boolean isNucleotide();
267 * Test if alignment contains RNA structure
269 * @return true if RNA structure AligmnentAnnotation was added to alignment
271 public boolean hasRNAStructure();
274 * Set alignment to be a nucleotide sequence
277 public void setNucleotide(boolean b);
280 * Get the associated dataset for the alignment.
282 * @return Alignment containing dataset sequences or null of this is a
285 public Alignment getDataset();
288 * Set the associated dataset for the alignment, or create one.
291 * The dataset alignment or null to construct one.
293 public void setDataset(Alignment dataset);
296 * pads sequences with gaps (to ensure the set looks like an alignment)
298 * @return boolean true if alignment was modified
300 public boolean padGaps();
302 public HiddenSequences getHiddenSequences();
305 * Compact representation of alignment
309 public CigarArray getCompactAlignment();
312 * Set an arbitrary key value pair for an alignment. Note: both key and value
313 * objects should return a meaningful, human readable response to .toString()
318 public void setProperty(Object key, Object value);
321 * Get a named property from the alignment.
324 * @return value of property
326 public Object getProperty(Object key);
329 * Get the property hashtable.
331 * @return hashtable of alignment properties (or null if none are defined)
333 public Hashtable getProperties();
336 * add a reference to a frame of aligned codons for this alignment
340 public void addCodonFrame(AlignedCodonFrame codons);
343 * remove a particular codon frame reference from this alignment
346 * @return true if codon frame was removed.
348 public boolean removeCodonFrame(AlignedCodonFrame codons);
351 * get all codon frames associated with this alignment
355 public AlignedCodonFrame[] getCodonFrames();
358 * get a particular codon frame
363 public AlignedCodonFrame getCodonFrame(int index);
366 * get codon frames involving sequenceI
368 public AlignedCodonFrame[] getCodonFrame(SequenceI seq);
371 * find sequence with given name in alignment
376 * true implies that case insensitive matching will <em>also</em> be
378 * @return matched sequence or null
380 public SequenceI findName(String token, boolean b);
383 * find next sequence with given name in alignment starting after a given
387 * the sequence after which the search will be started (usually the
388 * result of the last call to findName)
392 * true implies that case insensitive matching will <em>also</em> be
394 * @return matched sequence or null
396 public SequenceI findName(SequenceI startAfter, String token, boolean b);
399 * find first sequence in alignment which is involved in the given search
403 * @return -1 or index of sequence in alignment
405 public int findIndex(SearchResults results);
408 * append sequences and annotation from another alignment object to this one.
409 * Note: this is a straight transfer of object references, and may result in
410 * toappend's dependent data being transformed to fit the alignment (changing
411 * gap characters, etc...). If you are uncertain, use the copy Alignment copy
412 * constructor to create a new version which can be appended without side
416 * - the alignment to be appended.
418 public void append(AlignmentI toappend);
421 * Justify the sequences to the left or right by deleting and inserting gaps
422 * before the initial residue or after the terminal residue
425 * true if alignment padded to right, false to justify to left
426 * @return true if alignment was changed TODO: return undo object
428 public boolean justify(boolean right);
431 * add given annotation row at given position (0 is start, -1 is end)
436 public void addAnnotation(AlignmentAnnotation consensus, int i);
439 * search for or create a specific annotation row on the alignment
442 * name for annotation (must match)
444 * calcId for the annotation (null or must match)
446 * - value of autocalc flag for the annotation
448 * - null or specific sequence reference
450 * - null or specific group reference
452 * - CalcId for the annotation (must match)
454 * @return existing annotation matching the given attributes
456 public AlignmentAnnotation findOrCreateAnnotation(String name,
457 String calcId, boolean autoCalc, SequenceI seqRef,
458 SequenceGroup groupRef);
461 * move the given group up or down in the alignment by the given number of
462 * rows. Implementor assumes given group is already present on alignment - no
463 * recalculations are triggered.
470 public void moveSelectedSequencesByOne(SequenceGroup sg,
471 Map<SequenceI, SequenceCollectionI> map, boolean up);
474 * validate annotation after an edit and update any alignment state flags accordingly
475 * @param alignmentAnnotation
477 public void validateAnnotation(AlignmentAnnotation alignmentAnnotation);