Commit 2cb35802 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Added insertsize plot

parent e748e819
...@@ -4,7 +4,7 @@ import java.io.{ PrintWriter, File } ...@@ -4,7 +4,7 @@ import java.io.{ PrintWriter, File }
import nl.lumc.sasc.biopet.core.report.{ ReportBuilder, ReportPage, ReportSection } import nl.lumc.sasc.biopet.core.report.{ ReportBuilder, ReportPage, ReportSection }
import nl.lumc.sasc.biopet.core.summary.{ SummaryValue, Summary } import nl.lumc.sasc.biopet.core.summary.{ SummaryValue, Summary }
import nl.lumc.sasc.biopet.extensions.rscript.StackedBarPlot import nl.lumc.sasc.biopet.extensions.rscript.{XYPlot, StackedBarPlot}
/** /**
* Created by pjvan_thof on 3/30/15. * Created by pjvan_thof on 3/30/15.
...@@ -83,9 +83,68 @@ object BammetricsReport extends ReportBuilder { ...@@ -83,9 +83,68 @@ object BammetricsReport extends ReportBuilder {
plot.input = tsvFile plot.input = tsvFile
plot.output = pngFile plot.output = pngFile
plot.ylabel = Some("Reads") plot.ylabel = Some("Reads")
plot.width = Some(750) plot.width = Some(1200)
plot.title = Some("Aligned reads") plot.title = Some("Aligned reads")
plot.runLocal() plot.runLocal()
} }
def insertSizePlot(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.print("Library")
} 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 = {
new SummaryValue(List("bammetrics", "stats", "CollectInsertSizeMetrics", "histogram", "content"),
summary, Some(sample), lib).value.getOrElse(List(List("insert_size","All_Reads.fr_count"))) match {
case l:List[_] => {
l.tail.foreach(_ match {
case l:List[_] => {
val insertSize = l.head.toString.toInt
val count = l.tail.head.toString.toInt
val old = map.getOrElse(insertSize, Map())
map += insertSize -> (old + ((sample + lib.getOrElse("")) -> count))
}
case _ => throw new IllegalStateException("Must be a list")
})
}
case _ => throw new IllegalStateException("Must be a list")
}
}
summary.samples.foreach(fill(_, None))
for ((insertSize, counts) <- map) {
tsvWriter.print(insertSize)
for (sample <- summary.samples) {
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("Reads")
plot.xlabel = Some("Insertsize")
plot.width = Some(1200)
plot.title = Some("Insertsize")
plot.runLocal()
}
} }
library(reshape2)
library(ggplot2)
library(argparse)
parser <- ArgumentParser(description='Process some integers')
parser$add_argument('--input', dest='input', type='character', help='Input tsv file', required=TRUE)
parser$add_argument('--output', dest='output', type='character', help='Output png file', required=TRUE)
parser$add_argument('--width', dest='width', type='integer', default = 500)
parser$add_argument('--height', dest='height', type='integer', default = 500)
parser$add_argument('--xlabel', dest='xlabel', type='character')
parser$add_argument('--ylabel', dest='ylabel', type='character', required=TRUE)
parser$add_argument('--llabel', dest='llabel', type='character')
parser$add_argument('--title', dest='title', type='character')
arguments <- parser$parse_args()
png(filename = arguments$output, width = arguments$width, height = arguments$height)
DF <- read.table(arguments$input, header=TRUE)
if (is.null(arguments$xlabel)) xlab <- colnames(DF)[1] else xlab <- arguments$xlabel
colnames(DF)[1] <- "Rank"
DF1 <- melt(DF, id.var="Rank")
DF1 <- DF1[DF1$value > 0, ]
ggplot(DF1, aes(x = Rank, y = value, group = variable, color = variable)) +
xlab(xlab) +
ylab(arguments$ylabel) +
guides(fill=guide_legend(title=arguments$llabel)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8)) +
ggtitle(arguments$title) +
geom_line()
dev.off()
library('ggplot2')
library('reshape2')
args <- commandArgs(TRUE)
inputArg <- args[1]
outputArg <- args[2]
tsv<-read.table(inputArg, header = 1, sep= '\t', stringsAsFactors = F)
data <- melt(tsv)
data$X <- as.numeric(data$X)
data <- na.omit(data)
data <- data[data$value > 0,]
print("Starting to plot")
png(file = outputArg, width = 1500, height = 1500)
ggplot(data, aes(x=X, y=value, color=variable, group=variable)) + geom_line()
dev.off()
print("plot done")
package nl.lumc.sasc.biopet.extensions.rscript
import java.io.File
import nl.lumc.sasc.biopet.core.config.Configurable
import nl.lumc.sasc.biopet.extensions.RscriptCommandLineFunction
import org.broadinstitute.gatk.utils.commandline.{Input, Output}
/**
* Created by pjvan_thof on 4/29/15.
*/
class XYPlot(val root: Configurable) extends RscriptCommandLineFunction {
protected var script: File = config("script", default = "plotXY.R")
@Input
var input: File = _
@Output
var output: File = _
var width: Option[Int] = config("width")
var height: Option[Int] = config("height")
var xlabel: Option[String] = config("xlabel")
var ylabel: Option[String] = config("ylabel")
var llabel: Option[String] = config("llabel")
var title: Option[String] = config("title")
override def cmdLine: String = super.cmdLine +
required("--input", input) +
required("--output", output) +
optional("--width", width) +
optional("--height", height) +
optional("--xlabel", xlabel) +
required("--ylabel", ylabel) +
optional("--llabel", llabel) +
optional("--title", title)
}
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