diff --git a/src/main/scala/com/fulcrumgenomics/bam/SortBam.scala b/src/main/scala/com/fulcrumgenomics/bam/SortBam.scala index ad5d63212..e3118956c 100644 --- a/src/main/scala/com/fulcrumgenomics/bam/SortBam.scala +++ b/src/main/scala/com/fulcrumgenomics/bam/SortBam.scala @@ -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() } }