Skip to content

Commit

Permalink
Remove VariantContext use from VariantMask tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Kari Stromhaug committed Mar 30, 2022
1 parent 0f94276 commit aee52b8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/scala/com/fulcrumgenomics/vcf/VariantMask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ 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

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)
}

/**
Expand All @@ -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
Expand All @@ -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 }
}
Expand Down

0 comments on commit aee52b8

Please sign in to comment.