JAL-3700 mapped sequence group includes short (or all gapped) sequences
[jalview.git] / src / jalview / util / MappingUtils.java
index 6294ca1..177c54d 100644 (file)
@@ -343,26 +343,23 @@ public final class MappingUtils
         firstUngappedPos++;
       }
 
-      /*
-       * If this sequence is only gaps in the selected range, skip it
-       */
-      if (firstUngappedPos > selectionEndRes)
-      {
-        continue;
-      }
+      boolean allGapped = (firstUngappedPos > selectionEndRes);
 
       int lastUngappedPos = selectionEndRes;
-      while (lastUngappedPos >= selectionStartRes
-              && Comparison.isGap(selected.getCharAt(lastUngappedPos)))
+      if (!allGapped)
       {
-        lastUngappedPos--;
+        while (lastUngappedPos >= selectionStartRes
+                && Comparison.isGap(selected.getCharAt(lastUngappedPos)))
+        {
+          lastUngappedPos--;
+        }
       }
 
       /*
        * Find the selected start/end residue positions in sequence
        */
-      int startResiduePos = selected.findPosition(firstUngappedPos);
-      int endResiduePos = selected.findPosition(lastUngappedPos);
+      int startResiduePos = allGapped ? 0 : selected.findPosition(firstUngappedPos);
+      int endResiduePos = allGapped ? 0 : selected.findPosition(lastUngappedPos);
 
       for (AlignedCodonFrame acf : codonFrames)
       {
@@ -376,6 +373,14 @@ public final class MappingUtils
           {
             continue;
           }
+          mappedGroup.addSequence(seq, false);
+          if (allGapped)
+          {
+            /*
+             * sequence is mapped but includes no mapped residues
+             */
+            continue;
+          }
           int mappedStartResidue = 0;
           int mappedEndResidue = 0;
           List<AlignedCodonFrame> mapping = Arrays.asList(acf);
@@ -403,7 +408,6 @@ public final class MappingUtils
           int mappedEndCol = seq.findIndex(mappedEndResidue) - 1;
           maxEndCol = maxEndCol == -1 ? mappedEndCol
                   : Math.max(maxEndCol, mappedEndCol);
-          mappedGroup.addSequence(seq, false);
           break;
         }
       }