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