From e09f609a74ef7e2484b3fb13b38184020bc554c4 Mon Sep 17 00:00:00 2001 From: Peter van 't Hof <p.j.van_t_hof@lumc.nl> Date: Thu, 19 Feb 2015 17:04:46 +0100 Subject: [PATCH] Added scala docs --- .../biopet/core/summary/Summarizable.scala | 10 +++++ .../biopet/core/summary/SummaryQScript.scala | 38 ++++++++++++++++++- .../biopet/core/summary/WriteSummary.scala | 24 +++++++++++- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/summary/Summarizable.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/summary/Summarizable.scala index a1901ed79..918d57a6b 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/summary/Summarizable.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/summary/Summarizable.scala @@ -5,12 +5,22 @@ import java.io.File import nl.lumc.sasc.biopet.core.config.Configurable /** + * Trait for class to let them accept into a Summary + * * Created by pjvan_thof on 2/14/15. */ trait Summarizable extends Configurable { + /** + * Must return files to store into summary + * @return + */ def summaryFiles: Map[String, File] + /** + * Must returns stats to store into summary + * @return + */ def summaryStats: Map[String, Any] /** diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/summary/SummaryQScript.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/summary/SummaryQScript.scala index 82bdad86c..e5257b1f8 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/summary/SummaryQScript.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/summary/SummaryQScript.scala @@ -14,16 +14,30 @@ trait SummaryQScript extends BiopetQScript { /** Key is sample/library, None is sample or library is not applicable */ private[summary] var summarizables: Map[(String, Option[String], Option[String]), List[Summarizable]] = Map() + + /** Qscripts summaries that need to be merge into this summary */ private[summary] var summaryQScripts: List[SummaryQScript] = Nil + /** Name of the pipeline in the summary */ var summaryName = configName + /** Must return a map with used settings for this pipeline */ def summarySettings: Map[String, Any] + /** File to put in the summary for thie pipeline */ def summaryFiles: Map[String, File] + /** Name of summary output file */ def summaryFile: File + /** + * Add a module to summary for this pipeline + * + * Auto detect sample and library from pipeline + * + * @param summarizable summarizable to add to summary for this pipeline + * @param name Name of module + */ def addSummarizable(summarizable: Summarizable, name: String): Unit = { this match { case tag: SampleLibraryTag => addSummarizable(summarizable, name, tag.sampleId, tag.libId) @@ -31,19 +45,39 @@ trait SummaryQScript extends BiopetQScript { } } + /** + * Add a module to summary for this pipeline + * + * @param summarizable summarizable to add to summary for this pipeline + * @param name Name of module + * @param sampleId + */ def addSummarizable(summarizable: Summarizable, name: String, sampleId: Option[String]): Unit = { addSummarizable(summarizable, name, sampleId, None) } + /** + * Add a module to summary for this pipeline + * + * @param summarizable summarizable to add to summary for this pipeline + * @param name Name of module + * @param sampleId + * @param libraryId + */ def addSummarizable(summarizable: Summarizable, name: String, sampleId: Option[String], libraryId: Option[String]): Unit = { if (libraryId.isDefined) require(sampleId.isDefined) // Library always require a sample summarizables += (name, sampleId, libraryId) -> (summarizable :: summarizables.getOrElse((name, sampleId, libraryId), Nil)) } + /** + * Add an other qscript to merge in output summary + * @param summaryQScript + */ def addSummaryQScript(summaryQScript: SummaryQScript): Unit = { summaryQScripts :+= summaryQScript } + /** Add jobs to qscript to execute summary, also add checksum jobs */ def addSummaryJobs: Unit = { val writeSummary = new WriteSummary(this) @@ -73,11 +107,11 @@ trait SummaryQScript extends BiopetQScript { add(writeSummary) } - - protected[summary] val executables: mutable.Map[String, (File, String)] = mutable.Map() } object SummaryQScript { import scala.collection.mutable.Map + + /** Cache to have no duplicate jobs */ protected[summary] val md5sumCache: Map[File, File] = Map() } \ No newline at end of file diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/summary/WriteSummary.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/summary/WriteSummary.scala index c73cc0505..5d41744a8 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/summary/WriteSummary.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/summary/WriteSummary.scala @@ -20,6 +20,7 @@ class WriteSummary(val root: Configurable) extends InProcessFunction with Config require(root.isInstanceOf[SummaryQScript], "root is not a SummaryQScript") + /** To access qscript for this summary */ val qscript = root.asInstanceOf[SummaryQScript] @Input(doc = "deps", required = false) @@ -43,8 +44,8 @@ class WriteSummary(val root: Configurable) extends InProcessFunction with Config super.freezeFieldValues() } + /** Function to create summary */ def run(): Unit = { - val pipelineMap = { val files = parseFiles(qscript.summaryFiles) val settings = qscript.summarySettings @@ -100,6 +101,12 @@ class WriteSummary(val root: Configurable) extends InProcessFunction with Config } } + /** + * Convert summarizable to a summary map + * @param summarizable + * @param name + * @return + */ def parseSummarizable(summarizable: Summarizable, name: String) = { val data = summarizable.summaryStats val files = parseFiles(summarizable.summaryFiles) @@ -108,10 +115,20 @@ class WriteSummary(val root: Configurable) extends InProcessFunction with Config (if (files.isEmpty) Map[String, Any]() else Map("files" -> Map(name -> files))) } + /** + * Parse files map to summary map + * @param files + * @return + */ def parseFiles(files: Map[String, File]): Map[String, Map[String, Any]] = { for ((key, file) <- files) yield key -> parseFile(file) } + /** + * parse single file summary map + * @param file + * @return + */ def parseFile(file: File): Map[String, Any] = { val map: mutable.Map[String, Any] = mutable.Map() map += "path" -> file.getAbsolutePath @@ -119,6 +136,11 @@ class WriteSummary(val root: Configurable) extends InProcessFunction with Config map.toMap } + /** + * Retrive checksum from file + * @param checksumFile + * @return + */ def parseChecksum(checksumFile: File): String = { Source.fromFile(checksumFile).getLines().toList.head.split(" ")(0) } -- GitLab