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

Added summary to VcfStats

parent 5c545796
......@@ -27,7 +27,7 @@ class ShivaVariantcallingGatk(val root: Configurable) extends QScript with Shiva
protected val defaultPrio = 1
protected val defaultUse = true
def outputFile = new File(outputDir, namePrefix + "haplotypecaller.vcf.gz")
def outputFile = new File(outputDir, namePrefix + ".haplotypecaller.vcf.gz")
def addJobs() {
val hc = new nl.lumc.sasc.biopet.extensions.gatk.broad.HaplotypeCaller(qscript)
......@@ -42,7 +42,7 @@ class ShivaVariantcallingGatk(val root: Configurable) extends QScript with Shiva
protected val defaultPrio = 20
protected val defaultUse = false
def outputFile = new File(outputDir, namePrefix + "unifiedgenotyper.vcf.gz")
def outputFile = new File(outputDir, namePrefix + ".unifiedgenotyper.vcf.gz")
def addJobs() {
val ug = new nl.lumc.sasc.biopet.extensions.gatk.broad.UnifiedGenotyper(qscript)
......@@ -57,7 +57,7 @@ class ShivaVariantcallingGatk(val root: Configurable) extends QScript with Shiva
protected val defaultPrio = 5
protected val defaultUse = false
def outputFile = new File(outputDir, namePrefix + "haplotypecaller_allele.vcf.gz")
def outputFile = new File(outputDir, namePrefix + ".haplotypecaller_allele.vcf.gz")
def addJobs() {
val hc = new nl.lumc.sasc.biopet.extensions.gatk.broad.HaplotypeCaller(qscript)
......@@ -74,7 +74,7 @@ class ShivaVariantcallingGatk(val root: Configurable) extends QScript with Shiva
protected val defaultPrio = 9
protected val defaultUse = false
def outputFile = new File(outputDir, namePrefix + "unifiedgenotyper_allele.vcf.gz")
def outputFile = new File(outputDir, namePrefix + ".unifiedgenotyper_allele.vcf.gz")
def addJobs() {
val ug = new nl.lumc.sasc.biopet.extensions.gatk.broad.UnifiedGenotyper(qscript)
......@@ -91,7 +91,7 @@ class ShivaVariantcallingGatk(val root: Configurable) extends QScript with Shiva
protected val defaultPrio = 5
protected val defaultUse = false
def outputFile = new File(outputDir, namePrefix + "haplotypecaller_gvcf.vcf.gz")
def outputFile = new File(outputDir, namePrefix + ".haplotypecaller_gvcf.vcf.gz")
def addJobs() {
val gvcfFiles = for (inputBam <- inputBams) yield {
......
......@@ -4,23 +4,31 @@ import java.io.{ FileOutputStream, PrintWriter, File }
import htsjdk.variant.variantcontext.{ VariantContext, Genotype }
import htsjdk.variant.vcf.VCFFileReader
import nl.lumc.sasc.biopet.core.summary.Summarizable
import nl.lumc.sasc.biopet.core.{ BiopetJavaCommandLineFunction, ToolCommand }
import nl.lumc.sasc.biopet.core.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Output, Input }
import scala.collection.JavaConversions._
import scala.collection.mutable
import scala.io.Source
import scala.sys.process.{ Process, ProcessLogger }
import htsjdk.samtools.util.Interval
/**
* Created by pjvan_thof on 1/10/15.
*/
class VcfStats(val root: Configurable) extends BiopetJavaCommandLineFunction {
class VcfStats(val root: Configurable) extends BiopetJavaCommandLineFunction with Summarizable {
javaMainClass = getClass.getName
@Input(doc = "Input fastq", shortName = "I", required = true)
var input: File = _
@Output
protected var generalStats: File = null
@Output
protected var genotypeStats: File = null
override val defaultVmem = "4G"
override val defaultThreads = 3
......@@ -32,7 +40,9 @@ class VcfStats(val root: Configurable) extends BiopetJavaCommandLineFunction {
*/
def setOutputDir(dir: File): Unit = {
outputDir = dir
this.jobOutputFile = new File(dir, ".vcfstats.out")
generalStats = new File(dir, "general.tsv")
genotypeStats = new File(dir, "genotype_general.tsv")
jobOutputFile = new File(dir, ".vcfstats.out")
}
/**
......@@ -42,6 +52,27 @@ class VcfStats(val root: Configurable) extends BiopetJavaCommandLineFunction {
override def commandLine = super.commandLine +
required("-I", input) +
required("-o", outputDir)
/**
* Returns general stats to the summary
* @return
*/
def summaryStats: Map[String, Any] = {
(for (
line <- Source.fromFile(generalStats).getLines();
values = line.split("\t") if values.size >= 2 && !values(0).isEmpty
) yield values(0) -> values(1).toInt
).toMap
}
/**
* return only general files to summary
* @return
*/
def summaryFiles: Map[String, File] = Map(
"general_stats" -> generalStats,
"genotype_stats" -> genotypeStats
)
}
object VcfStats extends ToolCommand {
......
......@@ -22,16 +22,16 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag {
def namePrefix: String = {
(sampleId, libId) match {
case (Some(sampleId), Some(libId)) => sampleId + "-" + libId + "."
case (Some(sampleId), _) => sampleId + "."
case _ => ""
case (Some(sampleId), Some(libId)) => sampleId + "-" + libId
case (Some(sampleId), _) => sampleId
case _ => config("name_prefix")
}
}
def init: Unit = {
}
def finalFile = new File(outputDir, namePrefix + "final.vcf.gz")
def finalFile = new File(outputDir, namePrefix + ".final.vcf.gz")
def biopetScript: Unit = {
val callers = usedCallers.sortBy(_.prio)
......@@ -44,6 +44,12 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag {
for (caller <- callers) {
caller.addJobs()
cv.addInput(caller.outputFile, caller.name)
val vcfStats = new VcfStats(qscript)
vcfStats.input = caller.outputFile
vcfStats.setOutputDir(new File(caller.outputDir, "vcfstats"))
add(vcfStats)
addSummarizable(vcfStats, namePrefix + "-vcfstats-" + caller.name)
}
add(cv)
......@@ -51,6 +57,7 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag {
vcfStats.input = finalFile
vcfStats.setOutputDir(new File(outputDir, "vcfstats"))
add(vcfStats)
addSummarizable(vcfStats, namePrefix + "-vcfstats-final")
addSummaryJobs
}
......@@ -75,7 +82,7 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag {
protected val defaultPrio = 999
protected val defaultUse = true
def outputFile = new File(outputDir, namePrefix + "raw.vcf.gz")
def outputFile = new File(outputDir, namePrefix + ".raw.vcf.gz")
def addJobs() {
val rawFiles = inputBams.map(bamFile => {
......
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