Commit 42abd53f authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Added nested class, configContains() now replaced by config.contains()

parent 45e799b7
......@@ -9,30 +9,31 @@ trait Configurable extends Logging {
val configPath: List[String] = if (root != null) root.configFullPath else List()
protected val configName = getClass.getSimpleName.toLowerCase
protected val configFullPath = configName :: configPath
def config(key: String, default: Any = null, submodule: String = null, required: Boolean = false, freeVar:Boolean = true): ConfigValue = {
val m = if (submodule != null) submodule else configName
val p = if (submodule != null) configName :: configPath else configPath
if (!configContains(key, submodule, freeVar) && default == null) {
if (required) {
logger.error("Value in config could not be found but it is required, key: " + key + " module: " + m + " path: " + p)
throw new IllegalStateException("Value in config could not be found but it is required, key: " + key + " module: " + m + " path: " + p)
} else return null
val config = new ConfigFuntions
protected class ConfigFuntions {
def apply(key: String, default: Any = null, submodule: String = null, required: Boolean = false, freeVar:Boolean = true): ConfigValue = {
val m = if (submodule != null) submodule else configName
val p = if (submodule != null) configName :: configPath else configPath
if (!contains(key, submodule, freeVar) && default == null) {
if (required) {
logger.error("Value in config could not be found but it is required, key: " + key + " module: " + m + " path: " + p)
throw new IllegalStateException("Value in config could not be found but it is required, key: " + key + " module: " + m + " path: " + p)
} else return null
}
if (default == null) return globalConfig(m, p, key, freeVar)
else return globalConfig(m, p, key, default, freeVar)
}
if (default == null) return globalConfig(m, p, key, freeVar)
else return globalConfig(m, p, key, default, freeVar)
}
//def config(key:String, default:Any) = globalConfig(configName, configPath, key, default)
//def config(key:String, default:Any, module:String) = globalConfig(module, configName :: configPath, key, default)
def contains(key: String, submodule: String = null, freeVar:Boolean = true) = {
val m = if (submodule != null) submodule else configName
val p = if (submodule != null) configName :: configPath else configPath
//def configContains(key:String) = globalConfig.contains(configName, configPath, key)
def configContains(key: String, submodule: String = null, freeVar:Boolean = true) = {
val m = if (submodule != null) submodule else configName
val p = if (submodule != null) configName :: configPath else configPath
globalConfig.contains(m, p, key, freeVar)
globalConfig.contains(m, p, key, freeVar)
}
}
implicit def configValue2file(value: ConfigValue): File = if (value != null) new File(Configurable.any2string(value.value)) else null
implicit def configValue2string(value: ConfigValue): String = if (value != null) Configurable.any2string(value.value) else null
implicit def configValue2long(value: ConfigValue): Long = if (value != null) Configurable.any2long(value.value) else 0
......
package nl.lumc.sasc.biopet.extensions
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
import java.io.File
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.core.config.Configurable
......@@ -23,11 +21,11 @@ class Cutadapt(val root: Configurable) extends BiopetCommandLineFunction {
var default_clip_mode: String = config("default_clip_mode", default = "3")
var opt_adapter: Set[String] = Set()
if (configContains("adapter")) for (adapter <- config("adapter").getList) opt_adapter += adapter.toString
if (config.contains("adapter")) for (adapter <- config("adapter").getList) opt_adapter += adapter.toString
var opt_anywhere: Set[String] = Set()
if (configContains("anywhere")) for (adapter <- config("anywhere").getList) opt_anywhere += adapter.toString
if (config.contains("anywhere")) for (adapter <- config("anywhere").getList) opt_anywhere += adapter.toString
var opt_front: Set[String] = Set()
if (configContains("front")) for (adapter <- config("front").getList) opt_front += adapter.toString
if (config.contains("front")) for (adapter <- config("front").getList) opt_front += adapter.toString
var opt_discard: Boolean = config("discard")
var opt_minimum_length: String = config("minimum_length", 1)
......
......@@ -29,12 +29,12 @@ class BamMetrics(val root: Configurable) extends QScript with BiopetQScript {
for (file <- configfiles) globalConfig.loadConfigFile(file)
if (outputDir == null) throw new IllegalStateException("Missing Output directory on BamMetrics module")
else if (!outputDir.endsWith("/")) outputDir += "/"
if (configContains("targetBed")) {
if (config.contains("targetBed")) {
for (file <- config("targetBed").getList) {
bedFiles +:= new File(file.toString)
}
}
if (baitBedFile == null && configContains("targetBait")) baitBedFile = config("targetBait")
if (baitBedFile == null && config.contains("targetBait")) baitBedFile = config("targetBait")
}
def biopetScript() {
......
......@@ -25,7 +25,7 @@ class GatkBenchmarkGenotyping(val root: Configurable) extends QScript with Biope
var dbsnp: File = _
def init() {
if (configContains("gvcffiles")) for (file <- config("gvcffiles").getList) {
if (config.contains("gvcffiles")) for (file <- config("gvcffiles").getList) {
gvcfFiles ::= file.toString
}
if (reference == null) reference = config("reference")
......
......@@ -52,8 +52,8 @@ class GatkGenotyping(val root: Configurable) extends QScript with BiopetQScript
def addGenotypeGVCFs(gvcfFiles: List[File], outputFile: File): File = {
val genotypeGVCFs = new GenotypeGVCFs() with gatkArguments {
this.variant = gvcfFiles
if (configContains("dbsnp")) this.dbsnp = config("dbsnp")
if (configContains("scattercount", submodule = "genotypegvcfs"))
if (config.contains("dbsnp")) this.dbsnp = config("dbsnp")
if (config.contains("scattercount", submodule = "genotypegvcfs"))
this.scatterCount = config("scattercount", submodule = "genotypegvcfs")
this.out = outputFile
if (config("inputtype", "dna").getString == "rna") {
......@@ -73,7 +73,7 @@ class GatkGenotyping(val root: Configurable) extends QScript with BiopetQScript
this.variant = inputFile
for (sample <- samples) this.sample_name :+= sample
this.excludeNonVariants = true
if (configContains("scattercount", submodule = "selectvariants"))
if (config.contains("scattercount", submodule = "selectvariants"))
this.scatterCount = config("scattercount", submodule = "selectvariants")
this.out = outputDir + name + ".vcf"
}
......
......@@ -31,7 +31,7 @@ class GatkPipeline(val root: Configurable) extends QScript with MultiSampleQScri
for (file <- configfiles) globalConfig.loadConfigFile(file)
reference = config("reference", required = true)
dbsnp = config("dbsnp")
if (configContains("gvcfFiles"))
if (config.contains("gvcfFiles"))
for (file <- config("gvcfFiles").getList)
gvcfFiles :+= file.toString
if (outputDir == null) throw new IllegalStateException("Missing Output directory on gatk module")
......@@ -156,25 +156,25 @@ class GatkPipeline(val root: Configurable) extends QScript with MultiSampleQScri
val variantRecalibrator = new VariantRecalibrator() with gatkArguments {
if (mode_arg == "indel") {
this.mode = org.broadinstitute.gatk.tools.walkers.variantrecalibration.VariantRecalibratorArgumentCollection.Mode.INDEL
if (configContains("mills", submodule = "variantrecalibrator"))
if (config.contains("mills", submodule = "variantrecalibrator"))
this.resource :+= new TaggedFile(config("mills", submodule = "variantrecalibrator").getString, "known=false,training=true,truth=true,prior=12.0")
} else { // SNP
this.mode = org.broadinstitute.gatk.tools.walkers.variantrecalibration.VariantRecalibratorArgumentCollection.Mode.SNP
if (configContains("hapmap", submodule = "variantrecalibrator"))
if (config.contains("hapmap", submodule = "variantrecalibrator"))
this.resource +:= new TaggedFile(config("hapmap", submodule = "variantrecalibrator").getString, "known=false,training=true,truth=true,prior=15.0")
if (configContains("omni", submodule = "variantrecalibrator"))
if (config.contains("omni", submodule = "variantrecalibrator"))
this.resource +:= new TaggedFile(config("omni", submodule = "variantrecalibrator").getString, "known=false,training=true,truth=true,prior=12.0")
if (configContains("1000G", submodule = "variantrecalibrator"))
if (config.contains("1000G", submodule = "variantrecalibrator"))
this.resource +:= new TaggedFile(config("1000G", submodule = "variantrecalibrator").getString, "known=false,training=true,truth=false,prior=10.0")
}
if (configContains("dbsnp", submodule = "variantrecalibrator"))
if (config.contains("dbsnp", submodule = "variantrecalibrator"))
this.resource :+= new TaggedFile(config("dbsnp", submodule = "variantrecalibrator").getString, "known=true,training=false,truth=false,prior=2.0")
this.nt = 4
this.memoryLimit = nt * 2
this.an = Seq("QD", "DP", "FS", "ReadPosRankSum", "MQRankSum")
if (configContains("minnumbadvariants", submodule = "variantrecalibrator"))
if (config.contains("minnumbadvariants", submodule = "variantrecalibrator"))
this.minNumBadVariants = config("minnumbadvariants", submodule = "variantrecalibrator")
if (configContains("maxgaussians", submodule = "variantrecalibrator"))
if (config.contains("maxgaussians", submodule = "variantrecalibrator"))
this.maxGaussians = config("maxgaussians", submodule = "variantrecalibrator")
}
return variantRecalibrator
......@@ -191,7 +191,7 @@ class GatkPipeline(val root: Configurable) extends QScript with MultiSampleQScri
}
this.nt = 3
this.memoryLimit = nt * 2
if (configContains("scattercount", submodule = "applyrecalibration"))
if (config.contains("scattercount", submodule = "applyrecalibration"))
this.scatterCount = config("scattercount", submodule = "applyrecalibration")
}
return applyRecalibration
......@@ -203,7 +203,7 @@ class GatkPipeline(val root: Configurable) extends QScript with MultiSampleQScri
this.input_file = bamfiles
this.dbsnp = config("dbsnp", submodule = "variantannotator")
this.out = swapExt(dir, inputvcf, ".vcf", ".anotated.vcf")
if (configContains("scattercount", submodule = "variantannotator"))
if (config.contains("scattercount", submodule = "variantannotator"))
this.scatterCount = config("scattercount", submodule = "variantannotator")
}
add(variantAnnotator)
......@@ -215,7 +215,7 @@ class GatkPipeline(val root: Configurable) extends QScript with MultiSampleQScri
val combineGVCFs = new CombineGVCFs with gatkArguments {
this.variant = input
this.o = output
if (configContains("scattercount", submodule = "variantannotator"))
if (config.contains("scattercount", submodule = "variantannotator"))
this.scatterCount = config("scattercount", submodule = "combinegvcfs")
}
add(combineGVCFs)
......
......@@ -63,7 +63,7 @@ class GatkVariantcalling(val root: Configurable) extends QScript with BiopetQScr
this.I :+= inputBam
this.o = swapExt(dir, inputBam, ".bam", ".realign.intervals")
this.jobResourceRequests :+= "h_vmem=5G"
if (configContains("scattercount", "realignertargetcreator")) this.scatterCount = config("scattercount", 1, "realignertargetcreator")
if (config.contains("scattercount", "realignertargetcreator")) this.scatterCount = config("scattercount", 1, "realignertargetcreator")
}
realignerTargetCreator.isIntermediate = true
add(realignerTargetCreator)
......@@ -72,7 +72,7 @@ class GatkVariantcalling(val root: Configurable) extends QScript with BiopetQScr
this.I :+= inputBam
this.targetIntervals = realignerTargetCreator.o
this.o = swapExt(dir, inputBam, ".bam", ".realign.bam")
if (configContains("scattercount", "indelrealigner")) this.scatterCount = config("scattercount", 1, "indelrealigner")
if (config.contains("scattercount", "indelrealigner")) this.scatterCount = config("scattercount", 1, "indelrealigner")
}
indelRealigner.isIntermediate = true
add(indelRealigner)
......@@ -85,7 +85,7 @@ class GatkVariantcalling(val root: Configurable) extends QScript with BiopetQScr
this.I :+= inputBam
this.o = swapExt(dir, inputBam, ".bam", ".baserecal")
if (dbsnp != null) this.knownSites :+= dbsnp
if (configContains("scattercount", "baserecalibrator")) this.scatterCount = config("scattercount", 1, "baserecalibrator")
if (config.contains("scattercount", "baserecalibrator")) this.scatterCount = config("scattercount", 1, "baserecalibrator")
this.nct = config("threads", 1, "baserecalibrator")
}
add(baseRecalibrator)
......@@ -95,7 +95,7 @@ class GatkVariantcalling(val root: Configurable) extends QScript with BiopetQScr
this.o = swapExt(dir, inputBam, ".bam", ".baserecal.after")
this.BQSR = baseRecalibrator.o
if (dbsnp != null) this.knownSites :+= dbsnp
if (configContains("scattercount", "baserecalibrator")) this.scatterCount = config("scattercount", 1, "baserecalibrator")
if (config.contains("scattercount", "baserecalibrator")) this.scatterCount = config("scattercount", 1, "baserecalibrator")
this.nct = config("threads", 1, "baserecalibrator")
}
add(baseRecalibratorAfter)
......@@ -111,7 +111,7 @@ class GatkVariantcalling(val root: Configurable) extends QScript with BiopetQScr
this.I :+= inputBam
this.o = swapExt(dir, inputBam, ".bam", ".baserecal.bam")
this.BQSR = baseRecalibrator.o
if (configContains("scattercount", "printreads")) this.scatterCount = config("scattercount", 1, "printreads")
if (config.contains("scattercount", "printreads")) this.scatterCount = config("scattercount", 1, "printreads")
}
printReads.isIntermediate = true
add(printReads)
......@@ -122,10 +122,10 @@ class GatkVariantcalling(val root: Configurable) extends QScript with BiopetQScr
def addHaplotypeCaller(bamfiles: List[File], outputfile: File): File = {
val haplotypeCaller = new HaplotypeCaller with gatkArguments {
this.min_mapping_quality_score = config("minMappingQualityScore", 20, "haplotypecaller")
if (configContains("scattercount", "haplotypecaller")) this.scatterCount = config("scattercount", 1, "haplotypecaller")
if (config.contains("scattercount", "haplotypecaller")) this.scatterCount = config("scattercount", 1, "haplotypecaller")
this.input_file = bamfiles
this.out = outputfile
if (configContains("dbsnp")) this.dbsnp = config("dbsnp")
if (config.contains("dbsnp")) this.dbsnp = config("dbsnp")
this.nct = config("threads", default = 3, submodule = "haplotypecaller")
if (config("outputToBam", default = false, submodule = "haplotypecaller").getBoolean) {
this.bamOutput = outputfile.getAbsolutePath + ".bam"
......@@ -134,7 +134,7 @@ class GatkVariantcalling(val root: Configurable) extends QScript with BiopetQScr
}
this.memoryLimit = this.nct * 2
if (configContains("allSitePLs")) this.allSitePLs = config("allSitePLs")
if (config.contains("allSitePLs")) this.allSitePLs = config("allSitePLs")
// GVCF options
if (gvcfMode) {
......@@ -165,8 +165,8 @@ class GatkVariantcalling(val root: Configurable) extends QScript with BiopetQScr
val genotypeGVCFs = new GenotypeGVCFs() with gatkArguments {
this.variant = gvcfFiles
this.annotation ++= Seq("FisherStrand", "QualByDepth", "ChromosomeCounts")
if (configContains("dbsnp")) this.dbsnp = config("dbsnp")
if (configContains("scattercount", "genotypegvcfs")) this.scatterCount = config("scattercount", 1, "genotypegvcfs")
if (config.contains("dbsnp")) this.dbsnp = config("dbsnp")
if (config.contains("scattercount", "genotypegvcfs")) this.scatterCount = config("scattercount", 1, "genotypegvcfs")
this.out = outputDir + outputName + ".vcf"
this.stand_call_conf = config("stand_call_conf", 30, "genotypegvcfs")
this.stand_emit_conf = config("stand_emit_conf", 30, "genotypegvcfs")
......
......@@ -33,7 +33,7 @@ class GatkVcfSampleCompare(val root: Configurable) extends QScript with BiopetQS
def init() {
if (reference == null) reference = config("reference")
if (configContains("targetBed"))
if (config.contains("targetBed"))
for (bed <- config("targetBed").getList)
targetBed :+= bed.toString
if (outputDir == null) throw new IllegalStateException("Missing Output directory on gatk module")
......
......@@ -89,18 +89,18 @@ class Mapping(val root: Configurable) extends QScript with BiopetQScript {
if (input_R1 == null) throw new IllegalStateException("Missing Fastq R1 on mapping module")
paired = (input_R2 != null)
if (RGLB == null && configContains("RGLB")) RGLB = config("RGLB")
if (RGLB == null && config.contains("RGLB")) RGLB = config("RGLB")
else if (RGLB == null) throw new IllegalStateException("Missing Readgroup library on mapping module")
if (RGSM == null && configContains("RGSM")) RGSM = config("RGSM")
if (RGSM == null && config.contains("RGSM")) RGSM = config("RGSM")
else if (RGLB == null) throw new IllegalStateException("Missing Readgroup sample on mapping module")
if (RGID == null && configContains("RGID")) RGID = config("RGID")
if (RGID == null && config.contains("RGID")) RGID = config("RGID")
else if (RGID == null && RGSM != null && RGLB != null) RGID = RGSM + "-" + RGLB
else if (RGID == null) throw new IllegalStateException("Missing Readgroup ID on mapping module")
if (RGPL == null) RGPL = config("RGPL", "illumina")
if (RGPU == null) RGPU = config("RGPU", "na")
if (RGCN == null && configContains("RGCN")) RGCN = config("RGCN")
if (RGDS == null && configContains("RGDS")) RGDS = config("RGDS")
if (RGCN == null && config.contains("RGCN")) RGCN = config("RGCN")
if (RGDS == null && config.contains("RGDS")) RGDS = config("RGDS")
if (outputName == null) outputName = RGID
......@@ -108,7 +108,7 @@ class Mapping(val root: Configurable) extends QScript with BiopetQScript {
if (!chunking) chunking = config("chunking", false)
if (chunking) {
if (numberChunks.isEmpty) {
if (configContains("numberchunks")) numberChunks = config("numberchunks", default = None)
if (config.contains("numberchunks")) numberChunks = config("numberchunks", default = None)
else {
val chunkSize: Int = config("chunksize", (1 << 30))
val filesize = if (input_R1.getName.endsWith(".gz") || input_R1.getName.endsWith(".gzip")) input_R1.length * 3
......
Supports Markdown
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