Commit fbc8e4ab authored by akaljuvee's avatar akaljuvee
Browse files

using the new summary

parent 1d34f764
#import(nl.lumc.sasc.biopet.utils.summary.Summary) #import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb)
#import(nl.lumc.sasc.biopet.utils.summary.db.Schema.Sample)
#import(java.io.File) #import(java.io.File)
<%@ var summary: SummaryDb %>
<%@ var allSamples: Seq[Sample]%>
<%@ var rootPath: String %> <%@ var rootPath: String %>
<%@ var outputDir: File %> <%@ var outputDir: File %>
<%@ var sampleId: Option[String] = None %> <%@ var runId: Int %>
<%@ var summary: Summary %> <%@ var sampleId: Option[Int] = None %>
<%@ var showPlot: Boolean = false %> <%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %> <%@ var showTable: Boolean = true %>
<%@ var showIntro: Boolean = true %> <%@ var showIntro: Boolean = true %>
#{ #{
val sampleNames: List[String] = sampleId match { val sampleNames: Seq[String] = sampleId match {
case Some(sampleName) => List(sampleName.toString) case Some(sampleId) => Seq(allSamples.filter(s => s.id == sampleId).head.name)
case _ => summary.samples.toList.sorted case _ => allSamples.collect({case s: Sample => s.name}).sorted
} }
val counts: Map[String, Map[String, Array[Long]]] = ShivaSvCallingReport.parseSummaryForSvCounts(summary) val counts: Map[String, Map[String, Array[Long]]] = ShivaSvCallingReport.parseSummaryForSvCounts(summary, runId, sampleNames)
val traCounts: Map[String, Long] = ShivaSvCallingReport.parseSummaryForTranslocations(summary) val traCounts: Map[String, Long] = ShivaSvCallingReport.parseSummaryForTranslocations(summary, runId, sampleNames)
var svTypes = List( var svTypes = List(
SvTypeForReport("DEL", "Deletions", "svSummaryDeletions.tsv", "svSummaryDeletions.png"), SvTypeForReport("DEL", "Deletions", "svSummaryDeletions.tsv", "svSummaryDeletions.png"),
......
...@@ -3,7 +3,11 @@ package nl.lumc.sasc.biopet.pipelines.shiva ...@@ -3,7 +3,11 @@ package nl.lumc.sasc.biopet.pipelines.shiva
import java.io.{ File, PrintWriter } import java.io.{ File, PrintWriter }
import nl.lumc.sasc.biopet.utils.rscript.LinePlot import nl.lumc.sasc.biopet.utils.rscript.LinePlot
import nl.lumc.sasc.biopet.utils.summary.Summary import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb.{ ModuleName, PipelineName, SampleName }
import scala.concurrent.Await
import scala.concurrent.duration.Duration
object ShivaSvCallingReport { object ShivaSvCallingReport {
...@@ -11,11 +15,11 @@ object ShivaSvCallingReport { ...@@ -11,11 +15,11 @@ object ShivaSvCallingReport {
val histogramPlotTicks: Array[Int] = Array(100, 1000, 10000, 100000, 1000000, 10000000, 100000000) val histogramPlotTicks: Array[Int] = Array(100, 1000, 10000, 100000, 1000000, 10000000, 100000000)
val histogramText: List[String] = List("<=100bp", "0.1-1kb", "1-10kb", "10-100kb", "0.1-1Mb", "1-10Mb", ">10Mb") val histogramText: List[String] = List("<=100bp", "0.1-1kb", "1-10kb", "10-100kb", "0.1-1Mb", "1-10Mb", ">10Mb")
def parseSummaryForSvCounts(summary: Summary): Map[String, Map[String, Array[Long]]] = { def parseSummaryForSvCounts(summary: SummaryDb, runId: Int, sampleNames: Seq[String]): Map[String, Map[String, Array[Long]]] = {
var delCounts, insCounts, dupCounts, invCounts: Map[String, Array[Long]] = Map() var delCounts, insCounts, dupCounts, invCounts: Map[String, Array[Long]] = Map()
for (sampleName <- summary.samples) { for (sampleName <- sampleNames) {
var sampleCounts: Map[String, Any] = summary.getSampleValue(sampleName, "shivasvcalling", "stats", "variantsBySizeAndType").get.asInstanceOf[Map[String, Any]] val sampleCounts: Map[String, Any] = Await.result(summary.getStat(runId, PipelineName("shivasvcalling"), ModuleName("variantsBySizeAndType"), SampleName(sampleName)), Duration.Inf).get
for ((svType, counts) <- sampleCounts.collect({ case (k, v: List[_]) => (k, v.toArray[Any]) })) { for ((svType, counts) <- sampleCounts.collect({ case (k, v: List[_]) => (k, v.toArray[Any]) })) {
val elem: Tuple2[String, Array[Long]] = (sampleName, counts.collect({ case x: Long => x })) val elem: Tuple2[String, Array[Long]] = (sampleName, counts.collect({ case x: Long => x }))
svType match { svType match {
...@@ -35,16 +39,16 @@ object ShivaSvCallingReport { ...@@ -35,16 +39,16 @@ object ShivaSvCallingReport {
result result
} }
def parseSummaryForTranslocations(summary: Summary): Map[String, Long] = { def parseSummaryForTranslocations(summary: SummaryDb, runId: Int, sampleNames: Seq[String]): Map[String, Long] = {
var traCounts: Map[String, Long] = Map() var traCounts: Map[String, Long] = Map()
for (sampleName <- summary.samples) { for (sampleName <- sampleNames) {
var counts: Map[String, Any] = summary.getSampleValue(sampleName, "shivasvcalling", "stats", "variantsBySizeAndType").get.asInstanceOf[Map[String, Any]] val counts: Map[String, Any] = Await.result(summary.getStat(runId, PipelineName("shivasvcalling"), ModuleName("variantsBySizeAndType"), SampleName(sampleName)), Duration.Inf).get
traCounts += (sampleName -> counts.get("TRA").get.asInstanceOf[Long]) traCounts += (sampleName -> counts.get("TRA").get.asInstanceOf[Long])
} }
if (traCounts.exists(elem => elem._2 > 0)) traCounts else Map.empty if (traCounts.exists(elem => elem._2 > 0)) traCounts else Map.empty
} }
def writeTsvFiles(sampleNames: List[String], counts: Map[String, Map[String, Array[Long]]], svTypes: List[SvTypeForReport], outFileAllTypes: String, outDir: File): Unit = { def writeTsvFiles(sampleNames: Seq[String], counts: Map[String, Map[String, Array[Long]]], svTypes: List[SvTypeForReport], outFileAllTypes: String, outDir: File): Unit = {
val tsvWriter = new PrintWriter(new File(outDir, outFileAllTypes)) val tsvWriter = new PrintWriter(new File(outDir, outFileAllTypes))
tsvWriter.print("sv_type\tsample") tsvWriter.print("sv_type\tsample")
...@@ -64,7 +68,7 @@ object ShivaSvCallingReport { ...@@ -64,7 +68,7 @@ object ShivaSvCallingReport {
tsvWriter.close() tsvWriter.close()
} }
def writeTsvFileForSvType(svType: SvTypeForReport, counts: Map[String, Array[Long]], sampleNames: List[String], outDir: File): Unit = { def writeTsvFileForSvType(svType: SvTypeForReport, counts: Map[String, Array[Long]], sampleNames: Seq[String], outDir: File): Unit = {
val tsvWriter = new PrintWriter(new File(outDir, svType.tsvFileName)) val tsvWriter = new PrintWriter(new File(outDir, svType.tsvFileName))
tsvWriter.print("histogramBin") tsvWriter.print("histogramBin")
......
Supports Markdown
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