2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
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.
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.
21 package jalview.datamodel;
23 import java.util.Hashtable;
24 import java.util.List;
28 * Data structure to hold and manipulate a multiple sequence alignment
30 public interface AlignmentI extends AnnotatedCollectionI
33 * Calculates the number of sequences in an alignment
35 * @return Number of sequences in alignment
37 public int getHeight();
40 * Calculates the maximum width of the alignment, including gaps.
42 * @return Greatest sequence length within alignment.
45 public int getWidth();
48 * Calculates if this set of sequences (visible and invisible) are all the
51 * @return true if all sequences in alignment are the same length
53 public boolean isAligned();
56 * Calculates if this set of sequences is all the same length
58 * @param includeHidden
59 * optionally exclude hidden sequences from test
60 * @return true if all (or just visible) sequences are the same length
62 public boolean isAligned(boolean includeHidden);
65 * Gets sequences as a Synchronized collection
67 * @return All sequences in alignment.
70 public List<SequenceI> getSequences();
73 * Gets sequences as a SequenceI[]
75 * @return All sequences in alignment.
77 public SequenceI[] getSequencesArray();
80 * Find a specific sequence in this alignment.
83 * Index of required sequence.
85 * @return SequenceI at given index.
87 public SequenceI getSequenceAt(int i);
90 * Add a new sequence to this alignment.
93 * New sequence will be added at end of alignment.
95 public void addSequence(SequenceI seq);
98 * Used to set a particular index of the alignment with the given sequence.
101 * Index of sequence to be updated.
103 * New sequence to be inserted.
105 public void setSequenceAt(int i, SequenceI seq);
108 * Deletes a sequence from the alignment
111 * Sequence to be deleted.
113 public void deleteSequence(SequenceI s);
116 * Deletes a sequence from the alignment.
119 * Index of sequence to be deleted.
121 public void deleteSequence(int i);
124 * Finds sequence in alignment using sequence name as query.
127 * Id of sequence to search for.
129 * @return Sequence matching query, if found. If not found returns null.
131 public SequenceI findName(String name);
133 public SequenceI[] findSequenceMatch(String name);
136 * Finds index of a given sequence in the alignment.
139 * Sequence to look for.
141 * @return Index of sequence within the alignment or -1 if not found
143 public int findIndex(SequenceI s);
146 * Finds group that given sequence is part of.
149 * Sequence in alignment.
151 * @return First group found for sequence. WARNING : Sequences may be members
152 * of several groups. This method is incomplete.
154 public SequenceGroup findGroup(SequenceI s);
157 * Finds all groups that a given sequence is part of.
160 * Sequence in alignment.
162 * @return All groups containing given sequence.
164 public SequenceGroup[] findAllGroups(SequenceI s);
167 * Adds a new SequenceGroup to this alignment.
170 * New group to be added.
172 public void addGroup(SequenceGroup sg);
175 * Deletes a specific SequenceGroup
178 * Group will be deleted from alignment.
180 public void deleteGroup(SequenceGroup g);
183 * Get all the groups associated with this alignment.
185 * @return All groups as a list.
187 public List<SequenceGroup> getGroups();
190 * Deletes all groups from this alignment.
192 public void deleteAllGroups();
195 * Adds a new AlignmentAnnotation to this alignment
197 * @note Care should be taken to ensure that annotation is at least as wide as
198 * the longest sequence in the alignment for rendering purposes.
200 public void addAnnotation(AlignmentAnnotation aa);
203 * moves annotation to a specified index in alignment annotation display stack
206 * the annotation object to be moved
208 * the destination position
210 public void setAnnotationIndex(AlignmentAnnotation aa, int index);
213 * Deletes a specific AlignmentAnnotation from the alignment, and removes its
214 * reference from any SequenceI or SequenceGroup object's annotation if and
215 * only if aa is contained within the alignment's annotation vector.
216 * Otherwise, it will do nothing.
219 * the annotation to delete
220 * @return true if annotation was deleted from this alignment.
222 public boolean deleteAnnotation(AlignmentAnnotation aa);
225 * Deletes a specific AlignmentAnnotation from the alignment, and optionally
226 * removes any reference from any SequenceI or SequenceGroup object's
227 * annotation if and only if aa is contained within the alignment's annotation
228 * vector. Otherwise, it will do nothing.
231 * the annotation to delete
233 * flag indicating if any references should be removed from
234 * annotation - use this if you intend to add the annotation back
236 * @return true if annotation was deleted from this alignment.
238 public boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
241 * Get the annotation associated with this alignment (this can be null if no
242 * annotation has ever been created on the alignment)
244 * @return array of AlignmentAnnotation objects
247 public AlignmentAnnotation[] getAlignmentAnnotation();
250 * Change the gap character used in this alignment to 'gc'
253 * the new gap character.
255 public void setGapCharacter(char gc);
258 * Get the gap character used in this alignment
260 * @return gap character
262 public char getGapCharacter();
265 * Test for all nucleotide alignment
267 * @return true if alignment is nucleotide sequence
269 public boolean isNucleotide();
272 * Test if alignment contains RNA structure
274 * @return true if RNA structure AligmnentAnnotation was added to alignment
276 public boolean hasRNAStructure();
279 * Set alignment to be a nucleotide sequence
282 public void setNucleotide(boolean b);
285 * Get the associated dataset for the alignment.
287 * @return Alignment containing dataset sequences or null of this is a
290 public Alignment getDataset();
293 * Set the associated dataset for the alignment, or create one.
296 * The dataset alignment or null to construct one.
298 public void setDataset(Alignment dataset);
301 * pads sequences with gaps (to ensure the set looks like an alignment)
303 * @return boolean true if alignment was modified
305 public boolean padGaps();
307 public HiddenSequences getHiddenSequences();
310 * Compact representation of alignment
314 public CigarArray getCompactAlignment();
317 * Set an arbitrary key value pair for an alignment. Note: both key and value
318 * objects should return a meaningful, human readable response to .toString()
323 public void setProperty(Object key, Object value);
326 * Get a named property from the alignment.
329 * @return value of property
331 public Object getProperty(Object key);
334 * Get the property hashtable.
336 * @return hashtable of alignment properties (or null if none are defined)
338 public Hashtable getProperties();
341 * add a reference to a frame of aligned codons for this alignment
345 public void addCodonFrame(AlignedCodonFrame codons);
348 * remove a particular codon frame reference from this alignment
351 * @return true if codon frame was removed.
353 public boolean removeCodonFrame(AlignedCodonFrame codons);
356 * get all codon frames associated with this alignment
360 public AlignedCodonFrame[] getCodonFrames();
363 * get a particular codon frame
368 public AlignedCodonFrame getCodonFrame(int index);
371 * get codon frames involving sequenceI
373 public AlignedCodonFrame[] getCodonFrame(SequenceI seq);
376 * find sequence with given name in alignment
381 * true implies that case insensitive matching will <em>also</em> be
383 * @return matched sequence or null
385 public SequenceI findName(String token, boolean b);
388 * find next sequence with given name in alignment starting after a given
392 * the sequence after which the search will be started (usually the
393 * result of the last call to findName)
397 * true implies that case insensitive matching will <em>also</em> be
399 * @return matched sequence or null
401 public SequenceI findName(SequenceI startAfter, String token, boolean b);
404 * find first sequence in alignment which is involved in the given search
408 * @return -1 or index of sequence in alignment
410 public int findIndex(SearchResults results);
413 * append sequences and annotation from another alignment object to this one.
414 * Note: this is a straight transfer of object references, and may result in
415 * toappend's dependent data being transformed to fit the alignment (changing
416 * gap characters, etc...). If you are uncertain, use the copy Alignment copy
417 * constructor to create a new version which can be appended without side
421 * - the alignment to be appended.
423 public void append(AlignmentI toappend);
426 * Justify the sequences to the left or right by deleting and inserting gaps
427 * before the initial residue or after the terminal residue
430 * true if alignment padded to right, false to justify to left
431 * @return true if alignment was changed TODO: return undo object
433 public boolean justify(boolean right);
436 * add given annotation row at given position (0 is start, -1 is end)
441 public void addAnnotation(AlignmentAnnotation consensus, int i);
444 * search for or create a specific annotation row on the alignment
447 * name for annotation (must match)
449 * calcId for the annotation (null or must match)
451 * - value of autocalc flag for the annotation
453 * - null or specific sequence reference
455 * - null or specific group reference
457 * - CalcId for the annotation (must match)
459 * @return existing annotation matching the given attributes
461 public AlignmentAnnotation findOrCreateAnnotation(String name,
462 String calcId, boolean autoCalc, SequenceI seqRef,
463 SequenceGroup groupRef);
466 * move the given group up or down in the alignment by the given number of
467 * rows. Implementor assumes given group is already present on alignment - no
468 * recalculations are triggered.
475 public void moveSelectedSequencesByOne(SequenceGroup sg,
476 Map<SequenceI, SequenceCollectionI> map, boolean up);
479 * validate annotation after an edit and update any alignment state flags
482 * @param alignmentAnnotation
484 public void validateAnnotation(AlignmentAnnotation alignmentAnnotation);