1 package jalview.datamodel;
\r
3 import jalview.util.MapList;
\r
5 public class Mapping {
\r
8 * start-end pairs mapping from
\r
9 * the associated sequence to the
\r
10 * sequence in the database
\r
12 * it also takes care of step difference between coordinate systems
\r
16 * The seuqence that map maps the associated seuqence to (if any).
\r
19 public Mapping(MapList map) {
\r
24 * create a new mapping from
\r
25 * @param exon int[] {start,end,start,end} series on associated sequence
\r
26 * @param is int[] {start,end,...} ranges on the reference frame being mapped to
\r
27 * @param i step size on associated sequence
\r
28 * @param j step size on mapped frame
\r
30 public Mapping(SequenceI to, int[] exon, int[] is, int i, int j)
\r
32 map = new MapList(exon, is, i, j);
\r
38 public MapList getMap() {
\r
43 * @param map the map to set
\r
45 public void setMap(MapList map) {
\r
48 public boolean equals(Mapping other) {
\r
53 if ((map!=null && other.map==null) || (map==null && other.map!=null))
\r
55 if (map.equals(other.map))
\r
60 * get the 'initial' position in the associated
\r
61 * sequence for a position in the mapped reference frame
\r
65 public int getPosition(int mpos)
\r
68 int[] mp = map.shiftTo(mpos);
\r
76 public int[] getWord(int mpos) {
\r
78 int[] mp=map.shiftTo(mpos);
\r
80 return new int[] {mp[0], mp[0]+mp[2]*(map.getFromRatio()-1)};
\r
86 * width of mapped unit in associated sequence
\r
89 public int getWidth() {
\r
91 return map.getFromRatio();
\r
97 * width of unit in mapped reference frame
\r
100 public int getMappedWidth() {
\r
102 return map.getToRatio();
\r
107 * get mapped position in the associated
\r
108 * reference frame for position pos in the
\r
109 * associated sequence.
\r
113 public int getMappedPosition(int pos) {
\r
115 int[] mp = map.shiftFrom(pos);
\r
123 public int[] getMappedWord(int pos) {
\r
125 int[] mp = map.shiftFrom(pos);
\r
128 return new int[] { mp[0], mp[0]+mp[2]*(map.getToRatio()-1)};
\r
134 * locates the region of feature f in the associated sequence's reference frame
\r
136 * @return one or more features corresponding to f
\r
138 public SequenceFeature[] locateFeature(SequenceFeature f)
\r
140 // this is a stopgap - features broken over exon boundaries will not be
\r
141 // broken into a collection of feature fragments.
\r
142 // TODO: implement creation of several features from a single feature on a discontinuously mapped seuqence
\r
143 // need a function like int [] fromrange = map.getRange(from,to)
\r
144 // need to make subgrouped sequence features.
\r
147 int[] frange = map.locateInFrom(f.getBegin(), f.getEnd());
\r
148 SequenceFeature[] vf = new SequenceFeature[frange.length/2];
\r
149 for (int i=0,v=0;i<frange.length;i+=2) {
\r
150 vf[v] = new SequenceFeature(f);
\r
151 vf[v].setBegin(frange[i]);
\r
152 vf[v].setEnd(frange[i+1]);
\r
153 if (frange.length>2)
\r
154 vf[v].setDescription(f.getDescription() +"\nPart "+v);
\r
160 int[] word = getWord(f.getBegin());
\r
161 if (word[0]<word[1])
\r
163 f.setBegin(word[0]);
\r
165 f.setBegin(word[1]);
\r
167 word = getWord(f.getEnd());
\r
168 if (word[0]>word[1])
\r
175 // give up and just return the feature.
\r
176 return new SequenceFeature[] { f };
\r
180 * return a series of contigs on the associated sequence corresponding to
\r
181 * the from,to interval on the mapped reference frame
\r
186 public int[] locateRange(int from, int to) {
\r
191 * return a series of contigs on the mapped reference frame corresponding to
\r
192 * the from,to interval on the associated sequence
\r
197 public int[] locateMappedRange(int from, int to) {
\r