int i = 0;
int j = 0;
final int offset = getAlignmentStart2wrt1();
Cigar cigar = getCigar();
if ( overhang_strategy != OVERHANG_STRATEGY.SOFTCLIP ) {
// we need to go through all the hassle below only if we do not do softclipping;
// otherwise offset is never negative
if ( offset < 0 ) {
for ( ; j < (-offset) ; j++ ) {
bread.append((char)read[j]);
bref.append(' ');
match.append(' ');
}
// at negative offsets, our cigar's first element carries overhanging bases
// that we have just printed above. Tweak the first element to
// exclude those bases. Here we create a new list of cigar elements, so the original
// list/original cigar are unchanged (they are unmodifiable anyway!)
List<CigarElement> tweaked = new ArrayList<CigarElement>();
tweaked.addAll(cigar.getCigarElements());
tweaked.set(0,new CigarElement(cigar.getCigarElement(0).getLength()+offset,
cigar.getCigarElement(0).getOperator()));
cigar = new Cigar(tweaked);
}
}
if ( offset > 0 ) { // note: the way this implementation works, cigar will ever start from S *only* if read starts before the ref, i.e. offset = 0
for ( ; i < getAlignmentStart2wrt1() ; i++ ) {
bref.append((char)ref[i]);
bread.append(' ');
match.append(' ');
}
}
for ( CigarElement e : cigar.getCigarElements() ) {
switch (e.getOperator()) {
case M :
for ( int z = 0 ; z < e.getLength() ; z++, i++, j++ ) {
bref.append((i<ref.length)?(char)ref[i]:' ');
bread.append((j < read.length)?(char)read[j]:' ');