Commit 595baf7d authored by rhpvorderman's avatar rhpvorderman

created plotconstructors in bammetrics

parent d0d60c78
......@@ -17,7 +17,12 @@ package nl.lumc.sasc.biopet.pipelines.bammetrics
import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.utils.config.Configurable
import nl.lumc.sasc.biopet.core.report.{ReportBuilder, ReportBuilderExtension, ReportPage, ReportSection}
import nl.lumc.sasc.biopet.core.report.{
ReportBuilder,
ReportBuilderExtension,
ReportPage,
ReportSection
}
import nl.lumc.sasc.biopet.utils.ConfigUtils
import nl.lumc.sasc.biopet.utils.rscript.{LinePlot, StackedBarPlot}
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb
......@@ -216,8 +221,7 @@ object BammetricsReport extends ReportBuilder {
def alignmentSummaryPlot(outputDir: File,
prefix: String,
summaryPlotLines: Seq[String],
libraryLevel: Boolean = false
): Unit = {
libraryLevel: Boolean = false): Unit = {
val tsvFile = new File(outputDir, prefix + ".tsv")
val pngFile = new File(outputDir, prefix + ".png")
val tsvWriter = new PrintWriter(tsvFile)
......@@ -237,6 +241,7 @@ object BammetricsReport extends ReportBuilder {
plot.title = Some("Aligned_reads")
plot.runLocal()
}
/**
* This is a generic method to create plots
* @param libraryLevel If enabled the plots will show data per library
......@@ -248,7 +253,7 @@ object BammetricsReport extends ReportBuilder {
* @param pipeline Query for the pipeline
* @param module Query for the module
*/
def summaryForPlot( summary: SummaryDb,
def summaryForPlot(summary: SummaryDb,
statsPaths: Map[String, List[String]],
yKeyList: List[String],
xKeyList: List[String],
......@@ -256,8 +261,7 @@ object BammetricsReport extends ReportBuilder {
module: ModuleQuery,
libraryLevel: Boolean = false,
sampleId: Option[Int] = None,
libraryId: Option[Int] = None
): Array[Map[String, Array[Any]]]= {
libraryId: Option[Int] = None): Array[Map[String, Array[Any]]] = {
val results: Map[(Int, Option[Int]), Map[String, Option[Array[Any]]]] = if (libraryLevel) {
summary
.getStatsForLibraries(runId, pipeline, module, sampleId = sampleId, keyValues = statsPaths)
......@@ -303,7 +307,6 @@ object BammetricsReport extends ReportBuilder {
* @param title Title of the plot
* @param removeZero
*/
def writePlotFromSummary(outputDir: File,
prefix: String,
tables: Array[Map[String, Array[Any]]],
......@@ -318,15 +321,23 @@ object BammetricsReport extends ReportBuilder {
writeTableToTsv(tsvFile, mergeTables(tables, yKeyList.head), yKeyList.head)
LinePlot(tsvFile,
LinePlot(
tsvFile,
pngFile,
xlabel = xlabel,
ylabel = ylabel,
title = title,
hideLegend = tables.size > 40, /* changed from results.size. Original results in summaryForPlot*/
removeZero = removeZero).runLocal()
hideLegend = tables.size > 40,
/* changed from results.size. Original results in summaryForPlot*/
removeZero = removeZero
).runLocal()
}
def insertSizePlotTables(summary: SummaryDb,
libraryLevel: Boolean = false,
sampleId: Option[Int] = None,
libraryId: Option[Int] = None): Array[Map[String, Array[Any]]] = {}
/**
* Generate a line plot for insertsize
*
......@@ -338,10 +349,7 @@ object BammetricsReport extends ReportBuilder {
*/
def insertSizePlot(outputDir: File,
prefix: String,
tables: Array[Map[String, Array[Any]]],
libraryLevel: Boolean = false,
sampleId: Option[Int] = None,
libraryId: Option[Int] = None): Unit = {
insertSizePlotTables: Array[Map[String, Array[Any]]]): Unit = {
val statsPaths = Map(
"insert_size" -> List("histogram", "insert_size"),
"count" -> List("histogram", "All_Reads.fr_count")
......@@ -350,7 +358,7 @@ object BammetricsReport extends ReportBuilder {
writePlotFromSummary(
outputDir,
prefix,
tables,
insertSizePlotTables,
libraryLevel,
sampleId,
libraryId,
......@@ -365,41 +373,45 @@ object BammetricsReport extends ReportBuilder {
)
}
def mappingQualityPlotSummary(summary: SummaryDb,
): Unit = {
def mappingQualityPlotTables(summary: SummaryDb,
libraryLevel: Boolean = false,
sampleId: Option[Int] = None,
libraryId: Option[Int] = None): Array[Map[String, Array[Any]]] = {
val statsPaths = Map(
"mapping_quality" -> List("mapping_quality", "histogram", "values"),
"count" -> List("mapping_quality", "histogram", "counts")
)
val plotSummary: Array[Map[String, Array[Any]]] = summaryForPlot(summary, statsPaths,
val plotTables: Array[Map[String, Array[Any]]] = summaryForPlot(summary,
statsPaths,
"mapping_quality" :: Nil,
"count" :: Nil,
"bammetrics",
"bamstats"
)
plotSummary
"bamstats",
libraryLevel,
sampleId,
libraryId)
plotTables
}
def mappingQualityPlot(outputDir: File,
prefix: String,
mappingQualityPlotSummary: Array[Map[String, Array[Any]]],
libraryLevel: Boolean = false,
sampleId: Option[Int] = None,
libraryId: Option[Int] = None): Unit = {
val statsPaths = Map(
"mapping_quality" -> List("mapping_quality", "histogram", "values"),
"count" -> List("mapping_quality", "histogram", "counts")
)
mappingQualityPlotTables: Array[Map[String, Array[Any]]]): Unit = {
writePlotFromSummary(outputDir,
prefix,
mappingQualityPlotSummary,
mappingQualityPlotTables,
"mapping_quality" :: Nil,
"count" :: Nil,"Mapping Quality", "Reads","Mapping Quality")
"count" :: Nil,
"Mapping Quality",
"Reads",
"Mapping Quality")
}
def clippingPlotTables(summary: SummaryDb,
libraryLevel: Boolean = false,
sampleId: Option[Int] = None,
libraryId: Option[Int] = None): Array[Map[String, Array[Any]]] = {}
def clippingPlot(outputDir: File,
prefix: String,
tables: Array[Map[String, Array[Any]]],
clippingPlotTables: Array[Map[String, Array[Any]]],
libraryLevel: Boolean = false,
sampleId: Option[Int] = None,
libraryId: Option[Int] = None): Unit = {
......@@ -537,7 +549,7 @@ object BamMetricsAlignmentReport {
sampleLevel: Boolean = false,
showPlot: Boolean = false,
showIntro: Boolean = true,
showTable: Boolean = true): Map[String,Any] = {
showTable: Boolean = true): Map[String, Any] = {
val statsPaths = Map(
"All" -> List("flagstats", "All"),
......@@ -545,10 +557,11 @@ object BamMetricsAlignmentReport {
"Duplicates" -> List("flagstats", "Duplicates"),
"NotPrimaryAlignment" -> List("flagstats", "NotPrimaryAlignment")
)
val alignmentSummaryResults = summary.getStatsForLibraries(runId,"bammetrics","bamstats", sampleId, statsPaths)
val alignmentSummaryResults =
summary.getStatsForLibraries(runId, "bammetrics", "bamstats", sampleId, statsPaths)
val alignmentSummaryPlotLines: Option[Seq[String]] =
if (showPlot)
Some(BammetricsReport.alignmentSummaryPlotLines(summary,sampleId,!sampleLevel))
Some(BammetricsReport.alignmentSummaryPlotLines(summary, sampleId, !sampleLevel))
else None
Map(
"alignmentSummaryResults" -> alignmentSummaryResults,
......@@ -569,15 +582,14 @@ object BamMetricsMappingQuality {
allLibraries: Seq[Library],
sampleId: Option[Int],
libId: Option[Int],
sampleLevel: Boolean= false,
sampleLevel: Boolean = false,
showPlot: Boolean = false,
showIntro: Boolean = true,
showTable: Boolean = true): Map[String,Any] = {
showTable: Boolean = true): Map[String, Any] = {
val samples = sampleId match {
case Some(id) => allSamples.filter(_.id == id).toList
case _ => allSamples.toList
}
val
}
}
......@@ -14,7 +14,12 @@
*/
package nl.lumc.sasc.biopet.pipelines.mapping
import nl.lumc.sasc.biopet.core.report.{MultisampleReportBuilder, ReportBuilderExtension, ReportPage, ReportSection}
import nl.lumc.sasc.biopet.core.report.{
MultisampleReportBuilder,
ReportBuilderExtension,
ReportPage,
ReportSection
}
import nl.lumc.sasc.biopet.pipelines.bammetrics.{BamMetricsAlignmentReport, BammetricsReport}
import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport
import nl.lumc.sasc.biopet.pipelines.gears.GearsKronaPlot
......@@ -95,11 +100,40 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder {
val flexiprepExecuted = Await
.result(summary.getStatsSize(runId, "flexiprep", mustHaveLibrary = true), Duration.Inf) >= 1
val krakenDustbinAnalysis = GearsKronaPlot.values(summary, runId, "gearskraken", "krakenreport", samples, libraries, sampleId, libId )
val centrifugeAnalysis = GearsKronaPlot.values(summary, runId, "gearscentrifuge", "centrifuge_report", samples, libraries, sampleId, libId )
val centrifugeUniqueAnalysis = GearsKronaPlot.values(summary, runId, "gearscentrifuge", "centrifuge_unique_report", samples, libraries, sampleId, libId )
val alignmentSummary = BamMetricsAlignmentReport.values(summary, runId, samples, libraries, sampleId, libId, sampleLevel =true,showPlot=true,showTable=false)
val mappingQualitySummary= BammetricsReport.mappingQualityPlotSummary(summary)
val krakenDustbinAnalysis = GearsKronaPlot.values(summary,
runId,
"gearskraken",
"krakenreport",
samples,
libraries,
sampleId,
libId)
val centrifugeAnalysis = GearsKronaPlot.values(summary,
runId,
"gearscentrifuge",
"centrifuge_report",
samples,
libraries,
sampleId,
libId)
val centrifugeUniqueAnalysis = GearsKronaPlot.values(summary,
runId,
"gearscentrifuge",
"centrifuge_unique_report",
samples,
libraries,
sampleId,
libId)
val alignmentSummary = BamMetricsAlignmentReport.values(summary,
runId,
samples,
libraries,
sampleId,
libId,
sampleLevel = true,
showPlot = true,
showTable = false)
val mappingQualitySummary = BammetricsReport.mappingQualityPlotTables(summary)
Future {
ReportPage(
List("Samples" -> generateSamplesPage(pageArgs)) ++
......@@ -108,13 +142,15 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder {
"Dustbin analysis - Kraken" -> Future.successful(
ReportPage(List(),
List("Krona plot" -> ReportSection(
"/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",krakenDustbinAnalysis)),
"/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
krakenDustbinAnalysis)),
Map())))
else Nil) ++ (if (centrifugeExecuted)
List(
"Centrifuge analysis" -> Future.successful(ReportPage(
List("Non-unique" -> Future.successful(
ReportPage(List(),
List(
"Non-unique" -> Future.successful(ReportPage(
List(),
List("All mappings" -> ReportSection(
"/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
centrifugeAnalysis)),
......
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