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

Added base version of validate vcf

parent 0b4c76c5
......@@ -45,6 +45,7 @@ object BiopetToolsExecutable extends BiopetExecutable {
nl.lumc.sasc.biopet.tools.SquishBed,
nl.lumc.sasc.biopet.tools.SummaryToTsv,
nl.lumc.sasc.biopet.tools.ValidateFastq,
nl.lumc.sasc.biopet.tools.ValidateVcf,
nl.lumc.sasc.biopet.tools.VcfFilter,
nl.lumc.sasc.biopet.tools.VcfStats,
nl.lumc.sasc.biopet.tools.VcfToTsv,
......
package nl.lumc.sasc.biopet.tools
import java.io.File
import htsjdk.variant.vcf.VCFFileReader
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.intervals.{ BedRecord, BedRecordList }
import scala.collection.JavaConversions._
/**
* Created by pjvanthof on 10/12/2016.
*/
object ValidateVcf extends ToolCommand {
case class Args(inputVcf: File = null,
reference: File = null,
failOnError: Boolean = true) extends AbstractArgs
class OptParser extends AbstractOptParser {
opt[File]('i', "inputVcf") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(inputVcf = x)
} text "Vcf file to check"
opt[File]('R', "reference") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(reference = x)
} text "Reference fasta to check vcf file against"
opt[Unit]("disableFail") maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(failOnError = false)
} text "Disable failing, tool still stops at the first error but exitcode 0 is given"
}
def main(args: Array[String]): Unit = {
logger.info("Start")
val argsParser = new OptParser
val cmdArgs: Args = argsParser.parse(args, Args()) getOrElse (throw new IllegalArgumentException)
val regions = BedRecordList.fromReference(cmdArgs.reference)
val vcfReader = new VCFFileReader(cmdArgs.inputVcf, true)
try {
for (record <- vcfReader.iterator()) {
val contig = record.getContig
require(regions.chrRecords.contains(contig),
s"contig in vcf file is not on reference: ${contig}")
val start = record.getStart
val end = record.getEnd
require(regions.chrRecords(contig).exists(_.overlapWith(BedRecord("contig", start, start))),
s"Position does not exist on reference: ${contig}:$start")
if (end != start) require(regions.chrRecords(contig).exists(_.overlapWith(BedRecord("contig", end, end))),
s"Position does not exist on reference: ${contig}:$end")
require(start <= end, "End is higher then Start, this should not be possible")
}
} catch {
case e: IllegalArgumentException =>
if (cmdArgs.failOnError) throw e
else logger.warn(e.getMessage)
}
vcfReader.close()
logger.info("No error found")
}
}
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