X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FMapping.java;h=06e224387b3c784360c365602489acf56371f26f;hb=1e085f14ae2f19adfac0153c437ee891f0ad07bc;hp=1272538fb41432cf9599a93b22a09f9b81f9e7fd;hpb=4d7f98a6dd54d9863ba449ec79dcd95d25ed863d;p=jalview.git diff --git a/src/jalview/datamodel/Mapping.java b/src/jalview/datamodel/Mapping.java index 1272538..06e2243 100644 --- a/src/jalview/datamodel/Mapping.java +++ b/src/jalview/datamodel/Mapping.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9) + * Copyright (C) 2015 The Jalview Authors * * This file is part of Jalview. * @@ -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(); @@ -165,7 +171,8 @@ public class Mapping // i.e. code like getNextCodon() if (toPosition <= currentToRange[1]) { - char pep = Mapping.this.to.getSequence()[toPosition - 1]; + SequenceI seq = Mapping.this.to; + char pep = seq.getSequence()[toPosition - seq.getStart()]; toPosition++; return String.valueOf(pep); } @@ -242,7 +249,11 @@ public class Mapping */ private int getAlignedColumn(int sequencePos) { - while (alignedBases < sequencePos + /* + * 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) @@ -692,7 +703,7 @@ public class Mapping public Iterator getCodonIterator(SequenceI seq, char gapChar) { - return new AlignedCodonIterator(seq.getSequence(), gapChar); + return new AlignedCodonIterator(seq, gapChar); } }