From: gmungoc Date: Wed, 2 Dec 2020 19:59:33 +0000 (+0000) Subject: JAL-3761 helper method reinstated to avoid code duplication X-Git-Tag: Release_2_11_2_0~34^2~18 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4cd6de8afe3884f615bf0f3e33ac107fbeeafbe5;hp=1e507c915398542fe6e206e7a6f2620283243f1e;p=jalview.git JAL-3761 helper method reinstated to avoid code duplication --- diff --git a/src/jalview/util/MapList.java b/src/jalview/util/MapList.java index 198066d..745f367 100644 --- a/src/jalview/util/MapList.java +++ b/src/jalview/util/MapList.java @@ -1155,27 +1155,8 @@ public class MapList */ public int[] locateInFrom(int start, int end) { - if (end < start) - { - int tmp = end; - end = start; - start = tmp; - } - - /* - * traverse toShifts and mark offsets in fromShifts - * of any positions that lie in [start, end] - */ - BitSet offsets = getMappedOffsetsForPositions(start, end, toShifts, + return mapPositions(start, end, toShifts, fromShifts, toRatio, fromRatio); - - /* - * traverse fromShifts and collect positions at the marked offsets - */ - List mapped = getPositionsForOffsets(fromShifts, offsets); - - // TODO: or just return the List and adjust calling code to match - return mapped.isEmpty() ? null : MappingUtils.rangeListToArray(mapped); } /** @@ -1190,6 +1171,29 @@ public class MapList */ public int[] locateInTo(int start, int end) { + return mapPositions(start, end, fromShifts, toShifts, + fromRatio, toRatio); + } + + /** + * Helper method that returns the [start1, end1, start2, end2, ...] positions + * in {@code targetRange} that map to positions between {@code start} and + * {@code end} in {@code sourceRange}. Note that for a reverse strand mapping + * this will return ranges with end < start. Returns null if no mapped + * positions are found in start-end. + * + * @param start + * @param end + * @param sourceRange + * @param targetRange + * @param sourceWordLength + * @param targetWordLength + * @return + */ + final static int[] mapPositions(int start, int end, + List sourceRange, List targetRange, + int sourceWordLength, int targetWordLength) + { if (end < start) { int tmp = end; @@ -1198,17 +1202,18 @@ public class MapList } /* - * traverse fromShifts and mark offsets in toShifts + * traverse sourceRange and mark offsets in targetRange * of any positions that lie in [start, end] */ - BitSet offsets = getMappedOffsetsForPositions(start, end, fromShifts, - fromRatio, toRatio); + BitSet offsets = getMappedOffsetsForPositions(start, end, sourceRange, + sourceWordLength, targetWordLength); /* - * traverse toShifts and collect positions at the marked offsets + * traverse targetRange and collect positions at the marked offsets */ - List mapped = getPositionsForOffsets(toShifts, offsets); + List mapped = getPositionsForOffsets(targetRange, offsets); + // TODO: or just return the List and adjust calling code to match return mapped.isEmpty() ? null : MappingUtils.rangeListToArray(mapped); }