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 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.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, excluding hidden
36 * @return Number of sequences in alignment
41 * Calculates the number of sequences in an alignment, including hidden
44 * @return Number of sequences in alignment
46 int getAbsoluteHeight();
50 * Calculates the maximum width of the alignment, including gaps.
52 * @return Greatest sequence length within alignment, or -1 if no sequences
59 * Calculates if this set of sequences (visible and invisible) are all the
62 * @return true if all sequences in alignment are the same length
67 * Calculates if this set of sequences is all the same length
69 * @param includeHidden
70 * optionally exclude hidden sequences from test
71 * @return true if all (or just visible) sequences are the same length
73 boolean isAligned(boolean includeHidden);
76 * Answers if the sequence at alignmentIndex is hidden
78 * @param alignmentIndex
80 * @return true if the sequence is hidden
82 boolean isHidden(int alignmentIndex);
85 * Gets sequences as a Synchronized collection
87 * @return All sequences in alignment.
90 List<SequenceI> getSequences();
93 * Gets sequences as a SequenceI[]
95 * @return All sequences in alignment.
97 SequenceI[] getSequencesArray();
100 * Find a specific sequence in this alignment.
103 * Index of required sequence.
105 * @return SequenceI at given index.
107 SequenceI getSequenceAt(int i);
110 * Find a specific sequence in this alignment.
113 * Index of required sequence in full alignment, i.e. if all columns
116 * @return SequenceI at given index.
118 SequenceI getSequenceAtAbsoluteIndex(int i);
121 * Returns a map of lists of sequences keyed by sequence name.
125 Map<String, List<SequenceI>> getSequencesByName();
128 * Add a new sequence to this alignment.
131 * New sequence will be added at end of alignment.
133 void addSequence(SequenceI seq);
136 * Used to set a particular index of the alignment with the given sequence.
139 * Index of sequence to be updated. if i>length, sequence will be
140 * added to end, with no intervening positions.
142 * New sequence to be inserted. The existing sequence at position i
144 * @return existing sequence (or null if i>current length)
146 SequenceI replaceSequenceAt(int i, SequenceI seq);
149 * Deletes a sequence from the alignment. Updates hidden sequences to account
150 * for the removed sequence. Do NOT use this method to delete sequences which
154 * Sequence to be deleted.
156 void deleteSequence(SequenceI s);
159 * Deletes a sequence from the alignment. Updates hidden sequences to account
160 * for the removed sequence. Do NOT use this method to delete sequences which
164 * Index of sequence to be deleted.
166 void deleteSequence(int i);
169 * Deletes a sequence in the alignment which has been hidden.
172 * Index of sequence to be deleted
174 void deleteHiddenSequence(int i);
177 * Finds sequence in alignment using sequence name as query.
180 * Id of sequence to search for.
182 * @return Sequence matching query, if found. If not found returns null.
184 SequenceI findName(String name);
186 SequenceI[] findSequenceMatch(String name);
189 * Finds index of a given sequence in the alignment.
192 * Sequence to look for.
194 * @return Index of sequence within the alignment or -1 if not found
196 int findIndex(SequenceI s);
199 * Returns the first group (in the order in which groups were added) that
200 * includes the given sequence instance and aligned position (base 0), or null
204 * - must be contained in the alignment (not a dataset sequence)
209 SequenceGroup findGroup(SequenceI seq, int position);
212 * Finds all groups that a given sequence is part of.
215 * Sequence in alignment.
217 * @return All groups containing given sequence.
219 SequenceGroup[] findAllGroups(SequenceI s);
222 * Adds a new SequenceGroup to this alignment.
225 * New group to be added.
227 void addGroup(SequenceGroup sg);
230 * Deletes a specific SequenceGroup
233 * Group will be deleted from alignment.
235 void deleteGroup(SequenceGroup g);
238 * Get all the groups associated with this alignment.
240 * @return All groups as a list.
242 List<SequenceGroup> getGroups();
245 * Deletes all groups from this alignment.
247 void deleteAllGroups();
250 * Adds a new AlignmentAnnotation to this alignment
252 * @note Care should be taken to ensure that annotation is at least as wide as
253 * the longest sequence in the alignment for rendering purposes.
255 void addAnnotation(AlignmentAnnotation aa);
258 * moves annotation to a specified index in alignment annotation display stack
261 * the annotation object to be moved
263 * the destination position
265 void setAnnotationIndex(AlignmentAnnotation aa, int index);
268 * Delete all annotations, including auto-calculated if the flag is set true.
269 * Returns true if at least one annotation was deleted, else false.
271 * @param includingAutoCalculated
274 boolean deleteAllAnnotations(boolean includingAutoCalculated);
277 * Deletes a specific AlignmentAnnotation from the alignment, and removes its
278 * reference from any SequenceI or SequenceGroup object's annotation if and
279 * only if aa is contained within the alignment's annotation vector.
280 * Otherwise, it will do nothing.
283 * the annotation to delete
284 * @return true if annotation was deleted from this alignment.
286 boolean deleteAnnotation(AlignmentAnnotation aa);
289 * Deletes a specific AlignmentAnnotation from the alignment, and optionally
290 * removes any reference from any SequenceI or SequenceGroup object's
291 * annotation if and only if aa is contained within the alignment's annotation
292 * vector. Otherwise, it will do nothing.
295 * the annotation to delete
297 * flag indicating if any references should be removed from
298 * annotation - use this if you intend to add the annotation back
300 * @return true if annotation was deleted from this alignment.
302 boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
305 * Get the annotation associated with this alignment (this can be null if no
306 * annotation has ever been created on the alignment)
308 * @return array of AlignmentAnnotation objects
311 AlignmentAnnotation[] getAlignmentAnnotation();
314 * Change the gap character used in this alignment to 'gc'
317 * the new gap character.
319 void setGapCharacter(char gc);
322 * Get the gap character used in this alignment
324 * @return gap character
326 char getGapCharacter();
329 * Test if alignment contains RNA structure
331 * @return true if RNA structure AligmnentAnnotation was added to alignment
333 boolean hasRNAStructure();
336 * Get the associated dataset for the alignment.
338 * @return Alignment containing dataset sequences or null of this is a
341 AlignmentI getDataset();
344 * Set the associated dataset for the alignment, or create one.
347 * The dataset alignment or null to construct one.
349 void setDataset(AlignmentI dataset);
352 * pads sequences with gaps (to ensure the set looks like an alignment)
354 * @return boolean true if alignment was modified
358 HiddenSequences getHiddenSequences();
360 HiddenColumns getHiddenColumns();
363 * Compact representation of alignment
367 CigarArray getCompactAlignment();
370 * Set an arbitrary key value pair for an alignment. Note: both key and value
371 * objects should return a meaningful, human readable response to .toString()
376 void setProperty(Object key, Object value);
379 * Get a named property from the alignment.
382 * @return value of property
384 Object getProperty(Object key);
387 * Get the property hashtable.
389 * @return hashtable of alignment properties (or null if none are defined)
391 Map<Object, Object> getProperties();
394 * add a reference to a frame of aligned codons for this alignment
398 void addCodonFrame(AlignedCodonFrame codons);
401 * remove a particular codon frame reference from this alignment
404 * @return true if codon frame was removed.
406 boolean removeCodonFrame(AlignedCodonFrame codons);
409 * get all codon frames associated with this alignment
413 List<AlignedCodonFrame> getCodonFrames();
416 * Set the codon frame mappings (replacing any existing list).
418 void setCodonFrames(List<AlignedCodonFrame> acfs);
421 * get codon frames involving sequenceI
423 List<AlignedCodonFrame> getCodonFrame(SequenceI seq);
426 * find sequence with given name in alignment
431 * true implies that case insensitive matching will <em>also</em> be
433 * @return matched sequence or null
435 SequenceI findName(String token, boolean b);
438 * find next sequence with given name in alignment starting after a given
442 * the sequence after which the search will be started (usually the
443 * result of the last call to findName)
447 * true implies that case insensitive matching will <em>also</em> be
449 * @return matched sequence or null
451 SequenceI findName(SequenceI startAfter, String token, boolean b);
454 * find first sequence in alignment which is involved in the given search
458 * @return -1 or index of sequence in alignment
460 int findIndex(SearchResultsI results);
463 * append sequences and annotation from another alignment object to this one.
464 * Note: this is a straight transfer of object references, and may result in
465 * toappend's dependent data being transformed to fit the alignment (changing
466 * gap characters, etc...). If you are uncertain, use the copy Alignment copy
467 * constructor to create a new version which can be appended without side
471 * - the alignment to be appended.
473 void append(AlignmentI toappend);
476 * Justify the sequences to the left or right by deleting and inserting gaps
477 * before the initial residue or after the terminal residue
480 * true if alignment padded to right, false to justify to left
481 * @return true if alignment was changed TODO: return undo object
483 boolean justify(boolean right);
486 * add given annotation row at given position (0 is start, -1 is end)
491 void addAnnotation(AlignmentAnnotation consensus, int i);
494 * search for or create a specific annotation row on the alignment
497 * name for annotation (must match)
499 * calcId for the annotation (null or must match)
501 * - value of autocalc flag for the annotation
503 * - null or specific sequence reference
505 * - null or specific group reference
507 * - CalcId for the annotation (must match)
509 * @return existing annotation matching the given attributes
511 AlignmentAnnotation findOrCreateAnnotation(String name, String calcId,
512 boolean autoCalc, SequenceI seqRef, SequenceGroup groupRef);
515 * move the given group up or down in the alignment by the given number of
516 * rows. Implementor assumes given group is already present on alignment - no
517 * recalculations are triggered.
524 void moveSelectedSequencesByOne(SequenceGroup sg,
525 Map<SequenceI, SequenceCollectionI> map, boolean up);
528 * validate annotation after an edit and update any alignment state flags
531 * @param alignmentAnnotation
533 void validateAnnotation(AlignmentAnnotation alignmentAnnotation);
536 * Align this alignment the same as the given one. If both of the same type
537 * (nucleotide/protein) then align both identically. If this is nucleotide and
538 * the other is protein, make 3 gaps for each gap in the protein sequences. If
539 * this is protein and the other is nucleotide, insert a gap for each 3 gaps
540 * (or part thereof) between nucleotide bases. Returns the number of mapped
541 * sequences that were realigned .
546 int alignAs(AlignmentI al);
549 * Returns the set of distinct sequence names in the alignment.
553 Set<String> getSequenceNames();
556 * Checks if the alignment has at least one sequence with one non-gaped
561 public boolean hasValidSequence();
564 * Update any mappings to 'virtual' sequences to compatible real ones, if
565 * present in the added sequences. Returns a count of mappings updated.
570 int realiseMappings(List<SequenceI> seqs);
573 * Returns the first AlignedCodonFrame that has a mapping between the given
580 AlignedCodonFrame getMapping(SequenceI mapFrom, SequenceI mapTo);
582 public void setHiddenColumns(HiddenColumns cols);