AlleleTolerance implements CopyNumberTolerance { @Override public boolean inTolerance(@NotNull final FittedRegion first, @NotNull final FittedRegion second) { double purityAdjustment = purityAdjustment(purityAdjuster); int minBafCount = Math.min(first.bafCount(), second.bafCount()); if (minBafCount > 0) { double observedBafDeviation = Math.abs(first.observedBAF() - second.observedBAF()); double maxCopyNumber = Math.max(first.tumorCopyNumber(), second.tumorCopyNumber()); double maxMinorAllelePloidyDeviation = purityAdjustment * tolerance(MIN_ABSOLUTE_COPY_NUMBER_TOLERANCE, 0.5 * maxCopyNumber, minBafCount); double minorAllelePloidyDeviation = Math.abs(first.minorAlleleCopyNumber() - second.minorAlleleCopyNumber()); if (Doubles.greaterThan(minorAllelePloidyDeviation, maxMinorAllelePloidyDeviation) && Doubles.greaterThan(observedBafDeviation, MIN_OBSERVED_BAF_CHANGE)) { return false; } } int minWindowDepthCount = Math.min(first.depthWindowCount(), second.depthWindowCount()); double absTolerance = purityAdjustment * tolerance(MIN_ABSOLUTE_COPY_NUMBER_TOLERANCE, 2, minWindowDepthCount); double relTolerance = purityAdjustment * tolerance(MIN_RELATIVE_COPY_NUMBER_TOLERANCE, 0.8, minWindowDepthCount); boolean copyNumberInTolerance = inAbsoluteTolerance(absTolerance, first.tumorCopyNumber(), second.tumorCopyNumber()) || inRelativeTolerance(relTolerance, first.tumorCopyNumber(), second.tumorCopyNumber()); boolean refNormalisedCopyNumberInTolerance = inAbsoluteTolerance(absTolerance, first.refNormalisedCopyNumber(), second.refNormalisedCopyNumber()) || inRelativeTolerance( relTolerance, first.refNormalisedCopyNumber(), second.refNormalisedCopyNumber()); return copyNumberInTolerance || refNormalisedCopyNumberInTolerance; } AlleleTolerance(@NotNull final PurityAdjuster purityAdjuster); @Override boolean inTolerance(@NotNull final FittedRegion first, @NotNull final FittedRegion second);  }
@Test public void testMinObservedBafDeviation() { FittedRegion left = createBafRegion(1000, 1, 0); FittedRegion right = createBafRegion(1000, 0.5, 0); assertTrue(victim.inTolerance(left, right)); left = ImmutableFittedRegion.copyOf(left).withObservedBAF(0.031); assertFalse(victim.inTolerance(left, right)); }
@Test public void testMinBafCount() { FittedRegion left = createBafRegion(0, 1, 0.031); FittedRegion right = createBafRegion(1000, 0.5, 0); assertTrue(victim.inTolerance(left, right)); left = ImmutableFittedRegion.copyOf(left).withBafCount(1000); assertFalse(victim.inTolerance(left, right)); }
@Test public void testRelativeChange() { FittedRegion left = createCopyNumberRegion(1000, 10, 10); FittedRegion right = createCopyNumberRegion(1000, 9.1, 9.1); assertTrue(victim.inTolerance(left, right)); left = createCopyNumberRegion(1000, 2, 2); right = createCopyNumberRegion(1000, 1.1, 1.1); assertFalse(victim.inTolerance(left, right)); }