AAFrequency optimized
[jalview.git] / src / jalview / datamodel / Alignment.java
index 8c320f7..a770264 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
@@ -70,11 +70,7 @@ public class Alignment implements AlignmentI
      * @param seqs SeqCigar[]
      */
     public Alignment(SeqCigar[] alseqs) {
-
-      SequenceI[] seqs = new SequenceI[alseqs.length];
-      for (int i=0; i<alseqs.length; i++) {
-        seqs[i] = alseqs[i].getSeq(this.gapCharacter);
-      }
+      SequenceI[] seqs = SeqCigar.createAlignmentSequences(alseqs, gapCharacter, new ColumnSelection(), null);
       initAlignment(seqs);
     }
     /**
@@ -83,7 +79,7 @@ public class Alignment implements AlignmentI
      * JBPNote - must also check that compactAlignment resolves to a set of SeqCigars - or construct them appropriately.
      * @param compactAlignment CigarArray
      */
-    public Alignment(CigarArray compactAlignment) {
+    public static AlignmentI createAlignment(CigarArray compactAlignment) {
       throw new Error("Alignment(CigarArray) not yet implemented");
       // this(compactAlignment.refCigars);
     }
@@ -176,11 +172,17 @@ public class Alignment implements AlignmentI
     {
         return groups;
     }
-
     /** Takes out columns consisting entirely of gaps (-,.," ")
      */
-    public void removeGaps()
-    {
+    public void removeGaps() {
+      removeGaps((ShiftList)null);
+    }
+    /**
+     * remove gaps in alignment - recording any frame shifts in shiftrecord
+     * intended to be passed to ColumnSelection.compensateForEdits(shiftrecord)
+     * @param shiftrecord
+     */
+    public void removeGaps(ShiftList shiftrecord) {
         SequenceI[] seqs = getVisibleAndRepresentedSeqs();
         int j, jSize = seqs.length;
 
@@ -223,6 +225,9 @@ public class Alignment implements AlignmentI
             if (!delete && startCol > -1)
             {
               deleteColumns(seqs, startCol, endCol);
+              if (shiftrecord!=null) {
+                shiftrecord.addShift(startCol, 1+endCol-startCol);
+              }
               width -= (endCol - startCol);
               i -= (endCol - startCol);
               startCol = -1;
@@ -233,6 +238,9 @@ public class Alignment implements AlignmentI
         if (delete && startCol > -1)
         {
           deleteColumns(seqs, startCol, endCol);
+          if (shiftrecord!=null) {
+            shiftrecord.addShift(startCol, 1+endCol-startCol);
+          }
         }
     }
 
@@ -431,6 +439,28 @@ public class Alignment implements AlignmentI
         return null;
     }
 
+    public SequenceI [] findSequenceMatch(String name)
+    {
+      Vector matches = new Vector();
+      int i = 0;
+
+      while (i < sequences.size())
+      {
+          if (getSequenceAt(i).getName().equals(name))
+          {
+              matches.addElement(getSequenceAt(i));
+          }
+          i++;
+      }
+
+      SequenceI [] result = new SequenceI[matches.size()];
+      for(i=0; i<result.length; i++)
+        result[i] = (SequenceI)matches.elementAt(i);
+
+      return result;
+
+    }
+
 
     /**    */
     public int findIndex(SequenceI s)
@@ -535,15 +565,6 @@ public class Alignment implements AlignmentI
         return gapCharacter;
     }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
-    public Vector getAAFrequency()
-    {
-        return AAFrequency.calculate(sequences, 0, getWidth());
-    }
 
     /**
      * DOCUMENT ME!
@@ -715,7 +736,8 @@ public class Alignment implements AlignmentI
                                    ),
                                    getSequenceAt(i).getStart(),
                                    getSequenceAt(i).getEnd());
-
+            seqs[i].sequenceFeatures = getSequenceAt(i).getSequenceFeatures();
+            getSequenceAt(i).setSequenceFeatures(null);
             getSequenceAt(i).setDatasetSequence(seqs[i]);
           }
         }
@@ -811,7 +833,7 @@ public class Alignment implements AlignmentI
   {
     SeqCigar alseqs[] = new SeqCigar[sequences.size()];
     for (int i=0; i<sequences.size(); i++) {
-      alseqs[i] = new SeqCigar((SequenceI) sequences.get(i));
+      alseqs[i] = new SeqCigar((SequenceI) sequences.elementAt(i));
     }
     return new CigarArray(alseqs);
   }