From aee52b85c1c498cba13aa0efaf10340317abbdad Mon Sep 17 00:00:00 2001 From: Kari Stromhaug Date: Wed, 30 Mar 2022 09:33:56 -0600 Subject: [PATCH] Remove VariantContext use from VariantMask tool --- .../com/fulcrumgenomics/vcf/VariantMask.scala | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/scala/com/fulcrumgenomics/vcf/VariantMask.scala b/src/main/scala/com/fulcrumgenomics/vcf/VariantMask.scala index 9b5c11846..50c949ef7 100644 --- a/src/main/scala/com/fulcrumgenomics/vcf/VariantMask.scala +++ b/src/main/scala/com/fulcrumgenomics/vcf/VariantMask.scala @@ -26,6 +26,7 @@ package com.fulcrumgenomics.vcf import com.fulcrumgenomics.FgBioDef._ import com.fulcrumgenomics.fasta.SequenceDictionary +import com.fulcrumgenomics.vcf.api.{Variant, VcfSource} import htsjdk.variant.variantcontext.VariantContext import htsjdk.variant.vcf.VCFFileReader @@ -33,18 +34,17 @@ import scala.collection.mutable object VariantMask { /** Generate a variant mask from the provided VCF. */ - def apply(path: PathToVcf): VariantMask = apply(new VCFFileReader(path.toFile)) + def apply(path: PathToVcf): VariantMask = apply(VcfSource(path)) /** Generate a variant mask from the provided VCF reader. */ - def apply(reader: VCFFileReader): VariantMask = { - import com.fulcrumgenomics.fasta.Converters.FromSAMSequenceDictionary - val dict = reader.getFileHeader.getSequenceDictionary.fromSam + def apply(reader: VcfSource): VariantMask = { + val dict = reader.header.dict require(dict != null && dict.length > 0, "Generating a VariantMask requires VCFs contain contig lines.") - apply(reader.iterator(), dict) + apply(reader.iterator, dict) } /** Generates a VariantMask from the variants in the provided iterator. */ - def apply(variants: Iterator[VariantContext], dict: SequenceDictionary) = new VariantMask(variants, dict) + def apply(variants: Iterator[Variant], dict: SequenceDictionary) = new VariantMask(variants, dict) } /** @@ -55,7 +55,7 @@ object VariantMask { * @param variants a coordinate sorted iterator of variants * @param dict the sequence dictionary for the reference */ -class VariantMask(variants: Iterator[VariantContext], val dict: SequenceDictionary) { +class VariantMask(variants: Iterator[Variant], val dict: SequenceDictionary) { private val iterator = variants.bufferBetter private var currentMask: mutable.BitSet = new mutable.BitSet(0) private var currentIndex: Int = -1 @@ -74,7 +74,7 @@ class VariantMask(variants: Iterator[VariantContext], val dict: SequenceDictiona val bits = new mutable.BitSet(ref.length) iterator.dropWhile(v => dict(v.getContig).index < refIndex) .takeWhile(v => dict(v.getContig).index == refIndex) - .filterNot(v => v.isFiltered) + .filterNot(v => v.filters.nonEmpty) // TODO verify that this is correct .foreach { v => forloop (from=v.getStart, until=v.getEnd+1) { i => bits(i-1) = true } }