krakenKrona.ssp 1.89 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1 2 3 4 5 6 7 8 9 10 11 12
#import(nl.lumc.sasc.biopet.utils.summary.Summary)
#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)
<%@ var summary: Summary %>
<%@ var rootPath: String %>
<%@ var sampleId: Option[String] = None %>
<%@ var libId: Option[String] = None %>
<%@ var args: Map[String, Any] %>
<%@ var outputDir: File %>
13
<%@ var centrifugeTag: Option[String] = None %>
Peter van 't Hof's avatar
Peter van 't Hof committed
14 15
<%@ var summaryStatsTag: String = "krakenreport" %>
<%@ var summaryModuleTag: String = "gearskraken" %>
Peter van 't Hof's avatar
Peter van 't Hof committed
16 17

<%
18
    val summaries = if (sampleId.isEmpty) {
Peter van 't Hof's avatar
Peter van 't Hof committed
19 20
        summary.getSampleValues(summaryModuleTag, "stats", summaryStatsTag).map(x => x._1 -> x._2.get.asInstanceOf[Map[String, Any]])
    } else summary.getValue(sampleId, libId, summaryModuleTag, "stats", summaryStatsTag).map(sampleId.get -> _.asInstanceOf[Map[String, Any]]).toList.toMap
Peter van 't Hof's avatar
Peter van 't Hof committed
21

22 23 24 25 26
    val totalReads = if (sampleId.isEmpty) {
        centrifugeTag.map {tag => summary.getSampleValues(summaryModuleTag, "stats", tag, "metrics", "Read").map(x => x._1 -> x._2.getOrElse(0L).toString.toLong) }
    } else centrifugeTag.flatMap(tag => summary.getValue(sampleId, libId, summaryModuleTag, "stats", tag, "metrics", "Read"))
      .map(value => Map(sampleId.get -> value.toString.toLong))

Peter van 't Hof's avatar
Peter van 't Hof committed
27 28
    val tempFile = File.createTempFile("krona.", ".xml")
    tempFile.deleteOnExit()
29
    GearsKraken.convertKrakenSummariesToKronaXml(summaries, tempFile, totalReads)
Peter van 't Hof's avatar
Peter van 't Hof committed
30 31 32 33 34

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


Peter van 't Hof's avatar
Peter van 't Hof committed
35
    val file = new File(outputDir, s"$summaryModuleTag-$summaryStatsTag.html")
Peter van 't Hof's avatar
Peter van 't Hof committed
36 37 38 39 40
    val writer = new PrintWriter(file)
    writer.println(output)
    writer.close()
%>

Peter van 't Hof's avatar
Peter van 't Hof committed
41
<iframe src="${summaryModuleTag}-${summaryStatsTag}.html" style="width:100%;height:80vh;border:none;"></iframe>