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