Bugfix for AlignmentUtils.trimCigarByBases
-- Previous version would trim down 2M2D2M into 2M if you asked for the first 2 bases, but this can result in incorrect alignment of the bases to the reference as the bases no longer span the full reference interval expected. Fixed and added unit tests
This commit is contained in:
parent
2bcbdd469f
commit
f5a301fb63
|
|
@ -934,7 +934,7 @@ public final class AlignmentUtils {
|
|||
*/
|
||||
public static Cigar trimCigarByBases(final Cigar cigar, final int start, final int end) {
|
||||
if ( start < 0 ) throw new IllegalArgumentException("Start must be >= 0 but got " + start);
|
||||
if ( end < start ) throw new IllegalArgumentException("End " + end + " is < start start " + start);
|
||||
if ( end < start ) throw new IllegalArgumentException("End " + end + " is < start = " + start);
|
||||
if ( end > cigar.getReadLength() ) throw new IllegalArgumentException("End is beyond the cigar's read length " + end + " for cigar " + cigar );
|
||||
|
||||
final Cigar result = trimCigar(cigar, start, end, false);
|
||||
|
|
@ -962,7 +962,7 @@ public final class AlignmentUtils {
|
|||
|
||||
int pos = 0;
|
||||
for ( final CigarElement elt : cigar.getCigarElements() ) {
|
||||
if ( pos > end ) break;
|
||||
if ( pos > end && (byReference || elt.getOperator() != CigarOperator.D) ) break;
|
||||
|
||||
switch ( elt.getOperator() ) {
|
||||
case D:
|
||||
|
|
|
|||
|
|
@ -792,7 +792,8 @@ public class AlignmentUtilsUnitTest {
|
|||
tests.add(new Object[]{"2M2D2I", 3, 3, "1I"});
|
||||
tests.add(new Object[]{"2M2D2I", 2, 2, "2D1I"});
|
||||
tests.add(new Object[]{"2M2D2I", 1, 2, "1M2D1I"});
|
||||
tests.add(new Object[]{"2M2D2I", 1, 1, "1M"});
|
||||
tests.add(new Object[]{"2M2D2I", 0, 1, "2M2D"});
|
||||
tests.add(new Object[]{"2M2D2I", 1, 1, "1M2D"});
|
||||
|
||||
return tests.toArray(new Object[][]{});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue