Java Code Examples for org.apache.commons.lang3.mutable.MutableDouble#getValue()

The following examples show how to use org.apache.commons.lang3.mutable.MutableDouble#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GermlineFilter.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private double computeMinorAlleleFraction(final VariantContext vc, final Mutect2FilteringEngine filteringEngine, final int[] alleleCounts) {
    final MutableDouble weightedSumOfMafs = new MutableDouble(0);
    vc.getGenotypes().stream().filter(filteringEngine::isTumor).forEach(tumorGenotype -> {
        final String sample = tumorGenotype.getSampleName();
        final List<MinorAlleleFractionRecord> segments = tumorSegments.containsKey(sample) ? tumorSegments.get(sample).getOverlaps(vc).stream().collect(Collectors.toList())
                : Collections.emptyList();

        // minor allele fraction -- we abbreviate the name to make the formulas below less cumbersome
        final double maf = segments.isEmpty() ? 0.5 : segments.get(0).getMinorAlleleFraction();

        weightedSumOfMafs.add(maf * MathUtils.sum(tumorGenotype.getAD()));
    });


    // weighted average of sample minor allele fractions.  This is the expected allele fraction of a germline het in the aggregated read counts
    return weightedSumOfMafs.getValue() / MathUtils.sum(alleleCounts);
}
 
Example 2
Source File: ThresholdCalculator.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Compute the filtering threshold that maximizes the F_beta score
 *
 * @param posteriors A list of posterior probabilities, which gets sorted
 * @param beta relative weight of recall to precision
 */
@VisibleForTesting
static double calculateThresholdBasedOnOptimalFScore(final List<Double> posteriors, final double beta){
    ParamUtils.isPositiveOrZero(beta, "requested F-score beta must be non-negative");

    Collections.sort(posteriors);

    final double expectedTruePositives = posteriors.stream()
            .mapToDouble(prob -> 1 - prob).sum();


    // starting from filtering everything (threshold = 0) increase the threshold to maximize the F score
    final MutableDouble truePositives = new MutableDouble(0);
    final MutableDouble falsePositives = new MutableDouble(0);
    final MutableDouble falseNegatives = new MutableDouble(expectedTruePositives);
    int optimalIndexInclusive = -1; // include all indices up to and including this. -1 mean filter all.
    double optimalFScore = 0;   // if you exclude everything, recall is zero

    final int N = posteriors.size();

    for (int n = 0; n < N; n++){
        truePositives.add(1 - posteriors.get(n));
        falsePositives.add(posteriors.get(n));
        falseNegatives.subtract(1 - posteriors.get(n));
        final double F = (1+beta*beta)*truePositives.getValue() /
                ((1+beta*beta)*truePositives.getValue() + beta*beta*falseNegatives.getValue() + falsePositives.getValue());
        if (F >= optimalFScore) {
            optimalIndexInclusive = n;
            optimalFScore = F;
        }
    }

    return optimalIndexInclusive == -1 ? 0 : (optimalIndexInclusive == N - 1 ? 1 : posteriors.get(optimalIndexInclusive));
}