2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 import jalview.datamodel.SequenceI;
27 * Simple way of mapping a linear series to a new linear range with new points introduced.
28 * Use at your own risk!
29 * Now growing to be used for interval ranges (position, offset) storing deletions/insertions
31 public class ShiftList
36 shifts = new Vector();
41 * @param pos start position for shift (in original reference frame)
42 * @param shift length of shift
44 public void addShift(int pos, int shift)
48 while (sidx<shifts.size() && (rshift=(int[]) shifts.elementAt(sidx))[0]<pos)
50 if (sidx==shifts.size())
51 shifts.insertElementAt(new int[] { pos, shift}, sidx);
60 * @return int shifted position
62 public int shift(int pos)
69 while (sidx<shifts.size()
71 (rshift=((int[]) shifts.elementAt(sidx++)))[0]<=pos) {
82 shifts.removeAllElements();
86 * @return ShiftList with inverse shift operations
88 public ShiftList getInverse() {
89 ShiftList inverse=new ShiftList();
91 for (int i=0,j=shifts.size(); i<j; i++) {
92 int[] sh=(int[]) shifts.get(i);
94 inverse.shifts.add(new int[] {sh[0], -sh[1]});
101 * parse a 1d map of position 1<i<n to L<pos[i]<N
102 * such as that returned from SequenceI.gapMap()
104 * @return shifts from map index to mapped position
106 public static ShiftList parseMap(int[] gapMap) {
107 ShiftList shiftList = null;
108 if (gapMap!=null && gapMap.length>0) {
109 shiftList=new ShiftList();
110 for (int i=0,p=0; i<gapMap.length; p++,i++) {
112 shiftList.addShift(p, gapMap[i]-p);