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

- Added sub configs for gatk buildin modules

parent 31ea0eee
...@@ -17,7 +17,6 @@ class Gatk(private var globalConfig: Config) extends QScript { ...@@ -17,7 +17,6 @@ class Gatk(private var globalConfig: Config) extends QScript {
@Argument(doc="Output directory", shortName="outputDir", required=true) var outputDir: String = _ @Argument(doc="Output directory", shortName="outputDir", required=true) var outputDir: String = _
def this() = this(new Config()) def this() = this(new Config())
var config: Config = _ var config: Config = _
var scatterCount: Int = _
var referenceFile: File = _ var referenceFile: File = _
var dbsnp: File = _ var dbsnp: File = _
var gvcfFiles: List[File] = Nil var gvcfFiles: List[File] = Nil
...@@ -34,7 +33,6 @@ class Gatk(private var globalConfig: Config) extends QScript { ...@@ -34,7 +33,6 @@ class Gatk(private var globalConfig: Config) extends QScript {
referenceFile = config.getAsString("referenceFile") referenceFile = config.getAsString("referenceFile")
dbsnp = config.getAsString("dbsnp") dbsnp = config.getAsString("dbsnp")
gvcfFiles = config.getAsListOfStrings("gvcfFiles", Nil) gvcfFiles = config.getAsListOfStrings("gvcfFiles", Nil)
scatterCount = config.getAsInt("scatterCount", 1)
if (outputDir == null) throw new IllegalStateException("Missing Output directory on flexiprep module") if (outputDir == null) throw new IllegalStateException("Missing Output directory on flexiprep module")
else if (!outputDir.endsWith("/")) outputDir += "/" else if (!outputDir.endsWith("/")) outputDir += "/"
} }
...@@ -55,14 +53,16 @@ class Gatk(private var globalConfig: Config) extends QScript { ...@@ -55,14 +53,16 @@ class Gatk(private var globalConfig: Config) extends QScript {
//SampleWide jobs //SampleWide jobs
if (gvcfFiles.size > 0) { if (gvcfFiles.size > 0) {
val genotypeGVCFs = new GenotypeGVCFs() with gatkArguments { val genotypeGVCFs = new GenotypeGVCFs() with gatkArguments {
val config: Config = Config.mergeConfigs(qscript.config.getAsConfig("genotypegvcfs"), qscript.config)
this.variant = gvcfFiles this.variant = gvcfFiles
this.scatterCount = scatterCount if (config.contains("scattercount")) this.scatterCount = config.getAsInt("scattercount")
this.out = new File(outputDir,"final.vcf") this.out = new File(outputDir,"final.vcf")
} }
add(genotypeGVCFs) add(genotypeGVCFs)
//Snp recal //Snp recal
val snpVariantRecalibrator = new VariantRecalibrator() with gatkArguments { val snpVariantRecalibrator = new VariantRecalibrator() with gatkArguments {
val config: Config = Config.mergeConfigs(qscript.config.getAsConfig("variantrecalibrator"), qscript.config)
this.input +:= genotypeGVCFs.out this.input +:= genotypeGVCFs.out
this.nt = 4 this.nt = 4
this.memoryLimit = 2 * nt this.memoryLimit = 2 * nt
...@@ -78,6 +78,7 @@ class Gatk(private var globalConfig: Config) extends QScript { ...@@ -78,6 +78,7 @@ class Gatk(private var globalConfig: Config) extends QScript {
add(snpVariantRecalibrator) add(snpVariantRecalibrator)
val snpApplyRecalibration = new ApplyRecalibration() with gatkArguments { val snpApplyRecalibration = new ApplyRecalibration() with gatkArguments {
val config: Config = Config.mergeConfigs(qscript.config.getAsConfig("applyrecalibration"), qscript.config)
this.input +:= genotypeGVCFs.out this.input +:= genotypeGVCFs.out
this.recal_file = snpVariantRecalibrator.recal_file this.recal_file = snpVariantRecalibrator.recal_file
this.tranches_file = snpVariantRecalibrator.tranches_file this.tranches_file = snpVariantRecalibrator.tranches_file
...@@ -86,12 +87,13 @@ class Gatk(private var globalConfig: Config) extends QScript { ...@@ -86,12 +87,13 @@ class Gatk(private var globalConfig: Config) extends QScript {
this.mode = org.broadinstitute.sting.gatk.walkers.variantrecalibration.VariantRecalibratorArgumentCollection.Mode.SNP this.mode = org.broadinstitute.sting.gatk.walkers.variantrecalibration.VariantRecalibratorArgumentCollection.Mode.SNP
this.nt = 3 this.nt = 3
this.memoryLimit = 2 * nt this.memoryLimit = 2 * nt
if (scatterCount > 1) this.scatterCount = qscript.scatterCount if (config.contains("scattercount")) this.scatterCount = config.getAsInt("scattercount")
} }
add(snpApplyRecalibration) add(snpApplyRecalibration)
//indel recal //indel recal
val indelVariantRecalibrator = new VariantRecalibrator() with gatkArguments { val indelVariantRecalibrator = new VariantRecalibrator() with gatkArguments {
val config: Config = Config.mergeConfigs(qscript.config.getAsConfig("variantrecalibrator"), qscript.config)
this.input +:= genotypeGVCFs.out this.input +:= genotypeGVCFs.out
this.nt = 4 this.nt = 4
this.memoryLimit = 2 * nt this.memoryLimit = 2 * nt
...@@ -105,6 +107,7 @@ class Gatk(private var globalConfig: Config) extends QScript { ...@@ -105,6 +107,7 @@ class Gatk(private var globalConfig: Config) extends QScript {
add(indelVariantRecalibrator) add(indelVariantRecalibrator)
val indelApplyRecalibration = new ApplyRecalibration() with gatkArguments { val indelApplyRecalibration = new ApplyRecalibration() with gatkArguments {
val config: Config = Config.mergeConfigs(qscript.config.getAsConfig("applyrecalibration"), qscript.config)
this.input +:= genotypeGVCFs.out this.input +:= genotypeGVCFs.out
this.recal_file = indelVariantRecalibrator.recal_file this.recal_file = indelVariantRecalibrator.recal_file
this.tranches_file = indelVariantRecalibrator.tranches_file this.tranches_file = indelVariantRecalibrator.tranches_file
...@@ -113,7 +116,7 @@ class Gatk(private var globalConfig: Config) extends QScript { ...@@ -113,7 +116,7 @@ class Gatk(private var globalConfig: Config) extends QScript {
this.mode = org.broadinstitute.sting.gatk.walkers.variantrecalibration.VariantRecalibratorArgumentCollection.Mode.INDEL this.mode = org.broadinstitute.sting.gatk.walkers.variantrecalibration.VariantRecalibratorArgumentCollection.Mode.INDEL
this.nt = 3 this.nt = 3
this.memoryLimit = 2 * nt this.memoryLimit = 2 * nt
if (scatterCount > 1) this.scatterCount = qscript.scatterCount if (config.contains("scattercount")) this.scatterCount = config.getAsInt("scattercount")
} }
add(indelApplyRecalibration) add(indelApplyRecalibration)
} else logger.warn("No gVCFs to genotype") } else logger.warn("No gVCFs to genotype")
...@@ -141,19 +144,20 @@ class Gatk(private var globalConfig: Config) extends QScript { ...@@ -141,19 +144,20 @@ class Gatk(private var globalConfig: Config) extends QScript {
} }
// Variant calling // Variant calling
val haplotypeCaller = new HaplotypeCaller with gatkArguments val haplotypeCaller = new HaplotypeCaller with gatkArguments {
if (scatterCount > 1) haplotypeCaller.scatterCount = scatterCount * 15 val config: Config = Config.mergeConfigs(qscript.config.getAsConfig("haplotypecaller"), qscript.config)
haplotypeCaller.input_file = outputFiles("FinalBams") if (config.contains("scattercount")) this.scatterCount = config.getAsInt("scattercount")
haplotypeCaller.out = new File(outputDir,sampleID + "/" + sampleID + ".gvcf.vcf") this.input_file = outputFiles("FinalBams")
if (dbsnp != null) haplotypeCaller.dbsnp = qscript.dbsnp this.out = new File(outputDir,sampleID + "/" + sampleID + ".gvcf.vcf")
haplotypeCaller.nct = 3 if (dbsnp != null) this.dbsnp = qscript.dbsnp
haplotypeCaller.memoryLimit = haplotypeCaller.nct * 2 this.nct = 3
this.memoryLimit = this.nct * 2
// GVCF options
haplotypeCaller.emitRefConfidence = org.broadinstitute.sting.gatk.walkers.haplotypecaller.HaplotypeCaller.ReferenceConfidenceMode.GVCF // GVCF options
haplotypeCaller.variant_index_type = GATKVCFIndexType.LINEAR this.emitRefConfidence = org.broadinstitute.sting.gatk.walkers.haplotypecaller.HaplotypeCaller.ReferenceConfidenceMode.GVCF
haplotypeCaller.variant_index_parameter = 128000 this.variant_index_type = GATKVCFIndexType.LINEAR
this.variant_index_parameter = 128000
}
if (haplotypeCaller.input_file.size > 0) { if (haplotypeCaller.input_file.size > 0) {
add(haplotypeCaller) add(haplotypeCaller)
outputFiles += ("gvcf" -> List(haplotypeCaller.out)) outputFiles += ("gvcf" -> List(haplotypeCaller.out))
...@@ -165,22 +169,15 @@ class Gatk(private var globalConfig: Config) extends QScript { ...@@ -165,22 +169,15 @@ class Gatk(private var globalConfig: Config) extends QScript {
} }
// Called for each run from a sample // Called for each run from a sample
def runJobs(runConfig:Config,sampleConfig:Config) : Map[String,File] = { def runJobs(runConfig:Config, sampleConfig:Config) : Map[String,File] = {
var outputFiles:Map[String,File] = Map() var outputFiles:Map[String,File] = Map()
var paired: Boolean = false val runID: String = runConfig.getAsString("ID")
var runID: String = "" val fastq_R1: String = runConfig.getAsString("R1", null)
var fastq_R1: String = "" val fastq_R2: String = runConfig.getAsString("R2", null)
var fastq_R2: String = "" val paired: Boolean = (fastq_R2 != null)
var sampleID: String = sampleConfig.get("ID").toString val sampleID: String = sampleConfig.get("ID").toString
if (runConfig.contains("R1")) { if (fastq_R1 != null) {
fastq_R1 = runConfig.get("R1").toString val runDir: String = outputDir + sampleID + "/run_" + runID + "/"
if (runConfig.contains("R2")) {
fastq_R2 = runConfig.get("R2").toString
paired = true
}
if (runConfig.contains("ID")) runID = runConfig.get("ID").toString
else throw new IllegalStateException("Missing ID on run for sample: " + sampleID)
var runDir: String = outputDir + sampleID + "/run_" + runID + "/"
val flexiprep = new Flexiprep(config) val flexiprep = new Flexiprep(config)
flexiprep.input_R1 = fastq_R1 flexiprep.input_R1 = fastq_R1
...@@ -246,18 +243,20 @@ class Gatk(private var globalConfig: Config) extends QScript { ...@@ -246,18 +243,20 @@ class Gatk(private var globalConfig: Config) extends QScript {
def addIndelRealign(inputBam:File, dir:String): File = { def addIndelRealign(inputBam:File, dir:String): File = {
val realignerTargetCreator = new RealignerTargetCreator with gatkArguments { val realignerTargetCreator = new RealignerTargetCreator with gatkArguments {
val config: Config = Config.mergeConfigs(qscript.config.getAsConfig("realignertargetcreator"), qscript.config)
this.I :+= inputBam this.I :+= inputBam
this.o = swapExt(dir,inputBam,".bam",".realign.intervals") this.o = swapExt(dir,inputBam,".bam",".realign.intervals")
this.jobResourceRequests :+= "h_vmem=5G" this.jobResourceRequests :+= "h_vmem=5G"
if (scatterCount > 1) this.scatterCount = qscript.scatterCount if (config.contains("scattercount")) this.scatterCount = config.getAsInt("scattercount")
} }
add(realignerTargetCreator) add(realignerTargetCreator)
val indelRealigner = new IndelRealigner with gatkArguments { val indelRealigner = new IndelRealigner with gatkArguments {
val config: Config = Config.mergeConfigs(qscript.config.getAsConfig("indelrealigner"), qscript.config)
this.I :+= inputBam this.I :+= inputBam
this.targetIntervals = realignerTargetCreator.o this.targetIntervals = realignerTargetCreator.o
this.o = swapExt(dir,inputBam,".bam",".realign.bam") this.o = swapExt(dir,inputBam,".bam",".realign.bam")
if (scatterCount > 1) this.scatterCount = qscript.scatterCount if (config.contains("scattercount")) this.scatterCount = config.getAsInt("scattercount")
} }
add(indelRealigner) add(indelRealigner)
...@@ -266,19 +265,21 @@ class Gatk(private var globalConfig: Config) extends QScript { ...@@ -266,19 +265,21 @@ class Gatk(private var globalConfig: Config) extends QScript {
def addBaseRecalibrator(inputBam:File, dir:String): File = { def addBaseRecalibrator(inputBam:File, dir:String): File = {
val baseRecalibrator = new BaseRecalibrator with gatkArguments { val baseRecalibrator = new BaseRecalibrator with gatkArguments {
val config: Config = Config.mergeConfigs(qscript.config.getAsConfig("baserecalibrator"), qscript.config)
this.I :+= inputBam this.I :+= inputBam
this.o = swapExt(dir,inputBam,".bam",".baserecal") this.o = swapExt(dir,inputBam,".bam",".baserecal")
this.knownSites :+= dbsnp this.knownSites :+= dbsnp
if (scatterCount > 1) this.scatterCount = qscript.scatterCount if (config.contains("scattercount")) this.scatterCount = config.getAsInt("scattercount")
this.nct = 2 this.nct = 2
} }
add(baseRecalibrator) add(baseRecalibrator)
val printReads = new PrintReads with gatkArguments { val printReads = new PrintReads with gatkArguments {
val config: Config = Config.mergeConfigs(qscript.config.getAsConfig("printreads"), qscript.config)
this.I :+= inputBam this.I :+= inputBam
this.o = swapExt(dir,inputBam,".bam",".baserecal.bam") this.o = swapExt(dir,inputBam,".bam",".baserecal.bam")
this.BQSR = baseRecalibrator.o this.BQSR = baseRecalibrator.o
if (scatterCount > 1) this.scatterCount = qscript.scatterCount if (config.contains("scattercount")) this.scatterCount = config.getAsInt("scattercount")
} }
return printReads.o return printReads.o
......
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