X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FMapping.java;h=eb594be726254e46996edaa5e68af9b17af6adf4;hb=8f920d337154e092f5f9056ffde3cdf2735eca43;hp=559ae4cd8b05b9552fa26ca0f0da58bd00b53b85;hpb=be32c14cd8e48fe0a207cd7030cb9cd46f894678;p=jalview.git diff --git a/src/jalview/datamodel/Mapping.java b/src/jalview/datamodel/Mapping.java index 559ae4c..eb594be 100644 --- a/src/jalview/datamodel/Mapping.java +++ b/src/jalview/datamodel/Mapping.java @@ -48,6 +48,11 @@ public class Mapping private final char[] alignedSeq; /* + * the sequence start residue + */ + private int start; + + /* * Next position (base 0) in the aligned sequence */ private int alignedColumn = 0; @@ -90,13 +95,14 @@ public class Mapping /** * Constructor * - * @param cs - * the aligned sequence characters + * @param seq + * the aligned sequence * @param gapChar */ - public AlignedCodonIterator(char[] cs, char gapChar) + public AlignedCodonIterator(SequenceI seq, char gapChar) { - this.alignedSeq = cs; + this.alignedSeq = seq.getSequence(); + this.start = seq.getStart(); this.gap = gapChar; fromRanges = map.getFromRanges().iterator(); toRanges = map.getToRanges().iterator(); @@ -163,8 +169,10 @@ public class Mapping { // TODO should ideally handle toRatio other than 1 as well... // i.e. code like getNextCodon() - if (toPosition <= currentToRange[1]) { - char pep = Mapping.this.to.getSequence()[toPosition - 1]; + if (toPosition <= currentToRange[1]) + { + SequenceI seq = Mapping.this.to; + char pep = seq.getSequence()[toPosition - seq.getStart()]; toPosition++; return String.valueOf(pep); } @@ -241,8 +249,11 @@ public class Mapping */ private int getAlignedColumn(int sequencePos) { - while (alignedBases < sequencePos - && alignedColumn < alignedSeq.length) + /* + * allow for offset e.g. treat pos 8 as 2 if sequence starts at 7 + */ + int truePos = sequencePos - (start - 1); + while (alignedBases < truePos && alignedColumn < alignedSeq.length) { if (alignedSeq[alignedColumn++] != gap) { @@ -466,8 +477,7 @@ public class Mapping int[] mp = map.shiftFrom(pos); if (mp != null) { - return new int[] - { mp[0], mp[0] + mp[2] * (map.getToRatio() - 1) }; + return new int[] { mp[0], mp[0] + mp[2] * (map.getToRatio() - 1) }; } } return null; @@ -528,8 +538,7 @@ public class Mapping } } // give up and just return the feature. - return new SequenceFeature[] - { f }; + return new SequenceFeature[] { f }; } /** @@ -565,8 +574,7 @@ public class Mapping } return map.locateInFrom(from, to); } - return new int[] - { from, to }; + return new int[] { from, to }; } /** @@ -602,8 +610,7 @@ public class Mapping } return map.locateInTo(from, to); } - return new int[] - { from, to }; + return new int[] { from, to }; } /** @@ -631,13 +638,11 @@ public class Mapping { for (int m = 0; m < mpr.length; m += 2) { - toRange.addElement(new int[] - { mpr[m], mpr[m + 1] }); + toRange.addElement(new int[] { mpr[m], mpr[m + 1] }); int[] xpos = locateRange(mpr[m], mpr[m + 1]); for (int x = 0; x < xpos.length; x += 2) { - fromRange.addElement(new int[] - { xpos[x], xpos[x + 1] }); + fromRange.addElement(new int[] { xpos[x], xpos[x + 1] }); } } } @@ -663,24 +668,6 @@ public class Mapping return copy; } - public static void main(String[] args) - { - /** - * trite test of the intersectVisContigs method for a simple DNA -> Protein - * exon map and a range of visContigs - */ - MapList fk = new MapList(new int[] - { 1, 6, 8, 13, 15, 23 }, new int[] - { 1, 7 }, 3, 1); - Mapping m = new Mapping(fk); - Mapping m_1 = m.intersectVisContigs(new int[] - { fk.getFromLowest(), fk.getFromHighest() }); - Mapping m_2 = m.intersectVisContigs(new int[] - { 1, 7, 11, 20 }); - System.out.println("" + m_1.map.getFromRanges()); - - } - /** * get the sequence being mapped to - if any * @@ -706,6 +693,7 @@ public class Mapping * * @see java.lang.Object#finalize() */ + @Override protected void finalize() throws Throwable { map = null; @@ -715,7 +703,7 @@ public class Mapping public Iterator getCodonIterator(SequenceI seq, char gapChar) { - return new AlignedCodonIterator(seq.getSequence(), gapChar); + return new AlignedCodonIterator(seq, gapChar); } }