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, or -1 if no sequences
51 * Calculates if this set of sequences (visible and invisible) are all the
54 * @return true if all sequences in alignment are the same length
59 * Calculates if this set of sequences is all the same length
61 * @param includeHidden
62 * optionally exclude hidden sequences from test
63 * @return true if all (or just visible) sequences are the same length
65 boolean isAligned(boolean includeHidden);
68 * Gets sequences as a Synchronized collection
70 * @return All sequences in alignment.
73 List<SequenceI> getSequences();
76 * Gets sequences as a SequenceI[]
78 * @return All sequences in alignment.
80 SequenceI[] getSequencesArray();
83 * Find a specific sequence in this alignment.
86 * Index of required sequence.
88 * @return SequenceI at given index.
90 SequenceI getSequenceAt(int i);
93 * Returns a map of lists of sequences keyed by sequence name.
97 Map<String, List<SequenceI>> getSequencesByName();
100 * Add a new sequence to this alignment.
103 * New sequence will be added at end of alignment.
105 void addSequence(SequenceI seq);
108 * Used to set a particular index of the alignment with the given sequence.
111 * Index of sequence to be updated. if i>length, sequence will be
112 * added to end, with no intervening positions.
114 * New sequence to be inserted. The existing sequence at position i
116 * @return existing sequence (or null if i>current length)
118 SequenceI replaceSequenceAt(int i, SequenceI seq);
121 * Deletes a sequence from the alignment
124 * Sequence to be deleted.
126 void deleteSequence(SequenceI s);
129 * Deletes a sequence from the alignment.
132 * Index of sequence to be deleted.
134 void deleteSequence(int i);
137 * Finds sequence in alignment using sequence name as query.
140 * Id of sequence to search for.
142 * @return Sequence matching query, if found. If not found returns null.
144 SequenceI findName(String name);
146 SequenceI[] findSequenceMatch(String name);
149 * Finds index of a given sequence in the alignment.
152 * Sequence to look for.
154 * @return Index of sequence within the alignment or -1 if not found
156 int findIndex(SequenceI s);
159 * Returns the first group (in the order in which groups were added) that
160 * includes the given sequence instance and aligned position (base 0), or null
164 * - must be contained in the alignment (not a dataset sequence)
169 SequenceGroup findGroup(SequenceI seq, int position);
172 * Finds all groups that a given sequence is part of.
175 * Sequence in alignment.
177 * @return All groups containing given sequence.
179 SequenceGroup[] findAllGroups(SequenceI s);
182 * Adds a new SequenceGroup to this alignment.
185 * New group to be added.
187 void addGroup(SequenceGroup sg);
190 * Deletes a specific SequenceGroup
193 * Group will be deleted from alignment.
195 void deleteGroup(SequenceGroup g);
198 * Get all the groups associated with this alignment.
200 * @return All groups as a list.
202 List<SequenceGroup> getGroups();
205 * Deletes all groups from this alignment.
207 void deleteAllGroups();
210 * Adds a new AlignmentAnnotation to this alignment
212 * @note Care should be taken to ensure that annotation is at least as wide as
213 * the longest sequence in the alignment for rendering purposes.
215 void addAnnotation(AlignmentAnnotation aa);
218 * moves annotation to a specified index in alignment annotation display stack
221 * the annotation object to be moved
223 * the destination position
225 void setAnnotationIndex(AlignmentAnnotation aa, int index);
228 * Delete all annotations, including auto-calculated if the flag is set true.
229 * Returns true if at least one annotation was deleted, else false.
231 * @param includingAutoCalculated
234 boolean deleteAllAnnotations(boolean includingAutoCalculated);
237 * Deletes a specific AlignmentAnnotation from the alignment, and removes its
238 * reference from any SequenceI or SequenceGroup object's annotation if and
239 * only if aa is contained within the alignment's annotation vector.
240 * Otherwise, it will do nothing.
243 * the annotation to delete
244 * @return true if annotation was deleted from this alignment.
246 boolean deleteAnnotation(AlignmentAnnotation aa);
249 * Deletes a specific AlignmentAnnotation from the alignment, and optionally
250 * removes any reference from any SequenceI or SequenceGroup object's
251 * annotation if and only if aa is contained within the alignment's annotation
252 * vector. Otherwise, it will do nothing.
255 * the annotation to delete
257 * flag indicating if any references should be removed from
258 * annotation - use this if you intend to add the annotation back
260 * @return true if annotation was deleted from this alignment.
262 boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
265 * Get the annotation associated with this alignment (this can be null if no
266 * annotation has ever been created on the alignment)
268 * @return array of AlignmentAnnotation objects
271 AlignmentAnnotation[] getAlignmentAnnotation();
274 * Change the gap character used in this alignment to 'gc'
277 * the new gap character.
279 void setGapCharacter(char gc);
282 * Get the gap character used in this alignment
284 * @return gap character
286 char getGapCharacter();
289 * Test if alignment contains RNA structure
291 * @return true if RNA structure AligmnentAnnotation was added to alignment
293 boolean hasRNAStructure();
296 * Get the associated dataset for the alignment.
298 * @return Alignment containing dataset sequences or null of this is a
301 AlignmentI getDataset();
304 * Set the associated dataset for the alignment, or create one.
307 * The dataset alignment or null to construct one.
309 void setDataset(AlignmentI dataset);
312 * pads sequences with gaps (to ensure the set looks like an alignment)
314 * @return boolean true if alignment was modified
318 HiddenSequences getHiddenSequences();
321 * Compact representation of alignment
325 CigarArray getCompactAlignment();
328 * Set an arbitrary key value pair for an alignment. Note: both key and value
329 * objects should return a meaningful, human readable response to .toString()
334 void setProperty(Object key, Object value);
337 * Get a named property from the alignment.
340 * @return value of property
342 Object getProperty(Object key);
345 * Get the property hashtable.
347 * @return hashtable of alignment properties (or null if none are defined)
349 Hashtable getProperties();
352 * add a reference to a frame of aligned codons for this alignment
356 void addCodonFrame(AlignedCodonFrame codons);
359 * remove a particular codon frame reference from this alignment
362 * @return true if codon frame was removed.
364 boolean removeCodonFrame(AlignedCodonFrame codons);
367 * get all codon frames associated with this alignment
371 List<AlignedCodonFrame> getCodonFrames();
374 * Set the codon frame mappings (replacing any existing list).
376 void setCodonFrames(List<AlignedCodonFrame> acfs);
379 * get codon frames involving sequenceI
381 List<AlignedCodonFrame> getCodonFrame(SequenceI seq);
384 * find sequence with given name in alignment
389 * true implies that case insensitive matching will <em>also</em> be
391 * @return matched sequence or null
393 SequenceI findName(String token, boolean b);
396 * find next sequence with given name in alignment starting after a given
400 * the sequence after which the search will be started (usually the
401 * result of the last call to findName)
405 * true implies that case insensitive matching will <em>also</em> be
407 * @return matched sequence or null
409 SequenceI findName(SequenceI startAfter, String token, boolean b);
412 * find first sequence in alignment which is involved in the given search
416 * @return -1 or index of sequence in alignment
418 int findIndex(SearchResultsI results);
421 * append sequences and annotation from another alignment object to this one.
422 * Note: this is a straight transfer of object references, and may result in
423 * toappend's dependent data being transformed to fit the alignment (changing
424 * gap characters, etc...). If you are uncertain, use the copy Alignment copy
425 * constructor to create a new version which can be appended without side
429 * - the alignment to be appended.
431 void append(AlignmentI toappend);
434 * Justify the sequences to the left or right by deleting and inserting gaps
435 * before the initial residue or after the terminal residue
438 * true if alignment padded to right, false to justify to left
439 * @return true if alignment was changed TODO: return undo object
441 boolean justify(boolean right);
444 * add given annotation row at given position (0 is start, -1 is end)
449 void addAnnotation(AlignmentAnnotation consensus, int i);
452 * search for or create a specific annotation row on the alignment
455 * name for annotation (must match)
457 * calcId for the annotation (null or must match)
459 * - value of autocalc flag for the annotation
461 * - null or specific sequence reference
463 * - null or specific group reference
465 * - CalcId for the annotation (must match)
467 * @return existing annotation matching the given attributes
469 AlignmentAnnotation findOrCreateAnnotation(String name, String calcId,
470 boolean autoCalc, SequenceI seqRef, SequenceGroup groupRef);
473 * move the given group up or down in the alignment by the given number of
474 * rows. Implementor assumes given group is already present on alignment - no
475 * recalculations are triggered.
482 void moveSelectedSequencesByOne(SequenceGroup sg,
483 Map<SequenceI, SequenceCollectionI> map, boolean up);
486 * validate annotation after an edit and update any alignment state flags
489 * @param alignmentAnnotation
491 void validateAnnotation(AlignmentAnnotation alignmentAnnotation);
494 * Align this alignment the same as the given one. If both of the same type
495 * (nucleotide/protein) then align both identically. If this is nucleotide and
496 * the other is protein, make 3 gaps for each gap in the protein sequences. If
497 * this is protein and the other is nucleotide, insert a gap for each 3 gaps
498 * (or part thereof) between nucleotide bases. Returns the number of mapped
499 * sequences that were realigned .
504 int alignAs(AlignmentI al);
507 * Returns the set of distinct sequence names in the alignment.
511 Set<String> getSequenceNames();
514 * Checks if the alignment has at least one sequence with one non-gaped
519 public boolean hasValidSequence();
522 * Update any mappings to 'virtual' sequences to compatible real ones, if
523 * present in the added sequences. Returns a count of mappings updated.
528 int realiseMappings(List<SequenceI> seqs);
531 * Returns the first AlignedCodonFrame that has a mapping between the given
538 AlignedCodonFrame getMapping(SequenceI mapFrom, SequenceI mapTo);
541 * Calculate the visible start and end index of an alignment. The result is
542 * returned an int array where: int[0] = startIndex, and int[1] = endIndex.
547 public int[] getVisibleStartAndEndIndex(List<int[]> hiddenCols);