X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FMappingUtils.java;fp=src%2Fjalview%2Futil%2FMappingUtils.java;h=6294ca132ae9ba1b8135bb08b206043e07a81ac1;hb=c17981672620e0b780a2338bd0c74e55cf9ddec2;hp=499fc6bdb421befd9d769383af628ff77864c24e;hpb=feeb56fc2f3d7c40a46466ff52c7663cc96d6c70;p=jalview.git diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java index 499fc6b..6294ca1 100644 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@ -20,6 +20,13 @@ */ package jalview.util; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + import jalview.analysis.AlignmentSorter; import jalview.api.AlignViewportI; import jalview.bin.Cache; @@ -41,13 +48,6 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - /** * Helper methods for manipulations involving sequence mappings. * @@ -835,7 +835,7 @@ public final class MappingUtils { if (range.length % 2 != 0) { - System.err.println( + Cache.log.error( "Error unbalance start/end ranges: " + ranges.toString()); return 0; } @@ -991,7 +991,7 @@ public final class MappingUtils /* * not coded for [start1, end1, start2, end2, ...] */ - System.err.println( + Cache.log.error( "MappingUtils.removeEndPositions doesn't handle multiple ranges"); return; } @@ -1002,7 +1002,7 @@ public final class MappingUtils /* * not coded for a reverse strand range (end < start) */ - System.err.println( + Cache.log.error( "MappingUtils.removeEndPositions doesn't handle reverse strand"); return; } @@ -1037,4 +1037,66 @@ public final class MappingUtils } return result; } + + /** + * Returns the maximal start-end positions in the given (ordered) list of + * ranges which is overlapped by the given begin-end range, or null if there + * is no overlap. + * + *
+ * Examples: + * if ranges is {[4, 8], [10, 12], [16, 19]} + * then + * findOverlap(ranges, 1, 20) == [4, 19] + * findOverlap(ranges, 6, 11) == [6, 11] + * findOverlap(ranges, 9, 15) == [10, 12] + * findOverlap(ranges, 13, 15) == null + *+ * + * @param ranges + * @param begin + * @param end + * @return + */ + protected static int[] findOverlap(List