MultisampleMappingReport.scala 11.2 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 16
package nl.lumc.sasc.biopet.pipelines.mapping

Peter van 't Hof's avatar
Peter van 't Hof committed
17
import nl.lumc.sasc.biopet.core.report.{ MultisampleReportBuilder, ReportBuilderExtension, ReportPage, ReportSection }
18 19 20 21
import nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport
import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport
import nl.lumc.sasc.biopet.utils.config.Configurable

Peter van 't Hof's avatar
Peter van 't Hof committed
22 23
import scala.concurrent.Await
import scala.concurrent.duration.Duration
Peter van 't Hof's avatar
Peter van 't Hof committed
24 25
import scalaz._
import Scalaz._
Peter van 't Hof's avatar
Peter van 't Hof committed
26

27
/**
Peter van 't Hof's avatar
Peter van 't Hof committed
28 29
 * Created by pjvanthof on 11/01/16.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
30
class MultisampleMappingReport(val parent: Configurable) extends ReportBuilderExtension {
31 32 33 34 35 36 37 38 39
  def builder = MultisampleMappingReport
}

object MultisampleMappingReport extends MultisampleMappingReportTrait {
  /** Name of the report */
  def reportName = "Mapping Report"
}

trait MultisampleMappingReportTrait extends MultisampleReportBuilder {
40
  /** Front section for the report */
Peter van 't Hof's avatar
Peter van 't Hof committed
41
  def frontSection: ReportSection = ReportSection("/nl/lumc/sasc/biopet/pipelines/mapping/multisampleMappingFront.ssp")
42

43 44
  def additionalSections: List[(String, ReportSection)] = Nil

Peter van 't Hof's avatar
Peter van 't Hof committed
45 46
  def pipelineName = "multisamplemapping"

Peter van 't Hof's avatar
Peter van 't Hof committed
47 48 49
  override def extFiles = super.extFiles ++ List("js/gears.js", "js/krona-2.0.js", "img/krona/loading.gif", "img/krona/hidden.png", "img/krona/favicon.ico")
    .map(x => ExtFile("/nl/lumc/sasc/biopet/pipelines/gears/report/ext/" + x, x))

50 51
  /** Root page for the carp report */
  def indexPage = {
Peter van 't Hof's avatar
Peter van 't Hof committed
52

Peter van 't Hof's avatar
Peter van 't Hof committed
53
    val krakenExecuted = Await.result(summary.getStatsSize(runId, Some("gearskraken".right), Some(Some("krakenreport".right)),
Peter van 't Hof's avatar
Peter van 't Hof committed
54
      library = Some(None), mustHaveSample = true), Duration.Inf) >= 1
Peter van 't Hof's avatar
Peter van 't Hof committed
55
    val centrifugeExecuted = Await.result(summary.getStatsSize(runId, Some("gearscentrifuge".right), Some(Some("centrifuge_report".right)),
Peter van 't Hof's avatar
Peter van 't Hof committed
56
      library = Some(None), mustHaveSample = true), Duration.Inf) >= 1
Peter van 't Hof's avatar
Peter van 't Hof committed
57
    val wgsExecuted = Await.result(summary.getStatsSize(runId, Some("bammetrics".right), Some(Some("wgs".right)),
Peter van 't Hof's avatar
Peter van 't Hof committed
58
      library = Some(None), mustHaveSample = true), Duration.Inf) >= 1
Peter van 't Hof's avatar
Peter van 't Hof committed
59
    val rnaExecuted = Await.result(summary.getStatsSize(runId, Some("bammetrics".right), Some(Some("rna".right)),
Peter van 't Hof's avatar
Peter van 't Hof committed
60
      library = Some(None), mustHaveSample = true), Duration.Inf) >= 1
Peter van 't Hof's avatar
Peter van 't Hof committed
61
    val insertsizeExecuted = Await.result(summary.getStatsSize(runId, Some("bammetrics".right), Some(Some("CollectInsertSizeMetrics".right)),
Peter van 't Hof's avatar
Peter van 't Hof committed
62
      library = Some(None), mustHaveSample = true), Duration.Inf) >= 1
Peter van 't Hof's avatar
Peter van 't Hof committed
63 64
    val mappingExecuted = Await.result(summary.getStatsSize(runId, Some("mapping".right), Some(None), mustHaveLibrary = true), Duration.Inf) >= 1
    val mappingSettings = summary.getSettingsForLibraries(runId, "mapping".right, None, keyValues = Map("paired" -> List("paired")))
Peter van 't Hof's avatar
Peter van 't Hof committed
65
    val pairedFound = !mappingExecuted || mappingSettings.exists(_._2.exists(_._2 == Option(true)))
Peter van 't Hof's avatar
Peter van 't Hof committed
66
    val flexiprepExecuted = Await.result(summary.getStatsSize(runId, Some("flexiprep".right), mustHaveLibrary = true), Duration.Inf) >= 1
Peter van 't Hof's avatar
Peter van 't Hof committed
67

68 69
    ReportPage(
      List("Samples" -> generateSamplesPage(pageArgs)) ++
Peter van 't Hof's avatar
Peter van 't Hof committed
70
        (if (krakenExecuted) List("Dustbin analysis - Kraken" -> ReportPage(List(), List(
71 72
          "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
          )), Map()))
Peter van 't Hof's avatar
Peter van 't Hof committed
73 74 75 76 77
        else Nil) ++ (if (centrifugeExecuted) List("Centriguge analysis" -> ReportPage(List("Non-unique" -> ReportPage(List(), List("All mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
          Map("summaryStatsTag" -> "centrifuge_report")
        )), Map())), List(
          "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
            Map("summaryStatsTag" -> "centrifuge_unique_report")
78
          )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge"))))
79 80
        else Nil) ++
        List("Reference" -> ReportPage(List(), List(
Peter van 't Hof's avatar
Peter van 't Hof committed
81
          "Reference" -> ReportSection("/nl/lumc/sasc/biopet/core/report/reference.ssp", Map("pipeline" -> pipelineName))
82
        ), Map()),
Peter van 't Hof's avatar
Peter van 't Hof committed
83
          "Files" -> filesPage(),
84 85 86 87
          "Versions" -> ReportPage(List(), List("Executables" -> ReportSection("/nl/lumc/sasc/biopet/core/report/executables.ssp"
          )), Map())
        ),
      List(
88 89 90
        "Report" -> frontSection) ++
        additionalSections ++
        List("Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp",
91
          Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)
Peter van 't Hof's avatar
Peter van 't Hof committed
92
        ), "Mapping Quality" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/mappingQuality.ssp",
93
          Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)
Peter van 't Hof's avatar
Peter van 't Hof committed
94
        ), "Clipping" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/clipping.ssp",
95
          Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)
96
        )) ++
97
        (if (pairedFound && insertsizeExecuted) List("Insert Size" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp",
Peter van 't Hof's avatar
Peter van 't Hof committed
98 99
          Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)))
        else Nil) ++
Peter van 't Hof's avatar
Peter van 't Hof committed
100
        (if (wgsExecuted) List("Whole genome coverage" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/wgsHistogram.ssp",
Peter van 't Hof's avatar
Peter van 't Hof committed
101 102
          Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)))
        else Nil) ++
Peter van 't Hof's avatar
Peter van 't Hof committed
103
        (if (rnaExecuted) List("Rna coverage" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/rnaHistogram.ssp",
Peter van 't Hof's avatar
Peter van 't Hof committed
104 105
          Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)))
        else Nil) ++
106
        (if (flexiprepExecuted) List("QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp",
107
          Map("showPlot" -> true, "showTable" -> false)),
Peter van 't Hof's avatar
Peter van 't Hof committed
108 109
          "QC bases" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp",
            Map("showPlot" -> true, "showTable" -> false))
110 111
        )
        else Nil),
112
      pageArgs ++ Map("pipeline" -> pipelineName)
113 114 115 116
    )
  }

  /** Files page, can be used general or at sample level */
Peter van 't Hof's avatar
Peter van 't Hof committed
117
  def filesPage(sampleId: Option[Int] = None, libraryId: Option[Int] = None): ReportPage = {
Peter van 't Hof's avatar
Peter van 't Hof committed
118
    val flexiprepExecuted = Await.result(summary.getStatsSize(runId, Some("flexiprep".right), Some(None), mustHaveLibrary = true), Duration.Inf) >= 1
119

Peter van 't Hof's avatar
Peter van 't Hof committed
120
    ReportPage(List(), Nil, Map())
121
  }
122 123

  /** Single sample page */
Peter van 't Hof's avatar
Peter van 't Hof committed
124
  def samplePage(sampleId: Int, args: Map[String, Any]): ReportPage = {
Peter van 't Hof's avatar
Peter van 't Hof committed
125 126 127 128 129 130
    val krakenExecuted = Await.result(summary.getStatsSize(runId, Some("gearskraken".right), Some(Some("krakenreport".right)),
      library = Some(None), sample = Some(Some(sampleId.left))), Duration.Inf) >= 1
    val centrifugeExecuted = Await.result(summary.getStatsSize(runId, Some("gearscentrifuge".right), Some(Some("centrifuge_report".right)),
      library = Some(None), sample = Some(Some(sampleId.left)), mustHaveSample = true), Duration.Inf) >= 1
    val flexiprepExecuted = Await.result(summary.getStatsSize(runId, Some("flexiprep".right),
      sample = Some(Some(sampleId.left)), mustHaveLibrary = true), Duration.Inf) >= 1
131

132 133
    ReportPage(List(
      "Libraries" -> generateLibraryPage(args),
134
      "Alignment" -> BammetricsReport.bamMetricsPage(summary, Some(sampleId), None)) ++
Peter van 't Hof's avatar
Peter van 't Hof committed
135
      (if (centrifugeExecuted) List("Centriguge analysis" -> ReportPage(List("Non-unique" -> ReportPage(List(), List("All mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
136
        Map("summaryStatsTag" -> "centrifuge_report", "centrifugeTag" -> Some("centrifuge"))
Peter van 't Hof's avatar
Peter van 't Hof committed
137 138 139 140 141
      )), Map())), List(
        "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
          Map("summaryStatsTag" -> "centrifuge_unique_report")
        )), Map("summaryModuleTag" -> "gearscentrifuge")))
      else Nil) ::: (if (krakenExecuted) List("Dustbin analysis" -> ReportPage(List(), List(
Peter van 't Hof's avatar
Peter van 't Hof committed
142
        "Krona Plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
143 144
        )), Map()))
      else Nil) ++
Peter van 't Hof's avatar
Peter van 't Hof committed
145
      List("Files" -> filesPage()
Peter van 't Hof's avatar
Peter van 't Hof committed
146
      ), List(
147
      "Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp",
148
        Map("showPlot" -> true)),
149
      "Preprocessing" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp", Map("sampleLevel" -> true))) ++
150
      (if (flexiprepExecuted) List("QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp"),
151
        "QC bases" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp")
152 153
      )
      else Nil), args)
154 155 156
  }

  /** Library page */
Peter van 't Hof's avatar
Peter van 't Hof committed
157
  def libraryPage(sampleId: Int, libId: Int, args: Map[String, Any]): ReportPage = {
Peter van 't Hof's avatar
Peter van 't Hof committed
158 159 160 161 162 163
    val krakenExecuted = Await.result(summary.getStatsSize(runId, Some("gearskraken".right), Some(Some("krakenreport".right)),
      library = Some(Some(libId.left)), sample = Some(Some(sampleId.left))), Duration.Inf) >= 1
    val centrifugeExecuted = Await.result(summary.getStatsSize(runId, Some("gearscentrifuge".right), Some(Some("centrifuge_report".right)),
      library = Some(Some(libId.left)), sample = Some(Some(sampleId.left)), mustHaveSample = true), Duration.Inf) >= 1
    val flexiprepExecuted = Await.result(summary.getStatsSize(runId, Some("flexiprep".right), library = Some(Some(libId.left)),
      sample = Some(Some(sampleId.left)), mustHaveLibrary = true), Duration.Inf) >= 1
Peter van 't Hof's avatar
Peter van 't Hof committed
164

Peter van 't Hof's avatar
Peter van 't Hof committed
165 166
    ReportPage(
      ("Alignment" -> BammetricsReport.bamMetricsPage(summary, Some(sampleId), Some(libId))) ::
167
        (if (flexiprepExecuted) List("QC" -> FlexiprepReport.flexiprepPage) else Nil) :::
Peter van 't Hof's avatar
Peter van 't Hof committed
168 169 170 171 172
        (if (centrifugeExecuted) List("Centriguge analysis" -> ReportPage(List("Non-unique" -> ReportPage(List(), List("All mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
          Map("summaryStatsTag" -> "centrifuge_report")
        )), Map())), List(
          "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
            Map("summaryStatsTag" -> "centrifuge_unique_report")
173
          )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge"))))
Peter van 't Hof's avatar
Peter van 't Hof committed
174
        else Nil) ::: (if (krakenExecuted) List("Dustbin analysis" -> ReportPage(List(), List(
Peter van 't Hof's avatar
Peter van 't Hof committed
175 176 177
          "Krona Plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
          )), Map()))
        else Nil),
178 179 180 181 182
      "Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp") ::
        (if (flexiprepExecuted) List("QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp"),
          "QC bases" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp"))
        else Nil),
      args)
183 184
  }
}