2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.util;
\r
21 import jalview.datamodel.SequenceI;
\r
27 * Simple way of mapping a linear series to a new linear range with new points introduced.
\r
28 * Use at your own risk!
\r
29 * <p>Title: ShiftList</p>
\r
31 * <p>Description: </p>
\r
33 * <p>Copyright: Copyright (c) 2004</p>
\r
35 * <p>Company: Dundee University</p>
\r
37 * @author not attributable
\r
40 public class ShiftList
\r
42 public Vector shifts;
\r
45 shifts = new Vector();
\r
50 * @param pos start position for shift (in original reference frame)
\r
51 * @param shift length of shift
\r
53 public void addShift(int pos, int shift)
\r
57 while (sidx<shifts.size() && (rshift=(int[]) shifts.elementAt(sidx))[0]<pos)
\r
59 if (sidx==shifts.size())
\r
60 shifts.insertElementAt(new int[] { pos, shift}, sidx);
\r
69 * @return int shifted position
\r
71 public int shift(int pos)
\r
73 if (shifts.size()==0)
\r
78 while (sidx<shifts.size()
\r
80 (rshift=((int[]) shifts.elementAt(sidx++)))[0]<=pos) {
\r
81 shifted += rshift[1];
\r
91 shifts.removeAllElements();
\r
95 * @return ShiftList with inverse shift operations
\r
97 public ShiftList getInverse() {
\r
98 ShiftList inverse=new ShiftList();
\r
100 for (int i=0,j=shifts.size(); i<j; i++) {
\r
101 int[] sh=(int[]) shifts.elementAt(i);
\r
103 inverse.shifts.addElement(new int[] {sh[0], -sh[1]});
\r
110 * parse a 1d map of position 1<i<n to L<pos[i]<N
\r
111 * such as that returned from SequenceI.gapMap()
\r
115 public static ShiftList parseMap(int[] gapMap) {
\r
116 ShiftList shiftList = null;
\r
117 if (gapMap!=null && gapMap.length>0) {
\r
118 shiftList=new ShiftList();
\r
120 for (int i=0,p=0; i<gapMap.length; p++,i++) {
\r
121 if (p!=gapMap[i]) {
\r
122 shiftList.addShift(p, gapMap[i]-p);
\r