Skip to content

Commit 48b6570

Browse files
committed
fix: replace unsafe mateEnd.get with descriptive error in allele frequency calculation
The mateEnd.get call in numOverlappingTemplates would throw a bare NoSuchElementException when the BAM file lacks MC (mate CIGAR) tags. Replace with getOrElse that raises an IllegalStateException with a clear message directing users to add MC tags (e.g. via samtools fixmate). Keep checkAsPair unchanged since it does not access mateEnd.
1 parent ca7b619 commit 48b6570

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/main/scala/com/fulcrumgenomics/sv/tools/AggregateSvPileup.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,11 @@ case class AggregatedBreakpointPileup(id: String,
437437
val rec = samIter.next()
438438
if (!overlappers.contains(rec.name)) {
439439
if (checkAsPair(rec)) {
440+
val mateEnd = rec.mateEnd.getOrElse(throw new IllegalArgumentException(
441+
s"Record '${rec.name}' is paired with a mapped mate on the same contig but has no mate end position. " +
442+
"Ensure the BAM file contains the MC (mate CIGAR) tag, e.g. by running samtools fixmate."))
440443
if (breakends.positions.exists(
441-
pos => pos >= Math.min(rec.start, rec.mateStart) && pos <= Math.max(rec.end, rec.mateEnd.get))) {
444+
pos => pos >= Math.min(rec.start, rec.mateStart) && pos <= Math.max(rec.end, mateEnd))) {
442445
overlappers.add(rec.name)
443446
}
444447
} else if (breakends.positions.exists(pos => pos >= rec.start && pos <= rec.end)) {

0 commit comments

Comments
 (0)