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.List;
27 * ShiftList Simple way of mapping a linear series to a new linear range with
28 * new points introduced. Use at your own risk! Now growing to be used for
29 * interval ranges (position, offset) storing deletions/insertions
31 public class ShiftList
33 private List<int[]> shifts;
37 shifts = new ArrayList<int[]>();
44 * start position for shift (in original reference frame)
48 public void addShift(int pos, int shift)
54 while (sidx < shifts.size() && (rshift = shifts.get(sidx))[0] < pos)
58 if (sidx == shifts.size())
60 shifts.add(sidx, new int[] { pos, shift });
74 * @return int shifted position
76 public int shift(int pos)
78 if (shifts.size() == 0)
85 while (sidx < shifts.size()
86 && (rshift = (shifts.get(sidx++)))[0] <= pos)
96 public synchronized void clear()
104 * @return ShiftList with inverse shift operations
106 public ShiftList getInverse()
108 ShiftList inverse = new ShiftList();
109 synchronized (shifts)
113 for (int[] sh : shifts)
117 inverse.shifts.add(new int[] { sh[0], -sh[1] });
126 * parse a 1d map of position 1<i<n to L<pos[i]<N such as that
127 * returned from SequenceI.gapMap()
130 * @return shifts from map index to mapped position
132 public static ShiftList parseMap(int[] gapMap)
134 ShiftList shiftList = null;
135 if (gapMap != null && gapMap.length > 0)
137 shiftList = new ShiftList();
138 for (int i = 0, p = 0; i < gapMap.length; p++, i++)
142 shiftList.addShift(p, gapMap[i] - p);
150 public List<int[]> getShifts()