2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.datamodel;
24 * Data structure to hold and manipulate a multiple sequence alignment
26 public interface AlignmentI extends AnnotatedCollectionI
29 * Calculates the number of sequences in an alignment
31 * @return Number of sequences in alignment
33 public int getHeight();
36 * Calculates the maximum width of the alignment, including gaps.
38 * @return Greatest sequence length within alignment.
41 public int getWidth();
44 * Calculates if this set of sequences (visible and invisible) are all the
47 * @return true if all sequences in alignment are the same length
49 public boolean isAligned();
52 * Calculates if this set of sequences is all the same length
54 * @param includeHidden
55 * optionally exclude hidden sequences from test
56 * @return true if all (or just visible) sequences are the same length
58 public boolean isAligned(boolean includeHidden);
61 * Gets sequences as a Synchronized collection
63 * @return All sequences in alignment.
66 public List<SequenceI> getSequences();
69 * Gets sequences as a SequenceI[]
71 * @return All sequences in alignment.
73 public SequenceI[] getSequencesArray();
76 * Find a specific sequence in this alignment.
79 * Index of required sequence.
81 * @return SequenceI at given index.
83 public SequenceI getSequenceAt(int i);
86 * Add a new sequence to this alignment.
89 * New sequence will be added at end of alignment.
91 public void addSequence(SequenceI seq);
94 * Used to set a particular index of the alignment with the given sequence.
97 * Index of sequence to be updated.
99 * New sequence to be inserted.
101 public void setSequenceAt(int i, SequenceI seq);
104 * Deletes a sequence from the alignment
107 * Sequence to be deleted.
109 public void deleteSequence(SequenceI s);
112 * Deletes a sequence from the alignment.
115 * Index of sequence to be deleted.
117 public void deleteSequence(int i);
120 * Finds sequence in alignment using sequence name as query.
123 * Id of sequence to search for.
125 * @return Sequence matching query, if found. If not found returns null.
127 public SequenceI findName(String name);
129 public SequenceI[] findSequenceMatch(String name);
132 * Finds index of a given sequence in the alignment.
135 * Sequence to look for.
137 * @return Index of sequence within the alignment or -1 if not found
139 public int findIndex(SequenceI s);
142 * Finds group that given sequence is part of.
145 * Sequence in alignment.
147 * @return First group found for sequence. WARNING : Sequences may be members
148 * of several groups. This method is incomplete.
150 public SequenceGroup findGroup(SequenceI s);
153 * Finds all groups that a given sequence is part of.
156 * Sequence in alignment.
158 * @return All groups containing given sequence.
160 public SequenceGroup[] findAllGroups(SequenceI s);
163 * Adds a new SequenceGroup to this alignment.
166 * New group to be added.
168 public void addGroup(SequenceGroup sg);
171 * Deletes a specific SequenceGroup
174 * Group will be deleted from alignment.
176 public void deleteGroup(SequenceGroup g);
179 * Get all the groups associated with this alignment.
181 * @return All groups as a list.
183 public List<SequenceGroup> getGroups();
186 * Deletes all groups from this alignment.
188 public void deleteAllGroups();
191 * Adds a new AlignmentAnnotation to this alignment
193 * @note Care should be taken to ensure that annotation is at least as wide as
194 * the longest sequence in the alignment for rendering purposes.
196 public void addAnnotation(AlignmentAnnotation aa);
199 * moves annotation to a specified index in alignment annotation display stack
202 * the annotation object to be moved
204 * the destination position
206 public void setAnnotationIndex(AlignmentAnnotation aa, int index);
209 * Deletes a specific AlignmentAnnotation from the alignment, and removes its
210 * reference from any SequenceI or SequenceGroup object's annotation if and
211 * only if aa is contained within the alignment's annotation vector.
212 * Otherwise, it will do nothing.
215 * the annotation to delete
216 * @return true if annotation was deleted from this alignment.
218 public boolean deleteAnnotation(AlignmentAnnotation aa);
221 * Deletes a specific AlignmentAnnotation from the alignment, and optionally
222 * removes any reference from any SequenceI or SequenceGroup object's
223 * annotation if and only if aa is contained within the alignment's annotation
224 * vector. Otherwise, it will do nothing.
227 * the annotation to delete
229 * flag indicating if any references should be removed from
230 * annotation - use this if you intend to add the annotation back
232 * @return true if annotation was deleted from this alignment.
234 public boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
237 * Get the annotation associated with this alignment (this can be null if no
238 * annotation has ever been created on the alignment)
240 * @return array of AlignmentAnnotation objects
243 public AlignmentAnnotation[] getAlignmentAnnotation();
246 * Change the gap character used in this alignment to 'gc'
249 * the new gap character.
251 public void setGapCharacter(char gc);
254 * Get the gap character used in this alignment
256 * @return gap character
258 public char getGapCharacter();
261 * Test for all nucleotide alignment
263 * @return true if alignment is nucleotide sequence
265 public boolean isNucleotide();
268 * Test if alignment contains RNA structure
270 * @return true if RNA structure AligmnentAnnotation was added to alignment
272 public boolean hasRNAStructure();
275 * Set alignment to be a nucleotide sequence
278 public void setNucleotide(boolean b);
281 * Get the associated dataset for the alignment.
283 * @return Alignment containing dataset sequences or null of this is a
286 public Alignment getDataset();
289 * Set the associated dataset for the alignment, or create one.
292 * The dataset alignment or null to construct one.
294 public void setDataset(Alignment dataset);
297 * pads sequences with gaps (to ensure the set looks like an alignment)
299 * @return boolean true if alignment was modified
301 public boolean padGaps();
303 public HiddenSequences getHiddenSequences();
306 * Compact representation of alignment
310 public CigarArray getCompactAlignment();
313 * Set an arbitrary key value pair for an alignment. Note: both key and value
314 * objects should return a meaningful, human readable response to .toString()
319 public void setProperty(Object key, Object value);
322 * Get a named property from the alignment.
325 * @return value of property
327 public Object getProperty(Object key);
330 * Get the property hashtable.
332 * @return hashtable of alignment properties (or null if none are defined)
334 public Hashtable getProperties();
337 * add a reference to a frame of aligned codons for this alignment
341 public void addCodonFrame(AlignedCodonFrame codons);
344 * remove a particular codon frame reference from this alignment
347 * @return true if codon frame was removed.
349 public boolean removeCodonFrame(AlignedCodonFrame codons);
352 * get all codon frames associated with this alignment
356 public AlignedCodonFrame[] getCodonFrames();
359 * get a particular codon frame
364 public AlignedCodonFrame getCodonFrame(int index);
367 * get codon frames involving sequenceI
369 public AlignedCodonFrame[] getCodonFrame(SequenceI seq);
372 * find sequence with given name in alignment
377 * true implies that case insensitive matching will <em>also</em> be
379 * @return matched sequence or null
381 public SequenceI findName(String token, boolean b);
384 * find next sequence with given name in alignment starting after a given
388 * the sequence after which the search will be started (usually the
389 * result of the last call to findName)
393 * true implies that case insensitive matching will <em>also</em> be
395 * @return matched sequence or null
397 public SequenceI findName(SequenceI startAfter, String token, boolean b);
400 * find first sequence in alignment which is involved in the given search
404 * @return -1 or index of sequence in alignment
406 public int findIndex(SearchResults results);
409 * append sequences and annotation from another alignment object to this one.
410 * Note: this is a straight transfer of object references, and may result in
411 * toappend's dependent data being transformed to fit the alignment (changing
412 * gap characters, etc...). If you are uncertain, use the copy Alignment copy
413 * constructor to create a new version which can be appended without side
417 * - the alignment to be appended.
419 public void append(AlignmentI toappend);
422 * Justify the sequences to the left or right by deleting and inserting gaps
423 * before the initial residue or after the terminal residue
426 * true if alignment padded to right, false to justify to left
427 * @return true if alignment was changed TODO: return undo object
429 public boolean justify(boolean right);
432 * add given annotation row at given position (0 is start, -1 is end)
437 public void addAnnotation(AlignmentAnnotation consensus, int i);
440 * search for or create a specific annotation row on the alignment
443 * name for annotation (must match)
445 * calcId for the annotation (null or must match)
447 * - value of autocalc flag for the annotation
449 * - null or specific sequence reference
451 * - null or specific group reference
453 * - CalcId for the annotation (must match)
455 * @return existing annotation matching the given attributes
457 public AlignmentAnnotation findOrCreateAnnotation(String name,
458 String calcId, boolean autoCalc, SequenceI seqRef,
459 SequenceGroup groupRef);
462 * move the given group up or down in the alignment by the given number of
463 * rows. Implementor assumes given group is already present on alignment - no
464 * recalculations are triggered.
471 public void moveSelectedSequencesByOne(SequenceGroup sg,
472 Map<SequenceI, SequenceCollectionI> map, boolean up);
475 * validate annotation after an edit and update any alignment state flags accordingly
476 * @param alignmentAnnotation
478 public void validateAnnotation(AlignmentAnnotation alignmentAnnotation);