JAL-2909 Updated tests
[jalview.git] / src / jalview / datamodel / CigarParser.java
index fd5694c..0abe9bf 100644 (file)
@@ -68,11 +68,12 @@ public class CigarParser
         {
           // ERROR
           int pos = rec.getStart() + refnext;
-          System.out.println("Insertion not added to seqInserts: " + pos);
+          System.out.println(
+                  "Read " + rec.getReadName() + " has an insertion at "
+                          + pos + " which is not in seqInserts");
         }
         else
         {
-
           // we just inserted something
           // remove these inserts now - should be very first entry
           int count = seqInserts.get(rec.getStart() + refnext);
@@ -270,7 +271,7 @@ public class CigarParser
       SAMRecord rec = it.next();
       Iterator<CigarElement> cit = rec.getCigar().getCigarElements()
               .iterator();
-      int next = 0;
+      int next = 1;
       while (cit.hasNext())
       {
         CigarElement el = cit.next();
@@ -278,12 +279,11 @@ public class CigarParser
         {
         case I:
           // add to insertions list, and move along the read
-          // location is 1 past the current position of next
-          // (note if we try to retrieve +1 position from reference by calling
-          // getReferencePositionAtReadPosition(next+1) we get 0 because it's an
-          // insertion!)
-          int refLocation = rec.getReferencePositionAtReadPosition(next)
-                  + 1;
+          // location is the start of next CIGAR segment
+          // because getReferencePositionAtReadPosition returns 0 for read
+          // positions which are not in the reference (like insertions)
+          int refLocation = rec.getReferencePositionAtReadPosition(
+                  next + el.getLength());
 
           // if there's already an insertion at this location, keep the longest
           // insertion; if there's no insertion keep this one