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[]
75 * @return int shifted position
77 public int shift(int pos)
79 if (shifts.size() == 0)
86 while (sidx < shifts.size()
87 && (rshift = (shifts.get(sidx++)))[0] <= pos)
97 public synchronized void clear()
105 * @return ShiftList with inverse shift operations
107 public ShiftList getInverse()
109 ShiftList inverse = new ShiftList();
110 synchronized (shifts)
114 for (int[] sh : shifts)
118 inverse.shifts.add(new int[]
128 * parse a 1d map of position 1<i<n to L<pos[i]<N such as that
129 * returned from SequenceI.gapMap()
132 * @return shifts from map index to mapped position
134 public static ShiftList parseMap(int[] gapMap)
136 ShiftList shiftList = null;
137 if (gapMap != null && gapMap.length > 0)
139 shiftList = new ShiftList();
140 for (int i = 0, p = 0; i < gapMap.length; p++, i++)
144 shiftList.addShift(p, gapMap[i] - p);
152 public List<int[]> getShifts()