Commit 2c35b3fa authored by Peter van 't Hof's avatar Peter van 't Hof

Added sample config validations

parent 2ee7793a
......@@ -3,6 +3,7 @@ package nl.lumc.sasc.biopet.core
import java.io.File
import nl.lumc.sasc.biopet.utils.config.Config
import nl.lumc.sasc.biopet.utils.summary.Summary
import nl.lumc.sasc.biopet.utils.{ConfigUtils, Question, ToolCommand}
/**
......@@ -27,7 +28,8 @@ trait TemplateTool extends ToolCommand {
val argsParser = new OptParser
val cmdArgs: Args = argsParser.parse(args, Args()) getOrElse (throw new IllegalArgumentException)
val standard: Map[String, Any] = Map("output_dir" -> Question.string("Output directory", validation = List(isAbsolutePath, parentIsWritable)))
val standard: Map[String, Any] = Map("output_dir" -> Question.string("Output directory",
validation = List(isAbsolutePath, parentIsWritable)))
val config = pipelineMap(standard, cmdArgs.expert)
println(ConfigUtils.mapToYaml(config))
......@@ -35,6 +37,8 @@ trait TemplateTool extends ToolCommand {
def pipelineMap(map: Map[String, Any], expert: Boolean): Map[String, Any]
val sampleConfigs: List[File] = Nil
}
object TemplateTool {
......@@ -65,4 +69,34 @@ object TemplateTool {
false
} else true
}
def askSampleConfigs(currentList: List[File] = Nil): List[File] = {
val configFile = new File(Question.string("Sample config file", validation = List(mustExist, isAbsolutePath)))
val configMap = new Summary(configFile)
println(s"${configMap.samples.size} samples found in config " +
s"with in total ${configMap.libraries.map(_._2.size).sum} libraries for '$configFile'")
if (Question.boolean("Is this correct?")) {
if (Question.boolean("Add more sample configs?")) askSampleConfigs(configFile :: currentList)
else {
val files = configFile :: currentList
if (files.size > 1) {
val configs = files.map(ConfigUtils.fileToConfigMap(_))
val sizes = configs.map(new Summary(_)).map(x => (x.samples.size, x.libraries.map(_._2.size).sum))
val samples = sizes.map(_._1).sum
val libs = sizes.map(_._2).sum
val mergedConfig = new Summary(configs.foldLeft(Map[String, Any]())((a,b) => ConfigUtils.mergeMaps(a, b)))
val mergesSamples = mergedConfig.samples.size
val mergesLibraries = mergedConfig.libraries.map(_._2.size).sum
if (mergesSamples != samples) println("WARNING: Overlapping samples detected")
if (mergesLibraries != libs) println("WARNING: Overlapping libraries detected")
println(s"$mergesSamples samples found in merged config with in total $mergesLibraries libraries")
if (Question.boolean("Is this correct?")) files
else {
println("Resetting sample configs")
askSampleConfigs()
}
} else files
}
} else askSampleConfigs(currentList)
}
}
\ No newline at end of file
......@@ -23,8 +23,9 @@ import nl.lumc.sasc.biopet.utils.ConfigUtils
*
* Created by pjvan_thof on 3/26/15.
*/
class Summary(file: File) {
val map = ConfigUtils.fileToConfigMap(file)
class Summary(val map: Map[String, Any]) {
def this(file: File) = this(ConfigUtils.fileToConfigMap(file))
/** List of all samples in the summary */
lazy val samples: Set[String] = {
......
package nl.lumc.sasc.biopet.pipelines.shiva.template
import java.io.File
import nl.lumc.sasc.biopet.core.{Reference, TemplateTool}
import nl.lumc.sasc.biopet.utils.Question
/**
* Created by pjvanthof on 17/12/2016.
*/
object Shiva extends TemplateTool {
override val sampleConfigs: List[File] = TemplateTool.askSampleConfigs()
def pipelineMap(map: Map[String, Any], expert: Boolean): Map[String, Any] = {
map ++ Reference.askReference
map ++ Reference.askReference ++
Map("variantcallers" -> Question.list("Variantcallers",
posibleValues = List("haplotypercaller", "haplotypecaller_gvcf")))
}
}
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