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

Delete a bunch of unused methods #6107

Merged
merged 10 commits into from
Aug 26, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public final class SVDDenoisingUtils {
private static final Logger logger = LogManager.getLogger(SVDDenoisingUtils.class);

private static final double EPSILON = 1E-9;
private static final double INV_LN2 = MathUtils.INV_LOG_2;
private static final double LN2_EPSILON = Math.log(EPSILON) * INV_LN2;
private static final double LN2_EPSILON = Math.log(EPSILON) * MathUtils.INV_LOG_2;

private SVDDenoisingUtils() {}

Expand Down Expand Up @@ -459,7 +458,8 @@ private static int countNumberPassingFilter(final boolean[] filter) {

private static void transformToFractionalCoverage(final RealMatrix matrix) {
logger.info("Transforming read counts to fractional coverage...");
final double[] sampleSums = MathUtils.rowSums(matrix);
final double[] sampleSums = IntStream.range(0, matrix.getRowDimension())
.mapToDouble(r -> MathUtils.sum(matrix.getRow(r))).toArray();
matrix.walkInOptimizedOrder(new DefaultRealMatrixChangingVisitor() {
@Override
public double visit(int sampleIndex, int intervalIndex, double value) {
Expand Down Expand Up @@ -498,6 +498,6 @@ private static int calculateMaximumZerosCount(final int numTotalCounts,
}

private static double safeLog2(final double x) {
return x < EPSILON ? LN2_EPSILON : Math.log(x) * INV_LN2;
return x < EPSILON ? LN2_EPSILON : Math.log(x) * MathUtils.INV_LOG_2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,6 @@ static int calculateGenotypeQuality(final CopyNumberPosteriorDistribution copyNu
}

private static int convertLogProbabilityToPhredScore(final double posteriorProbInLogSpace) {
return (int) FastMath.floor(-10.0 * posteriorProbInLogSpace * MathUtils.LOG10_OF_E);
return (int) FastMath.floor(-10.0 * posteriorProbInLogSpace * MathUtils.LOG10_E);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.broadinstitute.hellbender.tools.walkers.annotator;

import htsjdk.variant.variantcontext.*;
import htsjdk.variant.vcf.VCFConstants;
import htsjdk.variant.vcf.VCFFormatHeaderLine;
import htsjdk.variant.vcf.VCFStandardHeaderLines;
import org.broadinstitute.barclay.help.DocumentedFeature;
import org.broadinstitute.hellbender.engine.ReferenceContext;
import org.broadinstitute.hellbender.utils.MathUtils;
Expand Down Expand Up @@ -54,14 +52,14 @@ public void annotate(final ReferenceContext ref,
for ( final Genotype genotype : genotypes ) {
if ( genotype.hasAD() ) {
final int[] AD = genotype.getAD();
final double[] allAlleleFractions = MathUtils.normalizeFromRealSpace(Arrays.stream(AD).mapToDouble(x -> x).toArray());
final double[] allAlleleFractions = MathUtils.normalizeSumToOne(Arrays.stream(AD).mapToDouble(x -> x).toArray());
gb.attribute(getKeyNames().get(0), Arrays.copyOfRange(allAlleleFractions, 1, allAlleleFractions.length)); //omit the first entry of the array corresponding to the reference
}
// if there is no AD value calculate it now using likelihoods
else if (likelihoods != null) {
DepthPerAlleleBySample adCalc = new DepthPerAlleleBySample();
final int[] AD = adCalc.annotateWithLikelihoods(vc, g, new LinkedHashSet<>(vc.getAlleles()), likelihoods);
final double[] allAlleleFractions = MathUtils.normalizeFromRealSpace(Arrays.stream(AD).mapToDouble(x -> x*1.0).toArray());
final double[] allAlleleFractions = MathUtils.normalizeSumToOne(Arrays.stream(AD).mapToDouble(x -> x*1.0).toArray());
gb.attribute(getKeyNames().get(0), Arrays.copyOfRange(allAlleleFractions, 1, allAlleleFractions.length)); //omit the first entry of the array corresponding to the reference
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public AFCalculationResult(final int[] alleleCountsOfMLE,
}
if ( ! allelesUsedInGenotyping.containsAll(log10pRefByAllele.keySet()) ) {
throw new IllegalArgumentException("log10pRefByAllele doesn't contain all of the alleles used in genotyping: log10pRefByAllele " + log10pRefByAllele + " but allelesUsedInGenotyping " + allelesUsedInGenotyping);
}if ( ! MathUtils.goodLog10ProbVector(log10LikelihoodsOfAC, LOG_10_ARRAY_SIZES, false) ) {
}if ( ! MathUtils.isValidLog10ProbabilityVector(log10LikelihoodsOfAC, LOG_10_ARRAY_SIZES, false) ) {
throw new IllegalArgumentException("log10LikelihoodsOfAC are bad " + Utils.join(",", log10LikelihoodsOfAC));
}
if ( ! MathUtils.goodLog10ProbVector(log10PriorsOfAC, LOG_10_ARRAY_SIZES, false) ) {
if ( ! MathUtils.isValidLog10ProbabilityVector(log10PriorsOfAC, LOG_10_ARRAY_SIZES, false) ) {
throw new IllegalArgumentException("log10priors are bad " + Utils.join(",", log10PriorsOfAC));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,27 @@ public SortedSet<VariantContext> getVariationEvents(final int maxMnpDistance) {
public void regenerateVariationEvents(int maxMnpDistance) {
final List<Haplotype> haplotypeList = getHaplotypeList();
EventMap.buildEventMapsForHaplotypes(haplotypeList, fullReferenceWithPadding, paddedReferenceLoc, debug, maxMnpDistance);
variationEvents = EventMap.getAllVariantContexts(haplotypeList);
variationEvents = getAllVariantContexts(haplotypeList);
lastMaxMnpDistanceUsed = OptionalInt.of(maxMnpDistance);
variationPresent = haplotypeList.stream().anyMatch(Haplotype::isNonReference);
}

/**
* Get all of the VariantContexts in the event maps for all haplotypes, sorted by their start position
* @param haplotypes the set of haplotypes to grab the VCs from
* @return a sorted set of variant contexts
*/
private static SortedSet<VariantContext> getAllVariantContexts( final List<Haplotype> haplotypes ) {
// Using the cigar from each called haplotype figure out what events need to be written out in a VCF file
final TreeSet<VariantContext> vcs = new TreeSet<>(Comparator.comparingInt(VariantContext::getStart));

for( final Haplotype h : haplotypes ) {
vcs.addAll(h.getEventMap().getVariantContexts());
}

return vcs;
}

public void setDebug(boolean debug) {
this.debug = debug;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private static final double germlineProbability(final double alleleFrequency, fi
final double[] relativeProbsOfHetHomArtifact = {hetPrior * hetLikelihood + homPrior * homLikelihood, ARTIFACT_PRIOR * artifactLikelihood};

// check for invalid probabilities just in case of finite precision error
return MathUtils.sum(relativeProbsOfHetHomArtifact) < 0 ? 0 : MathUtils.normalizeFromRealSpace(relativeProbsOfHetHomArtifact)[0];
return MathUtils.sum(relativeProbsOfHetHomArtifact) < 0 ? 0 : MathUtils.normalizeSumToOne(relativeProbsOfHetHomArtifact)[0];
}

private BetaDistributionShape fitBeta(final List<int[]> altAndRefCounts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private void addGenotypes(final ReadLikelihoods<Allele> logLikelihoods,
final double[] flatPriorPseudocounts = new IndexRange(0, logMatrix.numberOfAlleles()).mapToDouble(a -> 1);
final double[] alleleFractionsPosterior = logMatrix.numberOfReads() == 0 ? flatPriorPseudocounts :
SomaticLikelihoodsEngine.alleleFractionsPosterior(getAsRealMatrix(logMatrix), flatPriorPseudocounts);
final double[] tumorAlleleFractionsMean = MathUtils.normalizeFromRealSpace(alleleFractionsPosterior);
final double[] tumorAlleleFractionsMean = MathUtils.normalizeSumToOne(alleleFractionsPosterior);

// TODO: We shouldn't always assume that the genotype in the normal is hom ref
final Allele ref = logMatrix.getAllele(getRefIndex(logMatrix));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ EStep strandArtifactProbability(final double strandArtifactPrior, int forwardCou
final double reverseLogPrior = Math.log(strandArtifactPrior/2);
final double noneLogPrior = Math.log(1 - strandArtifactPrior);

final double[] forwardReverseNoneProbs = MathUtils.normalizeLog10(new double[] {(forwardLogLikelihood + forwardLogPrior) * MathUtils.LOG10_OF_E,
(reverseLogLikelihood + reverseLogPrior)* MathUtils.LOG10_OF_E, (noneLogLikelihood + noneLogPrior) * MathUtils.LOG10_OF_E}, false, true);
final double[] forwardReverseNoneProbs = MathUtils.normalizeLog10(new double[] {(forwardLogLikelihood + forwardLogPrior) * MathUtils.LOG10_E,
(reverseLogLikelihood + reverseLogPrior)* MathUtils.LOG10_E, (noneLogLikelihood + noneLogPrior) * MathUtils.LOG10_E}, false, true);

return new EStep(forwardReverseNoneProbs[0], forwardReverseNoneProbs[1], forwardCount, reverseCount, forwardAltCount, reverseAltCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public static double[] computeResponsibilities(final Nucleotide refAllele, final
private static double computeLogPosterior(final int altDepth, final int altF1R2Depth, final int depth,
final double statePrior, final BetaDistributionShape afPseudoCounts,
final BetaDistributionShape f1r2PseudoCounts){
Utils.validateArg(MathUtils.isAProbability(statePrior), String.format("statePrior must be a probability but got %f", statePrior));
Utils.validateArg(MathUtils.isValidProbability(statePrior), String.format("statePrior must be a probability but got %f", statePrior));

return Math.log(statePrior)
+ new BetaBinomialDistribution(null, afPseudoCounts.getAlpha(), afPseudoCounts.getBeta(), depth).logProbability(altDepth)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package org.broadinstitute.hellbender.utils;

import org.apache.commons.math3.special.Gamma;
import org.apache.commons.math3.util.MathArrays;

import java.util.Arrays;
import java.util.Collections;
import java.util.stream.IntStream;

/**
* The Dirichlet distribution is a distribution on multinomial distributions: if pi is a vector of positive multinomial weights
Expand Down Expand Up @@ -53,7 +50,7 @@ public double[] effectiveMultinomialWeights() {

public double[] effectiveLog10MultinomialWeights() {
final double digammaOfSum = Gamma.digamma(MathUtils.sum(alpha));
return MathUtils.applyToArray(alpha, a -> (Gamma.digamma(a) - digammaOfSum) * MathUtils.LOG10_OF_E);
return MathUtils.applyToArray(alpha, a -> (Gamma.digamma(a) - digammaOfSum) * MathUtils.LOG10_E);
}

public double[] effectiveLogMultinomialWeights() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static GenotypeCounts computeDiploidGenotypeCounts(final VariantContext v
varIndex = idxVector[2];
}
}
biallelicLikelihoods = MathUtils.normalizeFromRealSpace(new double[] {normalizedLikelihoods[idxAA], normalizedLikelihoods[hetIndex], normalizedLikelihoods[varIndex]});
biallelicLikelihoods = MathUtils.normalizeSumToOne(new double[] {normalizedLikelihoods[idxAA], normalizedLikelihoods[hetIndex], normalizedLikelihoods[varIndex]});
}
else {
biallelicLikelihoods = normalizedLikelihoods;
Expand Down
Loading