Commit 17ac2dce authored by Peter van 't Hof's avatar Peter van 't Hof

Adding report to shiva pipeline

parent 6a31f16a
package nl.lumc.sasc.biopet.pipelines.bammetrics
import java.io.{PrintWriter, File}
import java.io.{ PrintWriter, File }
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
/**
......@@ -65,8 +65,10 @@ object BammetricsReport extends ReportBuilder {
}
if (libraryLevel) {
for (sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get);
lib <- summary.libraries(sample)) {
for (
sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get);
lib <- summary.libraries(sample)
) {
tsvWriter.println(getLine(summary, sample, Some(lib)))
}
} else {
......@@ -85,5 +87,4 @@ object BammetricsReport extends ReportBuilder {
plot.runLocal()
}
}
......@@ -28,6 +28,6 @@ ggplot(DF1, aes(x = Rank, y = value, fill = variable)) +
ylab(arguments$ylabel) +
guides(fill=guide_legend(title=arguments$llabel)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8)) +
geom_bar(stat = "identity", width=0.75)
geom_bar(stat = "identity", width=1)
dev.off()
......@@ -18,6 +18,7 @@ package nl.lumc.sasc.biopet.core
import java.io.File
import java.io.PrintWriter
import nl.lumc.sasc.biopet.core.config.{ ConfigValueIndex, Config, Configurable }
import nl.lumc.sasc.biopet.core.report.{ ReportBuilderExtension, ReportBuilder }
import org.broadinstitute.gatk.utils.commandline.Argument
import org.broadinstitute.gatk.queue.QSettings
import org.broadinstitute.gatk.queue.function.QFunction
......@@ -57,6 +58,9 @@ trait BiopetQScript extends Configurable with GatkLogging {
/** Pipeline itself */
def biopetScript
/** Returns the extension to make the report */
def reportClass: Option[ReportBuilderExtension] = None
/** Script from queue itself, final to force some checks for each pipeline and write report */
final def script() {
outputDir = config("output_dir")
......@@ -81,6 +85,8 @@ trait BiopetQScript extends Configurable with GatkLogging {
globalConfig.writeReport(qSettings.runName, new File(outputDir, ".log/" + qSettings.runName))
else BiopetQScript.addError("Parent of output dir: '" + outputDir.getParent + "' is not writeable, outputdir can not be created")
reportClass.foreach(add(_))
BiopetQScript.checkErrors
}
......
......@@ -2,8 +2,9 @@ package nl.lumc.sasc.biopet.core.report
import java.io.{ PrintWriter, File }
import nl.lumc.sasc.biopet.core.ToolCommand
import nl.lumc.sasc.biopet.core.{ BiopetJavaCommandLineFunction, ToolCommand }
import nl.lumc.sasc.biopet.core.summary.Summary
import org.broadinstitute.gatk.utils.commandline.Input
import org.fusesource.scalate.{ TemplateSource, TemplateEngine }
import scala.io.Source
......@@ -11,15 +12,40 @@ import scala.io.Source
/**
* Created by pjvan_thof on 3/27/15.
*/
trait ReportBuilderExtension extends BiopetJavaCommandLineFunction {
val builder: ReportBuilder
@Input(required = true)
var summaryFile: File = _
var outputDir: File = _
var args: Map[String, String] = Map()
override def beforeGraph: Unit = {
super.beforeGraph
jobOutputFile = new File(outputDir, ".report.log.out")
javaMainClass = builder.getClass.getName.takeWhile(_ != '$')
}
override def commandLine: String = {
super.commandLine +
required("--summary", summaryFile) +
required("--outputDir", outputDir) +
args.map(x => required(x._1, x._2)).mkString
}
}
trait ReportBuilder extends ToolCommand {
case class Args(summary: File = null, outputDir: File = null, pageArgs: Map[String, String] = Map()) extends AbstractArgs
class OptParser extends AbstractOptParser {
opt[File]('s', "summary") required () maxOccurs (1) valueName ("<file>") action { (x, c) =>
opt[File]('s', "summary") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(summary = x)
}
opt[File]('o', "outputDir") required () maxOccurs (1) valueName ("<file>") action { (x, c) =>
opt[File]('o', "outputDir") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(outputDir = x)
}
opt[Map[String, String]]('a', "args") action { (x, c) =>
......@@ -50,7 +76,7 @@ trait ReportBuilder extends ToolCommand {
val cssDir = new File(cmdArgs.outputDir, "css")
cssDir.mkdirs()
val cssWriter = new PrintWriter(new File(cssDir, "biopet.css"))
Source.fromInputStream(getClass.getResourceAsStream("/nl/lumc/sasc/biopet/core/report/biopet.css")).getLines().foreach(cssWriter.println(_))
Source.fromInputStream(getClass.getResourceAsStream("/nl/lumc/sasc/biopet/core/report/biopet.css")).getLines().foreach(cssWriter.println)
cssWriter.close()
logger.info("Parsing summary")
......
......@@ -4,7 +4,7 @@ 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.{Output, Input}
import org.broadinstitute.gatk.utils.commandline.{ Output, Input }
/**
* Created by pjvan_thof on 4/29/15.
......
package nl.lumc.sasc.biopet.pipelines.flexiprep
import java.io.{PrintWriter, File}
import java.io.{ PrintWriter, File }
import nl.lumc.sasc.biopet.core.report.{ ReportSection, ReportPage, ReportBuilder }
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
/**
......@@ -44,10 +44,10 @@ object FlexiprepReport extends ReportBuilder {
// FIXME: Not yet finished
def readSummaryPlot(outputDir: File,
prefix: String,
read: String,
summary: Summary,
sampleId: Option[String] = None): Unit = {
prefix: String,
read: String,
summary: Summary,
sampleId: Option[String] = None): Unit = {
val tsvFile = new File(outputDir, prefix + ".tsv")
val pngFile = new File(outputDir, prefix + ".png")
val tsvWriter = new PrintWriter(tsvFile)
......@@ -74,8 +74,10 @@ object FlexiprepReport extends ReportBuilder {
sb.toString
}
for (sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get);
lib <- summary.libraries(sample)) {
for (
sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get);
lib <- summary.libraries(sample)
) {
tsvWriter.println(getLine(summary, sample, lib))
}
......@@ -112,8 +114,10 @@ object FlexiprepReport extends ReportBuilder {
sb.toString
}
for (sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get);
lib <- summary.libraries(sample)) {
for (
sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get);
lib <- summary.libraries(sample)
) {
tsvWriter.println(getLine(summary, sample, lib))
}
......
package nl.lumc.sasc.biopet.pipelines.shiva
import java.io.{PrintWriter, File}
import java.io.{ PrintWriter, File }
import nl.lumc.sasc.biopet.core.report.{ ReportSection, MultisampleReportBuilder, ReportPage }
import nl.lumc.sasc.biopet.core.summary.{SummaryValue, Summary}
import nl.lumc.sasc.biopet.core.config.Configurable
import nl.lumc.sasc.biopet.core.report.{ ReportBuilderExtension, ReportSection, MultisampleReportBuilder, ReportPage }
import nl.lumc.sasc.biopet.core.summary.{ SummaryValue, Summary }
import nl.lumc.sasc.biopet.extensions.rscript.StackedBarPlot
import nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport
import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport
......@@ -11,6 +12,10 @@ import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport
/**
* Created by pjvan_thof on 3/30/15.
*/
class ShivaReport(val root: Configurable) extends ReportBuilderExtension {
val builder = ShivaReport
}
object ShivaReport extends MultisampleReportBuilder {
// FIXME: Not yet finished
......@@ -74,10 +79,10 @@ object ShivaReport extends MultisampleReportBuilder {
def reportName = "Shiva Report"
def variantSummaryPlot(outputDir: File,
prefix: String,
summary: Summary,
libraryLevel: Boolean = false,
sampleId: Option[String] = None): Unit = {
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)
......@@ -103,8 +108,10 @@ object ShivaReport extends MultisampleReportBuilder {
}
if (libraryLevel) {
for (sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get);
lib <- summary.libraries(sample)) {
for (
sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get);
lib <- summary.libraries(sample)
) {
tsvWriter.println(getLine(summary, sample, Some(lib)))
}
} else {
......
......@@ -45,6 +45,13 @@ trait ShivaTrait extends MultiSampleQScript with SummaryQScript {
addSummaryJobs
}
override def reportClass = {
val shiva = new ShivaReport(this)
shiva.outputDir = new File(outputDir, "report")
shiva.summaryFile = summaryFile
Some(shiva)
}
/** Method to make the variantcalling submodule of shiva */
def makeVariantcalling(multisample: Boolean = false): ShivaVariantcallingTrait = {
if (multisample) new ShivaVariantcalling(qscript) {
......
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