MultisampleMappingReport.scala 10.5 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.{ ReportBuilderExtension, ReportSection, ReportPage, MultisampleReportBuilder }
18 19 20 21 22
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
23 24
 * Created by pjvanthof on 11/01/16.
 */
25 26 27 28 29 30 31 32 33 34
class MultisampleMappingReport(val root: Configurable) extends ReportBuilderExtension {
  def builder = MultisampleMappingReport
}

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

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

38 39
  def additionalSections: List[(String, ReportSection)] = Nil

Peter van 't Hof's avatar
Peter van 't Hof committed
40 41
  def pipelineName = "multisamplemapping"

Peter van 't Hof's avatar
Peter van 't Hof committed
42 43 44
  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))

45 46
  /** Root page for the carp report */
  def indexPage = {
Peter van 't Hof's avatar
Peter van 't Hof committed
47

48
    val krakenExecuted = summary.getSampleValues("gearskraken", "stats", "krakenreport").values.forall(_.isDefined)
Peter van 't Hof's avatar
Peter van 't Hof committed
49
    val centrifugeExecuted = summary.getSampleValues("gearscentrifuge", "stats", "centrifuge_report").values.forall(_.isDefined)
Peter van 't Hof's avatar
Peter van 't Hof committed
50
    val wgsExecuted = summary.getSampleValues("bammetrics", "stats", "wgs").values.exists(_.isDefined)
Peter van 't Hof's avatar
Peter van 't Hof committed
51
    val rnaExecuted = summary.getSampleValues("bammetrics", "stats", "rna").values.exists(_.isDefined)
Peter van 't Hof's avatar
Peter van 't Hof committed
52
    val insertsizeExecuted = summary.getSampleValues("bammetrics", "stats", "CollectInsertSizeMetrics", "metrics").values.exists(_ != Some(None))
Peter van 't Hof's avatar
Peter van 't Hof committed
53
    val mappingExecuted = summary.getLibraryValues("mapping").exists(_._2.isDefined)
Peter van 't Hof's avatar
Peter van 't Hof committed
54
    val pairedFound = !mappingExecuted || summary.getLibraryValues("mapping", "settings", "paired").exists(_._2 == Some(true))
55
    val flexiprepExecuted = summary.getLibraryValues("flexiprep")
Peter van 't Hof's avatar
Peter van 't Hof committed
56
      .exists { case ((sample, lib), value) => value.isDefined }
Peter van 't Hof's avatar
Peter van 't Hof committed
57

58 59
    ReportPage(
      List("Samples" -> generateSamplesPage(pageArgs)) ++
Peter van 't Hof's avatar
Peter van 't Hof committed
60
        (if (krakenExecuted) List("Dustbin analysis - Kraken" -> ReportPage(List(), List(
61 62
          "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
          )), Map()))
Peter van 't Hof's avatar
Peter van 't Hof committed
63 64 65 66 67
        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")
68
          )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge"))))
69 70
        else Nil) ++
        List("Reference" -> ReportPage(List(), List(
Peter van 't Hof's avatar
Peter van 't Hof committed
71
          "Reference" -> ReportSection("/nl/lumc/sasc/biopet/core/report/reference.ssp", Map("pipeline" -> pipelineName))
72 73
        ), Map()),
          "Files" -> filesPage,
74 75 76 77
          "Versions" -> ReportPage(List(), List("Executables" -> ReportSection("/nl/lumc/sasc/biopet/core/report/executables.ssp"
          )), Map())
        ),
      List(
78 79 80
        "Report" -> frontSection) ++
        additionalSections ++
        List("Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp",
81
          Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)
Peter van 't Hof's avatar
Peter van 't Hof committed
82
        ), "Mapping Quality" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/mappingQuality.ssp",
83
          Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)
Peter van 't Hof's avatar
Peter van 't Hof committed
84
        ), "Clipping" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/clipping.ssp",
85
          Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)
86
        )) ++
87
        (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
88 89
          Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)))
        else Nil) ++
Peter van 't Hof's avatar
Peter van 't Hof committed
90
        (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
91 92
          Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)))
        else Nil) ++
Peter van 't Hof's avatar
Peter van 't Hof committed
93
        (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
94 95
          Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)))
        else Nil) ++
96
        (if (flexiprepExecuted) List("QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp",
97
          Map("showPlot" -> true, "showTable" -> false)),
Peter van 't Hof's avatar
Peter van 't Hof committed
98 99
          "QC bases" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp",
            Map("showPlot" -> true, "showTable" -> false))
100 101
        )
        else Nil),
102
      pageArgs ++ Map("pipeline" -> pipelineName)
103 104 105 106
    )
  }

  /** Files page, can be used general or at sample level */
107 108
  def filesPage: ReportPage = {
    val flexiprepExecuted = summary.getLibraryValues("flexiprep")
Peter van 't Hof's avatar
Peter van 't Hof committed
109
      .exists { case ((sample, lib), value) => value.isDefined }
110 111 112 113 114 115 116 117 118

    ReportPage(List(), (if (flexiprepExecuted) List(
      "Input fastq files" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepInputfiles.ssp"),
      "After QC fastq files" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepOutputfiles.ssp"))
    else Nil) :::
      List("Bam files per lib" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/mapping/outputBamfiles.ssp", Map("sampleLevel" -> false)),
        "Preprocessed bam files" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/mapping/outputBamfiles.ssp",
          Map("pipelineName" -> pipelineName, "fileTag" -> "output_bam_preprocess"))), Map())
  }
119 120 121

  /** Single sample page */
  def samplePage(sampleId: String, args: Map[String, Any]): ReportPage = {
122
    val krakenExecuted = summary.getValue(Some(sampleId), None, "gearskraken", "stats", "krakenreport").isDefined
Peter van 't Hof's avatar
Peter van 't Hof committed
123
    val centrifugeExecuted = summary.getValue(Some(sampleId), None, "gearscentrifuge", "stats", "centrifuge_report").isDefined
124
    val flexiprepExecuted = summary.getLibraryValues("flexiprep")
Peter van 't Hof's avatar
Peter van 't Hof committed
125
      .exists { case ((sample, lib), value) => sample == sampleId && value.isDefined }
126

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

  /** Library page */
  def libraryPage(sampleId: String, libId: String, args: Map[String, Any]): ReportPage = {
153
    val krakenExecuted = summary.getValue(Some(sampleId), Some(libId), "gearskraken", "stats", "krakenreport").isDefined
Peter van 't Hof's avatar
Peter van 't Hof committed
154
    val centrifugeExecuted = summary.getValue(Some(sampleId), Some(libId), "gearscentrifuge", "stats", "centrifuge_report").isDefined
Peter van 't Hof's avatar
Peter van 't Hof committed
155
    val flexiprepExecuted = summary.getValue(Some(sampleId), Some(libId), "flexiprep").isDefined
Peter van 't Hof's avatar
Peter van 't Hof committed
156

Peter van 't Hof's avatar
Peter van 't Hof committed
157 158
    ReportPage(
      ("Alignment" -> BammetricsReport.bamMetricsPage(summary, Some(sampleId), Some(libId))) ::
159
        (if (flexiprepExecuted) List("QC" -> FlexiprepReport.flexiprepPage) else Nil) :::
Peter van 't Hof's avatar
Peter van 't Hof committed
160 161 162 163 164
        (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")
165
          )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge"))))
Peter van 't Hof's avatar
Peter van 't Hof committed
166
        else Nil) ::: (if (krakenExecuted) List("Dustbin analysis" -> ReportPage(List(), List(
Peter van 't Hof's avatar
Peter van 't Hof committed
167 168 169
          "Krona Plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
          )), Map()))
        else Nil),
170 171 172 173 174
      "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)
175 176
  }
}