samtools/samtools — pull request #43 by peterjc (2013-04-19 11:12:12+00:00)
Title: Update BIN values in 'samtools depad'

By its nature, 'samtools depad' edits mapped reads, altering both the mapping position and CIGAR string. This means the mapped start and end can change, and therefore the BIN can change.

Prior to this fix the pre-editing BIN (from the padded reference) was being written to the BAM output, leading to subtle problems downstream when trying to use the depadded BAM file via the BAI index. For example, in Picard v1.89 this could trigger an java.lang.ArrayIndexOutOfBoundsException where an old BIN was outside the length of the unpadded reference sequence.

A workaround is to use 'samtools depad' with SAM output, and pipe this via 'samtools view' to convert from SAM to BAM (and thus force the recalculation of the BIN values).