added copy consensus sequence to consensus annotation popup menu
[jalview.git] / src / jalview / datamodel / ColumnSelection.java
index bd06ca3..2d22231 100644 (file)
@@ -237,7 +237,7 @@ public class ColumnSelection
             if (region[1]<region[0]) {
               hiddenColumns.removeElementAt(i--);
             }
-              
+
             if(region[0]<0)
               region[0] = 0;
             if(region[1] <0)
@@ -246,7 +246,7 @@ public class ColumnSelection
         }
     }
     /**
-     * Adjust hidden column boundaries based on a series of column 
+     * Adjust hidden column boundaries based on a series of column
      * additions or deletions in visible regions.
      * @param shiftrecord
      * @return
@@ -257,7 +257,7 @@ public class ColumnSelection
         if (shifts!=null && shifts.size()>0) {
           int shifted=0;
           for (int i=0,j=shifts.size(); i<j; i++) {
-            int[] sh = (int[]) shifts.get(i);
+            int[] sh = (int[]) shifts.elementAt(i);
             //compensateForEdit(shifted+sh[0], sh[1]);
             compensateForDelEdits(shifted+sh[0], sh[1]);
             shifted-=sh[1];
@@ -268,7 +268,7 @@ public class ColumnSelection
       return null;
     }
     /**
-     * removes intersection of position,length ranges in deletions 
+     * removes intersection of position,length ranges in deletions
      * from the start,end regions marked in intervals.
      * @param deletions
      * @param intervals
@@ -290,9 +290,9 @@ public class ColumnSelection
         }
         int endshift=sr[0]+sr[1]; // deletion ranges - -ve means an insert
         if (endshift<hr[0] || endshift<sr[0]) { // leadinghc disjoint or not a deletion
-          if (s<t) 
+          if (s<t)
             sr=(int[]) deletions.elementAt(++s);
-          else 
+          else
             s++;
           continue;
         }
@@ -314,17 +314,17 @@ public class ColumnSelection
             pruned=true;
           }
         }
-        if (!leadinghn) { 
+        if (!leadinghn) {
           if (trailinghc) {
-            if (trailinghn) { 
+            if (trailinghn) {
               hr[1]=sr[0]-1;
               pruned=true;
             }
           } else {
             // sr contained in hr
-            if (s<t) 
+            if (s<t)
               sr=(int[]) deletions.elementAt(++s);
-            else 
+            else
               s++;
             continue;
           }
@@ -334,7 +334,7 @@ public class ColumnSelection
     }
     private boolean pruneColumnList(Vector deletion, Vector list) {
       int s=0,t=deletion.size();
-      int[] sr=(int[])list.get(s++);
+      int[] sr=(int[])list.elementAt(s++);
       boolean pruned=false;
       int i=0, j=list.size();
       while (i<j && s<=t) {
@@ -347,7 +347,7 @@ public class ColumnSelection
             if (s<t)
               sr = (int[])deletion.elementAt(s);
             s++;
-          }          
+          }
         }
       }
       return pruned;
@@ -374,7 +374,7 @@ public class ColumnSelection
               selected=null;
           }
           // and shift the rest.
-          this.compensateForEdits(deletions);              
+          this.compensateForEdits(deletions);
         }
       }
     }
@@ -644,18 +644,18 @@ public class ColumnSelection
         if (copy.selected!=null) {
           selected = new Vector();
           for (int i=0,j=copy.selected.size(); i<j; i++) {
-            selected.set(i, ((Integer) copy.selected.get(i)));
+            selected.setElementAt( ((Integer) copy.selected.elementAt(i)), i);
           }
         }
         if (copy.hiddenColumns!=null) {
           hiddenColumns=new Vector();
           for (int i=0,j=copy.hiddenColumns.size(); i<j; i++) {
             int[] rh,cp;
-            rh = (int[])copy.hiddenColumns.get(i);
+            rh = (int[])copy.hiddenColumns.elementAt(i);
             if (rh!=null) {
               cp = new int[rh.length];
               System.arraycopy(rh, 0, cp, 0, rh.length);
-              hiddenColumns.set(i, cp);
+              hiddenColumns.setElementAt(cp, i);
             }
           }
         }
@@ -668,4 +668,61 @@ public class ColumnSelection
   public ColumnSelection()
   {
   }
+
+  public String[] getVisibleSequenceStrings(int start, int end, SequenceI[] seqs) {
+    int i,iSize=seqs.length;
+    String selection[] = new String[iSize];
+    if (hiddenColumns!=null && hiddenColumns.size()>0)
+      {
+      for (i=0; i<iSize; i++) {
+        StringBuffer visibleSeq = new StringBuffer();
+        Vector regions = getHiddenColumns();
+
+        int blockStart = start, blockEnd=end;
+        int [] region;
+           int hideStart, hideEnd;
+
+           for (int j = 0; j < regions.size(); j++)
+           {
+             region = (int[]) regions.elementAt(j);
+             hideStart = region[0];
+             hideEnd = region[1];
+
+             if(hideStart < start)
+             {
+               continue;
+             }
+
+             blockStart = Math.min(blockStart, hideEnd+1);
+             blockEnd = Math.min(blockEnd, hideStart);
+
+             if(blockStart>blockEnd)
+             {
+                break;
+             }
+
+
+             visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
+
+             blockStart = hideEnd+1;
+             blockEnd = end;
+           }
+
+           if(end>blockStart)
+             visibleSeq.append(seqs[i].getSequence(blockStart, end));
+
+           selection[i] = visibleSeq.toString();
+        }
+      }
+      else
+      {
+        for(i=0; i<iSize; i++)
+        {
+        selection[i] = seqs[i].getSequence(start, end);
+        }
+      }
+      
+    return selection;
+    }
+  
 }