GearsCentrifuge.scala 2.64 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
2
3
4
package nl.lumc.sasc.biopet.pipelines.gears

import nl.lumc.sasc.biopet.core.SampleLibraryTag
import nl.lumc.sasc.biopet.core.summary.SummaryQScript
5
6
import nl.lumc.sasc.biopet.extensions.Gzip
import nl.lumc.sasc.biopet.extensions.centrifuge.{Centrifuge, CentrifugeKreport}
Peter van 't Hof's avatar
Peter van 't Hof committed
7
8
9
10
11
import nl.lumc.sasc.biopet.extensions.tools.KrakenReportToJson
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.queue.QScript

/**
12
13
 * Created by pjvanthof on 19/09/16.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
14
15
16
17
18
19
20
21
class GearsCentrifuge(val root: Configurable) extends QScript with SummaryQScript with SampleLibraryTag {

  var fastqR1: File = _

  var fastqR2: Option[File] = None

  var outputName: String = _

22
  override def fixedValues = Map("centrifugekreport" -> Map("only_unique" -> false))
23
  override def defaults = Map("centrifugekreport" -> Map("show_zeros" -> true))
24

Peter van 't Hof's avatar
Peter van 't Hof committed
25
26
  def init(): Unit = {
    require(fastqR1 != null)
Peter van 't Hof's avatar
Peter van 't Hof committed
27
    require(outputName != null)
Peter van 't Hof's avatar
Peter van 't Hof committed
28
29
30
  }

  def biopetScript(): Unit = {
31
    val centrifugeOutput = new File(outputDir, s"$outputName.centrifuge.gz")
Peter van 't Hof's avatar
Peter van 't Hof committed
32
33
34
35
    val centrifuge = new Centrifuge(this)
    centrifuge.inputR1 = fastqR1
    centrifuge.inputR2 = fastqR2
    centrifuge.report = Some(new File(outputDir, s"$outputName.centrifuge.report"))
36
37
38
    val cmd = centrifuge | new Gzip(this) > centrifugeOutput
    cmd.threadsCorrection = -1
    add(cmd)
Peter van 't Hof's avatar
Peter van 't Hof committed
39

40
41
    makeKreport(List(centrifugeOutput), "centrifuge", unique = false)
    makeKreport(List(centrifugeOutput), "centrifuge_unique", unique = true)
42
43
44
45
46

    addSummaryJobs()
  }

  protected def makeKreport(inputFiles: List[File], name: String, unique: Boolean): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
47
    val centrifugeKreport = new CentrifugeKreport(this)
48
49
50
    centrifugeKreport.centrifugeOutputFiles = inputFiles
    centrifugeKreport.output = new File(outputDir, s"$outputName.$name.kreport")
    centrifugeKreport.onlyUnique = unique
Peter van 't Hof's avatar
Peter van 't Hof committed
51
52
53
54
    add(centrifugeKreport)

    val krakenReportJSON = new KrakenReportToJson(this)
    krakenReportJSON.inputReport = centrifugeKreport.output
55
    krakenReportJSON.output = new File(outputDir, s"$outputName.$name.krkn.json")
Peter van 't Hof's avatar
Peter van 't Hof committed
56
57
    krakenReportJSON.skipNames = config("skipNames", default = false)
    add(krakenReportJSON)
58
    addSummarizable(krakenReportJSON, s"${name}_report")
Peter van 't Hof's avatar
Peter van 't Hof committed
59
60
61
  }

  /** Location of summary file */
Peter van 't Hof's avatar
Peter van 't Hof committed
62
  def summaryFile = new File(outputDir, sampleId.getOrElse("sampleName_unknown") + ".centrifuge.summary.json")
Peter van 't Hof's avatar
Peter van 't Hof committed
63
64
65
66
67
68
69
70
71
72
73

  /** Pipeline settings shown in the summary file */
  def summarySettings: Map[String, Any] = Map()

  /** Statistics shown in the summary file */
  def summaryFiles: Map[String, File] = outputFiles + ("input_R1" -> fastqR1) ++ (fastqR2 match {
    case Some(file) => Map("input_R2" -> file)
    case _          => Map()
  })

}