Commit eb4539c3 authored by Peter van 't Hof's avatar Peter van 't Hof

Fix style

parent 74d3c3a9
......@@ -14,12 +14,12 @@
*/
package nl.lumc.sasc.biopet.pipelines.bammetrics
import java.io.{File, PrintWriter}
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.rscript.{ LinePlot, StackedBarPlot }
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb
import scala.concurrent.ExecutionContext.Implicits.global
......@@ -69,10 +69,9 @@ object BammetricsReport extends ReportBuilder {
val insertsizeMetrics = summary.getStatKeys(runId, Right(metricsTag), Some(Right("CollectInsertSizeMetrics")),
sample = sampleId.map(Left(_)), library = libId.map(Left(_)), Map("metrics" -> List("metrics")))
.exists(_._2.isDefined)
.exists(_._2.isDefined)
val targetSettings = summary.getSettingKeys(runId, Right(metricsTag),None, sample = sampleId.map(Left(_)), library = libId.map(Left(_)),
val targetSettings = summary.getSettingKeys(runId, Right(metricsTag), None, sample = sampleId.map(Left(_)), library = libId.map(Left(_)),
Map("amplicon_name" -> List("amplicon_name"), "roi_name" -> List("roi_name")))
val targets = (
targetSettings("amplicon_name"),
......@@ -136,9 +135,9 @@ object BammetricsReport extends ReportBuilder {
summary.getStatsForLibraries(runId, Right("bammetrics"), Some(Right("bamstats")),
sampleId = sampleId, keyValues = statsPaths).map(x => (x._1._1, Some(x._1._2)) -> x._2)
} else summary.getStatsForSamples(runId, Right("bammetrics"), Some(Right("bamstats")),
sample = sampleId.map(Left(_)), keyValues = statsPaths).map(x => (x._1, None) -> x._2)
sample = sampleId.map(Left(_)), keyValues = statsPaths).map(x => (x._1, None) -> x._2)
for (((s,l),result) <- results) {
for (((s, l), result) <- results) {
val sampleName: String = summary.getSampleName(s).map(_.get)
val libName: Option[String] = l.flatMap(x => Await.result(summary.getLibraryName(x), Duration.Inf))
val sb = new StringBuffer()
......@@ -168,20 +167,20 @@ object BammetricsReport extends ReportBuilder {
}
def writePlotFromSummary(outputDir: File,
prefix: String,
summary: SummaryDb,
libraryLevel: Boolean = false,
sampleId: Option[Int] = None,
libraryId: Option[Int] = None,
statsPaths: Map[String, List[String]],
xKey: String,
yKey: String,
pipeline: Either[Int,String],
module: Option[Either[Int,String]],
xlabel: Option[String] = None,
ylabel: Option[String] = None,
title: Option[String] = None,
removeZero: Boolean = true): Unit = {
prefix: String,
summary: SummaryDb,
libraryLevel: Boolean = false,
sampleId: Option[Int] = None,
libraryId: Option[Int] = None,
statsPaths: Map[String, List[String]],
xKey: String,
yKey: String,
pipeline: Either[Int, String],
module: Option[Either[Int, String]],
xlabel: Option[String] = None,
ylabel: Option[String] = None,
title: Option[String] = None,
removeZero: Boolean = true): Unit = {
val tsvFile = new File(outputDir, prefix + ".tsv")
val pngFile = new File(outputDir, prefix + ".png")
......@@ -191,14 +190,15 @@ object BammetricsReport extends ReportBuilder {
} else summary.getStatsForSamples(runId, pipeline, module, sample = sampleId.map(Left(_)), keyValues = statsPaths)
.map(x => (x._1, None) -> x._2.map(x => x._1 -> x._2.map(ConfigUtils.any2list(_).toArray)))
val tables: Array[Map[String, Array[Any]]] = results.map { case ((sample,library), map) =>
val tables: Array[Map[String, Array[Any]]] = results.map {
case ((sample, library), map) =>
val sampleName = Await.result(summary.getSampleName(sample), Duration.Inf)
.getOrElse(throw new IllegalStateException("Sample must be there"))
val libraryName = library.flatMap(l => Await.result(summary.getLibraryName(l), Duration.Inf))
Map(
yKey -> map(yKey).getOrElse(Array()),
(sampleName + libraryName.map("-" + _)getOrElse("")) -> map(xKey).getOrElse(Array())
)
Map(
yKey -> map(yKey).getOrElse(Array()),
(sampleName + libraryName.map("-" + _) getOrElse ("")) -> map(xKey).getOrElse(Array())
)
}.toArray
writeTableToTsv(tsvFile, mergeTables(tables, yKey), yKey)
......@@ -230,7 +230,7 @@ object BammetricsReport extends ReportBuilder {
"count" -> List("histogram", "All_Reads.fr_count")
)
writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId,statsPaths,
writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths,
"insert_size", "count", Right("bammetrics"), Some(Right("CollectInsertSizeMetrics")),
"Insert size", "Reads", "Insert size")
}
......
......@@ -50,14 +50,14 @@ trait MultisampleReportBuilder extends ReportBuilder {
val samplePages = samples.map(_.id)
.map(sampleId => sampleId -> samplePage(sampleId, args ++ Map("sampleId" -> Some(sampleId))))
.toList
ReportPage(samplePages.map(x => samples.find(_.name == x._1).get.name -> x._2), samplesSections, args)
ReportPage(samplePages.map(x => samples.find(_.id == x._1).get.name -> x._2), samplesSections, args)
}
/** Generate the libraries page for a single sample with a subpage for eacht library */
def generateLibraryPage(args: Map[String, Any]): ReportPage = {
val sampleId = args("sampleId") match {
case Some(x: Int) => x
case None => throw new IllegalStateException("Sample not found")
case None => throw new IllegalStateException("Sample not found")
}
val libraries = Await.result(summary.getLibraries(runId = Some(runId), sampleId = Some(sampleId)), Duration.Inf)
......@@ -65,6 +65,6 @@ trait MultisampleReportBuilder extends ReportBuilder {
val libPages = libraries.map(_.id)
.map(libId => libId -> libraryPage(sampleId, libId, args ++ Map("libId" -> Some(libId))))
.toList
ReportPage(libPages.map(x => libraries.find(_.name == x._1).get.name -> x._2), librariesSections, args)
ReportPage(libPages.map(x => libraries.find(_.id == x._1).get.name -> x._2), librariesSections, args)
}
}
......@@ -17,15 +17,15 @@ package nl.lumc.sasc.biopet.core.report
import java.io._
import nl.lumc.sasc.biopet.core.ToolCommandFunction
import nl.lumc.sasc.biopet.utils.summary.db.Schema.{Library, Sample}
import nl.lumc.sasc.biopet.utils.summary.db.Schema.{ Library, Sample }
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb
import nl.lumc.sasc.biopet.utils.{IoUtils, Logging, ToolCommand}
import nl.lumc.sasc.biopet.utils.{ IoUtils, Logging, ToolCommand }
import org.broadinstitute.gatk.utils.commandline.Input
import nl.lumc.sasc.biopet.utils.tryToParseNumber
import org.fusesource.scalate.{TemplateEngine, TemplateSource}
import org.fusesource.scalate.{ TemplateEngine, TemplateSource }
import scala.collection.mutable
import scala.concurrent.{Await, Future}
import scala.concurrent.{ Await, Future }
import scala.concurrent.duration.Duration
import scala.language.postfixOps
......@@ -73,8 +73,8 @@ trait ReportBuilderExtension extends ToolCommandFunction {
trait ReportBuilder extends ToolCommand {
implicit def toOption[T](x: T) : Option[T] = Option(x)
implicit def autoWait[T](x: Future[T]) : T = Await.result(x, Duration.Inf)
implicit def toOption[T](x: T): Option[T] = Option(x)
implicit def autoWait[T](x: Future[T]): T = Await.result(x, Duration.Inf)
case class Args(summaryDbFile: File = null,
outputDir: File = null,
......
package nl.lumc.sasc.biopet.utils.implicits
/**
* Created by pjvanthof on 20/02/2017.
*/
* Created by pjvanthof on 20/02/2017.
*/
object Either {
implicit def optionEitherLeft[T](x: Option[Either[T,_]]): Option[Option[T]] = {
implicit def optionEitherLeft[T](x: Option[Either[T, _]]): Option[Option[T]] = {
x match {
case Some(i:Either[T, _]) if i.isLeft => Some(i.left.toOption)
case _ => None
case Some(i: Either[T, _]) if i.isLeft => Some(i.left.toOption)
case _ => None
}
}
implicit def optionEitherRight[T](x: Option[Either[_,T]]): Option[Option[T]] = {
implicit def optionEitherRight[T](x: Option[Either[_, T]]): Option[Option[T]] = {
x match {
case Some(i:Either[_,T]) if i.isRight => Some(i.right.toOption)
case _ => None
case Some(i: Either[_, T]) if i.isRight => Some(i.right.toOption)
case _ => None
}
}
implicit def eitherLeft[T](x: Either[T,_]): Option[T] = {
implicit def eitherLeft[T](x: Either[T, _]): Option[T] = {
x match {
case Left(x) => Some(x)
case _ => None
case _ => None
}
}
implicit def eitherRight[T](x: Either[_,T]): Option[T] = {
implicit def eitherRight[T](x: Either[_, T]): Option[T] = {
x match {
case Right(x) => Some(x)
case _ => None
case _ => None
}
}
implicit def left[T](x:T): Left[T, _] = Left(x)
implicit def right[T](x:T): Right[_, T] = Right(x)
implicit def left[T](x:Option[T]): Option[Left[T, _]] = x.map(Left(_))
implicit def right[T](x:Option[T]): Option[Right[_, T]] = x.map(Right(_))
implicit def left[T](x: T): Left[T, _] = Left(x)
implicit def right[T](x: T): Right[_, T] = Right(x)
implicit def left[T](x: Option[T]): Option[Left[T, _]] = x.map(Left(_))
implicit def right[T](x: Option[T]): Option[Right[_, T]] = x.map(Right(_))
}
......@@ -15,7 +15,7 @@
package nl.lumc.sasc.biopet.pipelines.gears
import nl.lumc.sasc.biopet.utils.implicits.Either._
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.flexiprep.FlexiprepReport
import nl.lumc.sasc.biopet.utils.config.Configurable
......@@ -86,7 +86,6 @@ object GearsReport extends MultisampleReportBuilder {
val qiimeClosesOtuTable = Await.result(summary.getFile(runId, "gears", None, sampleName, None, key = "qiime_closed_otu_table"), Duration.Inf)
val qiimeOpenOtuTable = Await.result(summary.getFile(runId, "gears", None, sampleName, None, key = "qiime_open_otu_table"), Duration.Inf)
ReportPage((if (centrifugeExecuted) List("Centriguge analysis" -> ReportPage(List("Non-unique" -> ReportPage(List(), List("All mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
Map("summaryStatsTag" -> "centrifuge_report")
)), Map())), List(
......@@ -121,7 +120,6 @@ object GearsReport extends MultisampleReportBuilder {
val qiimeClosesOtuTable = Await.result(summary.getFile(runId, "gears", None, sName, lName, key = "qiime_closed_otu_table"), Duration.Inf)
val qiimeOpenOtuTable = Await.result(summary.getFile(runId, "gears", None, sName, lName, key = "qiime_open_otu_table"), Duration.Inf)
ReportPage(
(if (flexiprepExecuted) List("QC" -> FlexiprepReport.flexiprepPage) else Nil
) ::: (if (centrifugeExecuted) List("Centriguge analysis" -> ReportPage(List("Non-unique" -> ReportPage(List(), List("All mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
......
......@@ -14,7 +14,7 @@
*/
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.BammetricsReport
import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport
import nl.lumc.sasc.biopet.utils.config.Configurable
......
......@@ -14,14 +14,14 @@
*/
package nl.lumc.sasc.biopet.pipelines.shiva
import java.io.{File, PrintWriter}
import java.io.{ File, PrintWriter }
import nl.lumc.sasc.biopet.core.report._
import nl.lumc.sasc.biopet.pipelines.mapping.MultisampleMappingReportTrait
import nl.lumc.sasc.biopet.utils.config.Configurable
import nl.lumc.sasc.biopet.utils.rscript.StackedBarPlot
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb
import nl.lumc.sasc.biopet.utils.summary.{Summary, SummaryValue}
import nl.lumc.sasc.biopet.utils.summary.{ Summary, SummaryValue }
import scala.concurrent.Await
import scala.concurrent.duration.Duration
......@@ -43,9 +43,9 @@ trait ShivaReportTrait extends MultisampleMappingReportTrait {
def variantcallingExecuted = summary.getSettingKeys(runId, Right("shiva"), None, keyValues = Map("multisample_variantcalling" -> List("multisample_variantcalling"))).get("multisample_variantcalling")
.flatten match {
case Some(true) => true
case _ => false
}
case Some(true) => true
case _ => false
}
override def frontSection = ReportSection("/nl/lumc/sasc/biopet/pipelines/shiva/shivaFront.ssp")
......
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