2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
23 * ShiftList Simple way of mapping a linear series to a new linear range with
24 * new points introduced. Use at your own risk! Now growing to be used for
25 * interval ranges (position, offset) storing deletions/insertions
27 public class ShiftList
33 shifts = new Vector();
40 * start position for shift (in original reference frame)
44 public void addShift(int pos, int shift)
48 while (sidx < shifts.size()
49 && (rshift = (int[]) shifts.elementAt(sidx))[0] < pos)
53 if (sidx == shifts.size())
55 shifts.insertElementAt(new int[]
56 { pos, shift }, sidx);
69 * @return int shifted position
71 public int shift(int pos)
73 if (shifts.size() == 0)
80 while (sidx < shifts.size()
81 && (rshift = ((int[]) shifts.elementAt(sidx++)))[0] <= pos)
93 shifts.removeAllElements();
99 * @return ShiftList with inverse shift operations
101 public ShiftList getInverse()
103 ShiftList inverse = new ShiftList();
106 for (int i = 0, j = shifts.size(); i < j; i++)
108 int[] sh = (int[]) shifts.elementAt(i);
111 inverse.shifts.addElement(new int[]
120 * parse a 1d map of position 1<i<n to L<pos[i]<N such as that returned from
124 * @return shifts from map index to mapped position
126 public static ShiftList parseMap(int[] gapMap)
128 ShiftList shiftList = null;
129 if (gapMap != null && gapMap.length > 0)
131 shiftList = new ShiftList();
132 for (int i = 0, p = 0; i < gapMap.length; p++, i++)
136 shiftList.addShift(p, gapMap[i] - p);