1 package org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs;
2 
3 import org.broadinstitute.hellbender.utils.MathUtils;
4 import org.broadinstitute.hellbender.utils.haplotype.Haplotype;
5 
6 import java.util.List;
7 
8 /**
9  * Represents a result from a K-best haplotype search.
10  *
11  * @author Valentin Ruano-Rubio <valentin@broadinstitute.org>
12  */
13 public class KBestHaplotype<V extends BaseVertex, E extends BaseEdge> extends Path<V, E>{
14     private double score;
15     private boolean isReference;
16 
score()17     public double score() { return score; }
isReference()18     public boolean isReference() { return isReference; }
19 
KBestHaplotype(final V initialVertex, final BaseGraph<V,E> graph)20     public KBestHaplotype(final V initialVertex, final BaseGraph<V,E> graph) {
21         super(initialVertex, graph);
22         score = 0;
23     }
24 
KBestHaplotype(final KBestHaplotype<V, E> p, final E edge, final int totalOutgoingMultiplicity)25     public KBestHaplotype(final KBestHaplotype<V, E> p, final E edge, final int totalOutgoingMultiplicity) {
26         super(p, edge);
27         score = p.score + computeLogPenaltyScore( edge.getMultiplicity(), totalOutgoingMultiplicity);
28         isReference &= edge.isRef();
29     }
30 
computeLogPenaltyScore(int edgeMultiplicity, int totalOutgoingMultiplicity)31     public static double computeLogPenaltyScore(int edgeMultiplicity, int totalOutgoingMultiplicity) {
32         return MathUtils.log10(edgeMultiplicity) - MathUtils.log10(totalOutgoingMultiplicity);
33     }
34 
KBestHaplotype(final KBestHaplotype<V, E> p, final List<E> edgesToExtend, final double edgePenalty)35     public KBestHaplotype(final KBestHaplotype<V, E> p, final List<E> edgesToExtend, final double edgePenalty) {
36         super(p, edgesToExtend);
37         score = p.score() + edgePenalty;
38         isReference &= edgesToExtend.get(edgesToExtend.size() - 1).isRef();
39     }
40 
haplotype()41     public final Haplotype haplotype() {
42         final Haplotype haplotype = new Haplotype(getBases(),isReference());
43         haplotype.setScore(score());
44         return haplotype;
45     }
46 }
47