Commit 682d5937 authored by Peter van 't Hof's avatar Peter van 't Hof

Adding clipping and mapping quality plots to report

parent 16fafb4e
#import(nl.lumc.sasc.biopet.utils.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_insert_size", "standard_deviation", "median_insert_size")%>
<%@ 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>
#if (sampleId.isDefined && libId.isDefined)
This plot shows the clipping distribution for all libraries combined in sample <b>${sampleId}</b>.
#elseif(sampleId.isDefined)
This plot shows the clipping distribution for the libraries of sample <b>${sampleId}</b>.
#else
This plot shows the clipping distribution for each of the <b>${samples.size}</b> samples.
#end
</p>
</div>
</div>
#end
#if (showPlot)
#{ BammetricsReport.clippingPlot(outputDir, "clipping", summary, !sampleLevel, sampleId = sampleId, libId = libId) }#
<div class="panel-body">
<img src="clipping.png" class="img-responsive" />
</div>
<div class="panel-footer">
#if (showTable)
<button type="button" class="btn btn-info" data-toggle="collapse" data-target="#clippingTable">
<i class="glyphicon glyphicon-eye-close"></i> Hide table</button>
#else
<button type="button" class="btn btn-info" data-toggle="collapse" data-target="#clippingTable">
<i class="glyphicon glyphicon-eye-open"></i> Show table</button>
#end
<button type="button" class="btn btn-info"><i class="glyphicon glyphicon-cloud-download"> <a href="clipping.tsv">tsv file</a></i></button>
</div>
#end
<div class="panel-body collapse #if (showTable)in#end" id="clippingTable">
<!-- Table -->
<table class="table">
<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("CollectInsertSizeMetrics", "metrics", field.toUpperCase)):_*).getOrElse("N/A")
}
}#
#for (value <- fieldValues)
<td>${value}</td>
#end
</tr>
#end
#end
</tbody>
</table>
</div>
#import(nl.lumc.sasc.biopet.utils.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_insert_size", "standard_deviation", "median_insert_size")%>
<%@ 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>
#if (sampleId.isDefined && libId.isDefined)
This plot shows the mapping quality distribution for all libraries combined in sample <b>${sampleId}</b>.
#elseif(sampleId.isDefined)
This plot shows the mapping quality distribution for the libraries of sample <b>${sampleId}</b>.
#else
This plot shows the mapping quality distribution for each of the <b>${samples.size}</b> samples.
#end
</p>
</div>
</div>
#end
#if (showPlot)
#{ BammetricsReport.mappingQualityPlot(outputDir, "mapping_quality", summary, !sampleLevel, sampleId = sampleId, libId = libId) }#
<div class="panel-body">
<img src="mapping_quality.png" class="img-responsive" />
</div>
<div class="panel-footer">
#if (showTable)
<button type="button" class="btn btn-info" data-toggle="collapse" data-target="#mapping_qualityTable">
<i class="glyphicon glyphicon-eye-close"></i> Hide table</button>
#else
<button type="button" class="btn btn-info" data-toggle="collapse" data-target="#mapping_qualityTable">
<i class="glyphicon glyphicon-eye-open"></i> Show table</button>
#end
<button type="button" class="btn btn-info"><i class="glyphicon glyphicon-cloud-download"> <a href="mapping_quality.tsv">tsv file</a></i></button>
</div>
#end
<div class="panel-body collapse #if (showTable)in#end" id="mapping_qualityTable">
<!-- Table -->
<table class="table">
<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("CollectInsertSizeMetrics", "metrics", field.toUpperCase)):_*).getOrElse("N/A")
}
}#
#for (value <- fieldValues)
<td>${value}</td>
#end
</tr>
#end
#end
</tbody>
</table>
</div>
......@@ -82,7 +82,9 @@ object BammetricsReport extends ReportBuilder {
targets.map(t => t -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/covstatsPlot.ssp", Map("target" -> Some(t)))),
Map())),
List(
"Summary" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp")) ++
"Summary" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp"),
"Mapping Quality" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/mappingQuality.ssp", Map("showPlot" -> true)),
"Clipping" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/clipping.ssp", Map("showPlot" -> true))) ++
(if (insertsizeMetrics) List("Insert Size" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp", Map("showPlot" -> true))
)
else Nil) ++ (if (wgsExecuted) List("Whole genome coverage" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/wgsHistogram.ssp",
......@@ -196,6 +198,62 @@ object BammetricsReport extends ReportBuilder {
removeZero = true).runLocal()
}
def mappingQualityPlot(outputDir: File,
prefix: String,
summary: Summary,
libraryLevel: Boolean = false,
sampleId: Option[String] = None,
libId: Option[String] = None): Unit = {
val tsvFile = new File(outputDir, prefix + ".tsv")
val pngFile = new File(outputDir, prefix + ".png")
def paths(name: String) = Map(
"mapping_quality" -> List("bammetrics", "stats", "bamstats", "mapping_quality", "value"),
name -> List("bammetrics", "stats", "bamstats", "mapping_quality", "count")
)
val tables = getSampleLibraries(summary, sampleId, libId, libraryLevel)
.map {
case (sample, lib) =>
getTableFromSummary(summary, paths(lib.map(l => s"$sample-$l").getOrElse(sample)), Some(sample), lib)
}
writeTableToTsv(tsvFile, mergeTables(tables.toArray, "mapping_quality"), "mapping_quality")
LinePlot(tsvFile, pngFile,
xlabel = Some("Mapping Quality"),
ylabel = Some("Reads"),
title = Some("Mapping Quality"),
removeZero = true).runLocal()
}
def clippingPlot(outputDir: File,
prefix: String,
summary: Summary,
libraryLevel: Boolean = false,
sampleId: Option[String] = None,
libId: Option[String] = None): Unit = {
val tsvFile = new File(outputDir, prefix + ".tsv")
val pngFile = new File(outputDir, prefix + ".png")
def paths(name: String) = Map(
"clipping" -> List("bammetrics", "stats", "bamstats", "clipping", "value"),
name -> List("bammetrics", "stats", "bamstats", "clipping", "count")
)
val tables = getSampleLibraries(summary, sampleId, libId, libraryLevel)
.map {
case (sample, lib) =>
getTableFromSummary(summary, paths(lib.map(l => s"$sample-$l").getOrElse(sample)), Some(sample), lib)
}
writeTableToTsv(tsvFile, mergeTables(tables.toArray, "clipping"), "clipping")
LinePlot(tsvFile, pngFile,
xlabel = Some("Clipping"),
ylabel = Some("Reads"),
title = Some("Clipping"),
removeZero = true).runLocal()
}
/**
* Generate a line plot for wgs coverage
*
......
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