1 package jalview.datamodel;
3 import jalview.util.MapList;
8 * start-end pairs mapping from
9 * the associated sequence to the
10 * sequence in the database
12 * it also takes care of step difference between coordinate systems
16 * The seuqence that map maps the associated seuqence to (if any).
19 public Mapping(MapList map) {
23 public Mapping(SequenceI to, MapList map) {
28 * create a new mapping from
29 * @param to the sequence being mapped
30 * @param exon int[] {start,end,start,end} series on associated sequence
31 * @param is int[] {start,end,...} ranges on the reference frame being mapped to
32 * @param i step size on associated sequence
33 * @param j step size on mapped frame
35 public Mapping(SequenceI to, int[] exon, int[] is, int i, int j)
37 this(to, new MapList(exon, is, i, j));
40 * create a duplicate (and independent) mapping object with
41 * the same reference to any SequenceI being mapped to.
44 public Mapping(Mapping map2)
46 if (map2!=this && map2!=null) {
49 map=new MapList(map2.map);
57 public MapList getMap() {
62 * @param map the map to set
64 public void setMap(MapList map) {
68 * Equals that compares both the to references and MapList mappings.
72 public boolean equals(Mapping other) {
79 if ((map!=null && other.map==null) || (map==null && other.map!=null))
81 if (map.equals(other.map))
86 * get the 'initial' position in the associated
87 * sequence for a position in the mapped reference frame
91 public int getPosition(int mpos)
94 int[] mp = map.shiftTo(mpos);
103 * gets boundary in direction of mapping
104 * @param position in mapped reference frame
105 * @return int{start, end} positions in associated sequence (in direction of mapped word)
107 public int[] getWord(int mpos) {
109 return map.getToWord(mpos);
114 * width of mapped unit in associated sequence
117 public int getWidth() {
119 return map.getFromRatio();
125 * width of unit in mapped reference frame
128 public int getMappedWidth() {
130 return map.getToRatio();
135 * get mapped position in the associated
136 * reference frame for position pos in the
137 * associated sequence.
141 public int getMappedPosition(int pos) {
143 int[] mp = map.shiftFrom(pos);
151 public int[] getMappedWord(int pos) {
153 int[] mp = map.shiftFrom(pos);
156 return new int[] { mp[0], mp[0]+mp[2]*(map.getToRatio()-1)};
162 * locates the region of feature f in the associated sequence's reference frame
164 * @return one or more features corresponding to f
166 public SequenceFeature[] locateFeature(SequenceFeature f)
168 if (true) { // f.getBegin()!=f.getEnd()) {
170 int[] frange = map.locateInFrom(f.getBegin(), f.getEnd());
171 SequenceFeature[] vf = new SequenceFeature[frange.length/2];
172 for (int i=0,v=0;i<frange.length;i+=2,v++) {
173 vf[v] = new SequenceFeature(f);
174 vf[v].setBegin(frange[i]);
175 vf[v].setEnd(frange[i+1]);
177 vf[v].setDescription(f.getDescription() +"\nPart "+v);
184 int[] word = getWord(f.getBegin());
191 word = getWord(f.getEnd());
199 // give up and just return the feature.
200 return new SequenceFeature[] { f };
204 * return a series of contigs on the associated sequence corresponding to
205 * the from,to interval on the mapped reference frame
210 public int[] locateRange(int from, int to) {
215 * return a series of contigs on the mapped reference frame corresponding to
216 * the from,to interval on the associated sequence
221 public int[] locateMappedRange(int from, int to) {