Commit 0a868bd9 authored by akaljuvee's avatar akaljuvee

sv-s are grouped by type also for the tables

parent ddada7c6
......@@ -7,37 +7,70 @@ import nl.lumc.sasc.biopet.utils.summary.Summary
object ShivaSvCallingReport {
val histogramBinBoundaries: Array[Int] = Array(100, 1000, 10000, 100000, 1000000, 10000000)
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[Any]]] = {
var result: Map[String, Map[String, Array[Any]]] = Map()
var delCounts, insCounts, dupCounts, invCounts: Map[String, Array[Any]] = Map()
for (sampleName <- summary.samples) {
var sampleCounts: Map[String, Any] = summary.getSampleValue(sampleName, "shivasvcalling", "stats", "variantsBySizeAndType").get.asInstanceOf[Map[String, Any]]
result = result + (sampleName -> sampleCounts.collect({ case (k, v: List[_]) => (k, v.toArray[Any]) }))
for ((svType, counts) <- sampleCounts.collect({ case (k, v: List[_]) => (k, v.toArray[Any]) })) {
svType match {
case "DEL" => delCounts = delCounts + (sampleName -> counts)
case "INS" => insCounts = insCounts + (sampleName -> counts)
case "DUP" => dupCounts = dupCounts + (sampleName -> counts)
case "INV" => invCounts = invCounts + (sampleName -> counts)
}
}
}
var result: Map[String, Map[String, Array[Any]]] = Map()
if (!delCounts.isEmpty) result = Map("DEL" -> delCounts)
if (!insCounts.isEmpty) result = result + ("INS" -> insCounts)
if (!dupCounts.isEmpty) result = result + ("DUP" -> dupCounts)
if (!invCounts.isEmpty) result = result + ("INV" -> invCounts)
result
}
def writeTsvForPlots(counts: Map[String, Map[String, Array[Any]]], svTypes: List[SvTypeForReport], outDir: File): Unit = {
val sampleNames = counts.keys
def writeTsvFiles(sampleNames: List[String], counts: Map[String, Map[String, Array[Any]]], svTypes: List[SvTypeForReport], outFileAllTypes: String, outDir: File): Unit = {
val tsvWriter = new PrintWriter(new File(outDir, outFileAllTypes))
tsvWriter.print("sv_type\tsample")
histogramText.foreach(bin => tsvWriter.print("\t" + bin))
tsvWriter.println()
for (sv <- svTypes) {
val tsvFile = new File(outDir, sv.tsvFileName)
val tsvWriter = new PrintWriter(tsvFile)
val countsForSvType: Map[String, Array[Any]] = counts.get(sv.svType).get
tsvWriter.print("binMax")
sampleNames.foreach(sampleName => tsvWriter.print("\t" + sampleName))
tsvWriter.println()
writeTsvFileForSvType(sv, countsForSvType, sampleNames, outDir)
for (i <- ShivaSvCalling.histogramBinBoundaries.indices) {
tsvWriter.print(ShivaSvCalling.histogramBinBoundaries(i))
sampleNames.foreach(sampleName => tsvWriter.print("\t" + counts.get(sampleName).get.get(sv.svType).get(i)))
tsvWriter.println()
for (sampleName <- sampleNames) {
tsvWriter.print(sv.svType + "\t" + sampleName + "\t")
tsvWriter.println(countsForSvType.get(sampleName).get.mkString("\t"))
}
val i = ShivaSvCalling.histogramBinBoundaries.length
tsvWriter.print(ShivaSvCalling.histogramBinBoundaries(i - 1) * 10)
sampleNames.foreach(sampleName => tsvWriter.print("\t" + counts.get(sampleName).get.get(sv.svType).get(i)))
tsvWriter.println()
}
tsvWriter.close()
}
tsvWriter.close()
def writeTsvFileForSvType(svType: SvTypeForReport, counts: Map[String, Array[Any]], sampleNames: List[String], outDir: File): Unit = {
val tsvWriter = new PrintWriter(new File(outDir, svType.tsvFileName))
tsvWriter.print("histogramBin")
sampleNames.foreach(sampleName => tsvWriter.print("\t" + sampleName))
tsvWriter.println()
for (i <- histogramBinBoundaries.indices) {
tsvWriter.print(histogramBinBoundaries(i))
sampleNames.foreach(sampleName => tsvWriter.print("\t" + counts.get(sampleName).get(i)))
tsvWriter.println()
}
val i = histogramBinBoundaries.length
tsvWriter.print(histogramBinBoundaries(i - 1) * 10)
sampleNames.foreach(sampleName => tsvWriter.print("\t" + counts.get(sampleName).get(i)))
tsvWriter.println()
tsvWriter.close()
}
def createPlots(svTypes: List[SvTypeForReport], outDir: File): Unit = {
......@@ -45,11 +78,12 @@ object ShivaSvCallingReport {
val tsvFile = new File(outDir, sv.tsvFileName)
val pngFile: File = new File(outDir, sv.pngFileName)
val plot = LinePlot(tsvFile, pngFile,
xlabel = Some(s"${sv.displayText} size"),
xlabel = Some(s"${sv.displayText.substring(0, sv.displayText.length - 1)} size"),
ylabel = Some("Number of loci"),
title = Some(sv.displayText + "s"),
width = 600,
title = Some(sv.displayText),
width = 400,
removeZero = false)
plot.height = Some(300)
plot.llabel = Some("Sample")
plot.xLog10 = true
plot.yLog10 = true
......
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