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.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, excluding hidden
37 * @return Number of sequences in alignment
42 * Calculates the number of sequences in an alignment, including hidden
45 * @return Number of sequences in alignment
47 int getAbsoluteHeight();
51 * Answers the width of the alignment, including gaps, that is, the length of
52 * the longest sequence, or -1 if there are no sequences. Avoid calling this
53 * method repeatedly where possible, as it has to perform a calculation. Note
54 * that this width includes any hidden columns.
57 * @see AlignmentI#getVisibleWidth()
64 * Answers the visible width of the alignment, including gaps, that is, the
65 * length of the longest sequence, excluding any hidden columns. Answers -1 if
66 * there are no sequences. Avoid calling this method repeatedly where
67 * possible, as it has to perform a calculation.
71 int getVisibleWidth();
74 * Calculates if this set of sequences (visible and invisible) are all the
77 * @return true if all sequences in alignment are the same length
82 * Calculates if this set of sequences is all the same length
84 * @param includeHidden
85 * optionally exclude hidden sequences from test
86 * @return true if all (or just visible) sequences are the same length
88 boolean isAligned(boolean includeHidden);
91 * Answers if the sequence at alignmentIndex is hidden
93 * @param alignmentIndex
95 * @return true if the sequence is hidden
97 boolean isHidden(int alignmentIndex);
100 * Gets sequences as a Synchronized collection
102 * @return All sequences in alignment.
105 List<SequenceI> getSequences();
108 * Gets sequences as a SequenceI[]
110 * @return All sequences in alignment.
112 SequenceI[] getSequencesArray();
115 * Find a specific sequence in this alignment.
118 * Index of required sequence.
120 * @return SequenceI at given index.
122 SequenceI getSequenceAt(int i);
125 * Find a specific sequence in this alignment.
128 * Index of required sequence in full alignment, i.e. if all columns
131 * @return SequenceI at given index.
133 SequenceI getSequenceAtAbsoluteIndex(int i);
136 * Returns a map of lists of sequences keyed by sequence name.
140 Map<String, List<SequenceI>> getSequencesByName();
143 * Add a new sequence to this alignment.
146 * New sequence will be added at end of alignment.
148 void addSequence(SequenceI seq);
151 * Used to set a particular index of the alignment with the given sequence.
154 * Index of sequence to be updated. if i>length, sequence will be
155 * added to end, with no intervening positions.
157 * New sequence to be inserted. The existing sequence at position i
159 * @return existing sequence (or null if i>current length)
161 SequenceI replaceSequenceAt(int i, SequenceI seq);
164 * Deletes a sequence from the alignment. Updates hidden sequences to account
165 * for the removed sequence. Do NOT use this method to delete sequences which
169 * Sequence to be deleted.
171 void deleteSequence(SequenceI s);
174 * Deletes a sequence from the alignment. Updates hidden sequences to account
175 * for the removed sequence. Do NOT use this method to delete sequences which
179 * Index of sequence to be deleted.
181 void deleteSequence(int i);
184 * Deletes a sequence in the alignment which has been hidden.
187 * Index of sequence to be deleted
189 void deleteHiddenSequence(int i);
192 * Finds sequence in alignment using sequence name as query.
195 * Id of sequence to search for.
197 * @return Sequence matching query, if found. If not found returns null.
199 SequenceI findName(String name);
201 SequenceI[] findSequenceMatch(String name);
204 * Finds index of a given sequence in the alignment.
207 * Sequence to look for.
209 * @return Index of sequence within the alignment or -1 if not found
211 int findIndex(SequenceI s);
214 * Returns the first group (in the order in which groups were added) that
215 * includes the given sequence instance and aligned position (base 0), or null
219 * - must be contained in the alignment (not a dataset sequence)
224 SequenceGroup findGroup(SequenceI seq, int position);
227 * Finds all groups that a given sequence is part of.
230 * Sequence in alignment.
232 * @return All groups containing given sequence.
234 SequenceGroup[] findAllGroups(SequenceI s);
237 * Adds a new SequenceGroup to this alignment.
240 * New group to be added.
242 void addGroup(SequenceGroup sg);
245 * Deletes a specific SequenceGroup
248 * Group will be deleted from alignment.
250 void deleteGroup(SequenceGroup g);
253 * Get all the groups associated with this alignment.
255 * @return All groups as a list.
257 List<SequenceGroup> getGroups();
260 * Deletes all groups from this alignment.
262 void deleteAllGroups();
265 * Adds a new AlignmentAnnotation to this alignment
267 * @note Care should be taken to ensure that annotation is at least as wide as
268 * the longest sequence in the alignment for rendering purposes.
270 void addAnnotation(AlignmentAnnotation aa);
273 * moves annotation to a specified index in alignment annotation display stack
276 * the annotation object to be moved
278 * the destination position
280 void setAnnotationIndex(AlignmentAnnotation aa, int index);
283 * Delete all annotations, including auto-calculated if the flag is set true.
284 * Returns true if at least one annotation was deleted, else false.
286 * @param includingAutoCalculated
289 boolean deleteAllAnnotations(boolean includingAutoCalculated);
292 * Deletes a specific AlignmentAnnotation from the alignment, and removes its
293 * reference from any SequenceI or SequenceGroup object's annotation if and
294 * only if aa is contained within the alignment's annotation vector.
295 * Otherwise, it will do nothing.
298 * the annotation to delete
299 * @return true if annotation was deleted from this alignment.
301 boolean deleteAnnotation(AlignmentAnnotation aa);
304 * Deletes a specific AlignmentAnnotation from the alignment, and optionally
305 * removes any reference from any SequenceI or SequenceGroup object's
306 * annotation if and only if aa is contained within the alignment's annotation
307 * vector. Otherwise, it will do nothing.
310 * the annotation to delete
312 * flag indicating if any references should be removed from
313 * annotation - use this if you intend to add the annotation back
315 * @return true if annotation was deleted from this alignment.
317 boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
320 * Get the annotation associated with this alignment (this can be null if no
321 * annotation has ever been created on the alignment)
323 * @return array of AlignmentAnnotation objects
326 AlignmentAnnotation[] getAlignmentAnnotation();
329 * Change the gap character used in this alignment to 'gc'
332 * the new gap character.
334 void setGapCharacter(char gc);
337 * Get the gap character used in this alignment
339 * @return gap character
341 char getGapCharacter();
344 * Test if alignment contains RNA structure
346 * @return true if RNA structure AligmnentAnnotation was added to alignment
348 boolean hasRNAStructure();
351 * Get the associated dataset for the alignment.
353 * @return Alignment containing dataset sequences or null of this is a
356 AlignmentI getDataset();
359 * Set the associated dataset for the alignment, or create one.
362 * The dataset alignment or null to construct one.
364 void setDataset(AlignmentI dataset);
367 * pads sequences with gaps (to ensure the set looks like an alignment)
369 * @return boolean true if alignment was modified
373 HiddenSequences getHiddenSequences();
375 HiddenColumns getHiddenColumns();
378 * Compact representation of alignment
382 CigarArray getCompactAlignment();
385 * Set an arbitrary key value pair for an alignment. Note: both key and value
386 * objects should return a meaningful, human readable response to .toString()
391 void setProperty(Object key, Object value);
394 * Get a named property from the alignment.
397 * @return value of property
399 Object getProperty(Object key);
402 * Get the property hashtable.
404 * @return hashtable of alignment properties (or null if none are defined)
406 Hashtable getProperties();
409 * add a reference to a frame of aligned codons for this alignment
413 void addCodonFrame(AlignedCodonFrame codons);
416 * remove a particular codon frame reference from this alignment
419 * @return true if codon frame was removed.
421 boolean removeCodonFrame(AlignedCodonFrame codons);
424 * get all codon frames associated with this alignment
428 List<AlignedCodonFrame> getCodonFrames();
431 * Set the codon frame mappings (replacing any existing list).
433 void setCodonFrames(List<AlignedCodonFrame> acfs);
436 * get codon frames involving sequenceI
438 List<AlignedCodonFrame> getCodonFrame(SequenceI seq);
441 * find sequence with given name in alignment
446 * true implies that case insensitive matching will <em>also</em> be
448 * @return matched sequence or null
450 SequenceI findName(String token, boolean b);
453 * find next sequence with given name in alignment starting after a given
457 * the sequence after which the search will be started (usually the
458 * result of the last call to findName)
462 * true implies that case insensitive matching will <em>also</em> be
464 * @return matched sequence or null
466 SequenceI findName(SequenceI startAfter, String token, boolean b);
469 * find first sequence in alignment which is involved in the given search
473 * @return -1 or index of sequence in alignment
475 int findIndex(SearchResultsI results);
478 * append sequences and annotation from another alignment object to this one.
479 * Note: this is a straight transfer of object references, and may result in
480 * toappend's dependent data being transformed to fit the alignment (changing
481 * gap characters, etc...). If you are uncertain, use the copy Alignment copy
482 * constructor to create a new version which can be appended without side
486 * - the alignment to be appended.
488 void append(AlignmentI toappend);
491 * Justify the sequences to the left or right by deleting and inserting gaps
492 * before the initial residue or after the terminal residue
495 * true if alignment padded to right, false to justify to left
496 * @return true if alignment was changed TODO: return undo object
498 boolean justify(boolean right);
501 * add given annotation row at given position (0 is start, -1 is end)
506 void addAnnotation(AlignmentAnnotation consensus, int i);
509 * search for or create a specific annotation row on the alignment
512 * name for annotation (must match)
514 * calcId for the annotation (null or must match)
516 * - value of autocalc flag for the annotation
518 * - null or specific sequence reference
520 * - null or specific group reference
522 * - CalcId for the annotation (must match)
524 * @return existing annotation matching the given attributes
526 AlignmentAnnotation findOrCreateAnnotation(String name, String calcId,
527 boolean autoCalc, SequenceI seqRef, SequenceGroup groupRef);
530 * move the given group up or down in the alignment by the given number of
531 * rows. Implementor assumes given group is already present on alignment - no
532 * recalculations are triggered.
539 void moveSelectedSequencesByOne(SequenceGroup sg,
540 Map<SequenceI, SequenceCollectionI> map, boolean up);
543 * validate annotation after an edit and update any alignment state flags
546 * @param alignmentAnnotation
548 void validateAnnotation(AlignmentAnnotation alignmentAnnotation);
551 * Align this alignment the same as the given one. If both of the same type
552 * (nucleotide/protein) then align both identically. If this is nucleotide and
553 * the other is protein, make 3 gaps for each gap in the protein sequences. If
554 * this is protein and the other is nucleotide, insert a gap for each 3 gaps
555 * (or part thereof) between nucleotide bases. Returns the number of mapped
556 * sequences that were realigned .
561 int alignAs(AlignmentI al);
564 * Returns the set of distinct sequence names in the alignment.
568 Set<String> getSequenceNames();
571 * Checks if the alignment has at least one sequence with one non-gaped
576 public boolean hasValidSequence();
579 * Update any mappings to 'virtual' sequences to compatible real ones, if
580 * present in the added sequences. Returns a count of mappings updated.
585 int realiseMappings(List<SequenceI> seqs);
588 * Returns the first AlignedCodonFrame that has a mapping between the given
595 AlignedCodonFrame getMapping(SequenceI mapFrom, SequenceI mapTo);
598 * Set the hidden columns collection on the alignment. Answers true if the
599 * hidden column selection changed, else false.
604 public boolean setHiddenColumns(HiddenColumns cols);
607 * Set the first sequence as representative and hide its insertions. Typically
608 * used when loading JPred files.
610 public void setupJPredAlignment();
613 * Add gaps into the sequences aligned to profileseq under the given
617 * sequence in al which sequences are aligned to
619 * alignment view where sequence corresponding to profileseq is first
621 * @return new HiddenColumns for new alignment view, with insertions into
622 * profileseq marked as hidden.
624 public HiddenColumns propagateInsertions(SequenceI profileseq,
625 AlignmentView input);