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

Peter van 't Hof's avatar
Peter van 't Hof committed
3
import nl.lumc.sasc.biopet.core.{ BiopetFifoPipe, SampleLibraryTag }
Peter van 't Hof's avatar
Peter van 't Hof committed
4
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
    centrifuge.metFile = Some(centrifugeMetOutput)
    val centrifugeCmd = centrifuge | new Gzip(this) > centrifugeOutput
Peter van 't Hof's avatar
Peter van 't Hof committed
39
    centrifugeCmd.threadsCorrection = -1
40
    add(centrifugeCmd)
Peter van 't Hof's avatar
Peter van 't Hof committed
41

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

    addSummaryJobs()
  }

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

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

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

  /** 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
71
72
73
74
75
  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
76
}