3 import jalview.datamodel.SequenceI;
9 * Simple way of mapping a linear series to a new linear range with new points introduced.
10 * Use at your own risk!
11 * <p>Title: ShiftList</p>
13 * <p>Description: </p>
15 * <p>Copyright: Copyright (c) 2004</p>
17 * <p>Company: Dundee University</p>
19 * @author not attributable
22 public class ShiftList
27 shifts = new Vector();
32 * @param pos start position for shift (in original reference frame)
33 * @param shift length of shift
35 public void addShift(int pos, int shift)
39 while (sidx<shifts.size() && (rshift=(int[]) shifts.elementAt(sidx))[0]<pos)
41 if (sidx==shifts.size())
42 shifts.insertElementAt(new int[] { pos, shift}, sidx);
51 * @return int shifted position
53 public int shift(int pos)
60 while (sidx<shifts.size()
62 (rshift=((int[]) shifts.elementAt(sidx++)))[0]<=pos) {
73 shifts.removeAllElements();
77 * @return ShiftList with inverse shift operations
79 public ShiftList getInverse() {
80 ShiftList inverse=new ShiftList();
82 for (int i=0,j=shifts.size(); i<j; i++) {
83 int[] sh=(int[]) shifts.get(i);
85 inverse.shifts.add(new int[] {sh[0], -sh[1]});
92 * parse a 1d map of position 1<i<n to L<pos[i]<N
93 * such as that returned from SequenceI.gapMap()
97 public static ShiftList parseMap(int[] gapMap) {
98 ShiftList shiftList = null;
99 if (gapMap!=null && gapMap.length>0) {
100 shiftList=new ShiftList();
102 for (int i=0,p=0; i<gapMap.length; p++,i++) {
104 shiftList.addShift(p, gapMap[i]-p);