@Test public void testIsInsideDeletion() { final List<CigarElement> cigarElements = Arrays.asList(new CigarElement(5, CigarOperator.S), new CigarElement(5, CigarOperator.M), new CigarElement(5, CigarOperator.EQ), new CigarElement(6, CigarOperator.N), new CigarElement(5, CigarOperator.X), new CigarElement(6, CigarOperator.D), new CigarElement(1, CigarOperator.P), new CigarElement(1, CigarOperator.H)); final Cigar cigar = new Cigar(cigarElements); for ( int i=-1; i <= 20; i++ ) { Assert.assertFalse(AlignmentUtils.isInsideDeletion(cigar, i)); } for ( int i=21; i <= 26; i++ ){ Assert.assertTrue(AlignmentUtils.isInsideDeletion(cigar, i)); } for ( int i=27; i <= 28; i++ ) { Assert.assertFalse(AlignmentUtils.isInsideDeletion(cigar, i)); } }
@Override protected Double getElementForRead(final GATKSAMRecord read, final int refLoc) { final int offset = ReadUtils.getReadCoordinateForReferenceCoordinate( read.getSoftStart(), read.getCigar(), refLoc, ReadUtils.ClippingTail.RIGHT_TAIL, true ); if ( offset == ReadUtils.CLIPPING_GOAL_NOT_REACHED ) return null; // If the offset inside a deletion, it does not lie on a read. if ( AlignmentUtils.isInsideDeletion(read.getCigar(), offset) ) { return INVALID_ELEMENT_FROM_READ; } int readPos = AlignmentUtils.calcAlignmentByteArrayOffset( read.getCigar(), offset, false, 0, 0 ); final int numAlignedBases = AlignmentUtils.getNumAlignedBasesCountingSoftClips( read ); if (readPos > numAlignedBases / 2) readPos = numAlignedBases - (readPos + 1); return (double)readPos; }
@Override protected Double getElementForRead(final GATKSAMRecord read, final int refLoc) { final int offset = ReadUtils.getReadCoordinateForReferenceCoordinate(read.getSoftStart(), read.getCigar(), refLoc, ReadUtils.ClippingTail.RIGHT_TAIL, true); if ( offset == ReadUtils.CLIPPING_GOAL_NOT_REACHED ) return null; // If the offset inside a deletion, it does not lie on a read. if ( AlignmentUtils.isInsideDeletion(read.getCigar(), offset) ) { return INVALID_ELEMENT_FROM_READ; } int readPos = AlignmentUtils.calcAlignmentByteArrayOffset(read.getCigar(), offset, false, 0, 0); final int numAlignedBases = AlignmentUtils.getNumAlignedBasesCountingSoftClips( read ); if (readPos > numAlignedBases / 2) readPos = numAlignedBases - (readPos + 1); return (double)readPos; }