2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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 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 License for more details.
17 * You should have received a copy of the GNU General 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;
29 * Data structure to hold and manipulate a multiple sequence alignment
31 public interface AlignmentI extends AnnotatedCollectionI
34 * Calculates the number of sequences in an alignment
36 * @return Number of sequences in alignment
42 * Calculates the maximum width of the alignment, including gaps.
44 * @return Greatest sequence length within alignment.
50 * Calculates if this set of sequences (visible and invisible) are all the
53 * @return true if all sequences in alignment are the same length
58 * Calculates if this set of sequences is all the same length
60 * @param includeHidden
61 * optionally exclude hidden sequences from test
62 * @return true if all (or just visible) sequences are the same length
64 boolean isAligned(boolean includeHidden);
67 * Gets sequences as a Synchronized collection
69 * @return All sequences in alignment.
72 List<SequenceI> getSequences();
75 * Gets sequences as a SequenceI[]
77 * @return All sequences in alignment.
79 SequenceI[] getSequencesArray();
82 * Find a specific sequence in this alignment.
85 * Index of required sequence.
87 * @return SequenceI at given index.
89 SequenceI getSequenceAt(int i);
92 * Returns a map of lists of sequences keyed by sequence name.
96 Map<String, List<SequenceI>> getSequencesByName();
99 * Add a new sequence to this alignment.
102 * New sequence will be added at end of alignment.
104 void addSequence(SequenceI seq);
107 * Used to set a particular index of the alignment with the given sequence.
110 * Index of sequence to be updated.
112 * New sequence to be inserted.
114 void setSequenceAt(int i, SequenceI seq);
117 * Deletes a sequence from the alignment
120 * Sequence to be deleted.
122 void deleteSequence(SequenceI s);
125 * Deletes a sequence from the alignment.
128 * Index of sequence to be deleted.
130 void deleteSequence(int i);
133 * Finds sequence in alignment using sequence name as query.
136 * Id of sequence to search for.
138 * @return Sequence matching query, if found. If not found returns null.
140 SequenceI findName(String name);
142 SequenceI[] findSequenceMatch(String name);
145 * Finds index of a given sequence in the alignment.
148 * Sequence to look for.
150 * @return Index of sequence within the alignment or -1 if not found
152 int findIndex(SequenceI s);
155 * Finds group that given sequence is part of.
158 * Sequence in alignment.
160 * @return First group found for sequence. WARNING : Sequences may be members
161 * of several groups. This method is incomplete.
163 SequenceGroup findGroup(SequenceI s);
166 * Finds all groups that a given sequence is part of.
169 * Sequence in alignment.
171 * @return All groups containing given sequence.
173 SequenceGroup[] findAllGroups(SequenceI s);
176 * Adds a new SequenceGroup to this alignment.
179 * New group to be added.
181 void addGroup(SequenceGroup sg);
184 * Deletes a specific SequenceGroup
187 * Group will be deleted from alignment.
189 void deleteGroup(SequenceGroup g);
192 * Get all the groups associated with this alignment.
194 * @return All groups as a list.
196 List<SequenceGroup> getGroups();
199 * Deletes all groups from this alignment.
201 void deleteAllGroups();
204 * Adds a new AlignmentAnnotation to this alignment
206 * @note Care should be taken to ensure that annotation is at least as wide as
207 * the longest sequence in the alignment for rendering purposes.
209 void addAnnotation(AlignmentAnnotation aa);
212 * moves annotation to a specified index in alignment annotation display stack
215 * the annotation object to be moved
217 * the destination position
219 void setAnnotationIndex(AlignmentAnnotation aa, int index);
222 * Delete all annotations, including auto-calculated if the flag is set true.
223 * Returns true if at least one annotation was deleted, else false.
225 * @param includingAutoCalculated
228 boolean deleteAllAnnotations(boolean includingAutoCalculated);
231 * Deletes a specific AlignmentAnnotation from the alignment, and removes its
232 * reference from any SequenceI or SequenceGroup object's annotation if and
233 * only if aa is contained within the alignment's annotation vector.
234 * Otherwise, it will do nothing.
237 * the annotation to delete
238 * @return true if annotation was deleted from this alignment.
240 boolean deleteAnnotation(AlignmentAnnotation aa);
243 * Deletes a specific AlignmentAnnotation from the alignment, and optionally
244 * removes any reference from any SequenceI or SequenceGroup object's
245 * annotation if and only if aa is contained within the alignment's annotation
246 * vector. Otherwise, it will do nothing.
249 * the annotation to delete
251 * flag indicating if any references should be removed from
252 * annotation - use this if you intend to add the annotation back
254 * @return true if annotation was deleted from this alignment.
256 boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
259 * Get the annotation associated with this alignment (this can be null if no
260 * annotation has ever been created on the alignment)
262 * @return array of AlignmentAnnotation objects
265 AlignmentAnnotation[] getAlignmentAnnotation();
268 * Change the gap character used in this alignment to 'gc'
271 * the new gap character.
273 void setGapCharacter(char gc);
276 * Get the gap character used in this alignment
278 * @return gap character
280 char getGapCharacter();
283 * Test for all nucleotide alignment
285 * @return true if alignment is nucleotide sequence
287 boolean isNucleotide();
290 * Test if alignment contains RNA structure
292 * @return true if RNA structure AligmnentAnnotation was added to alignment
294 boolean hasRNAStructure();
297 * Set alignment to be a nucleotide sequence
300 void setNucleotide(boolean b);
303 * Get the associated dataset for the alignment.
305 * @return Alignment containing dataset sequences or null of this is a
308 Alignment getDataset();
311 * Set the associated dataset for the alignment, or create one.
314 * The dataset alignment or null to construct one.
316 void setDataset(Alignment dataset);
319 * pads sequences with gaps (to ensure the set looks like an alignment)
321 * @return boolean true if alignment was modified
325 HiddenSequences getHiddenSequences();
328 * Compact representation of alignment
332 CigarArray getCompactAlignment();
335 * Set an arbitrary key value pair for an alignment. Note: both key and value
336 * objects should return a meaningful, human readable response to .toString()
341 void setProperty(Object key, Object value);
344 * Get a named property from the alignment.
347 * @return value of property
349 Object getProperty(Object key);
352 * Get the property hashtable.
354 * @return hashtable of alignment properties (or null if none are defined)
356 Hashtable getProperties();
359 * add a reference to a frame of aligned codons for this alignment
363 void addCodonFrame(AlignedCodonFrame codons);
366 * remove a particular codon frame reference from this alignment
369 * @return true if codon frame was removed.
371 boolean removeCodonFrame(AlignedCodonFrame codons);
374 * get all codon frames associated with this alignment
378 Set<AlignedCodonFrame> getCodonFrames();
381 * Set the codon frame mappings (replacing any existing set).
383 void setCodonFrames(Set<AlignedCodonFrame> acfs);
386 * get codon frames involving sequenceI
388 List<AlignedCodonFrame> getCodonFrame(SequenceI seq);
391 * find sequence with given name in alignment
396 * true implies that case insensitive matching will <em>also</em> be
398 * @return matched sequence or null
400 SequenceI findName(String token, boolean b);
403 * find next sequence with given name in alignment starting after a given
407 * the sequence after which the search will be started (usually the
408 * result of the last call to findName)
412 * true implies that case insensitive matching will <em>also</em> be
414 * @return matched sequence or null
416 SequenceI findName(SequenceI startAfter, String token, boolean b);
419 * find first sequence in alignment which is involved in the given search
423 * @return -1 or index of sequence in alignment
425 int findIndex(SearchResults results);
428 * append sequences and annotation from another alignment object to this one.
429 * Note: this is a straight transfer of object references, and may result in
430 * toappend's dependent data being transformed to fit the alignment (changing
431 * gap characters, etc...). If you are uncertain, use the copy Alignment copy
432 * constructor to create a new version which can be appended without side
436 * - the alignment to be appended.
438 void append(AlignmentI toappend);
441 * Justify the sequences to the left or right by deleting and inserting gaps
442 * before the initial residue or after the terminal residue
445 * true if alignment padded to right, false to justify to left
446 * @return true if alignment was changed TODO: return undo object
448 boolean justify(boolean right);
451 * add given annotation row at given position (0 is start, -1 is end)
456 void addAnnotation(AlignmentAnnotation consensus, int i);
459 * search for or create a specific annotation row on the alignment
462 * name for annotation (must match)
464 * calcId for the annotation (null or must match)
466 * - value of autocalc flag for the annotation
468 * - null or specific sequence reference
470 * - null or specific group reference
472 * - CalcId for the annotation (must match)
474 * @return existing annotation matching the given attributes
476 AlignmentAnnotation findOrCreateAnnotation(String name,
477 String calcId, boolean autoCalc, SequenceI seqRef,
478 SequenceGroup groupRef);
481 * move the given group up or down in the alignment by the given number of
482 * rows. Implementor assumes given group is already present on alignment - no
483 * recalculations are triggered.
490 void moveSelectedSequencesByOne(SequenceGroup sg,
491 Map<SequenceI, SequenceCollectionI> map, boolean up);
494 * validate annotation after an edit and update any alignment state flags
497 * @param alignmentAnnotation
499 void validateAnnotation(AlignmentAnnotation alignmentAnnotation);
502 * Align this alignment the same as the given one. If both of the same type
503 * (nucleotide/protein) then align both identically. If this is nucleotide and
504 * the other is protein, make 3 gaps for each gap in the protein sequences. If
505 * this is protein and the other is nucleotide, insert a gap for each 3 gaps
506 * (or part thereof) between nucleotide bases. Returns the number of mapped
507 * sequences that were realigned .
512 int alignAs(AlignmentI al);
515 * Returns the set of distinct sequence names in the alignment.
519 Set<String> getSequenceNames();
522 * Checks if the alignment has at least one sequence with one non-gaped
527 public boolean hasValidSequence();