private final char[] alignedSeq;
/*
+ * the sequence start residue
+ */
+ private int start;
+
+ /*
* Next position (base 0) in the aligned sequence
*/
private int alignedColumn = 0;
/**
* 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();
// 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);
}
*/
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)
public Iterator<AlignedCodon> getCodonIterator(SequenceI seq, char gapChar)
{
- return new AlignedCodonIterator(seq.getSequence(), gapChar);
+ return new AlignedCodonIterator(seq, gapChar);
}
}