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
import nl.lumc.sasc.biopet.extensions.{ Gzip, Zcat }
Peter van 't Hof's avatar
Peter van 't Hof committed
6
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
23
  override def fixedValues = Map("centrifugekreport" -> Map("only_unique" -> false))

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

Peter van 't Hof's avatar
Peter van 't Hof committed
29
  def centrifugeOutput = new File(outputDir, s"$outputName.centrifuge.gz")
30
  def centrifugeMetOutput = new File(outputDir, s"$outputName.centrifuge.met")
Peter van 't Hof's avatar
Peter van 't Hof committed
31

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

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

    addSummaryJobs()
  }

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

    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

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

  /** Statistics shown in the summary file */
Peter van 't Hof's avatar
Peter van 't Hof committed
68
69
70
71
72
  def summaryFiles: Map[String, File] = outputFiles + ("input_R1" -> fastqR1, "centrifuge_output" -> centrifugeOutput) ++
    (fastqR2 match {
      case Some(file) => Map("input_R2" -> file)
      case _          => Map()
    })
Peter van 't Hof's avatar
Peter van 't Hof committed
73
}