refactored visible contig/gap map array intersection code to alignmentView
[jalview.git] / src / jalview / datamodel / AlignmentView.java
index 4079c9c..76f7bd8 100644 (file)
@@ -539,4 +539,42 @@ public class AlignmentView
     // TODO Auto-generated method stub\r
     return firstCol;\r
   }\r
+\r
+  /**\r
+   * compute a deletion map for the current view according to the given\r
+   * gap/match map\r
+   * \r
+   * @param gapMap (as returned from SequenceI.gapMap())\r
+   * @return int[] {intersection of visible regions with gapMap)\r
+   */\r
+  public int[] getVisibleContigMapFor(int[] gapMap)\r
+  {\r
+    int[] delMap = null;\r
+    int[] viscontigs = getVisibleContigs();\r
+    int spos = 0;\r
+    int i = 0;\r
+    if (viscontigs != null)\r
+    {\r
+      // viscontigs maps from a subset of the gapMap to the gapMap, so it will\r
+      // always be equal to or shorter than gapMap\r
+      delMap = new int[gapMap.length];\r
+      for (int contig = 0; contig < viscontigs.length; contig += 2)\r
+      {\r
+\r
+        while (spos < gapMap.length && gapMap[spos] < viscontigs[contig])\r
+        {\r
+          spos++;\r
+        }\r
+        while (spos < gapMap.length\r
+                && gapMap[spos] <= viscontigs[contig + 1])\r
+        {\r
+          delMap[i++] = spos++;\r
+        }\r
+      }\r
+      int tmap[] = new int[i];\r
+      System.arraycopy(delMap, 0, tmap, 0, i);\r
+      delMap = tmap;\r
+    }\r
+    return delMap;\r
+  }\r
 }\r