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

Change val name

parent 877f613f
...@@ -256,7 +256,7 @@ object VcfStats extends ToolCommand { ...@@ -256,7 +256,7 @@ object VcfStats extends ToolCommand {
} }
} }
protected var commandArgs: Args = _ protected var cmdArgs: Args = _
val defaultGenotypeFields = List("DP", "GQ", "AD", "AD-ref", "AD-alt", "AD-used", "AD-not_used", "general") val defaultGenotypeFields = List("DP", "GQ", "AD", "AD-ref", "AD-alt", "AD-used", "AD-not_used", "general")
...@@ -271,9 +271,9 @@ object VcfStats extends ToolCommand { ...@@ -271,9 +271,9 @@ object VcfStats extends ToolCommand {
def main(args: Array[String]): Unit = { def main(args: Array[String]): Unit = {
logger.info("Started") logger.info("Started")
val argsParser = new OptParser val argsParser = new OptParser
commandArgs = argsParser.parse(args, Args()) getOrElse sys.exit(1) cmdArgs = argsParser.parse(args, Args()) getOrElse sys.exit(1)
val reader = new VCFFileReader(commandArgs.inputFile, true) val reader = new VCFFileReader(cmdArgs.inputFile, true)
val header = reader.getFileHeader val header = reader.getFileHeader
val samples = header.getSampleNamesInOrder.toList val samples = header.getSampleNamesInOrder.toList
...@@ -281,33 +281,33 @@ object VcfStats extends ToolCommand { ...@@ -281,33 +281,33 @@ object VcfStats extends ToolCommand {
val adInfoTags = { val adInfoTags = {
(for ( (for (
infoTag <- commandArgs.infoTags if !defaultInfoFields.contains(infoTag) infoTag <- cmdArgs.infoTags if !defaultInfoFields.contains(infoTag)
) yield { ) yield {
require(header.getInfoHeaderLine(infoTag) != null, "Info tag '" + infoTag + "' not found in header of vcf file") require(header.getInfoHeaderLine(infoTag) != null, "Info tag '" + infoTag + "' not found in header of vcf file")
infoTag infoTag
}) ::: (for ( }) ::: (for (
line <- header.getInfoHeaderLines if commandArgs.allInfoTags if !defaultInfoFields.contains(line.getID) if !commandArgs.infoTags.contains(line.getID) line <- header.getInfoHeaderLines if cmdArgs.allInfoTags if !defaultInfoFields.contains(line.getID) if !cmdArgs.infoTags.contains(line.getID)
) yield { ) yield {
line.getID line.getID
}).toList ::: defaultInfoFields }).toList ::: defaultInfoFields
} }
val adGenotypeTags = (for ( val adGenotypeTags = (for (
genotypeTag <- commandArgs.genotypeTags if !defaultGenotypeFields.contains(genotypeTag) genotypeTag <- cmdArgs.genotypeTags if !defaultGenotypeFields.contains(genotypeTag)
) yield { ) yield {
require(header.getFormatHeaderLine(genotypeTag) != null, "Format tag '" + genotypeTag + "' not found in header of vcf file") require(header.getFormatHeaderLine(genotypeTag) != null, "Format tag '" + genotypeTag + "' not found in header of vcf file")
genotypeTag genotypeTag
}) ::: (for ( }) ::: (for (
line <- header.getFormatHeaderLines if commandArgs.allGenotypeTags if !defaultGenotypeFields.contains(line.getID) if !commandArgs.genotypeTags.contains(line.getID) if line.getID != "PL" line <- header.getFormatHeaderLines if cmdArgs.allGenotypeTags if !defaultGenotypeFields.contains(line.getID) if !cmdArgs.genotypeTags.contains(line.getID) if line.getID != "PL"
) yield { ) yield {
line.getID line.getID
}).toList ::: defaultGenotypeFields }).toList ::: defaultGenotypeFields
val bedRecords = (commandArgs.intervals match { val bedRecords = (cmdArgs.intervals match {
case Some(intervals) => BedRecordList.fromFile(intervals).validateContigs(commandArgs.referenceFile) case Some(intervals) => BedRecordList.fromFile(intervals).validateContigs(cmdArgs.referenceFile)
case _ => BedRecordList.fromReference(commandArgs.referenceFile) case _ => BedRecordList.fromReference(cmdArgs.referenceFile)
}).combineOverlap.scatter(commandArgs.binSize) }).combineOverlap.scatter(cmdArgs.binSize)
val intervals: List[Interval] = bedRecords.toSamIntervals.toList val intervals: List[Interval] = bedRecords.toSamIntervals.toList
...@@ -343,7 +343,7 @@ object VcfStats extends ToolCommand { ...@@ -343,7 +343,7 @@ object VcfStats extends ToolCommand {
val stats = (for (intervals <- Random.shuffle(intervals).grouped(intervals.size / (if (intervals.size > 10) 4 else 1)).toList.par) yield { val stats = (for (intervals <- Random.shuffle(intervals).grouped(intervals.size / (if (intervals.size > 10) 4 else 1)).toList.par) yield {
val chunkStats = for (intervals <- intervals.grouped(25)) yield { val chunkStats = for (intervals <- intervals.grouped(25)) yield {
val binStats = for (interval <- intervals.par) yield { val binStats = for (interval <- intervals.par) yield {
val reader = new VCFFileReader(commandArgs.inputFile, true) val reader = new VCFFileReader(cmdArgs.inputFile, true)
var chunkCounter = 0 var chunkCounter = 0
val stats = createStats val stats = createStats
logger.info("Starting on: " + interval) logger.info("Starting on: " + interval)
...@@ -366,8 +366,8 @@ object VcfStats extends ToolCommand { ...@@ -366,8 +366,8 @@ object VcfStats extends ToolCommand {
} }
reader.close() reader.close()
if (commandArgs.writeBinStats) { if (cmdArgs.writeBinStats) {
val binOutputDir = new File(commandArgs.outputDir, "bins" + File.separator + interval.getContig) val binOutputDir = new File(cmdArgs.outputDir, "bins" + File.separator + interval.getContig)
writeGenotypeField(stats, samples, "general", binOutputDir, prefix = "genotype-" + interval.getStart + "-" + interval.getEnd) writeGenotypeField(stats, samples, "general", binOutputDir, prefix = "genotype-" + interval.getStart + "-" + interval.getEnd)
writeField(stats, "general", binOutputDir, prefix = interval.getStart + "-" + interval.getEnd) writeField(stats, "general", binOutputDir, prefix = interval.getStart + "-" + interval.getEnd)
...@@ -384,47 +384,47 @@ object VcfStats extends ToolCommand { ...@@ -384,47 +384,47 @@ object VcfStats extends ToolCommand {
logger.info("Done reading vcf records") logger.info("Done reading vcf records")
// Writing info fields to tsv files // Writing info fields to tsv files
val infoOutputDir = new File(commandArgs.outputDir, "infotags") val infoOutputDir = new File(cmdArgs.outputDir, "infotags")
writeField(stats, "general", commandArgs.outputDir) writeField(stats, "general", cmdArgs.outputDir)
for (field <- adInfoTags.distinct.par) { for (field <- adInfoTags.distinct.par) {
writeField(stats, field, infoOutputDir) writeField(stats, field, infoOutputDir)
for (line <- new FastaSequenceFile(commandArgs.referenceFile, true).getSequenceDictionary.getSequences) { for (line <- new FastaSequenceFile(cmdArgs.referenceFile, true).getSequenceDictionary.getSequences) {
val chr = line.getSequenceName val chr = line.getSequenceName
writeField(stats, field, new File(infoOutputDir, "chrs" + File.separator + chr), chr = chr) writeField(stats, field, new File(infoOutputDir, "chrs" + File.separator + chr), chr = chr)
} }
} }
// Write genotype field to tsv files // Write genotype field to tsv files
val genotypeOutputDir = new File(commandArgs.outputDir, "genotypetags") val genotypeOutputDir = new File(cmdArgs.outputDir, "genotypetags")
writeGenotypeField(stats, samples, "general", commandArgs.outputDir, prefix = "genotype") writeGenotypeField(stats, samples, "general", cmdArgs.outputDir, prefix = "genotype")
for (field <- adGenotypeTags.distinct.par) { for (field <- adGenotypeTags.distinct.par) {
writeGenotypeField(stats, samples, field, genotypeOutputDir) writeGenotypeField(stats, samples, field, genotypeOutputDir)
for (line <- new FastaSequenceFile(commandArgs.referenceFile, true).getSequenceDictionary.getSequences) { for (line <- new FastaSequenceFile(cmdArgs.referenceFile, true).getSequenceDictionary.getSequences) {
val chr = line.getSequenceName val chr = line.getSequenceName
writeGenotypeField(stats, samples, field, new File(genotypeOutputDir, "chrs" + File.separator + chr), chr = chr) writeGenotypeField(stats, samples, field, new File(genotypeOutputDir, "chrs" + File.separator + chr), chr = chr)
} }
} }
// Write sample distributions to tsv files // Write sample distributions to tsv files
val sampleDistributionsOutputDir = new File(commandArgs.outputDir, "sample_distributions") val sampleDistributionsOutputDir = new File(cmdArgs.outputDir, "sample_distributions")
for (field <- sampleDistributions) { for (field <- sampleDistributions) {
writeField(stats, "SampleDistribution-" + field, sampleDistributionsOutputDir) writeField(stats, "SampleDistribution-" + field, sampleDistributionsOutputDir)
} }
// Write general wiggle tracks // Write general wiggle tracks
for (field <- commandArgs.generalWiggle) { for (field <- cmdArgs.generalWiggle) {
val file = new File(commandArgs.outputDir, "wigs" + File.separator + "general-" + field + ".wig") val file = new File(cmdArgs.outputDir, "wigs" + File.separator + "general-" + field + ".wig")
writeWiggle(intervals, field, "count", file, genotype = false) writeWiggle(intervals, field, "count", file, genotype = false)
} }
// Write sample wiggle tracks // Write sample wiggle tracks
for (field <- commandArgs.genotypeWiggle; sample <- samples) { for (field <- cmdArgs.genotypeWiggle; sample <- samples) {
val file = new File(commandArgs.outputDir, "wigs" + File.separator + "genotype-" + sample + "-" + field + ".wig") val file = new File(cmdArgs.outputDir, "wigs" + File.separator + "genotype-" + sample + "-" + field + ".wig")
writeWiggle(intervals, field, sample, file, genotype = true) writeWiggle(intervals, field, sample, file, genotype = true)
} }
writeOverlap(stats, _.genotypeOverlap, commandArgs.outputDir + "/sample_compare/genotype_overlap", samples) writeOverlap(stats, _.genotypeOverlap, cmdArgs.outputDir + "/sample_compare/genotype_overlap", samples)
writeOverlap(stats, _.alleleOverlap, commandArgs.outputDir + "/sample_compare/allele_overlap", samples) writeOverlap(stats, _.alleleOverlap, cmdArgs.outputDir + "/sample_compare/allele_overlap", samples)
logger.info("Done") logger.info("Done")
} }
...@@ -440,8 +440,8 @@ object VcfStats extends ToolCommand { ...@@ -440,8 +440,8 @@ object VcfStats extends ToolCommand {
writer.println(s"fixedStep chrom=$chr start=1 step=$length span=$length") writer.println(s"fixedStep chrom=$chr start=1 step=$length span=$length")
for (interval <- intervals) { for (interval <- intervals) {
val file = { val file = {
if (genotype) new File(commandArgs.outputDir, "bins" + File.separator + chr + File.separator + "genotype-" + interval.getStart + "-" + interval.getEnd + "-general.tsv") if (genotype) new File(cmdArgs.outputDir, "bins" + File.separator + chr + File.separator + "genotype-" + interval.getStart + "-" + interval.getEnd + "-general.tsv")
else new File(commandArgs.outputDir, "bins" + File.separator + chr + File.separator + interval.getStart + "-" + interval.getEnd + "-general.tsv") else new File(cmdArgs.outputDir, "bins" + File.separator + chr + File.separator + interval.getStart + "-" + interval.getEnd + "-general.tsv")
} }
writer.println(valueFromTsv(file, row, column).getOrElse(0)) writer.println(valueFromTsv(file, row, column).getOrElse(0))
} }
......
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