MultisampleReportBuilder.scala 2.91 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.core.report

Peter van 't Hof's avatar
Peter van 't Hof committed
17
import scala.concurrent.{ Await, Future }
18
19
import scala.concurrent.duration.Duration

20
/**
21
22
23
 * This trait will generate a report with added function to generate sample and library pages for those existing in the summary.
 *
 * @author pjvan_thof
24
25
 */
trait MultisampleReportBuilder extends ReportBuilder {
26
27

  /** Method to generate a single sample page */
Peter van 't Hof's avatar
Peter van 't Hof committed
28
  def samplePage(sampleId: Int, args: Map[String, Any]): Future[ReportPage]
29

30
  /** Default list of samples, can be override */
31
32
33
34
35
36
  def samplesSections: List[(String, ReportSection)] = {
    List(
      ("Samples", ReportSection("/nl/lumc/sasc/biopet/core/report/samplesList.ssp"))
    )
  }

37
  /** Method to generate a single library page */
Peter van 't Hof's avatar
Peter van 't Hof committed
38
  def libraryPage(sampleId: Int, libraryId: Int, args: Map[String, Any]): Future[ReportPage]
39

40
  /** Default list of libraries, can be override */
41
  def librariesSections: List[(String, ReportSection)] = {
42
43
44
45
46
    List(
      ("Libraries", ReportSection("/nl/lumc/sasc/biopet/core/report/librariesList.ssp"))
    )
  }

47
  /** Generate the samples page including a single sample page for each sample in the summary */
Peter van 't Hof's avatar
Peter van 't Hof committed
48
  def generateSamplesPage(args: Map[String, Any]): Future[ReportPage] = Future {
49
50
    val samples = Await.result(summary.getSamples(runId = Some(runId)), Duration.Inf)
    val samplePages = samples.map(_.id)
51
      .map(sampleId => sampleId -> samplePage(sampleId, args ++ Map("sampleId" -> Some(sampleId))))
52
      .toList
Peter van 't Hof's avatar
Peter van 't Hof committed
53
    ReportPage(samplePages.map(x => samples.find(_.id == x._1).get.name -> x._2), samplesSections, args)
54
55
  }

56
  /** Generate the libraries page for a single sample with a subpage for eacht library */
Peter van 't Hof's avatar
Peter van 't Hof committed
57
  def generateLibraryPage(args: Map[String, Any]): Future[ReportPage] = Future {
58
    val sampleId = args("sampleId") match {
59
      case Some(x: Int) => x
Peter van 't Hof's avatar
Peter van 't Hof committed
60
      case None         => throw new IllegalStateException("Sample not found")
61
62
    }

63
64
65
    val libraries = Await.result(summary.getLibraries(runId = Some(runId), sampleId = Some(sampleId)), Duration.Inf)

    val libPages = libraries.map(_.id)
66
      .map(libId => libId -> libraryPage(sampleId, libId, args ++ Map("libId" -> Some(libId))))
67
      .toList
Peter van 't Hof's avatar
Peter van 't Hof committed
68
    ReportPage(libPages.map(x => libraries.find(_.id == x._1).get.name -> x._2), librariesSections, args)
69
70
  }
}