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);
102 public int[] getWord(int mpos) {
104 int[] mp=map.shiftTo(mpos);
106 return new int[] {mp[0], mp[0]+mp[2]*(map.getFromRatio()-1)};
112 * width of mapped unit in associated sequence
115 public int getWidth() {
117 return map.getFromRatio();
123 * width of unit in mapped reference frame
126 public int getMappedWidth() {
128 return map.getToRatio();
133 * get mapped position in the associated
134 * reference frame for position pos in the
135 * associated sequence.
139 public int getMappedPosition(int pos) {
141 int[] mp = map.shiftFrom(pos);
149 public int[] getMappedWord(int pos) {
151 int[] mp = map.shiftFrom(pos);
154 return new int[] { mp[0], mp[0]+mp[2]*(map.getToRatio()-1)};
160 * locates the region of feature f in the associated sequence's reference frame
162 * @return one or more features corresponding to f
164 public SequenceFeature[] locateFeature(SequenceFeature f)
166 // this is a stopgap - features broken over exon boundaries will not be
167 // broken into a collection of feature fragments.
168 // TODO: implement creation of several features from a single feature on a discontinuously mapped seuqence
169 // need a function like int [] fromrange = map.getRange(from,to)
170 // need to make subgrouped sequence features.
173 int[] frange = map.locateInFrom(f.getBegin(), f.getEnd());
174 SequenceFeature[] vf = new SequenceFeature[frange.length/2];
175 for (int i=0,v=0;i<frange.length;i+=2) {
176 vf[v] = new SequenceFeature(f);
177 vf[v].setBegin(frange[i]);
178 vf[v].setEnd(frange[i+1]);
180 vf[v].setDescription(f.getDescription() +"\nPart "+v);
186 int[] word = getWord(f.getBegin());
193 word = getWord(f.getEnd());
201 // give up and just return the feature.
202 return new SequenceFeature[] { f };
206 * return a series of contigs on the associated sequence corresponding to
207 * the from,to interval on the mapped reference frame
212 public int[] locateRange(int from, int to) {
217 * return a series of contigs on the mapped reference frame corresponding to
218 * the from,to interval on the associated sequence
223 public int[] locateMappedRange(int from, int to) {