Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump htsjdk to 3.0.3 #884

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,57 +24,47 @@

package com.fulcrumgenomics.vcf

import com.fulcrumgenomics.coord.LocatableOrdering
import com.fulcrumgenomics.fasta.SequenceDictionary
import htsjdk.variant.variantcontext.{VariantContext, VariantContextComparator}

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]],
Copy link
Member Author

@clintval clintval Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entrypoint was never used in this codebase. And it is no longer possible to use VariantContextComparator since it compares variants beyond location alone (source). Seems like my only option is deprecation and raising an exception.

comp: VariantContextComparator
): JointVariantContextIterator = {
new JointVariantContextIterator(
iters=iters,
dictOrComp = Right(comp)
)
throw new NotImplementedError("VariantContextComparator class can no longer order variant contexts on location alone.")
}
}

/**
* 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)
Copy link
Member Author

@clintval clintval Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class VariantContextComparator now compares more than just on location (source)

Searching the codebase, this was the only improper use of the new class (and unit tests were failing).

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 =>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable idx wasn't used and zipWithIndex is slower than mapping.

if (iter.isEmpty || ordering.compare(minCtx, iter.head) != 0) None
else Some(iter.next())
}
}
Expand Down