JAL-845 implement alignment of protein to match cDNA alignment
[jalview.git] / src / jalview / util / MapList.java
index 32f0256..48aebbf 100644 (file)
@@ -101,23 +101,23 @@ public class MapList
   }
 
   /**
-   * Returns the flattened 'from' ranges as [start1, end1, start2, end2, ...]
+   * Returns the 'from' ranges as {[start1, end1], [start2, end2], ...}
    * 
    * @return
    */
-  public int[] getFromRanges()
+  public List<int[]> getFromRanges()
   {
-    return getRanges(fromShifts);
+    return fromShifts;
   }
 
   /**
-   * Returns the flattened 'to' ranges as [start1, end1, start2, end2, ...]
+   * Returns the 'to' ranges as {[start1, end1], [start2, end2], ...}
    * 
    * @return
    */
-  public int[] getToRanges()
+  public List<int[]> getToRanges()
   {
-    return getRanges(toShifts);
+    return toShifts;
   }
 
   /**
@@ -191,6 +191,8 @@ public class MapList
    */
   public MapList(int from[], int to[], int fromRatio, int toRatio)
   {
+    this.fromRatio = fromRatio;
+    this.toRatio = toRatio;
     fromLowest = from[0];
     fromHighest = from[1];
     for (int i = 0; i < from.length; i += 2)
@@ -211,8 +213,6 @@ public class MapList
       toShifts.add(new int[]
       { to[i], to[i + 1] });
     }
-    this.fromRatio = fromRatio;
-    this.toRatio = toRatio;
   }
 
   /**
@@ -249,6 +249,38 @@ public class MapList
   }
 
   /**
+   * Constructor given ranges as lists of [start, end] positions
+   * 
+   * @param fromRange
+   * @param toRange
+   * @param fromRatio
+   * @param toRatio
+   */
+  public MapList(List<int[]> fromRange, List<int[]> toRange,
+          int fromRatio, int toRatio)
+  {
+    this.fromShifts = fromRange;
+    this.toShifts = toRange;
+    this.fromRatio = fromRatio;
+    this.toRatio = toRatio;
+
+    fromLowest = Integer.MAX_VALUE;
+    fromHighest = 0;
+    for (int[] range : fromRange) {
+      fromLowest = Math.min(fromLowest, range[0]);
+      fromHighest = Math.max(fromHighest, range[1]);
+    }
+
+    toLowest = Integer.MAX_VALUE;
+    toHighest = 0;
+    for (int[] range : toRange)
+    {
+      toLowest = Math.min(toLowest, range[0]);
+      toHighest = Math.max(toHighest, range[1]);
+    }
+  }
+
+  /**
    * get all mapped positions from 'from' to 'to'
    * 
    * @return int[][] { int[] { fromStart, fromFinish, toStart, toFinish }, int