krakenKrona.ssp 2.86 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
#import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb)
2
#import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb._)
Peter van 't Hof's avatar
Peter van 't Hof committed
3 4 5
#import(nl.lumc.sasc.biopet.utils.summary.db.Schema.Library)
#import(nl.lumc.sasc.biopet.utils.summary.db.Schema.Sample)
#import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb.Implicts._)
Peter van 't Hof's avatar
Peter van 't Hof committed
6 7 8 9 10
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(nl.lumc.sasc.biopet.core.report.ReportBuilder)
#import(nl.lumc.sasc.biopet.pipelines.gears.GearsKraken)
#import(java.io.File)
#import(java.io.PrintWriter)
Peter van 't Hof's avatar
Peter van 't Hof committed
11
<%@ var summary: SummaryDb %>
Peter van 't Hof's avatar
Peter van 't Hof committed
12
<%@ var rootPath: String %>
Peter van 't Hof's avatar
Peter van 't Hof committed
13 14
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
Peter van 't Hof's avatar
Peter van 't Hof committed
15 16
<%@ var args: Map[String, Any] %>
<%@ var outputDir: File %>
17
<%@ var centrifugeTag: Option[String] = None %>
Peter van 't Hof's avatar
Peter van 't Hof committed
18 19
<%@ var summaryStatsTag: String = "krakenreport" %>
<%@ var summaryModuleTag: String = "gearskraken" %>
Peter van 't Hof's avatar
Peter van 't Hof committed
20 21 22 23 24 25 26 27 28
<%@ var runId: Int %>
<%@ var allSamples: Seq[Sample] %>
<%@ var allLibraries: Seq[Library] %>
#{
    val samples = sampleId match {
    case Some(id) => allSamples.filter(_.id == id).toList
    case _ => allSamples.toList
    }
}#
Peter van 't Hof's avatar
Peter van 't Hof committed
29
<%
30 31 32 33
    val summaries = if (libId.isDefined) summary.getStatsForLibraries(runId, summaryModuleTag, summaryStatsTag, sampleId,
      Map("all" -> Nil)
    ).filter(_._1._2 == libId.get).map(x => x._1._1 -> x._2)
    else summary.getStatsForSamples(runId, summaryModuleTag, summaryStatsTag, sampleId.map(SummaryDb.SampleId),
Peter van 't Hof's avatar
Peter van 't Hof committed
34 35
      Map("all" -> Nil)
    )
Peter van 't Hof's avatar
Peter van 't Hof committed
36

37
    val totalReads = centrifugeTag.map { tag =>
38 39 40 41 42 43 44 45
    if (libId.isDefined) {
        val stats = summary.getStatsForLibraries(runId, summaryModuleTag, ModuleName(tag), sampleId,
            Map("total" -> List("metrics", "Read"))
        ).filter(_._1._2 == libId.get).head
        val lib = allLibraries.filter(_.id == stats._1._2).head
        val sample = allSamples.filter(_.id == stats._1._1).head
        Map(s"${sample.name}" -> stats._2("total").map(_.toString.toLong).getOrElse(0L))
    } else summary.getStatsForSamples(runId, summaryModuleTag, ModuleName(tag), sampleId.map(SummaryDb.SampleId),
46 47 48
        Map("total" -> List("metrics", "Read"))
        ).map(x => allSamples.find(_.id == x._1).head.name -> x._2("total").map(_.toString.toLong).getOrElse(0L))
    }
49

Peter van 't Hof's avatar
Peter van 't Hof committed
50 51
    val tempFile = File.createTempFile("krona.", ".xml")
    tempFile.deleteOnExit()
52
    GearsKraken.convertKrakenSummariesToKronaXml(summaries.map(x => allSamples.find(_.id == x._1).head.name -> x._2("all").map(_.asInstanceOf[Map[String, Any]]).getOrElse(Map())), tempFile, totalReads)
Peter van 't Hof's avatar
Peter van 't Hof committed
53 54 55 56 57

    val output = ReportBuilder.renderTemplate("/nl/lumc/sasc/biopet/core/report/krona.ssp",
    args ++ Map("kronaXml" -> tempFile))


58
    val file = new File(outputDir, s"$summaryModuleTag-$summaryStatsTag.html")
Peter van 't Hof's avatar
Peter van 't Hof committed
59 60 61 62 63
    val writer = new PrintWriter(file)
    writer.println(output)
    writer.close()
%>

64
<iframe src="${summaryModuleTag}-${summaryStatsTag}.html" style="width:100%;height:80vh;border:none;"></iframe>