maxIdLength redundant, deleteCols, trimLeft, removeGaps moved to Commands
[jalview.git] / src / jalview / datamodel / Alignment.java
index 86c140f..4485c46 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -146,8 +146,9 @@ public class Alignment implements AlignmentI
           getDataset().addSequence(ds);
         }
       }
-
       sequences.addElement(snew);
+
+      hiddenSequences.adjustHeightSequenceAdded();
     }
 
 
@@ -173,124 +174,6 @@ public class Alignment implements AlignmentI
         return groups;
     }
 
-    /** Takes out columns consisting entirely of gaps (-,.," ")
-     */
-    public void removeGaps()
-    {
-        SequenceI[] seqs = getVisibleAndRepresentedSeqs();
-        int j, jSize = seqs.length;
-
-        int width = 0;
-        for (int i = 0; i < jSize; i++)
-        {
-          if (seqs[i].getLength() > width)
-          {
-            width = seqs[i].getLength();
-          }
-        }
-
-        int startCol = -1, endCol = -1;
-        boolean delete = true;
-        for (int i = 0; i < width; i++)
-        {
-            delete = true;
-
-            for (j = 0; j < jSize; j++)
-            {
-                if (seqs[j].getLength() > i)
-                {
-                    if (!jalview.util.Comparison.isGap(seqs[j].getCharAt(i)))
-                    {
-                        if(delete)
-                          endCol = i;
-
-                        delete = false;
-                        break;
-                    }
-                }
-            }
-
-            if(delete && startCol==-1)
-            {
-              startCol = i;
-            }
-
-
-            if (!delete && startCol > -1)
-            {
-              deleteColumns(seqs, startCol, endCol);
-              width -= (endCol - startCol);
-              i -= (endCol - startCol);
-              startCol = -1;
-              endCol = -1;
-            }
-        }
-
-        if (delete && startCol > -1)
-        {
-          deleteColumns(seqs, startCol, endCol);
-        }
-    }
-
-    /** Removes a range of columns (start to end inclusive).
-     *
-     * @param seqs Sequences to remove columns from
-     * @param start Start column in the alignment
-     * @param end End column in the alignment
-     */
-    public void deleteColumns(SequenceI [] seqs, int start, int end)
-    {
-      for(int i=0; i<seqs.length; i++)
-        seqs[i].deleteChars(start, end);
-    }
-
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @param i DOCUMENT ME!
-     */
-    public void trimLeft(int i)
-    {
-        SequenceI[] seqs = getVisibleAndRepresentedSeqs();
-        int j, jSize = seqs.length;
-        for (j = 0; j < jSize; j++)
-        {
-            int newstart = seqs[j].findPosition(i);
-
-            if(i>seqs[j].getLength())
-            {
-              sequences.removeElement(seqs[j]);
-              j--;
-              jSize--;
-            }
-            else
-            {
-              seqs[j].setStart(newstart);
-              seqs[j].setSequence(seqs[j].getSequence().substring(i));
-            }
-        }
-    }
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @param i DOCUMENT ME!
-     */
-    public void trimRight(int i)
-    {
-        SequenceI[] seqs = getVisibleAndRepresentedSeqs();
-        int j, jSize = seqs.length;
-        for (j = 0; j < jSize; j++)
-        {
-            int newend = seqs[j].findPosition(i);
-
-            seqs[j].setEnd(newend);
-            if(seqs[j].getLength()>i)
-              seqs[j].setSequence(seqs[j].getSequence().substring(0, i + 1));
-        }
-    }
-
     /**
      * DOCUMENT ME!
      *
@@ -298,13 +181,7 @@ public class Alignment implements AlignmentI
      */
     public void deleteSequence(SequenceI s)
     {
-        for (int i = 0; i < getHeight(); i++)
-        {
-            if (getSequenceAt(i) == s)
-            {
-                deleteSequence(i);
-            }
-        }
+      deleteSequence(findIndex(s));
     }
 
     /**
@@ -314,7 +191,11 @@ public class Alignment implements AlignmentI
      */
     public void deleteSequence(int i)
     {
+      if(i>0 && i<getHeight())
+      {
         sequences.removeElementAt(i);
+        hiddenSequences.adjustHeightSequenceDeleted(i);
+      }
     }
 
 
@@ -394,8 +275,7 @@ public class Alignment implements AlignmentI
 
         while (i < sequences.size())
         {
-            Sequence s = (Sequence)getSequenceAt(i);
-            s.hiddenSequences = null;
+            SequenceI s = getSequenceAt(i);
             s.setColor(java.awt.Color.white);
             i++;
         }
@@ -406,9 +286,6 @@ public class Alignment implements AlignmentI
     {
         if (groups.contains(g))
         {
-          //remove any hidden representatives
-        //  for(int i=0; i<g.getsiz
-         //   g.getSequences()
             groups.removeElement(g);
         }
     }
@@ -502,32 +379,6 @@ public class Alignment implements AlignmentI
         return maxLength;
     }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public int getMaxIdLength()
-    {
-        int max = 0;
-        int i = 0;
-
-        while (i < sequences.size())
-        {
-            SequenceI seq = getSequenceAt(i);
-            String tmp = seq.getName() + "/" + seq.getStart() + "-" +
-                seq.getEnd();
-
-            if (tmp.length() > max)
-            {
-                max = tmp.length();
-            }
-
-            i++;
-        }
-
-        return max;
-    }
 
     /**
      * DOCUMENT ME!
@@ -557,15 +408,6 @@ public class Alignment implements AlignmentI
         return gapCharacter;
     }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public Vector getAAFrequency()
-    {
-        return AAFrequency.calculate(sequences, 0, getWidth());
-    }
 
     /**
      * DOCUMENT ME!
@@ -836,7 +678,9 @@ public class Alignment implements AlignmentI
     for (int i=0; i<sequences.size(); i++) {
       alseqs[i] = new SeqCigar((SequenceI) sequences.elementAt(i));
     }
-    return new CigarArray(alseqs);
+    CigarArray cal = new CigarArray(alseqs);
+    cal.addOperation(CigarArray.M, getWidth());
+    return cal;
   }
 
 }