2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.
26 * ShiftList Simple way of mapping a linear series to a new linear range with
27 * new points introduced. Use at your own risk! Now growing to be used for
28 * interval ranges (position, offset) storing deletions/insertions
30 public class ShiftList
36 shifts = new Vector();
43 * start position for shift (in original reference frame)
47 public void addShift(int pos, int shift)
51 while (sidx < shifts.size()
52 && (rshift = (int[]) shifts.elementAt(sidx))[0] < pos)
56 if (sidx == shifts.size())
58 shifts.insertElementAt(new int[]
59 { pos, shift }, sidx);
72 * @return int shifted position
74 public int shift(int pos)
76 if (shifts.size() == 0)
83 while (sidx < shifts.size()
84 && (rshift = ((int[]) shifts.elementAt(sidx++)))[0] <= pos)
96 shifts.removeAllElements();
102 * @return ShiftList with inverse shift operations
104 public ShiftList getInverse()
106 ShiftList inverse = new ShiftList();
109 for (int i = 0, j = shifts.size(); i < j; i++)
111 int[] sh = (int[]) shifts.elementAt(i);
114 inverse.shifts.addElement(new int[]
123 * parse a 1d map of position 1<i<n to L<pos[i]<N such as that returned from
127 * @return shifts from map index to mapped position
129 public static ShiftList parseMap(int[] gapMap)
131 ShiftList shiftList = null;
132 if (gapMap != null && gapMap.length > 0)
134 shiftList = new ShiftList();
135 for (int i = 0, p = 0; i < gapMap.length; p++, i++)
139 shiftList.addShift(p, gapMap[i] - p);