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.Collection;
24 import java.util.Hashtable;
25 import java.util.List;
30 * Data structure to hold and manipulate a multiple sequence alignment
32 public interface AlignmentI extends AnnotatedCollectionI
35 * Calculates the number of sequences in an alignment, excluding hidden
38 * @return Number of sequences in alignment
43 * Calculates the number of sequences in an alignment, including hidden
46 * @return Number of sequences in alignment
48 int getAbsoluteHeight();
52 * Answers the width of the alignment, including gaps, that is, the length of
53 * the longest sequence, or -1 if there are no sequences. Avoid calling this
54 * method repeatedly where possible, as it has to perform a calculation. Note
55 * that this width includes any hidden columns.
58 * @see AlignmentI#getVisibleWidth()
65 * Answers the visible width of the alignment, including gaps, that is, the
66 * length of the longest sequence, excluding any hidden columns. Answers -1 if
67 * there are no sequences. Avoid calling this method repeatedly where
68 * possible, as it has to perform a calculation.
72 int getVisibleWidth();
75 * Calculates if this set of sequences (visible and invisible) are all the
78 * @return true if all sequences in alignment are the same length
83 * Calculates if this set of sequences is all the same length
85 * @param includeHidden
86 * optionally exclude hidden sequences from test
87 * @return true if all (or just visible) sequences are the same length
89 boolean isAligned(boolean includeHidden);
92 * Answers if the sequence at alignmentIndex is hidden
94 * @param alignmentIndex
96 * @return true if the sequence is hidden
98 boolean isHidden(int alignmentIndex);
101 * Gets sequences as a Synchronized collection
103 * @return All sequences in alignment.
106 List<SequenceI> getSequences();
109 * Gets sequences as a SequenceI[]
111 * @return All sequences in alignment.
113 SequenceI[] getSequencesArray();
116 * Find a specific sequence in this alignment.
119 * Index of required sequence.
121 * @return SequenceI at given index.
123 SequenceI getSequenceAt(int i);
126 * Find a specific sequence in this alignment.
129 * Index of required sequence in full alignment, i.e. if all columns
132 * @return SequenceI at given index.
134 SequenceI getSequenceAtAbsoluteIndex(int i);
137 * Returns a map of lists of sequences keyed by sequence name.
141 Map<String, List<SequenceI>> getSequencesByName();
144 * Add a new sequence to this alignment.
147 * New sequence will be added at end of alignment.
149 void addSequence(SequenceI seq);
152 * Used to set a particular index of the alignment with the given sequence.
155 * Index of sequence to be updated. if i>length, sequence will be
156 * added to end, with no intervening positions.
158 * New sequence to be inserted. The existing sequence at position i
160 * @return existing sequence (or null if i>current length)
162 SequenceI replaceSequenceAt(int i, SequenceI seq);
165 * Deletes a sequence from the alignment. Updates hidden sequences to account
166 * for the removed sequence. Do NOT use this method to delete sequences which
170 * Sequence to be deleted.
172 void deleteSequence(SequenceI s);
175 * Deletes a sequence from the alignment. Updates hidden sequences to account
176 * for the removed sequence. Do NOT use this method to delete sequences which
180 * Index of sequence to be deleted.
182 void deleteSequence(int i);
185 * Deletes a sequence in the alignment which has been hidden.
188 * Index of sequence to be deleted
190 void deleteHiddenSequence(int i);
193 * Finds sequence in alignment using sequence name as query.
196 * Id of sequence to search for.
198 * @return Sequence matching query, if found. If not found returns null.
200 SequenceI findName(String name);
202 SequenceI[] findSequenceMatch(String name);
205 * Finds index of a given sequence in the alignment.
208 * Sequence to look for.
210 * @return Index of sequence within the alignment or -1 if not found
212 int findIndex(SequenceI s);
215 * Returns the first group (in the order in which groups were added) that
216 * includes the given sequence instance and aligned position (base 0), or null
220 * - must be contained in the alignment (not a dataset sequence)
225 SequenceGroup findGroup(SequenceI seq, int position);
228 * Finds all groups that a given sequence is part of.
231 * Sequence in alignment.
233 * @return All groups containing given sequence.
235 SequenceGroup[] findAllGroups(SequenceI s);
238 * Adds a new SequenceGroup to this alignment.
241 * New group to be added.
243 void addGroup(SequenceGroup sg);
246 * Deletes a specific SequenceGroup
249 * Group will be deleted from alignment.
251 void deleteGroup(SequenceGroup g);
254 * Get all the groups associated with this alignment.
256 * @return All groups as a list.
258 List<SequenceGroup> getGroups();
261 * Deletes all groups from this alignment.
263 void deleteAllGroups();
266 * Adds a new AlignmentAnnotation to this alignment
268 * @note Care should be taken to ensure that annotation is at least as wide as
269 * the longest sequence in the alignment for rendering purposes.
271 void addAnnotation(AlignmentAnnotation aa);
274 * moves annotation to a specified index in alignment annotation display stack
277 * the annotation object to be moved
279 * the destination position
281 void setAnnotationIndex(AlignmentAnnotation aa, int index);
284 * Delete all annotations, including auto-calculated if the flag is set true.
285 * Returns true if at least one annotation was deleted, else false.
287 * @param includingAutoCalculated
290 boolean deleteAllAnnotations(boolean includingAutoCalculated);
293 * Deletes a specific AlignmentAnnotation from the alignment, and removes its
294 * reference from any SequenceI or SequenceGroup object's annotation if and
295 * only if aa is contained within the alignment's annotation vector.
296 * Otherwise, it will do nothing.
299 * the annotation to delete
300 * @return true if annotation was deleted from this alignment.
302 boolean deleteAnnotation(AlignmentAnnotation aa);
305 * Deletes a specific AlignmentAnnotation from the alignment, and optionally
306 * removes any reference from any SequenceI or SequenceGroup object's
307 * annotation if and only if aa is contained within the alignment's annotation
308 * vector. Otherwise, it will do nothing.
311 * the annotation to delete
313 * flag indicating if any references should be removed from
314 * annotation - use this if you intend to add the annotation back
316 * @return true if annotation was deleted from this alignment.
318 boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
321 * Get the annotation associated with this alignment (this can be null if no
322 * annotation has ever been created on the alignment)
324 * @return array of AlignmentAnnotation objects
327 AlignmentAnnotation[] getAlignmentAnnotation();
330 * Change the gap character used in this alignment to 'gc'
333 * the new gap character.
335 void setGapCharacter(char gc);
338 * Get the gap character used in this alignment
340 * @return gap character
342 char getGapCharacter();
345 * Test if alignment contains RNA structure
347 * @return true if RNA structure AligmnentAnnotation was added to alignment
349 boolean hasRNAStructure();
352 * Get the associated dataset for the alignment.
354 * @return Alignment containing dataset sequences or null of this is a
357 AlignmentI getDataset();
360 * Set the associated dataset for the alignment, or create one.
363 * The dataset alignment or null to construct one.
365 void setDataset(AlignmentI dataset);
368 * pads sequences with gaps (to ensure the set looks like an alignment)
370 * @return boolean true if alignment was modified
374 HiddenSequences getHiddenSequences();
376 HiddenColumns getHiddenColumns();
379 * Compact representation of alignment
383 CigarArray getCompactAlignment();
386 * Set an arbitrary key value pair for an alignment. Note: both key and value
387 * objects should return a meaningful, human readable response to .toString()
392 void setProperty(Object key, Object value);
395 * Get a named property from the alignment.
398 * @return value of property
400 Object getProperty(Object key);
403 * Get the property hashtable.
405 * @return hashtable of alignment properties (or null if none are defined)
407 Hashtable getProperties();
410 * add a reference to a frame of aligned codons for this alignment
414 void addCodonFrame(AlignedCodonFrame codons);
417 * remove a particular codon frame reference from this alignment
420 * @return true if codon frame was removed.
422 boolean removeCodonFrame(AlignedCodonFrame codons);
425 * get all codon frames associated with this alignment
429 List<AlignedCodonFrame> getCodonFrames();
432 * Set the codon frame mappings (replacing any existing list).
434 void setCodonFrames(List<AlignedCodonFrame> acfs);
437 * get codon frames involving sequenceI
439 List<AlignedCodonFrame> getCodonFrame(SequenceI seq);
442 * find sequence with given name in alignment
447 * true implies that case insensitive matching will <em>also</em> be
449 * @return matched sequence or null
451 SequenceI findName(String token, boolean b);
454 * find next sequence with given name in alignment starting after a given
458 * the sequence after which the search will be started (usually the
459 * result of the last call to findName)
463 * true implies that case insensitive matching will <em>also</em> be
465 * @return matched sequence or null
467 SequenceI findName(SequenceI startAfter, String token, boolean b);
470 * find first sequence in alignment which is involved in the given search
474 * @return -1 or index of sequence in alignment
476 int findIndex(SearchResultsI results);
479 * append sequences and annotation from another alignment object to this one.
480 * Note: this is a straight transfer of object references, and may result in
481 * toappend's dependent data being transformed to fit the alignment (changing
482 * gap characters, etc...). If you are uncertain, use the copy Alignment copy
483 * constructor to create a new version which can be appended without side
487 * - the alignment to be appended.
489 void append(AlignmentI toappend);
492 * Justify the sequences to the left or right by deleting and inserting gaps
493 * before the initial residue or after the terminal residue
496 * true if alignment padded to right, false to justify to left
497 * @return true if alignment was changed TODO: return undo object
499 boolean justify(boolean right);
502 * add given annotation row at given position (0 is start, -1 is end)
507 void addAnnotation(AlignmentAnnotation consensus, int i);
510 * search for or create a specific annotation row on the alignment
513 * name for annotation (must match)
515 * calcId for the annotation (null or must match)
517 * - value of autocalc flag for the annotation
519 * - null or specific sequence reference
521 * - null or specific group reference
523 * - CalcId for the annotation (must match)
525 * @return existing annotation matching the given attributes
527 AlignmentAnnotation findOrCreateAnnotation(String name, String calcId,
528 boolean autoCalc, SequenceI seqRef, SequenceGroup groupRef);
531 * move the given group up or down in the alignment by the given number of
532 * rows. Implementor assumes given group is already present on alignment - no
533 * recalculations are triggered.
540 void moveSelectedSequencesByOne(SequenceGroup sg,
541 Map<SequenceI, SequenceCollectionI> map, boolean up);
544 * validate annotation after an edit and update any alignment state flags
547 * @param alignmentAnnotation
549 void validateAnnotation(AlignmentAnnotation alignmentAnnotation);
552 * Align this alignment the same as the given one. If both of the same type
553 * (nucleotide/protein) then align both identically. If this is nucleotide and
554 * the other is protein, make 3 gaps for each gap in the protein sequences. If
555 * this is protein and the other is nucleotide, insert a gap for each 3 gaps
556 * (or part thereof) between nucleotide bases. Returns the number of mapped
557 * sequences that were realigned .
562 int alignAs(AlignmentI al);
565 * Returns the set of distinct sequence names in the alignment.
569 Set<String> getSequenceNames();
572 * Checks if the alignment has at least one sequence with one non-gaped
577 public boolean hasValidSequence();
580 * Update any mappings to 'virtual' sequences to compatible real ones, if
581 * present in the added sequences. Returns a count of mappings updated.
586 int realiseMappings(List<SequenceI> seqs);
589 * Returns the first AlignedCodonFrame that has a mapping between the given
596 AlignedCodonFrame getMapping(SequenceI mapFrom, SequenceI mapTo);
599 * Set the hidden columns collection on the alignment. Answers true if the
600 * hidden column selection changed, else false.
605 public boolean setHiddenColumns(HiddenColumns cols);
608 * Set the first sequence as representative and hide its insertions. Typically
609 * used when loading JPred files.
611 public void setupJPredAlignment();
614 * Add gaps into the sequences aligned to profileseq under the given
618 * sequence in al which sequences are aligned to
620 * alignment view where sequence corresponding to profileseq is first
622 * @return new HiddenColumns for new alignment view, with insertions into
623 * profileseq marked as hidden.
625 public HiddenColumns propagateInsertions(SequenceI profileseq,
626 AlignmentView input);
629 * resolve a contact list instance (if any) associated with the annotation row
630 * and column position
636 ContactListI getContactListFor(AlignmentAnnotation _aa, int column);
638 AlignmentAnnotation addContactList(ContactMatrixI cm);
640 Collection<ContactMatrixI> getContactMaps();