public class Mapping {
/**
* Contains the
- * start-end pairs mapping from
- * the associated sequence to the
- * sequence in the database
+ * start-end pairs mapping from
+ * the associated sequence to the
+ * sequence in the database
* coordinate system
* it also takes care of step difference between coordinate systems
*/
this(to, new MapList(exon, is, i, j));
}
/**
- * create a duplicate (and independent) mapping object with
+ * create a duplicate (and independent) mapping object with
* the same reference to any SequenceI being mapped to.
* @param map2
*/
public Mapping(Mapping map2)
{
if (map2!=this && map2!=null) {
- if (map2.map!=null)
+ if (map2.map!=null)
{
map=new MapList(map2.map);
}
/**
* Equals that compares both the to references and MapList mappings.
* @param other
- * @return
+ * @return
*/
public boolean equals(Mapping other) {
if (other==null)
* @param mpos
* @return
*/
- public int getPosition(int mpos)
+ public int getPosition(int mpos)
{
if (map!=null) {
int[] mp = map.shiftTo(mpos);
if (map!=null) {
int[] mp=map.shiftTo(mpos);
if (mp!=null) {
- return new int[] {mp[0], mp[0]+mp[2]*(map.getFromRatio()-1)};
+ return new int[] {mp[0], mp[0]+mp[2]*(map.getFromRatio()-1)};
}
}
return null;
}
/**
- * width of mapped unit in associated sequence
- *
+ * width of mapped unit in associated sequence
+ *
*/
public int getWidth() {
if (map!=null) {
return null;
}
/**
- * locates the region of feature f in the associated sequence's reference frame
+ * locates the region of feature f in the associated sequence's reference frame
* @param f
* @return one or more features corresponding to f
*/
public SequenceFeature[] locateFeature(SequenceFeature f)
{
- // this is a stopgap - features broken over exon boundaries will not be
- // broken into a collection of feature fragments.
- // TODO: implement creation of several features from a single feature on a discontinuously mapped seuqence
- // need a function like int [] fromrange = map.getRange(from,to)
- // need to make subgrouped sequence features.
- if (true) {
+ if (true) { // f.getBegin()!=f.getEnd()) {
if (map!=null) {
int[] frange = map.locateInFrom(f.getBegin(), f.getEnd());
SequenceFeature[] vf = new SequenceFeature[frange.length/2];
return vf;
}
}
- if (false){
+ if (false) //else
+ {
int[] word = getWord(f.getBegin());
- if (word[0]<word[1])
+ if (word[0]<word[1])
{
f.setBegin(word[0]);
} else {
f.setBegin(word[1]);
}
word = getWord(f.getEnd());
- if (word[0]>word[1])
+ if (word[0]>word[1])
{
f.setEnd(word[0]);
} else {
// give up and just return the feature.
return new SequenceFeature[] { f };
}
-
+
/**
* return a series of contigs on the associated sequence corresponding to
* the from,to interval on the mapped reference frame
* @return
*/
public int[] locateMappedRange(int from, int to) {
- //TODO
+ //TODO
return null;
}
}
public int[] locateInFrom(int start, int end) {
// inefficient implementation
int fromStart[] = shiftTo(start);
- int fromEnd[] = shiftTo(end);
+ int fromEnd[] = shiftTo(end); // needs to be inclusive of end of symbol position
if (fromStart==null || fromEnd==null)
return null;
int iv[] = getIntervals(fromShifts, fromStart, fromEnd,fromRatio);
*/
private int[] getIntervals(Vector fromShifts2, int[] fromStart, int[] fromEnd, int fromRatio2)
{
- // correct for word direction for start and end
- int startpos = fromStart[0]+fromStart[2]*(fromRatio2-1);
- int endpos = fromEnd[0]+fromEnd[2]*(fromRatio2-1);
+ // TODO: correct for word boundary w.r.t. fromStart->fromEnd direction for startpos and endpos.
+ // test is (1,8,12,17) to (1,5) and features on to : 2,2; 3,3; 4,3; 3,4; 4,4; 5,3; 3,5; 2,4; 4,2;
+ // correct for word direction for start and end :
+ int startpos = fromStart[0]+fromStart[2]*(fromRatio2-1); // Math.min(fromStart[0], .. );
+ int endpos = fromEnd[0]+fromEnd[2]*(fromRatio2-1); // Math.max(fromEnd[0],);
int intv=0,intvSize= fromShifts2.size();
int iv[],i=0,fs=-1,fe=-1; // containing intervals
while (intv<intvSize && (fs==-1 || fe==-1)) {
return range;
}
/**
+ * get the 'initial' position of mpos in To
+ * @param mpos position in from
+ * @return position of first word in to reference frame
+ */
+public int getToPosition(int mpos)
+{
+ int[] mp = shiftTo(mpos);
+ if (mp!=null)
+ {
+ return mp[0];
+ }
+ return mpos;
+}
+/**
+ * get range of positions in To frame for the mpos word in From
+ * @param mpos position in From
+ * @return null or int[] first position in To for mpos, last position in to for Mpos
+ */
+public int[] getToWord(int mpos) {
+ int[] mp=shiftTo(mpos);
+ if (mp!=null) {
+ return new int[] {mp[0], mp[0]+mp[2]*(getFromRatio()-1)};
+ }
+ return null;
+}
+/**
+ * get From position in the associated
+ * reference frame for position pos in the
+ * associated sequence.
+ * @param pos
+ * @return
+ */
+public int getMappedPosition(int pos) {
+ int[] mp = shiftFrom(pos);
+ if (mp!=null)
+ {
+ return mp[0];
+ }
+ return pos;
+}
+public int[] getMappedWord(int pos) {
+ int[] mp = shiftFrom(pos);
+ if (mp!=null)
+ {
+ return new int[] { mp[0], mp[0]+mp[2]*(getToRatio()-1)};
+ }
+ return null;
+}
+
+ /**
* test routine. not incremental.
* @param ml
* @param fromS
System.out.print("\nTest locateInFrom\n");
{
int f=mmap[0][2],t=mmap[0][3];
- while (f<t) {
+ while (f<=t) {
System.out.println("Range "+f+" to "+t);
int rng[] = ml.locateInFrom(f,t);
if (rng!=null)
System.out.print("\nTest locateInTo\n");
{
int f=mmap[0][2],t=mmap[0][3];
- while (f<t) {
+ while (f<=t) {
System.out.println("Range "+f+" to "+t);
int rng[] = ml.locateInTo(f,t);
if (rng!=null) {