2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 * ShiftList Simple way of mapping a linear series to a new linear range with
25 * new points introduced. Use at your own risk! Now growing to be used for
26 * interval ranges (position, offset) storing deletions/insertions
28 public class ShiftList
34 shifts = new Vector();
41 * start position for shift (in original reference frame)
45 public void addShift(int pos, int shift)
49 while (sidx < shifts.size()
50 && (rshift = (int[]) shifts.elementAt(sidx))[0] < pos)
54 if (sidx == shifts.size())
56 shifts.insertElementAt(new int[]
57 { pos, shift }, sidx);
70 * @return int shifted position
72 public int shift(int pos)
74 if (shifts.size() == 0)
81 while (sidx < shifts.size()
82 && (rshift = ((int[]) shifts.elementAt(sidx++)))[0] <= pos)
94 shifts.removeAllElements();
100 * @return ShiftList with inverse shift operations
102 public ShiftList getInverse()
104 ShiftList inverse = new ShiftList();
107 for (int i = 0, j = shifts.size(); i < j; i++)
109 int[] sh = (int[]) shifts.elementAt(i);
112 inverse.shifts.addElement(new int[]
121 * parse a 1d map of position 1<i<n to L<pos[i]<N such as that returned from
125 * @return shifts from map index to mapped position
127 public static ShiftList parseMap(int[] gapMap)
129 ShiftList shiftList = null;
130 if (gapMap != null && gapMap.length > 0)
132 shiftList = new ShiftList();
133 for (int i = 0, p = 0; i < gapMap.length; p++, i++)
137 shiftList.addShift(p, gapMap[i] - p);