Sequence colour moved to viewport
[jalview.git] / src / jalview / datamodel / AlignmentView.java
index 22232b3..e668470 100644 (file)
@@ -40,6 +40,7 @@ public class AlignmentView
     private SeqCigar[] sequences = null;
   private int[] contigs = null;
   private int width=0;
+  private int firstCol=0;
   public AlignmentView(CigarArray seqcigararray)
   {
     if (!seqcigararray.isSeqCigarArray())
@@ -49,6 +50,15 @@ public class AlignmentView
     sequences = seqcigararray.getSeqCigarArray();
     width = seqcigararray.getWidth(); // visible width
   }
+  /**
+   * Create an alignmentView where the first column corresponds with the 'firstcol' column of some reference alignment 
+   * @param sdata
+   * @param firstcol
+   */
+  public AlignmentView(CigarArray sdata, int firstcol) {
+    this(sdata);
+    firstCol=firstcol;
+  }
 
   public void setSequences(SeqCigar[] sequences)
   {
@@ -64,7 +74,10 @@ public class AlignmentView
   {
     return sequences;
   }
-
+  /**
+   * @see CigarArray.getDeletedRegions
+   * @return int[] { vis_start, sym_start, length }
+   */
   public int[] getContigs()
   {
     return contigs;
@@ -382,5 +395,58 @@ public class AlignmentView
         return getAlignmentAndColumnSelection(gapCharacter);
     }
   }
-
+  /**
+   * returns simple array of start end positions of visible range on alignment.
+   * vis_start and vis_end are inclusive - use SequenceI.getSubSequence(vis_start, vis_end+1) to recover visible sequence from underlying alignment. 
+   * @return int[] { start_i, end_i } for 1<i<n visible regions.
+   */
+  public int[] getVisibleContigs() {
+    if (contigs != null && contigs.length > 0)
+    {
+      int start = 0;
+      int nvis = 0;
+      int fwidth = width;
+      for (int contig = 0; contig < contigs.length; contig += 3)
+      {
+        if ( (contigs[contig + 1] - start) > 0)
+        {
+          nvis++;
+        }
+        fwidth += contigs[contig + 2]; // end up with full region width (including hidden regions)
+        start = contigs[contig + 1] + contigs[contig + 2];
+      }
+      if (start < fwidth)
+      {
+        nvis++;
+      }
+      int viscontigs[] = new int[nvis*2];
+      nvis=0;
+      start=0;
+      for (int contig=0; contig<contigs.length; contig+=3) {
+        if ( (contigs[contig + 1] - start) > 0)
+        {
+          viscontigs[nvis] = start;
+          viscontigs[nvis+1]=contigs[contig+1]-1; // end is inclusive
+          nvis+=2;
+        }
+        start = contigs[contig + 1] + contigs[contig + 2];              
+      }
+      if (start<fwidth) {
+        viscontigs[nvis] = start;
+        viscontigs[nvis+1]=fwidth; // end is inclusive
+        nvis+=2;
+      }
+      return viscontigs;
+    } else {
+      return new int[] { 0, width};
+    }
+  }
+  /**
+   * 
+   * @return position of first visible column of AlignmentView within its parent's alignment reference frame 
+   */
+  public int getAlignmentOrigin() {
+    // TODO Auto-generated method stub
+    return firstCol;
+  }
 }