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));
}
Aggregations