Commit 9867341f authored by Peter van 't Hof's avatar Peter van 't Hof

Merge remote-tracking branch 'remotes/origin/develop' into release-0.8.0

# Conflicts:
#	gears/src/main/scala/nl/lumc/sasc/biopet/pipelines/gears/GearsReport.scala
parents 270dfad0 9cb69c59
...@@ -16,16 +16,19 @@ package nl.lumc.sasc.biopet.extensions.centrifuge ...@@ -16,16 +16,19 @@ package nl.lumc.sasc.biopet.extensions.centrifuge
import java.io.File import java.io.File
import nl.lumc.sasc.biopet.core.summary.Summarizable
import nl.lumc.sasc.biopet.core.{ BiopetCommandLineFunction, Version } import nl.lumc.sasc.biopet.core.{ BiopetCommandLineFunction, Version }
import nl.lumc.sasc.biopet.utils.config.Configurable import nl.lumc.sasc.biopet.utils.config.Configurable
import nl.lumc.sasc.biopet.utils.tryToParseNumber
import org.broadinstitute.gatk.utils.commandline.{ Input, Output } import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
import scala.io.Source
import scala.util.matching.Regex import scala.util.matching.Regex
/** /**
* Created by pjvanthof on 19/09/16. * Created by pjvanthof on 19/09/16.
*/ */
class Centrifuge(val root: Configurable) extends BiopetCommandLineFunction with Version { class Centrifuge(val root: Configurable) extends BiopetCommandLineFunction with Version with Summarizable {
@Input(doc = "Input: FastQ or FastA", required = true) @Input(doc = "Input: FastQ or FastA", required = true)
var inputR1: File = _ var inputR1: File = _
...@@ -143,4 +146,18 @@ class Centrifuge(val root: Configurable) extends BiopetCommandLineFunction with ...@@ -143,4 +146,18 @@ class Centrifuge(val root: Configurable) extends BiopetCommandLineFunction with
}) + }) +
(if (outputAsStsout) "" else required("-S", output)) + (if (outputAsStsout) "" else required("-S", output)) +
optional("--report-file", report) optional("--report-file", report)
/** Must return files to store into summary */
override def summaryFiles: Map[String, File] = metFile.map("metrics" -> _).toMap
/** Must returns stats to store into summary */
override def summaryStats: Any = {
metFile.map { file =>
val reader = Source.fromFile(file)
val header = reader.getLines().next().split("\t")
val values = reader.getLines().next().split("\t").map(tryToParseNumber(_, true).get)
reader.close()
Map("metrics" -> header.zip(values).toMap)
}.getOrElse(Map())
}
} }
...@@ -25,7 +25,7 @@ import scala.io.Source ...@@ -25,7 +25,7 @@ import scala.io.Source
*/ */
object DownloadNcbiAssembly extends ToolCommand { object DownloadNcbiAssembly extends ToolCommand {
case class Args(assemblyId: String = null, case class Args(assemblyReport: File = null,
outputFile: File = null, outputFile: File = null,
reportFile: Option[File] = None, reportFile: Option[File] = None,
contigNameHeader: Option[String] = None, contigNameHeader: Option[String] = None,
...@@ -33,8 +33,8 @@ object DownloadNcbiAssembly extends ToolCommand { ...@@ -33,8 +33,8 @@ object DownloadNcbiAssembly extends ToolCommand {
mustNotHave: List[(String, String)] = List()) extends AbstractArgs mustNotHave: List[(String, String)] = List()) extends AbstractArgs
class OptParser extends AbstractOptParser { class OptParser extends AbstractOptParser {
opt[String]('a', "assembly id") required () unbounded () valueName "<file>" action { (x, c) => opt[File]('a', "assembly_report") required () unbounded () valueName "<file>" action { (x, c) =>
c.copy(assemblyId = x) c.copy(assemblyReport = x)
} text "refseq ID from NCBI" } text "refseq ID from NCBI"
opt[File]('o', "output") required () unbounded () valueName "<file>" action { (x, c) => opt[File]('o', "output") required () unbounded () valueName "<file>" action { (x, c) =>
c.copy(outputFile = x) c.copy(outputFile = x)
...@@ -66,8 +66,8 @@ object DownloadNcbiAssembly extends ToolCommand { ...@@ -66,8 +66,8 @@ object DownloadNcbiAssembly extends ToolCommand {
val argsParser = new OptParser val argsParser = new OptParser
val cmdargs: Args = argsParser.parse(args, Args()) getOrElse (throw new IllegalArgumentException) val cmdargs: Args = argsParser.parse(args, Args()) getOrElse (throw new IllegalArgumentException)
logger.info(s"Reading ${cmdargs.assemblyId} from NCBI") logger.info(s"Reading ${cmdargs.assemblyReport}")
val reader = Source.fromURL(s"ftp://ftp.ncbi.nlm.nih.gov/genomes/ASSEMBLY_REPORTS/All/${cmdargs.assemblyId}.assembly.txt") val reader = Source.fromFile(cmdargs.assemblyReport)
val assamblyReport = reader.getLines().toList val assamblyReport = reader.getLines().toList
reader.close() reader.close()
cmdargs.reportFile.foreach { file => cmdargs.reportFile.foreach { file =>
......
...@@ -37,7 +37,7 @@ class DownloadNcbiAssemblyTest extends TestNGSuite with Matchers { ...@@ -37,7 +37,7 @@ class DownloadNcbiAssemblyTest extends TestNGSuite with Matchers {
val outputReport = File.createTempFile("test.", ".report") val outputReport = File.createTempFile("test.", ".report")
output.deleteOnExit() output.deleteOnExit()
outputReport.deleteOnExit() outputReport.deleteOnExit()
DownloadNcbiAssembly.main(Array("-a", "GCF_000844745.1", DownloadNcbiAssembly.main(Array("-a", new File(resourcePath("/GCF_000844745.1.report")).getAbsolutePath,
"-o", output.getAbsolutePath, "-o", output.getAbsolutePath,
"--report", outputReport.getAbsolutePath)) "--report", outputReport.getAbsolutePath))
......
...@@ -10,17 +10,23 @@ ...@@ -10,17 +10,23 @@
<%@ var libId: Option[String] = None %> <%@ var libId: Option[String] = None %>
<%@ var args: Map[String, Any] %> <%@ var args: Map[String, Any] %>
<%@ var outputDir: File %> <%@ var outputDir: File %>
<%@ var centrifugeTag: Option[String] = None %>
<%@ var summaryStatsTag: String = "krakenreport" %> <%@ var summaryStatsTag: String = "krakenreport" %>
<%@ var summaryModuleTag: String = "gearskraken" %> <%@ var summaryModuleTag: String = "gearskraken" %>
<% <%
val summaries = if (sampleId.isEmpty && libId.isEmpty) { val summaries = if (sampleId.isEmpty) {
summary.getSampleValues(summaryModuleTag, "stats", summaryStatsTag).map(x => x._1 -> x._2.get.asInstanceOf[Map[String, Any]]) summary.getSampleValues(summaryModuleTag, "stats", summaryStatsTag).map(x => x._1 -> x._2.get.asInstanceOf[Map[String, Any]])
} else summary.getValue(sampleId, libId, summaryModuleTag, "stats", summaryStatsTag).map(sampleId.get -> _.asInstanceOf[Map[String, Any]]).toList.toMap } else summary.getValue(sampleId, libId, summaryModuleTag, "stats", summaryStatsTag).map(sampleId.get -> _.asInstanceOf[Map[String, Any]]).toList.toMap
val totalReads = if (sampleId.isEmpty) {
centrifugeTag.map {tag => summary.getSampleValues(summaryModuleTag, "stats", tag, "metrics", "Read").map(x => x._1 -> x._2.getOrElse(0L).toString.toLong) }
} else centrifugeTag.flatMap(tag => summary.getValue(sampleId, libId, summaryModuleTag, "stats", tag, "metrics", "Read"))
.map(value => Map(sampleId.get -> value.toString.toLong))
val tempFile = File.createTempFile("krona.", ".xml") val tempFile = File.createTempFile("krona.", ".xml")
tempFile.deleteOnExit() tempFile.deleteOnExit()
GearsKraken.convertKrakenSummariesToKronaXml(summaries, tempFile) GearsKraken.convertKrakenSummariesToKronaXml(summaries, tempFile, totalReads)
val output = ReportBuilder.renderTemplate("/nl/lumc/sasc/biopet/core/report/krona.ssp", val output = ReportBuilder.renderTemplate("/nl/lumc/sasc/biopet/core/report/krona.ssp",
args ++ Map("kronaXml" -> tempFile)) args ++ Map("kronaXml" -> tempFile))
......
...@@ -52,6 +52,7 @@ class GearsCentrifuge(val root: Configurable) extends QScript with SummaryQScrip ...@@ -52,6 +52,7 @@ class GearsCentrifuge(val root: Configurable) extends QScript with SummaryQScrip
val centrifugeCmd = centrifuge | new Gzip(this) > centrifugeOutput val centrifugeCmd = centrifuge | new Gzip(this) > centrifugeOutput
centrifugeCmd.threadsCorrection = -1 centrifugeCmd.threadsCorrection = -1
add(centrifugeCmd) add(centrifugeCmd)
addSummarizable(centrifuge, "centrifuge")
makeKreport("centrifuge", unique = false) makeKreport("centrifuge", unique = false)
makeKreport("centrifuge_unique", unique = true) makeKreport("centrifuge_unique", unique = true)
......
...@@ -120,7 +120,7 @@ object GearsKraken { ...@@ -120,7 +120,7 @@ object GearsKraken {
convertKrakenSummariesToKronaXml(summaries, outputFile) convertKrakenSummariesToKronaXml(summaries, outputFile)
} }
def convertKrakenSummariesToKronaXml(summaries: Map[String, Map[String, Any]], outputFile: File): Unit = { def convertKrakenSummariesToKronaXml(summaries: Map[String, Map[String, Any]], outputFile: File, totalReads: Option[Map[String, Long]] = None): Unit = {
val samples = summaries.keys.toList.sorted val samples = summaries.keys.toList.sorted
...@@ -156,7 +156,7 @@ object GearsKraken { ...@@ -156,7 +156,7 @@ object GearsKraken {
if (k == "root") { if (k == "root") {
val unclassified = summaries(sample)("unclassified").asInstanceOf[Map[String, Any]]("size").asInstanceOf[Long] val unclassified = summaries(sample)("unclassified").asInstanceOf[Map[String, Any]]("size").asInstanceOf[Long]
<val> <val>
{ getValue(sample, (path ::: k :: Nil).tail, "size").getOrElse(0).toString.toLong + unclassified } { totalReads.flatMap(_.get(sample)).getOrElse(getValue(sample, (path ::: k :: Nil).tail, "size").getOrElse(0).toString.toLong + unclassified) }
</val> </val>
} else { } else {
<val> <val>
......
...@@ -50,7 +50,7 @@ object GearsReport extends MultisampleReportBuilder { ...@@ -50,7 +50,7 @@ object GearsReport extends MultisampleReportBuilder {
)), Map())), List( )), Map())), List(
"Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp", "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
Map("summaryStatsTag" -> "centrifuge_unique_report") Map("summaryStatsTag" -> "centrifuge_unique_report")
)), Map("summaryModuleTag" -> "gearscentrifuge"))) )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge"))))
else Nil) ::: (if (krakenExecuted) List("Kraken analysis" -> ReportPage(List(), List( else Nil) ::: (if (krakenExecuted) List("Kraken analysis" -> ReportPage(List(), List(
"Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp" "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
)), Map())) )), Map()))
...@@ -92,7 +92,7 @@ object GearsReport extends MultisampleReportBuilder { ...@@ -92,7 +92,7 @@ object GearsReport extends MultisampleReportBuilder {
)), Map())), List( )), Map())), List(
"Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp", "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
Map("summaryStatsTag" -> "centrifuge_unique_report") Map("summaryStatsTag" -> "centrifuge_unique_report")
)), Map("summaryModuleTag" -> "gearscentrifuge"))) )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge"))))
else Nil) ::: (if (krakenExecuted) List("Kraken analysis" -> ReportPage(List(), List( else Nil) ::: (if (krakenExecuted) List("Kraken analysis" -> ReportPage(List(), List(
"Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp" "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
)), Map())) )), Map()))
...@@ -126,7 +126,7 @@ object GearsReport extends MultisampleReportBuilder { ...@@ -126,7 +126,7 @@ object GearsReport extends MultisampleReportBuilder {
)), Map())), List( )), Map())), List(
"Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp", "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
Map("summaryStatsTag" -> "centrifuge_unique_report") Map("summaryStatsTag" -> "centrifuge_unique_report")
)), Map("summaryModuleTag" -> "gearscentrifuge"))) )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge"))))
else Nil) ::: (if (krakenExecuted) List("Kraken analysis" -> ReportPage(List(), List( else Nil) ::: (if (krakenExecuted) List("Kraken analysis" -> ReportPage(List(), List(
"Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp" "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
)), Map())) )), Map()))
......
...@@ -94,18 +94,21 @@ class GearsSingle(val root: Configurable) extends QScript with SummaryQScript wi ...@@ -94,18 +94,21 @@ class GearsSingle(val root: Configurable) extends QScript with SummaryQScript wi
Some(outputFile) Some(outputFile)
} }
if (!skipFlexiprep) { flexiprep.map { f =>
val flexiprep = new Flexiprep(this) f.inputR1 = read1
flexiprep.inputR1 = read1 f.inputR2 = read2
flexiprep.inputR2 = read2 f.sampleId = Some(sampleId.getOrElse("noSampleName"))
flexiprep.sampleId = if (sampleId.isEmpty) Some("noSampleName") else sampleId f.libId = Some(libId.getOrElse("noLibName"))
flexiprep.libId = if (libId.isEmpty) Some("noLibName") else libId f.outputDir = new File(outputDir, "flexiprep")
flexiprep.outputDir = new File(outputDir, "flexiprep") add(f)
add(flexiprep) (f.fastqR1Qc, f.fastqR2Qc)
(flexiprep.fastqR1Qc, flexiprep.fastqR2Qc) }.getOrElse((read1, read2))
} else (read1, read2)
} }
lazy protected val flexiprep: Option[Flexiprep] = if (!skipFlexiprep) {
Some(new Flexiprep(this))
} else None
/** Method to add jobs */ /** Method to add jobs */
def biopetScript(): Unit = { def biopetScript(): Unit = {
val (r1, r2): (File, Option[File]) = (fastqR1, fastqR2, bamFile) match { val (r1, r2): (File, Option[File]) = (fastqR1, fastqR2, bamFile) match {
......
...@@ -41,7 +41,7 @@ object GearsSingleReport extends ReportBuilder { ...@@ -41,7 +41,7 @@ object GearsSingleReport extends ReportBuilder {
else Nil) ++ else Nil) ++
(if (centrifugeExecuted) List("Centrifuge analysis" -> (if (centrifugeExecuted) List("Centrifuge analysis" ->
ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp", ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
Map("summaryModuleTag" -> "gearscentrifuge", "summaryStatsTag" -> "centrifuge_unique_report"))) Map("summaryModuleTag" -> "gearscentrifuge", "summaryStatsTag" -> "centrifuge_unique_report", "centrifugeTag" -> Some("centrifuge"))))
else Nil), else Nil),
pageArgs pageArgs
) )
......
...@@ -65,7 +65,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder { ...@@ -65,7 +65,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder {
)), Map())), List( )), Map())), List(
"Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp", "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
Map("summaryStatsTag" -> "centrifuge_unique_report") Map("summaryStatsTag" -> "centrifuge_unique_report")
)), Map("summaryModuleTag" -> "gearscentrifuge"))) )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge"))))
else Nil) ++ else Nil) ++
List("Reference" -> ReportPage(List(), List( List("Reference" -> ReportPage(List(), List(
"Reference" -> ReportSection("/nl/lumc/sasc/biopet/core/report/reference.ssp", Map("pipeline" -> pipelineName)) "Reference" -> ReportSection("/nl/lumc/sasc/biopet/core/report/reference.ssp", Map("pipeline" -> pipelineName))
...@@ -128,7 +128,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder { ...@@ -128,7 +128,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder {
"Libraries" -> generateLibraryPage(args), "Libraries" -> generateLibraryPage(args),
"Alignment" -> BammetricsReport.bamMetricsPage(summary, Some(sampleId), None)) ++ "Alignment" -> BammetricsReport.bamMetricsPage(summary, Some(sampleId), None)) ++
(if (centrifugeExecuted) List("Centriguge analysis" -> ReportPage(List("Non-unique" -> ReportPage(List(), List("All mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp", (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("summaryStatsTag" -> "centrifuge_report", "centrifugeTag" -> Some("centrifuge"))
)), Map())), List( )), Map())), List(
"Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp", "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
Map("summaryStatsTag" -> "centrifuge_unique_report") Map("summaryStatsTag" -> "centrifuge_unique_report")
...@@ -162,7 +162,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder { ...@@ -162,7 +162,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder {
)), Map())), List( )), Map())), List(
"Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp", "Unique mappings" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp",
Map("summaryStatsTag" -> "centrifuge_unique_report") Map("summaryStatsTag" -> "centrifuge_unique_report")
)), Map("summaryModuleTag" -> "gearscentrifuge"))) )), Map("summaryModuleTag" -> "gearscentrifuge", "centrifugeTag" -> Some("centrifuge"))))
else Nil) ::: (if (krakenExecuted) List("Dustbin analysis" -> ReportPage(List(), List( else Nil) ::: (if (krakenExecuted) List("Dustbin analysis" -> ReportPage(List(), List(
"Krona Plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp" "Krona Plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
)), Map())) )), Map()))
......
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