javadoc
[jalview.git] / src / jalview / datamodel / SeqCigar.java
index c9b737d..3366dcd 100644 (file)
@@ -62,10 +62,11 @@ public class SeqCigar
       throw new Error(
           "Implementation Error - unexpected null from getSequenceAndDeletions");
     }
-
+    int bounds[] = (int[]) edit_result[1];
     seq = new Sequence(refseq.getName(), (String) edit_result[0],
-                       refseq.getStart() + start+( (int[]) edit_result[1])[0],
-                       refseq.getStart() + start+( (int[]) edit_result[1])[2]);
+                       refseq.getStart() + start+bounds[0],
+                       refseq.getStart() + start+((bounds[2]==0) ? -1 : bounds[2]));
+    // seq.checkValidRange(); probably not needed
     seq.setDatasetSequence(refseq);
     return seq;
   }
@@ -218,24 +219,6 @@ public class SeqCigar
   {
     this.addOperation(M, range);
   }
-
-  /**
-   * Deleted regions mean that there will be discontinuous sequence numbering in the
-   * sequence returned by getSeq(char).
-   * @return true if there deletions
-   */
-  public boolean hasDeletedRegions()
-  {
-    for (int i = 0, l = length; i < l; i++)
-    {
-      if (operation[i] == D)
-      {
-        return true;
-      }
-    }
-    return false;
-  }
-
   /**
    * Adds
    * insertion and match operations based on seq to the cigar up to
@@ -365,10 +348,9 @@ public class SeqCigar
    * @return SequenceI[]
    */
   public static SequenceI[] createAlignmentSequences(SeqCigar[] alseqs,
-      char gapCharacter, ColumnSelection colsel)
+      char gapCharacter, ColumnSelection colsel, int[] segments)
   {
     SequenceI[] seqs = new SequenceI[alseqs.length];
-    Vector hiddenRegions=new Vector();
     StringBuffer[] g_seqs = new StringBuffer[alseqs.length];
     String[] alseqs_string=new String[alseqs.length];
     Object[] gs_regions = new Object[alseqs.length];
@@ -384,7 +366,7 @@ public class SeqCigar
       }
       g_seqs[i] = new StringBuffer( (String) ( (Object[]) gs_regions[i])[0]); // the visible gapped sequence
     }
-    // Now account for insertions.
+    // Now account for insertions. (well - deletions)
     // this is complicated because we must keep track of shifted positions in each sequence
     ShiftList shifts = new ShiftList();
     for (int i = 0; i < alseqs.length; i++)
@@ -423,7 +405,9 @@ public class SeqCigar
             }
           }
           shifts.addShift(region[2], insert.length); // update shift in alignment frame of reference
-          colsel.hideColumns(inspos, inspos+insert.length-1);
+          if (segments==null)
+            // add a hidden column for this deletion
+            colsel.hideColumns(inspos, inspos+insert.length-1);
         }
       }
     }
@@ -433,9 +417,16 @@ public class SeqCigar
       SequenceI ref = alseqs[i].getRefSeq();
       seqs[i] = new Sequence(ref.getName(), g_seqs[i].toString(),
                              ref.getStart() + alseqs[i].start+bounds[0],
-                             ref.getStart() + alseqs[i].start+bounds[2]);
+                             ref.getStart() + alseqs[i].start+(bounds[2]==0 ? -1 : bounds[2]));
       seqs[i].setDatasetSequence(ref);
     }
+    if (segments!=null) {
+      for (int i=0; i<segments.length; i+=3) {
+        //int start=shifts.shift(segments[i]-1)+1;
+        //int end=shifts.shift(segments[i]+segments[i+1]-1)-1;
+        colsel.hideColumns(segments[i+1], segments[i+1]+segments[i+2]-1);
+      }
+    }
     return seqs;
   }
 
@@ -546,13 +537,14 @@ public class SeqCigar
     {
       sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48);
       int sl = sub_se_gp.getWidth();
-      int st = sl - r - r;
+      int st = sl - 1 - r;
       for (int rs = 0; rs < 10; rs++)
       {
         int e = st + rs;
         sub_se_gp.deleteRange(st, e);
         String ssgapedseq = sub_se_gp.getSeq('-').getSequence();
         System.out.println(st + "," + e + "\t:" + ssgapedseq);
+        st -=3;
       }
     }
     {