GearsReport.scala 9.81 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.gears

Peter van 't Hof's avatar
Peter van 't Hof committed
17
18
import java.io.File

Peter van 't Hof's avatar
Peter van 't Hof committed
19
import nl.lumc.sasc.biopet.core.report.{ MultisampleReportBuilder, ReportBuilderExtension, ReportPage, ReportSection }
20
import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport
21
import nl.lumc.sasc.biopet.utils.config.Configurable
Peter van 't Hof's avatar
Peter van 't Hof committed
22
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb.Implicts._
Peter van 't Hof's avatar
Peter van 't Hof committed
23
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb.{ NoLibrary, NoModule, SampleId }
24

Peter van 't Hof's avatar
Peter van 't Hof committed
25
import scala.concurrent.{ Await, Future }
26
27
import scala.concurrent.duration.Duration

28
/**
Peter van 't Hof's avatar
Peter van 't Hof committed
29
30
 * Report for Gears
 *
31
32
 * Created by pjvan_thof on 12/10/15.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
33
class GearsReport(val parent: Configurable) extends ReportBuilderExtension {
34
35
36
37
38
  def builder = GearsReport
}

object GearsReport extends MultisampleReportBuilder {

39
40
  def pipelineName = "gears"

41
42
  def reportName = "Gears Report"

Peter van 't Hof's avatar
Peter van 't Hof committed
43
  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")
44
45
    .map(x => ExtFile("/nl/lumc/sasc/biopet/pipelines/gears/report/ext/" + x, x))

Peter van 't Hof's avatar
Peter van 't Hof committed
46
  def indexPage: Future[ReportPage] = Future {
Peter van 't Hof's avatar
Peter van 't Hof committed
47
48
    val run = Await.result(summary.getRuns(runId).map(_.head), Duration.Inf)

Peter van 't Hof's avatar
Peter van 't Hof committed
49
50
51
52
    val krakenExecuted = summary.getStatsSize(runId = runId, pipeline = "gearskraken", module = "krakenreport", library = NoLibrary, mustHaveSample = true) >= samples.size
    val centrifugeExecuted = summary.getStatsSize(runId, "gearscentrifuge", "centrifuge_report", library = NoLibrary, mustHaveSample = true) >= samples.size
    val qiimeClosesOtuTable = summary.getFile(runId, "gears", key = "qiime_closed_otu_table")
    val qiimeOpenOtuTable = summary.getFile(runId, "gears", key = "qiime_open_otu_table")
53

54
55
    val centrifugePage = (if (centrifugeExecuted) Some("Centriguge analysis" -> Future.successful(ReportPage(List("Non-unique" ->
      Future.successful(ReportPage(List(), List("All mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
56
57
58
59
60
61
62
        Map("summaryStatsTag" -> "centrifuge_report")
      )), Map()))), List(
      "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
        Map("summaryStatsTag" -> "centrifuge_unique_report")
      )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge")))))
    else None)

63
64
    val krakenPage = (if (krakenExecuted) Some("Kraken analysis" -> Future.successful(ReportPage(List(), List(
      "Krona plot" -> Future.successful(ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
65
66
67
      ))), Map())))
    else None)

68
69
    val qiimeClosedPage = (if (qiimeClosesOtuTable.isDefined) Some("Qiime closed reference analysis" -> Future.successful(ReportPage(List(), List(
      "Krona plot" -> Future.successful(ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/qiimeKrona.ssp"
70
71
72
      ))), Map("biomFile" -> new File(run.outputDir + File.separator + qiimeClosesOtuTable.get.path)))))
    else None)

73
    val qiimeOpenPage = (if (qiimeOpenOtuTable.isDefined) Some("Qiime open reference analysis" -> Future.successful(ReportPage(List(), List(
74
75
76
77
      "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/qiimeKrona.ssp"
      )), Map("biomFile" -> new File(run.outputDir + File.separator + qiimeOpenOtuTable.get.path)))))
    else None)

78
    ReportPage(
79
80
      List(centrifugePage, krakenPage, qiimeClosedPage, qiimeOpenPage).flatten ::: List(
        "Samples" -> generateSamplesPage(pageArgs)
Peter van 't Hof's avatar
Peter van 't Hof committed
81
      ),
82
83
84
85
86
87
88
89
90
91
92
93
94
      List(
        "Report" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/gearsFront.ssp")) ++
        List(
          "QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp",
            Map("showPlot" -> true, "showTable" -> false)),
          "QC bases" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp",
            Map("showPlot" -> true, "showTable" -> false))
        ),
      pageArgs
    )
  }

  /** Single sample page */
Peter van 't Hof's avatar
Peter van 't Hof committed
95
  def samplePage(sampleId: Int, args: Map[String, Any]): Future[ReportPage] = Future {
Peter van 't Hof's avatar
Peter van 't Hof committed
96
    val run = Await.result(summary.getRuns(runId).map(_.head), Duration.Inf)
Peter van 't Hof's avatar
Peter van 't Hof committed
97
98
    val krakenExecuted = Await.result(summary.getStatsSize(runId, "gearskraken", "krakenreport", sample = sampleId, library = NoLibrary), Duration.Inf) == 1
    val centrifugeExecuted = Await.result(summary.getStatsSize(runId, "gearscentrifuge", "centrifuge_report", sample = sampleId, library = None), Duration.Inf) == 1
99
100
    val qiimeClosesOtuTable = Await.result(summary.getFile(runId, "gearssingle", NoModule, sampleId, NoLibrary, "qiime_closed_otu_table"), Duration.Inf)
    val qiimeOpenOtuTable = Await.result(summary.getFile(runId, "gearssingle", NoModule, sampleId, NoLibrary, "qiime_open_otu_table"), Duration.Inf)
101

102
103
    ReportPage((if (centrifugeExecuted) List("Centriguge analysis" -> Future.successful(ReportPage(List(
      "Non-unique" -> Future.successful(ReportPage(List(), List("All mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
Peter van 't Hof's avatar
Peter van 't Hof committed
104
105
        Map("summaryStatsTag" -> "centrifuge_report")
      )), Map()))), List(
106
107
      "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
        Map("summaryStatsTag" -> "centrifuge_unique_report")
Peter van 't Hof's avatar
Peter van 't Hof committed
108
      )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge")))))
109
    else Nil) ::: (if (krakenExecuted) List("Kraken analysis" -> Future.successful(ReportPage(List(), List(
Peter van 't Hof's avatar
Peter van 't Hof committed
110
      "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
Peter van 't Hof's avatar
Peter van 't Hof committed
111
      )), Map())))
112
    else Nil) ::: (if (qiimeClosesOtuTable.isDefined) List("Qiime closed reference analysis" -> Future.successful(ReportPage(List(), List(
113
      "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/qiimeKrona.ssp"
Peter van 't Hof's avatar
Peter van 't Hof committed
114
      )), Map("biomFile" -> new File(run.outputDir + File.separator + qiimeClosesOtuTable.get.path)))))
115
    else Nil) ::: (if (qiimeOpenOtuTable.isDefined) List("Qiime open reference analysis" -> Future.successful(ReportPage(List(), List(
116
      "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/qiimeKrona.ssp"
Peter van 't Hof's avatar
Peter van 't Hof committed
117
      )), Map("biomFile" -> new File(run.outputDir + File.separator + qiimeOpenOtuTable.get.path)))))
118
    else Nil) ::: List(
119
120
121
122
123
124
125
      "Libraries" -> generateLibraryPage(args)
    ), List("QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp"),
      "QC bases" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp")
    ), args)
  }

  /** Library page */
Peter van 't Hof's avatar
Peter van 't Hof committed
126
  def libraryPage(sampleId: Int, libId: Int, args: Map[String, Any]): Future[ReportPage] = Future {
127
128
129
    val sName = Await.result(summary.getSampleName(sampleId), Duration.Inf)
    val lName = Await.result(summary.getLibraryName(libId), Duration.Inf)

Peter van 't Hof's avatar
Peter van 't Hof committed
130
    val flexiprepExecuted = Await.result(summary.getStatsSize(runId, "flexiprep", sample = sampleId, library = libId), Duration.Inf) >= 1
131

Peter van 't Hof's avatar
Peter van 't Hof committed
132
133
134
135
    val krakenExecuted = Await.result(summary.getStatsSize(runId, "gearskraken", "krakenreport", sample = sampleId, library = libId), Duration.Inf) == 1
    val centrifugeExecuted = Await.result(summary.getStatsSize(runId, "gearscentrifuge", "centrifuge_report", sample = sampleId, library = libId), Duration.Inf) == 1
    val qiimeClosesOtuTable = Await.result(summary.getFile(runId, "gears", NoModule, sampleId, libId, "qiime_closed_otu_table"), Duration.Inf)
    val qiimeOpenOtuTable = Await.result(summary.getFile(runId, "gears", NoModule, sampleId, libId, "qiime_open_otu_table"), Duration.Inf)
136

137
    ReportPage(
138
      (if (flexiprepExecuted) List("QC" -> FlexiprepReport.flexiprepPage) else Nil
139
140
      ) ::: (if (centrifugeExecuted) List("Centriguge analysis" -> Future.successful(ReportPage(List(
        "Non-unique" -> Future.successful(ReportPage(List(), List("All mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
Peter van 't Hof's avatar
Peter van 't Hof committed
141
142
          Map("summaryStatsTag" -> "centrifuge_report")
        )), Map()))), List(
143
144
        "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
          Map("summaryStatsTag" -> "centrifuge_unique_report")
Peter van 't Hof's avatar
Peter van 't Hof committed
145
        )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge")))))
146
      else Nil) ::: (if (krakenExecuted) List("Kraken analysis" -> Future.successful(ReportPage(List(), List(
Peter van 't Hof's avatar
Peter van 't Hof committed
147
        "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
Peter van 't Hof's avatar
Peter van 't Hof committed
148
        )), Map())))
149
      else Nil) ::: (if (qiimeClosesOtuTable.isDefined) List("Qiime closed reference analysis" -> Future.successful(ReportPage(List(), List(
150
        "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/qiimeKrona.ssp"
Peter van 't Hof's avatar
Peter van 't Hof committed
151
        )), Map("biomFile" -> new File(qiimeClosesOtuTable.get.path)))))
152
      else Nil) ::: (if (qiimeOpenOtuTable.isDefined) List("Qiime open reference analysis" -> Future.successful(ReportPage(List(), List(
153
        "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/qiimeKrona.ssp"
Peter van 't Hof's avatar
Peter van 't Hof committed
154
        )), Map("biomFile" -> new File(qiimeOpenOtuTable.get.path)))))
155
      else Nil), List(
156
157
158
159
160
161
        "QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp"),
        "QC bases" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp")
      ), args)
  }

}