X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignmentI.java;h=4b1220b1ab98bb4d23e31c3106c0c5b473ec5ef2;hb=48a66195bf4aee8b2c479d3bbbf4c1fb8b824f5a;hp=d9791f114eafb0fd8b97fefc865a757ca96595a5;hpb=482e093c4670a813c9eec254990178b209e32dbc;p=jalview.git
diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java
index d9791f1..4b1220b 100755
--- a/src/jalview/datamodel/AlignmentI.java
+++ b/src/jalview/datamodel/AlignmentI.java
@@ -1,179 +1,264 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.datamodel;
-import java.util.*;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* Data structure to hold and manipulate a multiple sequence alignment
*/
-public interface AlignmentI
+public interface AlignmentI extends AnnotatedCollectionI
{
/**
- * Calculates the number of sequences in an alignment
+ * Calculates the number of sequences in an alignment, excluding hidden
+ * sequences
*
* @return Number of sequences in alignment
*/
- public int getHeight();
+ int getHeight();
/**
- * Calculates the maximum width of the alignment, including gaps.
+ * Calculates the number of sequences in an alignment, including hidden
+ * sequences
*
- * @return Greatest sequence length within alignment.
+ * @return Number of sequences in alignment
*/
- public int getWidth();
+ int getAbsoluteHeight();
/**
- * Calculates if this set of sequences is all the same length
+ *
+ * Answers the width of the alignment, including gaps, that is, the length of
+ * the longest sequence, or -1 if there are no sequences. Avoid calling this
+ * method repeatedly where possible, as it has to perform a calculation. Note
+ * that this width includes any hidden columns.
+ *
+ * @return
+ * @see AlignmentI#getVisibleWidth()
+ */
+ @Override
+ int getWidth();
+
+ /**
+ *
+ * Answers the visible width of the alignment, including gaps, that is, the
+ * length of the longest sequence, excluding any hidden columns. Answers -1 if
+ * there are no sequences. Avoid calling this method repeatedly where
+ * possible, as it has to perform a calculation.
+ *
+ * @return
+ */
+ int getVisibleWidth();
+
+ /**
+ * Calculates if this set of sequences (visible and invisible) are all the
+ * same length
*
* @return true if all sequences in alignment are the same length
*/
- public boolean isAligned();
+ boolean isAligned();
/**
- * Gets sequences as a Vector
+ * Calculates if this set of sequences is all the same length
+ *
+ * @param includeHidden
+ * optionally exclude hidden sequences from test
+ * @return true if all (or just visible) sequences are the same length
+ */
+ boolean isAligned(boolean includeHidden);
+
+ /**
+ * Answers if the sequence at alignmentIndex is hidden
+ *
+ * @param alignmentIndex
+ * the index to check
+ * @return true if the sequence is hidden
+ */
+ boolean isHidden(int alignmentIndex);
+
+ /**
+ * Gets sequences as a Synchronized collection
*
* @return All sequences in alignment.
*/
- public Vector getSequences();
+ @Override
+ List getSequences();
/**
* Gets sequences as a SequenceI[]
*
* @return All sequences in alignment.
*/
- public SequenceI[] getSequencesArray();
+ SequenceI[] getSequencesArray();
+
+ /**
+ * Find a specific sequence in this alignment.
+ *
+ * @param i
+ * Index of required sequence.
+ *
+ * @return SequenceI at given index.
+ */
+ SequenceI getSequenceAt(int i);
/**
* Find a specific sequence in this alignment.
*
* @param i
- * Index of required sequence.
+ * Index of required sequence in full alignment, i.e. if all columns
+ * were visible
*
* @return SequenceI at given index.
*/
- public SequenceI getSequenceAt(int i);
+ SequenceI getSequenceAtAbsoluteIndex(int i);
+
+ /**
+ * Returns a map of lists of sequences keyed by sequence name.
+ *
+ * @return
+ */
+ Map> getSequencesByName();
/**
* Add a new sequence to this alignment.
*
* @param seq
- * New sequence will be added at end of alignment.
+ * New sequence will be added at end of alignment.
*/
- public void addSequence(SequenceI seq);
+ void addSequence(SequenceI seq);
/**
* Used to set a particular index of the alignment with the given sequence.
*
* @param i
- * Index of sequence to be updated.
+ * Index of sequence to be updated. if i>length, sequence will be
+ * added to end, with no intervening positions.
* @param seq
- * New sequence to be inserted.
+ * New sequence to be inserted. The existing sequence at position i
+ * will be replaced.
+ * @return existing sequence (or null if i>current length)
*/
- public void setSequenceAt(int i, SequenceI seq);
+ SequenceI replaceSequenceAt(int i, SequenceI seq);
/**
- * Deletes a sequence from the alignment
+ * Deletes a sequence from the alignment. Updates hidden sequences to account
+ * for the removed sequence. Do NOT use this method to delete sequences which
+ * are just hidden.
*
* @param s
- * Sequence to be deleted.
+ * Sequence to be deleted.
+ */
+ void deleteSequence(SequenceI s);
+
+ /**
+ * Deletes a sequence from the alignment. Updates hidden sequences to account
+ * for the removed sequence. Do NOT use this method to delete sequences which
+ * are just hidden.
+ *
+ * @param i
+ * Index of sequence to be deleted.
*/
- public void deleteSequence(SequenceI s);
+ void deleteSequence(int i);
/**
- * Deletes a sequence from the alignment.
+ * Deletes a sequence in the alignment which has been hidden.
*
* @param i
- * Index of sequence to be deleted.
+ * Index of sequence to be deleted
*/
- public void deleteSequence(int i);
+ void deleteHiddenSequence(int i);
/**
* Finds sequence in alignment using sequence name as query.
*
* @param name
- * Id of sequence to search for.
+ * Id of sequence to search for.
*
* @return Sequence matching query, if found. If not found returns null.
*/
- public SequenceI findName(String name);
+ SequenceI findName(String name);
- public SequenceI[] findSequenceMatch(String name);
+ SequenceI[] findSequenceMatch(String name);
/**
* Finds index of a given sequence in the alignment.
*
* @param s
- * Sequence to look for.
+ * Sequence to look for.
*
* @return Index of sequence within the alignment or -1 if not found
*/
- public int findIndex(SequenceI s);
+ int findIndex(SequenceI s);
/**
- * Finds group that given sequence is part of.
+ * Returns the first group (in the order in which groups were added) that
+ * includes the given sequence instance and aligned position (base 0), or null
+ * if none found
*
- * @param s
- * Sequence in alignment.
+ * @param seq
+ * - must be contained in the alignment (not a dataset sequence)
+ * @param position
*
- * @return First group found for sequence. WARNING : Sequences may be members
- * of several groups. This method is incomplete.
+ * @return
*/
- public SequenceGroup findGroup(SequenceI s);
+ SequenceGroup findGroup(SequenceI seq, int position);
/**
* Finds all groups that a given sequence is part of.
*
* @param s
- * Sequence in alignment.
+ * Sequence in alignment.
*
* @return All groups containing given sequence.
*/
- public SequenceGroup[] findAllGroups(SequenceI s);
+ SequenceGroup[] findAllGroups(SequenceI s);
/**
* Adds a new SequenceGroup to this alignment.
*
* @param sg
- * New group to be added.
+ * New group to be added.
*/
- public void addGroup(SequenceGroup sg);
+ void addGroup(SequenceGroup sg);
/**
* Deletes a specific SequenceGroup
*
* @param g
- * Group will be deleted from alignment.
+ * Group will be deleted from alignment.
*/
- public void deleteGroup(SequenceGroup g);
+ void deleteGroup(SequenceGroup g);
/**
* Get all the groups associated with this alignment.
*
- * @return All groups as a Vector.
+ * @return All groups as a list.
*/
- public Vector getGroups();
+ List getGroups();
/**
* Deletes all groups from this alignment.
*/
- public void deleteAllGroups();
+ void deleteAllGroups();
/**
* Adds a new AlignmentAnnotation to this alignment
@@ -181,64 +266,85 @@ public interface AlignmentI
* @note Care should be taken to ensure that annotation is at least as wide as
* the longest sequence in the alignment for rendering purposes.
*/
- public void addAnnotation(AlignmentAnnotation aa);
+ void addAnnotation(AlignmentAnnotation aa);
/**
* moves annotation to a specified index in alignment annotation display stack
*
* @param aa
- * the annotation object to be moved
+ * the annotation object to be moved
* @param index
- * the destination position
+ * the destination position
+ */
+ void setAnnotationIndex(AlignmentAnnotation aa, int index);
+
+ /**
+ * Delete all annotations, including auto-calculated if the flag is set true.
+ * Returns true if at least one annotation was deleted, else false.
+ *
+ * @param includingAutoCalculated
+ * @return
*/
- public void setAnnotationIndex(AlignmentAnnotation aa, int index);
+ boolean deleteAllAnnotations(boolean includingAutoCalculated);
/**
* Deletes a specific AlignmentAnnotation from the alignment, and removes its
- * reference from any SequenceI object's annotation if and only if aa is
- * contained within the alignment's annotation vector. Otherwise, it will do
- * nothing.
+ * reference from any SequenceI or SequenceGroup object's annotation if and
+ * only if aa is contained within the alignment's annotation vector.
+ * Otherwise, it will do nothing.
+ *
+ * @param aa
+ * the annotation to delete
+ * @return true if annotation was deleted from this alignment.
+ */
+ boolean deleteAnnotation(AlignmentAnnotation aa);
+
+ /**
+ * Deletes a specific AlignmentAnnotation from the alignment, and optionally
+ * removes any reference from any SequenceI or SequenceGroup object's
+ * annotation if and only if aa is contained within the alignment's annotation
+ * vector. Otherwise, it will do nothing.
*
* @param aa
- * the annotation to delete
+ * the annotation to delete
+ * @param unhook
+ * flag indicating if any references should be removed from
+ * annotation - use this if you intend to add the annotation back
+ * into the alignment
* @return true if annotation was deleted from this alignment.
*/
- public boolean deleteAnnotation(AlignmentAnnotation aa);
+ boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
/**
- * Get the annotation associated with this alignment
+ * Get the annotation associated with this alignment (this can be null if no
+ * annotation has ever been created on the alignment)
*
* @return array of AlignmentAnnotation objects
*/
- public AlignmentAnnotation[] getAlignmentAnnotation();
+ @Override
+ AlignmentAnnotation[] getAlignmentAnnotation();
/**
* Change the gap character used in this alignment to 'gc'
*
* @param gc
- * the new gap character.
+ * the new gap character.
*/
- public void setGapCharacter(char gc);
+ void setGapCharacter(char gc);
/**
* Get the gap character used in this alignment
*
* @return gap character
*/
- public char getGapCharacter();
-
- /**
- * Test for all nucleotide alignment
- *
- * @return true if alignment is nucleotide sequence
- */
- public boolean isNucleotide();
+ char getGapCharacter();
/**
- * Set alignment to be a nucleotide sequence
+ * Test if alignment contains RNA structure
*
+ * @return true if RNA structure AligmnentAnnotation was added to alignment
*/
- public void setNucleotide(boolean b);
+ boolean hasRNAStructure();
/**
* Get the associated dataset for the alignment.
@@ -246,31 +352,33 @@ public interface AlignmentI
* @return Alignment containing dataset sequences or null of this is a
* dataset.
*/
- public Alignment getDataset();
+ AlignmentI getDataset();
/**
* Set the associated dataset for the alignment, or create one.
*
* @param dataset
- * The dataset alignment or null to construct one.
+ * The dataset alignment or null to construct one.
*/
- public void setDataset(Alignment dataset);
+ void setDataset(AlignmentI dataset);
/**
* pads sequences with gaps (to ensure the set looks like an alignment)
*
* @return boolean true if alignment was modified
*/
- public boolean padGaps();
+ boolean padGaps();
+
+ HiddenSequences getHiddenSequences();
- public HiddenSequences getHiddenSequences();
+ HiddenColumns getHiddenColumns();
/**
* Compact representation of alignment
*
* @return CigarArray
*/
- public CigarArray getCompactAlignment();
+ CigarArray getCompactAlignment();
/**
* Set an arbitrary key value pair for an alignment. Note: both key and value
@@ -279,7 +387,7 @@ public interface AlignmentI
* @param key
* @param value
*/
- public void setProperty(Object key, Object value);
+ void setProperty(Object key, Object value);
/**
* Get a named property from the alignment.
@@ -287,21 +395,21 @@ public interface AlignmentI
* @param key
* @return value of property
*/
- public Object getProperty(Object key);
+ Object getProperty(Object key);
/**
* Get the property hashtable.
*
* @return hashtable of alignment properties (or null if none are defined)
*/
- public Hashtable getProperties();
+ Map