GearsReport.scala 9.7 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
import scala.concurrent.duration.Duration
Peter van 't Hof's avatar
Peter van 't Hof committed
27
import scala.concurrent.ExecutionContext.Implicits.global
28

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

object GearsReport extends MultisampleReportBuilder {

  def reportName = "Gears Report"

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

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

Peter van 't Hof's avatar
Peter van 't Hof committed
48
49
50
51
    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")
52

53
    ReportPage(
Peter van 't Hof's avatar
Peter van 't Hof committed
54
55
56
57
      (if (centrifugeExecuted) List("Centriguge analysis" -> Future(ReportPage(List("Non-unique" ->
        Future(ReportPage(List(), List("All mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
          Map("summaryStatsTag" -> "centrifuge_report")
        )), Map()))), List(
58
        "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
59
          Map("summaryStatsTag" -> "centrifuge_unique_report")
Peter van 't Hof's avatar
Peter van 't Hof committed
60
61
62
63
64
65
66
67
        )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge")))))
      else Nil) ::: (if (krakenExecuted) List("Kraken analysis" -> Future(ReportPage(List(), List(
        "Krona plot" -> Future(ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
        ))), Map())))
      else Nil) ::: (if (qiimeClosesOtuTable.isDefined) List("Qiime closed reference analysis" -> Future(ReportPage(List(), List(
        "Krona plot" -> Future(ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/qiimeKrona.ssp"
        ))), Map("biomFile" -> new File(run.outputDir + File.separator + qiimeClosesOtuTable.get.path)))))
      else Nil) ::: (if (qiimeOpenOtuTable.isDefined) List("Qiime open reference analysis" -> Future(ReportPage(List(), List(
68
        "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/qiimeKrona.ssp"
Peter van 't Hof's avatar
Peter van 't Hof committed
69
        )), Map("biomFile" -> new File(run.outputDir + File.separator + qiimeOpenOtuTable.get.path)))))
70
      else Nil) ::: List("Samples" -> generateSamplesPage(pageArgs)) ++
71
        Map(
Peter van 't Hof's avatar
Peter van 't Hof committed
72
          "Versions" -> Future(ReportPage(List(), List(
73
            "Executables" -> ReportSection("/nl/lumc/sasc/biopet/core/report/executables.ssp")
Peter van 't Hof's avatar
Peter van 't Hof committed
74
          ), Map()))
75
76
77
78
79
80
81
82
83
84
85
86
87
88
        ),
      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
89
  def samplePage(sampleId: Int, args: Map[String, Any]): Future[ReportPage] = Future {
Peter van 't Hof's avatar
Peter van 't Hof committed
90
    val run = Await.result(summary.getRuns(runId).map(_.head), Duration.Inf)
Peter van 't Hof's avatar
Peter van 't Hof committed
91
92
    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
93
94
    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)
95

Peter van 't Hof's avatar
Peter van 't Hof committed
96
97
98
99
    ReportPage((if (centrifugeExecuted) List("Centriguge analysis" -> Future(ReportPage(List(
      "Non-unique" -> Future(ReportPage(List(), List("All mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
        Map("summaryStatsTag" -> "centrifuge_report")
      )), Map()))), List(
100
101
      "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
102
103
      )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge")))))
    else Nil) ::: (if (krakenExecuted) List("Kraken analysis" -> Future(ReportPage(List(), List(
Peter van 't Hof's avatar
Peter van 't Hof committed
104
      "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
Peter van 't Hof's avatar
Peter van 't Hof committed
105
106
      )), Map())))
    else Nil) ::: (if (qiimeClosesOtuTable.isDefined) List("Qiime closed reference analysis" -> Future(ReportPage(List(), List(
107
      "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/qiimeKrona.ssp"
Peter van 't Hof's avatar
Peter van 't Hof committed
108
109
      )), Map("biomFile" -> new File(run.outputDir + File.separator + qiimeClosesOtuTable.get.path)))))
    else Nil) ::: (if (qiimeOpenOtuTable.isDefined) List("Qiime open reference analysis" -> Future(ReportPage(List(), List(
110
      "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/qiimeKrona.ssp"
Peter van 't Hof's avatar
Peter van 't Hof committed
111
      )), Map("biomFile" -> new File(run.outputDir + File.separator + qiimeOpenOtuTable.get.path)))))
112
    else Nil) ::: List(
113
114
115
116
117
118
119
      "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
120
  def libraryPage(sampleId: Int, libId: Int, args: Map[String, Any]): Future[ReportPage] = Future {
121
122
123
    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
124
    val flexiprepExecuted = Await.result(summary.getStatsSize(runId, "flexiprep", sample = sampleId, library = libId), Duration.Inf) >= 1
125

Peter van 't Hof's avatar
Peter van 't Hof committed
126
127
128
129
    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)
130

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

}