*/
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<int[]> mapped = getPositionsForOffsets(fromShifts, offsets);
-
- // TODO: or just return the List and adjust calling code to match
- return mapped.isEmpty() ? null : MappingUtils.rangeListToArray(mapped);
}
/**
*/
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<int[]> sourceRange, List<int[]> targetRange,
+ int sourceWordLength, int targetWordLength)
+ {
if (end < start)
{
int tmp = end;
}
/*
- * 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<int[]> mapped = getPositionsForOffsets(toShifts, offsets);
+ List<int[]> mapped = getPositionsForOffsets(targetRange, offsets);
+ // TODO: or just return the List and adjust calling code to match
return mapped.isEmpty() ? null : MappingUtils.rangeListToArray(mapped);
}