CheckChecksum.scala 1.65 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
2
3
4
5
6
7
8
9
10
/**
 * Biopet is built on top of GATK Queue for building bioinformatic
 * pipelines. It is mainly intended to support LUMC SHARK cluster which is running
 * SGE. But other types of HPC that are supported by GATK Queue (such as PBS)
 * should also be able to execute Biopet tools and pipelines.
 *
 * Copyright 2014 Sequencing Analysis Support Core - Leiden University Medical Center
 *
 * Contact us at: sasc@lumc.nl
 *
11
 * A dual licensing mode is applied. The source code within this project is freely available for non-commercial use under an AGPL
Peter van 't Hof's avatar
Peter van 't Hof committed
12
13
14
 * license; For commercial users or users who do not want to follow the AGPL
 * license, please contact us to obtain a separate license.
 */
15
package nl.lumc.sasc.biopet.core.extensions
Peter van 't Hof's avatar
Peter van 't Hof committed
16
17
18
19
20

import java.io.File

import nl.lumc.sasc.biopet.core.summary.WriteSummary
import org.broadinstitute.gatk.queue.function.InProcessFunction
Peter van 't Hof's avatar
Peter van 't Hof committed
21
import org.broadinstitute.gatk.utils.commandline.{ Argument, Input }
Peter van 't Hof's avatar
Peter van 't Hof committed
22
23
24
25
26
27

/**
 * This class checks md5sums and give an exit code 1 when md5sum is not the same
 *
 * Created by pjvanthof on 16/08/15.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
28
class CheckChecksum extends InProcessFunction {
Peter van 't Hof's avatar
Peter van 't Hof committed
29
30
31
32
  @Input(required = true)
  var inputFile: File = _

  @Input(required = true)
Peter van 't Hof's avatar
Peter van 't Hof committed
33
  var checksumFile: File = _
Peter van 't Hof's avatar
Peter van 't Hof committed
34
35

  @Argument(required = true)
Peter van 't Hof's avatar
Peter van 't Hof committed
36
  var checksum: String = _
Peter van 't Hof's avatar
Peter van 't Hof committed
37
38
39

  /** Exits whenever the input md5sum is not the same as the output md5sum */
  def run: Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
40
    val outputChecksum = WriteSummary.parseChecksum(checksumFile).toLowerCase
Peter van 't Hof's avatar
Peter van 't Hof committed
41

Peter van 't Hof's avatar
Peter van 't Hof committed
42
    if (outputChecksum != checksum.toLowerCase) {
Peter van 't Hof's avatar
Peter van 't Hof committed
43
      logger.error(s"Input file: '$inputFile' md5sum is not as expected, aborting pipeline")
Peter van 't Hof's avatar
Peter van 't Hof committed
44
45

      // 130 Simulates a ctr-C
Peter van 't Hof's avatar
Peter van 't Hof committed
46
      Runtime.getRuntime.halt(130)
Peter van 't Hof's avatar
Peter van 't Hof committed
47
48
49
    }
  }
}