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 * Answers the width of the alignment, including gaps, that is, the length of
51 * the longest sequence, or -1 if there are no sequences. Avoid calling this
52 * method repeatedly where possible, as it has to perform a calculation. Note
53 * that this width includes any hidden columns.
56 * @see AlignmentI#getVisibleWidth()
63 * Answers the visible width of the alignment, including gaps, that is, the
64 * length of the longest sequence, excluding any hidden columns. Answers -1 if
65 * there are no sequences. Avoid calling this method repeatedly where
66 * possible, as it has to perform a calculation.
70 int getVisibleWidth();
73 * Calculates if this set of sequences (visible and invisible) are all the
76 * @return true if all sequences in alignment are the same length
81 * Calculates if this set of sequences is all the same length
83 * @param includeHidden
84 * optionally exclude hidden sequences from test
85 * @return true if all (or just visible) sequences are the same length
87 boolean isAligned(boolean includeHidden);
90 * Answers if the sequence at alignmentIndex is hidden
92 * @param alignmentIndex
94 * @return true if the sequence is hidden
96 boolean isHidden(int alignmentIndex);
99 * Gets sequences as a Synchronized collection
101 * @return All sequences in alignment.
104 List<SequenceI> getSequences();
107 * Gets sequences as a SequenceI[]
109 * @return All sequences in alignment.
111 SequenceI[] getSequencesArray();
114 * Find a specific sequence in this alignment.
117 * Index of required sequence.
119 * @return SequenceI at given index.
121 SequenceI getSequenceAt(int i);
124 * Find a specific sequence in this alignment.
127 * Index of required sequence in full alignment, i.e. if all columns
130 * @return SequenceI at given index.
132 SequenceI getSequenceAtAbsoluteIndex(int i);
135 * Returns a map of lists of sequences keyed by sequence name.
139 Map<String, List<SequenceI>> getSequencesByName();
142 * Add a new sequence to this alignment.
145 * New sequence will be added at end of alignment.
147 void addSequence(SequenceI seq);
150 * Used to set a particular index of the alignment with the given sequence.
153 * Index of sequence to be updated. if i>length, sequence will be
154 * added to end, with no intervening positions.
156 * New sequence to be inserted. The existing sequence at position i
158 * @return existing sequence (or null if i>current length)
160 SequenceI replaceSequenceAt(int i, SequenceI seq);
163 * Deletes a sequence from the alignment. Updates hidden sequences to account
164 * for the removed sequence. Do NOT use this method to delete sequences which
168 * Sequence to be deleted.
170 void deleteSequence(SequenceI s);
173 * Deletes a sequence from the alignment. Updates hidden sequences to account
174 * for the removed sequence. Do NOT use this method to delete sequences which
178 * Index of sequence to be deleted.
180 void deleteSequence(int i);
183 * Deletes a sequence in the alignment which has been hidden.
186 * Index of sequence to be deleted
188 void deleteHiddenSequence(int i);
191 * Finds sequence in alignment using sequence name as query.
194 * Id of sequence to search for.
196 * @return Sequence matching query, if found. If not found returns null.
198 SequenceI findName(String name);
200 SequenceI[] findSequenceMatch(String name);
203 * Finds index of a given sequence in the alignment.
206 * Sequence to look for.
208 * @return Index of sequence within the alignment or -1 if not found
210 int findIndex(SequenceI s);
213 * Returns the first group (in the order in which groups were added) that
214 * includes the given sequence instance and aligned position (base 0), or null
218 * - must be contained in the alignment (not a dataset sequence)
223 SequenceGroup findGroup(SequenceI seq, int position);
226 * Finds all groups that a given sequence is part of.
229 * Sequence in alignment.
231 * @return All groups containing given sequence.
233 SequenceGroup[] findAllGroups(SequenceI s);
236 * Adds a new SequenceGroup to this alignment.
239 * New group to be added.
241 void addGroup(SequenceGroup sg);
244 * Deletes a specific SequenceGroup
247 * Group will be deleted from alignment.
249 void deleteGroup(SequenceGroup g);
252 * Get all the groups associated with this alignment.
254 * @return All groups as a list.
256 List<SequenceGroup> getGroups();
259 * Deletes all groups from this alignment.
261 void deleteAllGroups();
264 * Adds a new AlignmentAnnotation to this alignment
266 * @note Care should be taken to ensure that annotation is at least as wide as
267 * the longest sequence in the alignment for rendering purposes.
269 void addAnnotation(AlignmentAnnotation aa);
272 * moves annotation to a specified index in alignment annotation display stack
275 * the annotation object to be moved
277 * the destination position
279 void setAnnotationIndex(AlignmentAnnotation aa, int index);
282 * Delete all annotations, including auto-calculated if the flag is set true.
283 * Returns true if at least one annotation was deleted, else false.
285 * @param includingAutoCalculated
288 boolean deleteAllAnnotations(boolean includingAutoCalculated);
291 * Deletes a specific AlignmentAnnotation from the alignment, and removes its
292 * reference from any SequenceI or SequenceGroup object's annotation if and
293 * only if aa is contained within the alignment's annotation vector.
294 * Otherwise, it will do nothing.
297 * the annotation to delete
298 * @return true if annotation was deleted from this alignment.
300 boolean deleteAnnotation(AlignmentAnnotation aa);
303 * Deletes a specific AlignmentAnnotation from the alignment, and optionally
304 * removes any reference from any SequenceI or SequenceGroup object's
305 * annotation if and only if aa is contained within the alignment's annotation
306 * vector. Otherwise, it will do nothing.
309 * the annotation to delete
311 * flag indicating if any references should be removed from
312 * annotation - use this if you intend to add the annotation back
314 * @return true if annotation was deleted from this alignment.
316 boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
319 * Get the annotation associated with this alignment (this can be null if no
320 * annotation has ever been created on the alignment)
322 * @return array of AlignmentAnnotation objects
325 AlignmentAnnotation[] getAlignmentAnnotation();
328 * Change the gap character used in this alignment to 'gc'
331 * the new gap character.
333 void setGapCharacter(char gc);
336 * Get the gap character used in this alignment
338 * @return gap character
340 char getGapCharacter();
343 * Test if alignment contains RNA structure
345 * @return true if RNA structure AligmnentAnnotation was added to alignment
347 boolean hasRNAStructure();
350 * Get the associated dataset for the alignment.
352 * @return Alignment containing dataset sequences or null of this is a
355 AlignmentI getDataset();
358 * Set the associated dataset for the alignment, or create one.
361 * The dataset alignment or null to construct one.
363 void setDataset(AlignmentI dataset);
366 * pads sequences with gaps (to ensure the set looks like an alignment)
368 * @return boolean true if alignment was modified
372 HiddenSequences getHiddenSequences();
374 HiddenColumns getHiddenColumns();
377 * Compact representation of alignment
381 CigarArray getCompactAlignment();
384 * Set an arbitrary key value pair for an alignment. Note: both key and value
385 * objects should return a meaningful, human readable response to .toString()
390 void setProperty(Object key, Object value);
393 * Get a named property from the alignment.
396 * @return value of property
398 Object getProperty(Object key);
401 * Get the property hashtable.
403 * @return hashtable of alignment properties (or null if none are defined)
405 Map<Object, Object> getProperties();
408 * add a reference to a frame of aligned codons for this alignment
412 void addCodonFrame(AlignedCodonFrame codons);
415 * remove a particular codon frame reference from this alignment
418 * @return true if codon frame was removed.
420 boolean removeCodonFrame(AlignedCodonFrame codons);
423 * get all codon frames associated with this alignment
427 List<AlignedCodonFrame> getCodonFrames();
430 * Set the codon frame mappings (replacing any existing list).
432 void setCodonFrames(List<AlignedCodonFrame> acfs);
435 * get codon frames involving sequenceI
437 List<AlignedCodonFrame> getCodonFrame(SequenceI seq);
440 * find sequence with given name in alignment
445 * true implies that case insensitive matching will <em>also</em> be
447 * @return matched sequence or null
449 SequenceI findName(String token, boolean b);
452 * find next sequence with given name in alignment starting after a given
456 * the sequence after which the search will be started (usually the
457 * result of the last call to findName)
461 * true implies that case insensitive matching will <em>also</em> be
463 * @return matched sequence or null
465 SequenceI findName(SequenceI startAfter, String token, boolean b);
468 * find first sequence in alignment which is involved in the given search
472 * @return -1 or index of sequence in alignment
474 int findIndex(SearchResultsI results);
477 * append sequences and annotation from another alignment object to this one.
478 * Note: this is a straight transfer of object references, and may result in
479 * toappend's dependent data being transformed to fit the alignment (changing
480 * gap characters, etc...). If you are uncertain, use the copy Alignment copy
481 * constructor to create a new version which can be appended without side
485 * - the alignment to be appended.
487 void append(AlignmentI toappend);
490 * Justify the sequences to the left or right by deleting and inserting gaps
491 * before the initial residue or after the terminal residue
494 * true if alignment padded to right, false to justify to left
495 * @return true if alignment was changed TODO: return undo object
497 boolean justify(boolean right);
500 * add given annotation row at given position (0 is start, -1 is end)
505 void addAnnotation(AlignmentAnnotation consensus, int i);
508 * search for or create a specific annotation row on the alignment
511 * name for annotation (must match)
513 * calcId for the annotation (null or must match)
515 * - value of autocalc flag for the annotation
517 * - null or specific sequence reference
519 * - null or specific group reference
521 * - CalcId for the annotation (must match)
523 * @return existing annotation matching the given attributes
525 AlignmentAnnotation findOrCreateAnnotation(String name, String calcId,
526 boolean autoCalc, SequenceI seqRef, SequenceGroup groupRef);
529 * move the given group up or down in the alignment by the given number of
530 * rows. Implementor assumes given group is already present on alignment - no
531 * recalculations are triggered.
538 void moveSelectedSequencesByOne(SequenceGroup sg,
539 Map<SequenceI, SequenceCollectionI> map, boolean up);
542 * validate annotation after an edit and update any alignment state flags
545 * @param alignmentAnnotation
547 void validateAnnotation(AlignmentAnnotation alignmentAnnotation);
550 * Align this alignment the same as the given one. If both of the same type
551 * (nucleotide/protein) then align both identically. If this is nucleotide and
552 * the other is protein, make 3 gaps for each gap in the protein sequences. If
553 * this is protein and the other is nucleotide, insert a gap for each 3 gaps
554 * (or part thereof) between nucleotide bases. Returns the number of mapped
555 * sequences that were realigned .
560 int alignAs(AlignmentI al);
563 * Returns the set of distinct sequence names in the alignment.
567 Set<String> getSequenceNames();
570 * Checks if the alignment has at least one sequence with one non-gaped
575 public boolean hasValidSequence();
578 * Update any mappings to 'virtual' sequences to compatible real ones, if
579 * present in the added sequences. Returns a count of mappings updated.
584 int realiseMappings(List<SequenceI> seqs);
587 * Returns the first AlignedCodonFrame that has a mapping between the given
594 AlignedCodonFrame getMapping(SequenceI mapFrom, SequenceI mapTo);
597 * Set the hidden columns collection on the alignment. Answers true if the
598 * hidden column selection changed, else false.
603 public boolean setHiddenColumns(HiddenColumns cols);
606 * Set the first sequence as representative and hide its insertions. Typically
607 * used when loading JPred files.
609 public void setupJPredAlignment();
612 * Add gaps into the sequences aligned to profileseq under the given
616 * sequence in al which sequences are aligned to
618 * alignment view where sequence corresponding to profileseq is first
620 * @return new HiddenColumns for new alignment view, with insertions into
621 * profileseq marked as hidden.
623 public HiddenColumns propagateInsertions(SequenceI profileseq,
624 AlignmentView input);