Skip to content
Snippets Groups Projects
Commit 51468763 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Write empty file when no records exist

parent a081627f
No related branches found
No related tags found
No related merge requests found
......@@ -39,8 +39,6 @@ class SnptestToVcf(val root: Configurable) extends ToolCommandFunction with Refe
var contig: String = _
override def defaultCoreMemory = 6.0
override def beforeGraph(): Unit = {
super.beforeGraph()
if (reference == null) reference = referenceFasta()
......
......@@ -48,12 +48,27 @@ object SnptestToVcf extends ToolCommand {
infoHeader match {
case Some(header) => parseLines(header, infoIt, cmdArgs)
case _ => logger.info("No header and records found in file")
case _ =>
writeEmptyVcf(cmdArgs.outputVcf, cmdArgs.referenceFasta)
logger.info("No header and records found in file")
}
logger.info("Done")
}
def writeEmptyVcf(outputVcf: File, referenceFasta: File): Unit = {
val reference = new FastaSequenceFile(referenceFasta, true)
val vcfHeader = new VCFHeader()
vcfHeader.setSequenceDictionary(reference.getSequenceDictionary)
val writer = new AsyncVariantContextWriter(new VariantContextWriterBuilder()
.setOutputFile(outputVcf)
.setReferenceDictionary(vcfHeader.getSequenceDictionary)
.unsetOption(Options.INDEX_ON_THE_FLY)
.build)
writer.writeHeader(vcfHeader)
writer.close()
}
def parseLines(header: String, lineIt: Iterator[String], cmdArgs: Args): Unit = {
val headerKeys = header.split(" ")
val headerMap = headerKeys.zipWithIndex.toMap
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment