Commit 8b7c9688 authored by Peter van 't Hof's avatar Peter van 't Hof

Added WGS plot to report

parent 3dac3272
#import(nl.lumc.sasc.biopet.core.summary.Summary)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
#import(org.apache.commons.io.FileUtils)
<%@ var summary: Summary %>
<%@ var sampleId: Option[String] = None %>
<%@ var libId: Option[String] = None %>
<%@ var rootPath: String %>
<%@ var metricsTag: String = "bammetrics" %>
<%@ var sampleLevel: Boolean = false %>
<%@ var outputDir: File %>
<%@ var fields: List[String] = List("mean_coverage", "pct_5x", "pct_10x", "pct_15x", "pct_20x", "pct_25x", "pct_30x", "pct_40x", "pct_50x", "pct_60x", "pct_70x", "pct_80x", "pct_90x", "pct_100x")%>
<%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %>
<%@ var showIntro: Boolean = true%>
#{
val samples = sampleId match {
case Some(sample) => {
List(sample.toString)
}
case _ => summary.samples.toList
}
}#
#if (showIntro)
<br/>
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-6">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc risus est, volutpat quis enim sit amet, lacinia posuere ante. Mauris eget massa efficitur, luctus nisl ut, placerat nibh. Pellentesque id nulla maximus, rutrum dui nec, lobortis odio. Fusce eu enim ac sem auctor congue. Ut ac ullamcorper quam, eget sollicitudin felis. Maecenas posuere sagittis blandit. Proin mollis magna lectus, id gravida est consectetur vitae. Nulla id risus at tellus laoreet finibus in id lacus. Duis lobortis commodo nisl viverra tempor. Curabitur sit amet pretium dui, sit amet tincidunt mauris. Duis volutpat eu purus ut molestie.
</p>
</div>
</div>
#end
#if (showPlot)
#{ BammetricsReport.wgsHistogramPlot(outputDir, "wgs", summary, !sampleLevel, sampleId = sampleId) }#
<div class="panel-body">
<img src="wgs.png" class="img-responsive" />
</div>
<div class="panel-footer">
#if (showTable)
<button type="button" class="btn btn-info" data-toggle="collapse" data-target="#wgsTable">Hide table</button>
#else
<button type="button" class="btn btn-info" data-toggle="collapse" data-target="#wgsTable">Show table</button>
#end
<i class="glyphicon glyphicon-file"></i> <a href="wgs.tsv">tsv file</a>
</div>
#end
<div class="panel-body collapse #if (showTable)in#end" id="wgsTable">
<!-- Table -->
<table class="table sortable-theme-bootstrap" data-sortable>
<thead><tr>
<th data-sorted="true" data-sorted-direction="ascending">Sample</th>
#if (!sampleLevel) <th>Library</th> #end
#for (field <- fields)
<th>${field.replaceAll("_", " ")}</th>
#end
</tr></thead>
<tbody>
#for (sample <- samples.toList.sorted)
#{
val libs = (libId, sampleLevel) match {
case (_, true) => List("")
case (Some(libId), _) => List(libId.toString)
case _ => summary.libraries(sample).toList
}
}#
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample}/index.html">${sample}</a></td>
#for (libId <- libs)
#if (libs.head != libId) <tr> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample}/Libraries/${libId}/index.html">${libId}</a></td> #end
#{
val prefixPath = List("samples", sample) ::: (if (libId.isEmpty) Nil else List("libraries", libId)) ::: List("bammetrics", "stats")
val fieldValues = for (field <- fields) yield {
summary.getValue((prefixPath ::: List("wgs", "metrics", field.toUpperCase)):_*).getOrElse(prefixPath ::: metricsTag :: Nil)
}
}#
#for (value <- fieldValues)
<td>${value}</td>
#end
</tr>
#end
#end
</tbody>
</table>
</div>
......@@ -173,4 +173,84 @@ object BammetricsReport extends ReportBuilder {
plot.title = Some("Insert size")
plot.runLocal()
}
def wgsHistogramPlot(outputDir: File,
prefix: String,
summary: Summary,
libraryLevel: Boolean = false,
sampleId: Option[String] = None): Unit = {
val tsvFile = new File(outputDir, prefix + ".tsv")
val pngFile = new File(outputDir, prefix + ".png")
val tsvWriter = new PrintWriter(tsvFile)
if (libraryLevel) {
tsvWriter.println((for (
sample <- summary.samples if (sampleId.isEmpty || sampleId.get == sample);
lib <- summary.libraries(sample)
) yield s"$sample-$lib")
.mkString("library\t", "\t", ""))
} else {
sampleId match {
case Some(sample) => tsvWriter.println("\t" + sample)
case _ => tsvWriter.println(summary.samples.mkString("Sample\t", "\t", ""))
}
}
var map: Map[Int, Map[String, Int]] = Map()
def fill(sample: String, lib: Option[String]): Unit = {
val insertSize = new SummaryValue(List("bammetrics", "stats", "wgs", "histogram", "coverage"),
summary, Some(sample), lib).value.getOrElse(List())
val counts = new SummaryValue(List("bammetrics", "stats", "wgs", "histogram", "count"),
summary, Some(sample), lib).value.getOrElse(List())
(insertSize, counts) match {
case (l: List[_], l2: List[_]) => {
l.zip(l2).foreach(i => {
val insertSize = i._1.toString.toInt
val count = i._2.toString.toInt
val old = map.getOrElse(insertSize, Map())
if (libraryLevel) map += insertSize -> (old + ((s"$sample-" + lib.get) -> count))
else map += insertSize -> (old + (sample -> count))
})
}
case _ => throw new IllegalStateException("Must be a list")
}
}
if (libraryLevel) {
for (
sample <- summary.samples if (sampleId.isEmpty || sampleId.get == sample);
lib <- summary.libraries(sample)
) fill(sample, Some(lib))
} else if (sampleId.isDefined) fill(sampleId.get, None)
else summary.samples.foreach(fill(_, None))
for ((insertSize, counts) <- map) {
tsvWriter.print(insertSize)
if (libraryLevel) {
for (
sample <- summary.samples if (sampleId.isEmpty || sampleId.get == sample);
lib <- summary.libraries(sample)
) tsvWriter.print("\t" + counts.getOrElse(s"$sample-$lib", "0"))
} else {
for (sample <- summary.samples if (sampleId.isEmpty || sampleId.get == sample)) {
tsvWriter.print("\t" + counts.getOrElse(sample, "0"))
}
}
tsvWriter.println()
}
tsvWriter.close()
val plot = new XYPlot(null)
plot.input = tsvFile
plot.output = pngFile
plot.ylabel = Some("Bases")
plot.xlabel = Some("Coverage")
plot.width = Some(1200)
plot.removeZero = true
plot.title = Some("Whole genome coverage")
plot.runLocal()
}
}
......@@ -30,7 +30,7 @@ class CollectWgsMetrics(val root: Configurable) extends Picard with Summarizable
var minBaseQ: Option[Int] = config("minimum_base_quality")
@Argument(doc = "COVERAGE_CAP", required = false)
var covCap: Option[Int] = config("coverage_cap", default = 401)
var covCap: Option[Int] = config("coverage_cap")
@Argument(doc = "STOP_AFTER", required = false)
var stopAfter: Option[Long] = config("stop_after")
......
......@@ -41,6 +41,8 @@ object ShivaReport extends MultisampleReportBuilder {
),
"Insert Size" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp",
Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)),
"Whole genome coverage" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/wgsHistogram.ssp",
Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)),
"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",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment