Commit c3f100e5 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Adding md5sum checking

parent 6208b389
......@@ -89,7 +89,7 @@ trait BiopetQScript extends Configurable with GatkLogging {
globalConfig.writeReport(qSettings.runName, new File(outputDir, ".log/" + qSettings.runName))
else BiopetQScript.addError("Parent of output dir: '" + outputDir.getParent + "' is not writeable, outputdir can not be created")
inputFiles.foreach{ i =>
inputFiles.foreach { i =>
if (!i.file.exists()) BiopetQScript.addError(s"Input file does not exist: ${i.file}")
if (!i.file.canRead()) BiopetQScript.addError(s"Input file can not be read: ${i.file}")
}
......
......@@ -18,7 +18,7 @@ package nl.lumc.sasc.biopet.core.summary
import java.io.File
import nl.lumc.sasc.biopet.core._
import nl.lumc.sasc.biopet.extensions.Md5sum
import nl.lumc.sasc.biopet.extensions.{ CheckMd5, Md5sum }
import scala.collection.mutable
......@@ -27,7 +27,7 @@ import scala.collection.mutable
*
* Created by pjvan_thof on 2/14/15.
*/
trait SummaryQScript extends BiopetQScript {
trait SummaryQScript extends BiopetQScript { qscript =>
/** Key is sample/library, None is sample or library is not applicable */
private[summary] var summarizables: Map[(String, Option[String], Option[String]), List[Summarizable]] = Map()
......@@ -116,6 +116,20 @@ trait SummaryQScript extends BiopetQScript {
//TODO: add more checksums types
}
for (inputFile <- inputFiles) {
inputFile.md5 match {
case Some(checksum) => {
val checkMd5 = new CheckMd5
checkMd5.inputFile = inputFile.file
require(SummaryQScript.md5sumCache.contains(inputFile.file), "Md5 job is not executed, checksum file can't be found")
checkMd5.md5file = SummaryQScript.md5sumCache(inputFile.file)
checkMd5.md5sum = checksum
add(checkMd5)
}
case _ =>
}
}
for ((_, summarizableList) <- summarizables; summarizable <- summarizableList) {
summarizable match {
case f: BiopetCommandLineFunctionTrait => f.beforeGraph()
......
......@@ -153,10 +153,11 @@ class WriteSummary(val root: Configurable) extends InProcessFunction with Config
def parseFile(file: File): Map[String, Any] = {
val map: mutable.Map[String, Any] = mutable.Map()
map += "path" -> file.getAbsolutePath
if (md5sum) map += "md5" -> parseChecksum(SummaryQScript.md5sumCache(file))
if (md5sum) map += "md5" -> WriteSummary.parseChecksum(SummaryQScript.md5sumCache(file))
map.toMap
}
}
object WriteSummary {
/** Retrive checksum from file */
def parseChecksum(checksumFile: File): String = {
Source.fromFile(checksumFile).getLines().toList.head.split(" ")(0)
......
package nl.lumc.sasc.biopet.extensions
import java.io.File
import nl.lumc.sasc.biopet.core.summary.WriteSummary
import org.broadinstitute.gatk.queue.function.InProcessFunction
import org.broadinstitute.gatk.utils.commandline.{ Argument, Input }
/**
* This class checks md5sums and give an exit code 1 when md5sum is not the same
*
* Created by pjvanthof on 16/08/15.
*/
class CheckMd5 extends InProcessFunction {
@Input(required = true)
var inputFile: File = _
@Input(required = true)
var md5file: File = _
@Argument(required = true)
var md5sum: String = _
/** Exits whenever the input md5sum is not the same as the output md5sum */
def run: Unit = {
val outputMd5sum = WriteSummary.parseChecksum(md5file).toLowerCase
if (outputMd5sum != md5sum.toLowerCase) {
logger.error(s"Input file: '$inputFile' md5sum is not as expected, aborting pipeline")
System.exit(1)
}
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment