diff --git a/build.sbt b/build.sbt index c802a5878..cfae5e653 100644 --- a/build.sbt +++ b/build.sbt @@ -128,7 +128,7 @@ lazy val root = Project(id="fgbio", base=file(".")) "org.scala-lang.modules" %% "scala-xml" % "2.1.0", "com.fulcrumgenomics" %% "commons" % "1.4.0", "com.fulcrumgenomics" %% "sopt" % "1.1.0", - "com.github.samtools" % "htsjdk" % "2.24.1-26-ga38c78d-SNAPSHOT" excludeAll(htsjdkExcludes: _*), + "com.github.samtools" % "htsjdk" % "3.0.3" excludeAll(htsjdkExcludes: _*), "org.apache.commons" % "commons-math3" % "3.6.1", "com.beachape" %% "enumeratum" % "1.7.0", "com.intel.gkl" % "gkl" % "0.8.8", diff --git a/src/main/scala/com/fulcrumgenomics/vcf/JointVariantContextIterator.scala b/src/main/scala/com/fulcrumgenomics/vcf/JointVariantContextIterator.scala index 90e0518bc..b38bc23a1 100644 --- a/src/main/scala/com/fulcrumgenomics/vcf/JointVariantContextIterator.scala +++ b/src/main/scala/com/fulcrumgenomics/vcf/JointVariantContextIterator.scala @@ -24,6 +24,7 @@ package com.fulcrumgenomics.vcf +import com.fulcrumgenomics.coord.LocatableOrdering import com.fulcrumgenomics.fasta.SequenceDictionary import htsjdk.variant.variantcontext.{VariantContext, VariantContextComparator} @@ -31,19 +32,14 @@ object JointVariantContextIterator { def apply(iters: Seq[Iterator[VariantContext]], dict: SequenceDictionary ): JointVariantContextIterator = { - new JointVariantContextIterator( - iters=iters, - dictOrComp = Left(dict) - ) + new JointVariantContextIterator(iters = iters, dict = dict) } + @deprecated("VariantContextComparator will no longer compare variant contexts on location alone.") def apply(iters: Seq[Iterator[VariantContext]], comp: VariantContextComparator ): JointVariantContextIterator = { - new JointVariantContextIterator( - iters=iters, - dictOrComp = Right(comp) - ) + throw new NotImplementedError("VariantContextComparator class can no longer order variant contexts on location alone.") } } @@ -51,30 +47,24 @@ object JointVariantContextIterator { * Iterates over multiple variant context iterators such that we return a list of contexts for the union of sites * across the iterators. If samples is given, we subset each variant context to just that sample. */ -class JointVariantContextIterator private(iters: Seq[Iterator[VariantContext]], - dictOrComp: Either[SequenceDictionary, VariantContextComparator] - ) +class JointVariantContextIterator private(iters: Seq[Iterator[VariantContext]], dict: SequenceDictionary) extends Iterator[Seq[Option[VariantContext]]] { - import com.fulcrumgenomics.fasta.Converters.ToSAMSequenceDictionary if (iters.isEmpty) throw new IllegalArgumentException("No iterators given") private val iterators = iters.map(_.buffered) - private val comparator = dictOrComp match { - case Left(dict) => new VariantContextComparator(dict.asSam) - case Right(comp) => comp - } + private val ordering = LocatableOrdering(dict) def hasNext: Boolean = iterators.exists(_.nonEmpty) def next(): Seq[Option[VariantContext]] = { val minCtx = iterators.filter(_.nonEmpty).map(_.head).sortWith { - case (left: VariantContext, right: VariantContext) => comparator.compare(left, right) < 0 + case (left: VariantContext, right: VariantContext) => ordering.compare(left, right) < 0 }.head // TODO: could use a TreeSet to store the iterators, examine the head of each iterator, then pop the iterator with the min, // and add that iterator back in. - iterators.zipWithIndex.map { case(iter, idx) => - if (iter.isEmpty || this.comparator.compare(minCtx, iter.head) != 0) None + iterators.map { iter => + if (iter.isEmpty || ordering.compare(minCtx, iter.head) != 0) None else Some(iter.next()) } }