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

Refactor code

parent 4d20276b
...@@ -145,10 +145,8 @@ object VcfFilter extends ToolCommand { ...@@ -145,10 +145,8 @@ object VcfFilter extends ToolCommand {
val writer = new AsyncVariantContextWriter(new VariantContextWriterBuilder().setOutputFile(commandArgs.outputVcf).build) val writer = new AsyncVariantContextWriter(new VariantContextWriterBuilder().setOutputFile(commandArgs.outputVcf).build)
writer.writeHeader(header) writer.writeHeader(header)
val invertedWriter = if (commandArgs.invertedOutputVcf.isDefined) val invertedWriter = commandArgs.invertedOutputVcf.collect { case x => new VariantContextWriterBuilder().setOutputFile(x).build }
Some(new AsyncVariantContextWriter(new VariantContextWriterBuilder().setOutputFile(commandArgs.invertedOutputVcf.get).build)) invertedWriter.foreach(_.writeHeader(header))
else None
if (invertedWriter.isDefined) invertedWriter.get.writeHeader(header)
var counterTotal = 0 var counterTotal = 0
var counterLeft = 0 var counterLeft = 0
...@@ -167,16 +165,15 @@ object VcfFilter extends ToolCommand { ...@@ -167,16 +165,15 @@ object VcfFilter extends ToolCommand {
inIdSet(record)) { inIdSet(record)) {
writer.add(record) writer.add(record)
counterLeft += 1 counterLeft += 1
} else { } else
if (invertedWriter.isDefined) invertedWriter.get.add(record) invertedWriter.foreach(_.add(record))
}
counterTotal += 1 counterTotal += 1
if (counterTotal % 100000 == 0) logger.info(counterTotal + " variants processed, " + counterLeft + " left") if (counterTotal % 100000 == 0) logger.info(counterTotal + " variants processed, " + counterLeft + " left")
} }
logger.info(counterTotal + " variants processed, " + counterLeft + " left") logger.info(counterTotal + " variants processed, " + counterLeft + " left")
reader.close reader.close
writer.close writer.close
if (invertedWriter.isDefined) invertedWriter.get.close() invertedWriter.foreach(_.close())
logger.info("Done") logger.info("Done")
} }
......
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