X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FMapList.java;h=8ff640b582b417f46353d282c47b22f61c942a89;hb=5bc9afbf74ecf25e146938049d01ea36c18fd578;hp=e456dabdc281946dae004e527487d07569a7d11b;hpb=ab9351a591e5295be9e41bfa86238ccc2a8024f8;p=jalview.git diff --git a/src/jalview/util/MapList.java b/src/jalview/util/MapList.java index e456dab..8ff640b 100644 --- a/src/jalview/util/MapList.java +++ b/src/jalview/util/MapList.java @@ -41,12 +41,12 @@ public class MapList /* * Subregions (base 1) described as { [start1, end1], [start2, end2], ...} */ - private List fromShifts = new ArrayList(); + private List fromShifts; /* * Same format as fromShifts, for the 'mapped to' sequence */ - private List toShifts = new ArrayList(); + private List toShifts; /* * number of steps in fromShifts to one toRatio unit @@ -73,6 +73,15 @@ public class MapList private int toHighest; /** + * Constructor + */ + public MapList() + { + fromShifts = new ArrayList(); + toShifts = new ArrayList(); + } + + /** * Two MapList objects are equal if they are the same object, or they both * have populated shift ranges and all values are the same. */ @@ -180,7 +189,8 @@ public class MapList } /** - * Constructor. + * Constructor given from and to ranges as [start1, end1, start2, end2,...]. + * If any end is equal to the next start, the ranges will be merged. * * @param from * contiguous regions as [start1, end1, start2, end2, ...] @@ -193,25 +203,47 @@ public class MapList */ public MapList(int from[], int to[], int fromRatio, int toRatio) { + this(); this.fromRatio = fromRatio; this.toRatio = toRatio; fromLowest = from[0]; fromHighest = from[1]; + int added = 0; + for (int i = 0; i < from.length; i += 2) { fromLowest = Math.min(fromLowest, from[i]); fromHighest = Math.max(fromHighest, from[i + 1]); - - fromShifts.add(new int[] { from[i], from[i + 1] }); + if (added > 0 && from[i] == fromShifts.get(added - 1)[1]) + { + /* + * this range starts where the last ended - just extend it + */ + fromShifts.get(added - 1)[1] = from[i + 1]; + } + else + { + fromShifts.add(new int[] { from[i], from[i + 1] }); + added++; + } } toLowest = to[0]; toHighest = to[1]; + added = 0; for (int i = 0; i < to.length; i += 2) { toLowest = Math.min(toLowest, to[i]); toHighest = Math.max(toHighest, to[i + 1]); - toShifts.add(new int[] { to[i], to[i + 1] }); + if (added > 0 && to[i] == toShifts.get(added - 1)[1]) + { + toShifts.get(added - 1)[1] = to[i + 1]; + } + else + { + toShifts.add(new int[] { to[i], to[i + 1] }); + added++; + } } } @@ -222,6 +254,7 @@ public class MapList */ public MapList(MapList map) { + this(); // TODO not used - remove? this.fromLowest = map.fromLowest; this.fromHighest = map.fromHighest; @@ -257,6 +290,7 @@ public class MapList public MapList(List fromRange, List toRange, int fromRatio, int toRatio) { + this(); this.fromShifts = fromRange; this.toShifts = toRange; this.fromRatio = fromRatio;