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

Fix an instance of non-determinism in HaplotypeCaller #6104

Merged
merged 3 commits into from
Aug 27, 2019
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs;

import org.apache.commons.lang3.mutable.MutableInt;
import org.broadinstitute.hellbender.utils.BaseUtils;
import org.broadinstitute.hellbender.utils.Utils;
import org.jgrapht.alg.CycleDetector;

Expand All @@ -14,6 +15,9 @@
*/
public final class KBestHaplotypeFinder {

public static final Comparator<KBestHaplotype> K_BEST_HAPLOTYPE_COMPARATOR = Comparator.comparingDouble(KBestHaplotype::score)
.reversed()
.thenComparing(KBestHaplotype::getBases, BaseUtils.BASES_COMPARATOR.reversed()); // This is an arbitrary deterministic tie breaker.
private final SeqGraph graph;
final Set<SeqVertex> sinks;
final Set<SeqVertex> sources;
Expand Down Expand Up @@ -66,7 +70,7 @@ public KBestHaplotypeFinder(final SeqGraph graph) {
*/
public List<KBestHaplotype> findBestHaplotypes(final int maxNumberOfHaplotypes) {
final List<KBestHaplotype> result = new ArrayList<>();
final PriorityQueue<KBestHaplotype> queue = new PriorityQueue<>(Comparator.comparingDouble(KBestHaplotype::score).reversed());
final PriorityQueue<KBestHaplotype> queue = new PriorityQueue<>(K_BEST_HAPLOTYPE_COMPARATOR);
sources.forEach(source -> queue.add(new KBestHaplotype(source, graph)));

final Map<SeqVertex, MutableInt> vertexCounts = graph.vertexSet().stream()
Expand All @@ -86,7 +90,6 @@ public List<KBestHaplotype> findBestHaplotypes(final int maxNumberOfHaplotypes)
}

for (final BaseEdge edge : outgoingEdges) {
final SeqVertex targetVertex = graph.getEdgeTarget(edge);
queue.add(new KBestHaplotype(pathToExtend, edge, totalOutgoingMultiplicity));
}
}
Expand Down