Search in sources :

Example 1 with Doubles

use of com.hartwig.hmftools.common.numeric.Doubles in project hmftools by hartwigmedical.

the class StructuralVariantLegPloidyFactory method create.

@VisibleForTesting
@NotNull
Optional<ModifiableStructuralVariantLegPloidy> create(@NotNull StructuralVariantLeg leg, @NotNull final GenomeRegionSelector<T> selector) {
    final GenomePosition svPositionLeft = GenomePositions.create(leg.chromosome(), leg.position() - 1);
    final Optional<Double> left = selector.select(svPositionLeft).flatMap(x -> Optional.ofNullable(copyNumberExtractor.apply(x))).filter(Doubles::positive);
    final Optional<Double> right = selector.select(leg).flatMap(x -> Optional.ofNullable(copyNumberExtractor.apply(x))).filter(Doubles::positive);
    final Optional<Double> correct;
    final Optional<Double> alternate;
    if (leg.orientation() == 1) {
        correct = left;
        alternate = right;
    } else {
        correct = right;
        alternate = left;
    }
    if (!correct.isPresent() && !alternate.isPresent()) {
        return Optional.empty();
    }
    final double vaf = leg.alleleFrequency();
    final double ploidy;
    final double weight;
    if (correct.isPresent()) {
        double copyNumber = correct.get();
        ploidy = purityAdjustedPloidy(leg.chromosome(), vaf, copyNumber);
        weight = 1;
    } else {
        double copyNumber = alternate.get();
        double reciprocalVAF = vaf / (1 - vaf);
        if (!Double.isFinite(reciprocalVAF)) {
            return Optional.empty();
        }
        ploidy = purityAdjustedPloidy(leg.chromosome(), reciprocalVAF, copyNumber);
        weight = 1 / (1 + Math.pow(Math.max(copyNumber, 2) / Math.min(Math.max(copyNumber, 0.01), 2), 2));
    }
    return Optional.of(ModifiableStructuralVariantLegPloidy.create().from(leg).setVaf(vaf).setOrientation(leg.orientation()).setUnweightedImpliedPloidy(ploidy).setLeftCopyNumber(left).setRightCopyNumber(right).setWeight(weight));
}
Also used : GenomeRegionSelector(com.hartwig.hmftools.common.region.GenomeRegionSelector) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) List(java.util.List) Lists(com.google.common.collect.Lists) GenomeRegionSelectorFactory(com.hartwig.hmftools.common.region.GenomeRegionSelectorFactory) GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) Doubles(com.hartwig.hmftools.common.numeric.Doubles) PurityAdjuster(com.hartwig.hmftools.common.purple.PurityAdjuster) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) GenomePositions(com.hartwig.hmftools.common.position.GenomePositions) StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) GenomeRegion(com.hartwig.hmftools.common.region.GenomeRegion) Doubles(com.hartwig.hmftools.common.numeric.Doubles) GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 Doubles (com.hartwig.hmftools.common.numeric.Doubles)1 GenomePosition (com.hartwig.hmftools.common.position.GenomePosition)1 GenomePositions (com.hartwig.hmftools.common.position.GenomePositions)1 PurityAdjuster (com.hartwig.hmftools.common.purple.PurityAdjuster)1 GenomeRegion (com.hartwig.hmftools.common.region.GenomeRegion)1 GenomeRegionSelector (com.hartwig.hmftools.common.region.GenomeRegionSelector)1 GenomeRegionSelectorFactory (com.hartwig.hmftools.common.region.GenomeRegionSelectorFactory)1 StructuralVariant (com.hartwig.hmftools.common.variant.structural.StructuralVariant)1 StructuralVariantLeg (com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 NotNull (org.jetbrains.annotations.NotNull)1