import java.util.List;
/**
- * MapList Simple way of bijectively mapping a non-contiguous linear range to
- * another non-contiguous linear range Use at your own risk! TODO: efficient
- * implementation of private posMap method TODO: test/ensure that sense of from
- * and to ratio start position is conserved (codon start position recovery)
- * TODO: optimize to use int[][] arrays rather than vectors.
+ * A simple way of bijectively mapping a non-contiguous linear range to another
+ * non-contiguous linear range.
+ *
+ * Use at your own risk!
+ *
+ * TODO: efficient implementation of private posMap method
+ *
+ * TODO: test/ensure that sense of from and to ratio start position is conserved
+ * (codon start position recovery)
*/
public class MapList
{
+ /*
+ * Subregions (base 1) described as { [start1, end1], [start2, end2], ...}
+ */
private List<int[]> fromShifts = new ArrayList<int[]>();
+ /*
+ * Same format as fromShifts, for the 'mapped to' sequence
+ */
private List<int[]> toShifts = new ArrayList<int[]>();
- private int fromRatio; // number of steps in fromShifts to one toRatio unit
+ /*
+ * number of steps in fromShifts to one toRatio unit
+ */
+ private int fromRatio;
- private int toRatio; // number of steps in toShifts to one fromRatio
+ /*
+ * number of steps in toShifts to one fromRatio
+ */
+ private int toRatio;
/*
* lowest and highest value in the from Map
}
/**
+ * Returns the flattened 'from' ranges as [start1, end1, start2, end2, ...]
*
- * @return series of intervals mapped in from
+ * @return
*/
public int[] getFromRanges()
{
return getRanges(fromShifts);
}
+ /**
+ * Returns the flattened 'to' ranges as [start1, end1, start2, end2, ...]
+ *
+ * @return
+ */
public int[] getToRanges()
{
return getRanges(toShifts);
return toHighest;
}
- private void ensureRange(int[] limits, int pos)
- {
- if (limits[0] > pos)
- {
- limits[0] = pos;
- }
- if (limits[1] < pos)
- {
- limits[1] = pos;
- }
- }
-
+ /**
+ * Constructor.
+ *
+ * @param from
+ * contiguous regions as [start1, end1, start2, end2, ...]
+ * @param to
+ * same format as 'from'
+ * @param fromRatio
+ * phrase length in 'from' (e.g. 3 for dna)
+ * @param toRatio
+ * phrase length in 'to' (e.g. 1 for protein)
+ */
public MapList(int from[], int to[], int fromRatio, int toRatio)
{
fromLowest = from[0];
this.toRatio = toRatio;
}
+ /**
+ * Copy constructor. Creates an identical mapping.
+ *
+ * @param map
+ */
public MapList(MapList map)
{
+ // TODO not used - remove?
this.fromLowest = map.fromLowest;
this.fromHighest = map.fromHighest;
this.toLowest = map.toLowest;
* @param toRatio
* @return
*/
- private static int[] shift(int pos, List<int[]> shiftTo, int fromRatio,
+ protected static int[] shift(int pos, List<int[]> shiftTo, int fromRatio,
List<int[]> shiftFrom, int toRatio)
{
+ // TODO: javadoc; tests
int[] fromCount = countPos(shiftTo, pos);
if (fromCount == null)
{
*/
public boolean containsEither(boolean local, MapList map)
{
+ // TODO not used - remove?
if (local)
{
return ((getFromLowest() >= map.getFromLowest() && getFromHighest() <= map