GearsCentrifuge.scala 2.51 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
2
3
4
5
6
7
8
9
10
package nl.lumc.sasc.biopet.pipelines.gears

import nl.lumc.sasc.biopet.core.SampleLibraryTag
import nl.lumc.sasc.biopet.core.summary.SummaryQScript
import nl.lumc.sasc.biopet.extensions.centrifuge.{ Centrifuge, CentrifugeKreport }
import nl.lumc.sasc.biopet.extensions.tools.KrakenReportToJson
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.queue.QScript

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

  var fastqR1: File = _

  var fastqR2: Option[File] = None

  var outputName: String = _

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

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
29
30
31
32
33
34
35
36
  }

  def biopetScript(): Unit = {
    val centrifuge = new Centrifuge(this)
    centrifuge.inputR1 = fastqR1
    centrifuge.inputR2 = fastqR2
    centrifuge.output = new File(outputDir, s"$outputName.centrifuge")
    centrifuge.report = Some(new File(outputDir, s"$outputName.centrifuge.report"))
    add(centrifuge)

37
38
39
40
41
42
43
    makeKreport(List(centrifuge.output), "centrifuge", unique = false)
    makeKreport(List(centrifuge.output), "centrifuge_unique", unique = true)

    addSummaryJobs()
  }

  protected def makeKreport(inputFiles: List[File], name: String, unique: Boolean): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
44
    val centrifugeKreport = new CentrifugeKreport(this)
45
46
47
    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
48
49
50
51
    add(centrifugeKreport)

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

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

  /** 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()
  })

}