Formatting
[jalview.git] / src / jalview / datamodel / AlignmentView.java
index 8b86a82..79e0ba2 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Copyright (C) 2007 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
@@ -18,8 +18,6 @@
  */
 package jalview.datamodel;
 
-
-
 /**
  * <p>Title: </p>
  *
@@ -34,30 +32,34 @@ package jalview.datamodel;
  */
 public class AlignmentView
 {
-    /**
-     * Transient object compactly representing a 'view' of an alignment - with discontinuities marked.
-     */
-    private SeqCigar[] sequences = null;
+  /**
+   * Transient object compactly representing a 'view' of an alignment - with discontinuities marked.
+   */
+  private SeqCigar[] sequences = null;
   private int[] contigs = null;
-  private int width=0;
-  private int firstCol=0;
+  private int width = 0;
+  private int firstCol = 0;
   public AlignmentView(CigarArray seqcigararray)
   {
     if (!seqcigararray.isSeqCigarArray())
+    {
       throw new Error("Implementation Error - can only make an alignment view from a CigarArray of sequences.");
+    }
     //contigs = seqcigararray.applyDeletions();
     contigs = seqcigararray.getDeletedRegions();
     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) {
+  public AlignmentView(CigarArray sdata, int firstcol)
+  {
     this(sdata);
-    firstCol=firstcol;
+    firstCol = firstcol;
   }
 
   public void setSequences(SeqCigar[] sequences)
@@ -74,6 +76,7 @@ public class AlignmentView
   {
     return sequences;
   }
+
   /**
    * @see CigarArray.getDeletedRegions
    * @return int[] { vis_start, sym_start, length }
@@ -82,16 +85,22 @@ public class AlignmentView
   {
     return contigs;
   }
+
   /**
    * get the full alignment and a columnselection object marking the hidden regions
    * @param gapCharacter char
    * @return Object[] { SequenceI[], ColumnSelection}
    */
-  public Object[] getAlignmentAndColumnSelection(char gapCharacter) {
+  public Object[] getAlignmentAndColumnSelection(char gapCharacter)
+  {
     ColumnSelection colsel = new ColumnSelection();
 
-    return new Object[] { SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel, contigs), colsel};
+    return new Object[]
+        {
+        SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel,
+                                          contigs), colsel};
   }
+
   /**
    * getSequenceStrings
    *
@@ -100,8 +109,9 @@ public class AlignmentView
    */
   public String[] getSequenceStrings(char c)
   {
-    String[] seqs=new String[sequences.length];
-    for (int n=0; n<sequences.length; n++) {
+    String[] seqs = new String[sequences.length];
+    for (int n = 0; n < sequences.length; n++)
+    {
       String fullseq = sequences[n].getSequenceString(c);
       if (contigs != null)
       {
@@ -113,32 +123,42 @@ public class AlignmentView
           p = contigs[h + 1] + contigs[h + 2];
         }
         seqs[n] += fullseq.substring(p);
-      } else
+      }
+      else
+      {
         seqs[n] = fullseq;
+      }
     }
     return seqs;
   }
+
   /**
    *
    * @return visible number of columns in alignment view
    */
-  public int getWidth() {
+  public int getWidth()
+  {
     return width;
   }
 
-  protected void setWidth(int width) {
+  protected void setWidth(int width)
+  {
     this.width = width;
   }
+
   /**
    * get the contiguous subalignments in an alignment view.
    * @param gapCharacter char
    * @return SequenceI[][]
    */
-  public SequenceI[][] getVisibleContigs(char gapCharacter) {
+  public SequenceI[][] getVisibleContigs(char gapCharacter)
+  {
     SequenceI[][] smsa;
     int njobs = 1;
-    if (sequences==null || width<=0)
+    if (sequences == null || width <= 0)
+    {
       return null;
+    }
     if (contigs != null && contigs.length > 0)
     {
       int start = 0;
@@ -198,20 +218,25 @@ public class AlignmentView
     }
     return smsa;
   }
+
   /**
    * return full msa and hidden regions with visible blocks replaced with new sub alignments
    * @param nvismsa SequenceI[][]
    * @param orders AlignmentOrder[] corresponding to each SequenceI[] block.
    * @return Object[]
    */
-  public Object[] getUpdatedView(SequenceI[][] nvismsa, AlignmentOrder[] orders, char gapCharacter) {
+  public Object[] getUpdatedView(SequenceI[][] nvismsa, AlignmentOrder[] orders,
+                                 char gapCharacter)
+  {
     if (sequences == null || width <= 0)
     {
       throw new Error("empty view cannot be updated.");
     }
     if (nvismsa == null)
+    {
       throw new Error(
           "nvismsa==null. use getAlignmentAndColumnSelection() instead.");
+    }
     if (contigs != null && contigs.length > 0)
     {
       SequenceI[] alignment = new SequenceI[sequences.length];
@@ -231,10 +256,15 @@ public class AlignmentView
             if (nvismsa[j] != null)
             {
               SequenceI mseq[] = nvismsa[j];
-              AlignmentOrder order=(orders==null) ? null : orders[j];
+              AlignmentOrder order = (orders == null) ? null : orders[j];
               j++;
-              if (mseq.length!=sequences.length)
-                throw new Error("Mismatch between number of sequences in block "+j+" ("+mseq.length+") and the original view ("+sequences.length+")");
+              if (mseq.length != sequences.length)
+              {
+                throw new Error(
+                    "Mismatch between number of sequences in block " + j + " (" +
+                    mseq.length + ") and the original view (" +
+                    sequences.length + ")");
+              }
               swidth = mseq[0].getLength(); // JBPNote: could ensure padded here.
               for (int s = 0; s < mseq.length; s++)
               {
@@ -250,7 +280,8 @@ public class AlignmentView
                   {
                     alignment[s].setEnd(mseq[s].getEnd());
                   }
-                  if (order!=null) {
+                  if (order != null)
+                  {
                     order.updateSequence(mseq[s], alignment[s]);
                   }
                 }
@@ -264,8 +295,9 @@ public class AlignmentView
                 // recover input data
                 for (int s = 0; s < sequences.length; s++)
                 {
-                  SequenceI oseq = sequences[s].getSeq(gapCharacter).getSubSequence(start,
-                      contigs[contig + 1]);
+                  SequenceI oseq = sequences[s].getSeq(gapCharacter).
+                      getSubSequence(start,
+                                     contigs[contig + 1]);
                   if (swidth < oseq.getLength())
                   {
                     swidth = oseq.getLength();
@@ -295,7 +327,8 @@ public class AlignmentView
           // add hidden segment to right of next region
           for (int s = 0; s < sequences.length; s++)
           {
-            SequenceI hseq = sequences[s].getSeq(gapCharacter).getSubSequence(contigs[contig +
+            SequenceI hseq = sequences[s].getSeq(gapCharacter).getSubSequence(
+                contigs[contig +
                 1], start);
             if (alignment[s] == null)
             {
@@ -322,7 +355,7 @@ public class AlignmentView
           if (nvismsa[j] != null)
           {
             SequenceI mseq[] = nvismsa[j];
-            AlignmentOrder order = (orders!=null) ? orders[j] : null;
+            AlignmentOrder order = (orders != null) ? orders[j] : null;
             swidth = mseq[0].getLength();
             for (int s = 0; s < mseq.length; s++)
             {
@@ -338,7 +371,8 @@ public class AlignmentView
                 {
                   alignment[s].setEnd(mseq[s].getEnd());
                 }
-                if (order!=null) {
+                if (order != null)
+                {
                   order.updateSequence(mseq[s], alignment[s]);
                 }
               }
@@ -354,8 +388,9 @@ public class AlignmentView
                 // recover input data
                 for (int s = 0; s < sequences.length; s++)
                 {
-                  SequenceI oseq = sequences[s].getSeq(gapCharacter).getSubSequence(start,
-                      owidth + 1);
+                  SequenceI oseq = sequences[s].getSeq(gapCharacter).
+                      getSubSequence(start,
+                                     owidth + 1);
                   if (swidth < oseq.getLength())
                   {
                     swidth = oseq.getLength();
@@ -385,22 +420,37 @@ public class AlignmentView
           }
         }
       }
-      return new Object[] { alignment, columnselection};
-    } else {
-      if (nvismsa.length!=1)
-        throw new Error("Mismatch between visible blocks to update and number of contigs in view (contigs=0,blocks="+nvismsa.length);
-      if (nvismsa[0]!=null)
-        return new Object[] { nvismsa[0], new ColumnSelection()};
+      return new Object[]
+          {
+          alignment, columnselection};
+    }
+    else
+    {
+      if (nvismsa.length != 1)
+      {
+        throw new Error("Mismatch between visible blocks to update and number of contigs in view (contigs=0,blocks=" +
+                        nvismsa.length);
+      }
+      if (nvismsa[0] != null)
+      {
+        return new Object[]
+            {
+            nvismsa[0], new ColumnSelection()};
+      }
       else
+      {
         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() {
+  public int[] getVisibleContigs()
+  {
     if (contigs != null && contigs.length > 0)
     {
       int start = 0;
@@ -419,33 +469,41 @@ public class AlignmentView
       {
         nvis++;
       }
-      int viscontigs[] = new int[nvis*2];
-      nvis=0;
-      start=0;
-      for (int contig=0; contig<contigs.length; contig+=3) {
+      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;
+          viscontigs[nvis + 1] = contigs[contig + 1] - 1; // end is inclusive
+          nvis += 2;
         }
         start = contigs[contig + 1] + contigs[contig + 2];
       }
-      if (start<fwidth) {
+      if (start < fwidth)
+      {
         viscontigs[nvis] = start;
-        viscontigs[nvis+1]=fwidth; // end is inclusive
-        nvis+=2;
+        viscontigs[nvis + 1] = fwidth; // end is inclusive
+        nvis += 2;
       }
       return viscontigs;
-    } else {
-      return new int[] { 0, width};
+    }
+    else
+    {
+      return new int[]
+          {
+          0, width};
     }
   }
+
   /**
    *
    * @return position of first visible column of AlignmentView within its parent's alignment reference frame
    */
-  public int getAlignmentOrigin() {
+  public int getAlignmentOrigin()
+  {
     // TODO Auto-generated method stub
     return firstCol;
   }