2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.List;
27 import jalview.bin.Cache;
30 * A simple way of bijectively mapping a non-contiguous linear range to another
31 * non-contiguous linear range.
33 * Use at your own risk!
35 * TODO: efficient implementation of private posMap method
37 * TODO: test/ensure that sense of from and to ratio start position is conserved
38 * (codon start position recovery)
44 * Subregions (base 1) described as { [start1, end1], [start2, end2], ...}
46 private List<int[]> fromShifts;
49 * Same format as fromShifts, for the 'mapped to' sequence
51 private List<int[]> toShifts;
54 * number of steps in fromShifts to one toRatio unit
56 private int fromRatio;
59 * number of steps in toShifts to one fromRatio
64 * lowest and highest value in the from Map
66 private int fromLowest;
68 private int fromHighest;
71 * lowest and highest value in the to Map
75 private int toHighest;
82 fromShifts = new ArrayList<>();
83 toShifts = new ArrayList<>();
87 * Two MapList objects are equal if they are the same object, or they both
88 * have populated shift ranges and all values are the same.
91 public boolean equals(Object o)
93 if (o == null || !(o instanceof MapList))
98 MapList obj = (MapList) o;
103 if (obj.fromRatio != fromRatio || obj.toRatio != toRatio
104 || obj.fromShifts == null || obj.toShifts == null)
108 return Arrays.deepEquals(fromShifts.toArray(), obj.fromShifts.toArray())
109 && Arrays.deepEquals(toShifts.toArray(),
110 obj.toShifts.toArray());
114 * Returns a hashcode made from the fromRatio, toRatio, and from/to ranges
117 public int hashCode()
119 int hashCode = 31 * fromRatio;
120 hashCode = 31 * hashCode + toRatio;
121 for (int[] shift : fromShifts)
123 hashCode = 31 * hashCode + shift[0];
124 hashCode = 31 * hashCode + shift[1];
126 for (int[] shift : toShifts)
128 hashCode = 31 * hashCode + shift[0];
129 hashCode = 31 * hashCode + shift[1];
136 * Returns the 'from' ranges as {[start1, end1], [start2, end2], ...}
140 public List<int[]> getFromRanges()
146 * Returns the 'to' ranges as {[start1, end1], [start2, end2], ...}
150 public List<int[]> getToRanges()
156 * Flattens a list of [start, end] into a single [start1, end1, start2,
162 protected static int[] getRanges(List<int[]> shifts)
164 int[] rnges = new int[2 * shifts.size()];
166 for (int[] r : shifts)
176 * @return length of mapped phrase in from
178 public int getFromRatio()
185 * @return length of mapped phrase in to
187 public int getToRatio()
192 public int getFromLowest()
197 public int getFromHighest()
202 public int getToLowest()
207 public int getToHighest()
213 * Constructor given from and to ranges as [start1, end1, start2, end2,...].
214 * There is no validation check that the ranges do not overlap each other.
217 * contiguous regions as [start1, end1, start2, end2, ...]
219 * same format as 'from'
221 * phrase length in 'from' (e.g. 3 for dna)
223 * phrase length in 'to' (e.g. 1 for protein)
225 public MapList(int from[], int to[], int fromRatio, int toRatio)
228 this.fromRatio = fromRatio;
229 this.toRatio = toRatio;
230 fromLowest = Integer.MAX_VALUE;
231 fromHighest = Integer.MIN_VALUE;
233 for (int i = 0; i < from.length; i += 2)
236 * note lowest and highest values - bearing in mind the
237 * direction may be reversed
239 fromLowest = Math.min(fromLowest, Math.min(from[i], from[i + 1]));
240 fromHighest = Math.max(fromHighest, Math.max(from[i], from[i + 1]));
241 fromShifts.add(new int[] { from[i], from[i + 1] });
244 toLowest = Integer.MAX_VALUE;
245 toHighest = Integer.MIN_VALUE;
246 for (int i = 0; i < to.length; i += 2)
248 toLowest = Math.min(toLowest, Math.min(to[i], to[i + 1]));
249 toHighest = Math.max(toHighest, Math.max(to[i], to[i + 1]));
250 toShifts.add(new int[] { to[i], to[i + 1] });
255 * Copy constructor. Creates an identical mapping.
259 public MapList(MapList map)
262 // TODO not used - remove?
263 this.fromLowest = map.fromLowest;
264 this.fromHighest = map.fromHighest;
265 this.toLowest = map.toLowest;
266 this.toHighest = map.toHighest;
268 this.fromRatio = map.fromRatio;
269 this.toRatio = map.toRatio;
270 if (map.fromShifts != null)
272 for (int[] r : map.fromShifts)
274 fromShifts.add(new int[] { r[0], r[1] });
277 if (map.toShifts != null)
279 for (int[] r : map.toShifts)
281 toShifts.add(new int[] { r[0], r[1] });
287 * Constructor given ranges as lists of [start, end] positions. There is no
288 * validation check that the ranges do not overlap each other.
295 public MapList(List<int[]> fromRange, List<int[]> toRange, int fromRatio,
299 fromRange = coalesceRanges(fromRange);
300 toRange = coalesceRanges(toRange);
301 this.fromShifts = fromRange;
302 this.toShifts = toRange;
303 this.fromRatio = fromRatio;
304 this.toRatio = toRatio;
306 fromLowest = Integer.MAX_VALUE;
307 fromHighest = Integer.MIN_VALUE;
308 for (int[] range : fromRange)
310 if (range.length != 2)
312 // throw new IllegalArgumentException(range);
313 Cache.log.error("Invalid format for fromRange "
314 + Arrays.toString(range) + " may cause errors");
316 fromLowest = Math.min(fromLowest, Math.min(range[0], range[1]));
317 fromHighest = Math.max(fromHighest, Math.max(range[0], range[1]));
320 toLowest = Integer.MAX_VALUE;
321 toHighest = Integer.MIN_VALUE;
322 for (int[] range : toRange)
324 if (range.length != 2)
326 // throw new IllegalArgumentException(range);
327 Cache.log.error("Invalid format for toRange "
328 + Arrays.toString(range) + " may cause errors");
330 toLowest = Math.min(toLowest, Math.min(range[0], range[1]));
331 toHighest = Math.max(toHighest, Math.max(range[0], range[1]));
336 * Consolidates a list of ranges so that any contiguous ranges are merged.
337 * This assumes the ranges are already in start order (does not sort them).
339 * The main use case for this method is when mapping cDNA sequence to its
340 * protein product, based on CDS feature ranges which derive from spliced
341 * exons, but are contiguous on the cDNA sequence. For example
343 * CDS 1-20 // from exon1
344 * CDS 21-35 // from exon2
345 * CDS 36-71 // from exon3
346 * 'coalesce' to range 1-71
350 * @return the same list (if unchanged), else a new merged list, leaving the
351 * input list unchanged
353 public static List<int[]> coalesceRanges(final List<int[]> ranges)
355 if (ranges == null || ranges.size() < 2)
360 boolean changed = false;
361 List<int[]> merged = new ArrayList<>();
362 int[] lastRange = ranges.get(0);
363 int lastDirection = lastRange[1] >= lastRange[0] ? 1 : -1;
364 lastRange = new int[] { lastRange[0], lastRange[1] };
365 merged.add(lastRange);
366 boolean first = true;
368 for (final int[] range : ranges)
376 int direction = range[1] >= range[0] ? 1 : -1;
379 * if next range is in the same direction as last and contiguous,
380 * just update the end position of the last range
382 boolean sameDirection = range[1] == range[0]
383 || direction == lastDirection;
384 boolean extending = range[0] == lastRange[1] + lastDirection;
385 if (sameDirection && extending)
387 lastRange[1] = range[1];
392 lastRange = new int[] { range[0], range[1] };
393 merged.add(lastRange);
394 // careful: merging [5, 5] after [7, 6] should keep negative direction
395 lastDirection = (range[1] == range[0]) ? lastDirection : direction;
399 return changed ? merged : ranges;
403 * get all mapped positions from 'from' to 'to'
405 * @return int[][] { int[] { fromStart, fromFinish, toStart, toFinish }, int
406 * [fromFinish-fromStart+2] { toStart..toFinish mappings}}
408 protected int[][] makeFromMap()
410 // TODO not used - remove??
411 return posMap(fromShifts, fromRatio, toShifts, toRatio);
415 * get all mapped positions from 'to' to 'from'
417 * @return int[to position]=position mapped in from
419 protected int[][] makeToMap()
421 // TODO not used - remove??
422 return posMap(toShifts, toRatio, fromShifts, fromRatio);
426 * construct an int map for intervals in intVals
429 * @return int[] { from, to pos in range }, int[range.to-range.from+1]
430 * returning mapped position
432 private int[][] posMap(List<int[]> shiftTo, int ratio,
433 List<int[]> shiftFrom, int toRatio)
435 // TODO not used - remove??
436 int iv = 0, ivSize = shiftTo.size();
441 int[] intv = shiftTo.get(iv++);
442 int from = intv[0], to = intv[1];
450 intv = shiftTo.get(iv++);
469 int mp[][] = new int[to - from + 2][];
470 for (int i = 0; i < mp.length; i++)
472 int[] m = shift(i + from, shiftTo, ratio, shiftFrom, toRatio);
493 int[][] map = new int[][] { new int[] { from, to, tF, tT },
494 new int[to - from + 2] };
499 for (int i = 0; i < mp.length; i++)
503 map[1][i] = mp[i][0] - tF;
507 map[1][i] = -1; // indicates an out of range mapping
517 * start position for shift (in original reference frame)
521 * public void addShift(int pos, int shift) { int sidx = 0; int[]
522 * rshift=null; while (sidx<shifts.size() && (rshift=(int[])
523 * shifts.elementAt(sidx))[0]<pos) sidx++; if (sidx==shifts.size())
524 * shifts.insertElementAt(new int[] { pos, shift}, sidx); else
525 * rshift[1]+=shift; }
529 * shift from pos to To(pos)
533 * @return int shifted position in To, frameshift in From, direction of mapped
536 public int[] shiftFrom(int pos)
538 return shift(pos, fromShifts, fromRatio, toShifts, toRatio);
542 * inverse of shiftFrom - maps pos in To to a position in From
546 * @return shifted position in From, frameshift in To, direction of mapped
549 public int[] shiftTo(int pos)
551 return shift(pos, toShifts, toRatio, fromShifts, fromRatio);
562 protected static int[] shift(int pos, List<int[]> shiftTo, int fromRatio,
563 List<int[]> shiftFrom, int toRatio)
565 // TODO: javadoc; tests
566 int[] fromCount = countPos(shiftTo, pos);
567 if (fromCount == null)
571 int fromRemainder = (fromCount[0] - 1) % fromRatio;
572 int toCount = 1 + (((fromCount[0] - 1) / fromRatio) * toRatio);
573 int[] toPos = countToPos(shiftFrom, toCount);
576 return null; // throw new Error("Bad Mapping!");
578 // System.out.println(fromCount[0]+" "+fromCount[1]+" "+toCount);
579 return new int[] { toPos[0], fromRemainder, toPos[1] };
583 * count how many positions pos is along the series of intervals.
587 * @return number of positions or null if pos is not within intervals
589 protected static int[] countPos(List<int[]> shiftTo, int pos)
591 int count = 0, intv[], iv = 0, ivSize = shiftTo.size();
594 intv = shiftTo.get(iv++);
595 if (intv[0] <= intv[1])
597 if (pos >= intv[0] && pos <= intv[1])
599 return new int[] { count + pos - intv[0] + 1, +1 };
603 count += intv[1] - intv[0] + 1;
608 if (pos >= intv[1] && pos <= intv[0])
610 return new int[] { count + intv[0] - pos + 1, -1 };
614 count += intv[0] - intv[1] + 1;
622 * count out pos positions into a series of intervals and return the position
626 * @return position pos in interval set
628 protected static int[] countToPos(List<int[]> shiftFrom, int pos)
630 int count = 0, diff = 0, iv = 0, ivSize = shiftFrom.size();
631 int[] intv = { 0, 0 };
634 intv = shiftFrom.get(iv++);
635 diff = intv[1] - intv[0];
638 if (pos <= count + 1 + diff)
640 return new int[] { pos - count - 1 + intv[0], +1 };
649 if (pos <= count + 1 - diff)
651 return new int[] { intv[0] - (pos - count - 1), -1 };
659 return null;// (diff<0) ? (intv[1]-1) : (intv[0]+1);
663 * find series of intervals mapping from start-end in the From map.
666 * position mapped 'to'
668 * position mapped 'to'
669 * @return series of [start, end] ranges in sequence mapped 'from'
671 public int[] locateInFrom(int start, int end)
673 // inefficient implementation
674 int fromStart[] = shiftTo(start);
675 // needs to be inclusive of end of symbol position
676 int fromEnd[] = shiftTo(end);
678 return getIntervals(fromShifts, fromStart, fromEnd, fromRatio);
682 * find series of intervals mapping from start-end in the to map.
685 * position mapped 'from'
687 * position mapped 'from'
688 * @return series of [start, end] ranges in sequence mapped 'to'
690 public int[] locateInTo(int start, int end)
692 int toStart[] = shiftFrom(start);
693 int toEnd[] = shiftFrom(end);
694 return getIntervals(toShifts, toStart, toEnd, toRatio);
698 * like shift - except returns the intervals in the given vector of shifts
699 * which were spanned in traversing fromStart to fromEnd
705 * @return series of from,to intervals from from first position of starting
706 * region to final position of ending region inclusive
708 protected static int[] getIntervals(List<int[]> shiftFrom,
709 int[] fromStart, int[] fromEnd, int fromRatio2)
711 if (fromStart == null || fromEnd == null)
715 int startpos, endpos;
716 startpos = fromStart[0]; // first position in fromStart
717 endpos = fromEnd[0]; // last position in fromEnd
718 int endindx = (fromRatio2 - 1); // additional positions to get to last
719 // position from endpos
720 int intv = 0, intvSize = shiftFrom.size();
721 int iv[], i = 0, fs = -1, fe_s = -1, fe = -1; // containing intervals
722 // search intervals to locate ones containing startpos and count endindx
723 // positions on from endpos
724 while (intv < intvSize && (fs == -1 || fe == -1))
726 iv = shiftFrom.get(intv++);
729 endpos = iv[0]; // start counting from beginning of interval
730 endindx--; // inclusive of endpos
734 if (fs == -1 && startpos >= iv[0] && startpos <= iv[1])
738 if (endpos >= iv[0] && endpos <= iv[1])
746 if (endpos + endindx <= iv[1])
749 endpos = endpos + endindx; // end of end token is within this
754 endindx -= iv[1] - endpos; // skip all this interval too
761 if (fs == -1 && startpos <= iv[0] && startpos >= iv[1])
765 if (endpos <= iv[0] && endpos >= iv[1])
773 if (endpos - endindx >= iv[1])
776 endpos = endpos - endindx; // end of end token is within this
781 endindx -= endpos - iv[1]; // skip all this interval too
788 if (fs == fe && fe == -1)
792 List<int[]> ranges = new ArrayList<>();
797 // truncate initial interval
798 iv = shiftFrom.get(intv++);
799 iv = new int[] { iv[0], iv[1] };// clone
806 ranges.add(iv); // add initial range
807 iv = shiftFrom.get(intv++); // get next interval
808 iv = new int[] { iv[0], iv[1] };// clone
815 ranges.add(iv); // add only - or final range
819 // walk from end of interval.
820 i = shiftFrom.size() - 1;
825 iv = shiftFrom.get(i);
826 iv = new int[] { iv[1], iv[0] };// reverse and clone
827 // truncate initial interval
833 { // fix apparent logic bug when fe==-1
834 ranges.add(iv); // add (truncated) reversed interval
835 iv = shiftFrom.get(i);
836 iv = new int[] { iv[1], iv[0] }; // reverse and clone
840 // interval is already reversed
843 ranges.add(iv); // add only - or final range
845 // create array of start end intervals.
847 if (ranges != null && ranges.size() > 0)
849 range = new int[ranges.size() * 2];
851 intvSize = ranges.size();
853 while (intv < intvSize)
855 iv = ranges.get(intv);
858 ranges.set(intv++, null); // remove
865 * get the 'initial' position of mpos in To
869 * @return position of first word in to reference frame
871 public int getToPosition(int mpos)
873 // TODO not used - remove??
874 int[] mp = shiftTo(mpos);
883 * get range of positions in To frame for the mpos word in From
887 * @return null or int[] first position in To for mpos, last position in to
890 public int[] getToWord(int mpos)
892 int[] mp = shiftTo(mpos);
895 return new int[] { mp[0], mp[0] + mp[2] * (getFromRatio() - 1) };
901 * get From position in the associated reference frame for position pos in the
902 * associated sequence.
907 public int getMappedPosition(int pos)
909 // TODO not used - remove??
910 int[] mp = shiftFrom(pos);
918 public int[] getMappedWord(int pos)
920 // TODO not used - remove??
921 int[] mp = shiftFrom(pos);
924 return new int[] { mp[0], mp[0] + mp[2] * (getToRatio() - 1) };
931 * @return a MapList whose From range is this maplist's To Range, and vice
934 public MapList getInverse()
936 return new MapList(getToRanges(), getFromRanges(), getToRatio(),
941 * test for containment rather than equivalence to another mapping
944 * to be tested for containment
945 * @return true if local or mapped range map contains or is contained by this
948 public boolean containsEither(boolean local, MapList map)
950 // TODO not used - remove?
953 return ((getFromLowest() >= map.getFromLowest()
954 && getFromHighest() <= map.getFromHighest())
955 || (getFromLowest() <= map.getFromLowest()
956 && getFromHighest() >= map.getFromHighest()));
960 return ((getToLowest() >= map.getToLowest()
961 && getToHighest() <= map.getToHighest())
962 || (getToLowest() <= map.getToLowest()
963 && getToHighest() >= map.getToHighest()));
968 * String representation - for debugging, not guaranteed not to change
971 public String toString()
973 StringBuilder sb = new StringBuilder(64);
975 for (int[] shift : fromShifts)
977 sb.append(" ").append(Arrays.toString(shift));
980 sb.append(fromRatio).append(":").append(toRatio);
982 for (int[] shift : toShifts)
984 sb.append(" ").append(Arrays.toString(shift));
987 return sb.toString();
991 * Extend this map list by adding the given map's ranges. There is no
992 * validation check that the ranges do not overlap existing ranges (or each
993 * other), but contiguous ranges are merged.
997 public void addMapList(MapList map)
999 if (this.equals(map))
1003 this.fromLowest = Math.min(fromLowest, map.fromLowest);
1004 this.toLowest = Math.min(toLowest, map.toLowest);
1005 this.fromHighest = Math.max(fromHighest, map.fromHighest);
1006 this.toHighest = Math.max(toHighest, map.toHighest);
1008 for (int[] range : map.getFromRanges())
1010 addRange(range, fromShifts);
1012 for (int[] range : map.getToRanges())
1014 addRange(range, toShifts);
1019 * Adds the given range to a list of ranges. If the new range just extends
1020 * existing ranges, the current endpoint is updated instead.
1025 static void addRange(int[] range, List<int[]> addTo)
1028 * list is empty - add to it!
1030 if (addTo.size() == 0)
1036 int[] last = addTo.get(addTo.size() - 1);
1037 boolean lastForward = last[1] >= last[0];
1038 boolean newForward = range[1] >= range[0];
1041 * contiguous range in the same direction - just update endpoint
1043 if (lastForward == newForward && last[1] == range[0])
1050 * next range starts at +1 in forward sense - update endpoint
1052 if (lastForward && newForward && range[0] == last[1] + 1)
1059 * next range starts at -1 in reverse sense - update endpoint
1061 if (!lastForward && !newForward && range[0] == last[1] - 1)
1068 * just add the new range
1074 * Returns true if mapping is from forward strand, false if from reverse
1075 * strand. Result is just based on the first 'from' range that is not a single
1076 * position. Default is true unless proven to be false. Behaviour is not well
1077 * defined if the mapping has a mixture of forward and reverse ranges.
1081 public boolean isFromForwardStrand()
1083 return isForwardStrand(getFromRanges());
1087 * Returns true if mapping is to forward strand, false if to reverse strand.
1088 * Result is just based on the first 'to' range that is not a single position.
1089 * Default is true unless proven to be false. Behaviour is not well defined if
1090 * the mapping has a mixture of forward and reverse ranges.
1094 public boolean isToForwardStrand()
1096 return isForwardStrand(getToRanges());
1100 * A helper method that returns true unless at least one range has start >
1101 * end. Behaviour is undefined for a mixture of forward and reverse ranges.
1106 private boolean isForwardStrand(List<int[]> ranges)
1108 boolean forwardStrand = true;
1109 for (int[] range : ranges)
1111 if (range[1] > range[0])
1113 break; // forward strand confirmed
1115 else if (range[1] < range[0])
1117 forwardStrand = false;
1118 break; // reverse strand confirmed
1121 return forwardStrand;
1126 * @return true if from, or to is a three to 1 mapping
1128 public boolean isTripletMap()
1130 return (toRatio == 3 && fromRatio == 1)
1131 || (fromRatio == 3 && toRatio == 1);
1135 * Returns a map which is the composite of this one and the input map. That
1136 * is, the output map has the fromRanges of this map, and its toRanges are the
1137 * toRanges of this map as transformed by the input map.
1139 * Returns null if the mappings cannot be traversed (not all toRanges of this
1140 * map correspond to fromRanges of the input), or if this.toRatio does not
1141 * match map.fromRatio.
1145 * this: from [1-100] to [501-600]
1146 * input: from [10-40] to [60-90]
1147 * output: from [10-40] to [560-590]
1148 * Example 2 ('reverse strand exons'):
1149 * this: from [1-100] to [2000-1951], [1000-951] // transcript to loci
1150 * input: from [1-50] to [41-90] // CDS to transcript
1151 * output: from [10-40] to [1960-1951], [1000-971] // CDS to gene loci
1157 public MapList traverse(MapList map)
1165 * compound the ratios by this rule:
1166 * A:B with M:N gives A*M:B*N
1167 * reduced by greatest common divisor
1168 * so 1:3 with 3:3 is 3:9 or 1:3
1169 * 1:3 with 3:1 is 3:3 or 1:1
1170 * 1:3 with 1:3 is 1:9
1171 * 2:5 with 3:7 is 6:35
1173 int outFromRatio = getFromRatio() * map.getFromRatio();
1174 int outToRatio = getToRatio() * map.getToRatio();
1175 int gcd = MathUtils.gcd(outFromRatio, outToRatio);
1176 outFromRatio /= gcd;
1179 List<int[]> toRanges = new ArrayList<>();
1180 for (int[] range : getToRanges())
1182 int[] transferred = map.locateInTo(range[0], range[1]);
1183 if (transferred == null || transferred.length % 2 != 0)
1189 * convert [start1, end1, start2, end2, ...]
1190 * to [[start1, end1], [start2, end2], ...]
1192 for (int i = 0; i < transferred.length;)
1194 toRanges.add(new int[] { transferred[i], transferred[i + 1] });
1199 return new MapList(getFromRanges(), toRanges, outFromRatio, outToRatio);
1203 * Answers true if the mapping is from one contiguous range to another, else
1208 public boolean isContiguous()
1210 return fromShifts.size() == 1 && toShifts.size() == 1;
1214 * Returns the [start, end...] positions in the range mapped from, that are
1215 * mapped to by part or all of the given begin-end of the range mapped to.
1216 * Returns null if begin-end does not overlap any position mapped to.
1222 public int[] getOverlapsInFrom(final int begin, final int end)
1224 int[] overlaps = MappingUtils.findOverlap(toShifts, begin, end);
1226 return overlaps == null ? null : locateInFrom(overlaps[0], overlaps[1]);
1230 * Returns the [start, end...] positions in the range mapped to, that are
1231 * mapped to by part or all of the given begin-end of the range mapped from.
1232 * Returns null if begin-end does not overlap any position mapped from.
1238 public int[] getOverlapsInTo(final int begin, final int end)
1240 int[] overlaps = MappingUtils.findOverlap(fromShifts, begin, end);
1242 return overlaps == null ? null : locateInTo(overlaps[0], overlaps[1]);