Skip to content

Commit

Permalink
Validate IO in SortBam to provide nicer exceptions
Browse files Browse the repository at this point in the history
Using the `Io.assert*` within the constructor will yield better error messages for the user.

Also added an explicit close to the input `SamSource`
  • Loading branch information
nh13 authored May 30, 2024
1 parent d5b38ca commit adb0693
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/scala/com/fulcrumgenomics/bam/SortBam.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ class SortBam
@arg(flag='s', doc="Order into which to sort the records.") val sortOrder: SamOrder = SamOrder.Coordinate,
@arg(flag='m', doc="Max records in RAM.") val maxRecordsInRam: Int = SamWriter.DefaultMaxRecordsInRam
) extends FgBioTool with LazyLogging {

Io.assertReadable(input)
Io.assertCanWriteFile(output)

Check warning on line 64 in src/main/scala/com/fulcrumgenomics/bam/SortBam.scala

View check run for this annotation

Codecov / codecov/patch

src/main/scala/com/fulcrumgenomics/bam/SortBam.scala#L63-L64

Added lines #L63 - L64 were not covered by tests

override def execute(): Unit = {
Io.assertReadable(input)
Io.assertCanWriteFile(output)

val in = SamSource(input)
val out = SamWriter(output, in.header.clone(), sort=Some(sortOrder), maxRecordsInRam=maxRecordsInRam)
out ++= in
out.close()
in.safelyClose()

Check warning on line 71 in src/main/scala/com/fulcrumgenomics/bam/SortBam.scala

View check run for this annotation

Codecov / codecov/patch

src/main/scala/com/fulcrumgenomics/bam/SortBam.scala#L71

Added line #L71 was not covered by tests
}
}

0 comments on commit adb0693

Please sign in to comment.