Skip to content

Commit

Permalink
Validate IO in SortBam to provide nicer exceptions (#994)
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 committed Jul 15, 2024
1 parent 4b862fc commit f228b32
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 @@ -63,13 +63,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)

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()
}
}

0 comments on commit f228b32

Please sign in to comment.