StructuralVariantImplied { @NotNull ListMultimap<Chromosome, CombinedRegion> svImpliedCopyNumber(@NotNull final List<StructuralVariant> structuralVariants, @NotNull final ListMultimap<Chromosome, CombinedRegion> copyNumbers) { long previousMissingCopyNumbers = copyNumbers.size(); long currentMissingCopyNumbers = missingCopyNumberCount(copyNumbers); while (currentMissingCopyNumbers < previousMissingCopyNumbers && currentMissingCopyNumbers > 0) { final ListMultimap<Chromosome, CombinedRegion> processedCopyNumbers = ArrayListMultimap.create(); for (Chromosome chromosome : copyNumbers.keySet()) { copyNumbers.get(chromosome) .stream() .filter(CombinedRegion::isProcessed) .forEach(x -> processedCopyNumbers.put(chromosome, x)); } final List<StructuralVariantLegPloidy> ploidyList = svPloidyFactory.create(structuralVariants, processedCopyNumbers); final Map<GenomePosition, StructuralVariantLegPloidy> ploidyMap = ploidyList.stream().collect(Collectors.toMap(x -> GenomePositions.create(x.chromosome(), x.cnaPosition()), x -> x)); for (Chromosome chromosome : HumanChromosome.values()) { final List<CombinedRegion> chromosomeCopyNumbers = copyNumbers.get(chromosome); boolean svInferred = false; for (final CombinedRegion copyNumber : chromosomeCopyNumbers) { if (implyCopyNumberFromSV(copyNumber)) { final Optional<StructuralVariantLegPloidy> optionalStart = Optional.ofNullable(ploidyMap.get(GenomePositions.create(copyNumber.chromosome(), copyNumber.start()))) .filter(x -> x.impliedRightCopyNumberWeight() > 0); final Optional<StructuralVariantLegPloidy> optionalEnd = Optional.ofNullable(ploidyMap.get(GenomePositions.create(copyNumber.chromosome(), copyNumber.end() + 1))) .filter(x -> x.impliedLeftCopyNumberWeight() > 0); if (optionalStart.isPresent() || optionalEnd.isPresent()) { svInferred = true; inferCopyNumberFromStructuralVariants(copyNumber, optionalStart, optionalEnd); } } } if (svInferred) { ExtendStructuralVariant.extendStructuralVariants(chromosomeCopyNumbers); } } previousMissingCopyNumbers = currentMissingCopyNumbers; currentMissingCopyNumbers = missingCopyNumberCount(copyNumbers); } return copyNumbers; } StructuralVariantImplied(int averageReadDepth, double averageCopyNumber, @NotNull final PurityAdjuster purityAdjuster);   }
@Test public void testNonSymmetricMultiPass() { final StructuralVariant firstSV = sv(1000, 4001, StructuralVariantType.DEL, 0.25, 0.25); final StructuralVariant secondSV = sv(2000, 3001, StructuralVariantType.DEL, 1 / 3d, 1 / 3d); final CombinedRegion firstCN = copyNumber(1, 1000, 40, SegmentSupport.NONE); final CombinedRegion secondCN = copyNumber(1001, 2000, 0, SegmentSupport.DEL); final CombinedRegion thirdCN = copyNumber(2001, 3000, 0, SegmentSupport.DEL); final CombinedRegion forthCN = copyNumber(3001, 4000, 0, SegmentSupport.DEL); final CombinedRegion fifthCN = copyNumber(4001, 5000, 10, SegmentSupport.NONE); final List<StructuralVariant> svs = Lists.newArrayList(firstSV, secondSV); final ListMultimap<Chromosome, CombinedRegion> copyNumbers = copyNumbers(firstCN, secondCN, thirdCN, forthCN, fifthCN); final StructuralVariantImplied victim = new StructuralVariantImplied(100, 2, PURE); final List<CombinedRegion> result = victim.svImpliedCopyNumber(svs, copyNumbers).get(CHROMOSOME); assertEquals(5, result.size()); assertEquals(40.00, result.get(0).tumorCopyNumber(), EPSILON); assertEquals(33.75, result.get(1).tumorCopyNumber(), EPSILON); assertEquals(12.50, result.get(2).tumorCopyNumber(), EPSILON); assertEquals(03.75, result.get(3).tumorCopyNumber(), EPSILON); assertEquals(10.00, result.get(4).tumorCopyNumber(), EPSILON); }
@Test public void testSVSmoothing() { final StructuralVariant firstSV = sv(1000, 4001, StructuralVariantType.DEL, 0.25, 0.25); final StructuralVariant secondSV = sv(2000, 3001, StructuralVariantType.DEL, 1 / 3d, 1 / 3d); final CombinedRegion firstCN = copyNumber(1, 1000, 40, SegmentSupport.NONE); final CombinedRegion secondCN = copyNumber(1001, 2000, 0, SegmentSupport.DEL); final CombinedRegion thirdCN = copyNumber(2001, 3000, 0, SegmentSupport.NONE); final CombinedRegion forthCN = copyNumber(3001, 4000, 0, SegmentSupport.DEL); final CombinedRegion fifthCN = copyNumber(4001, 5000, 10, SegmentSupport.NONE); final List<StructuralVariant> svs = Lists.newArrayList(firstSV, secondSV); final ListMultimap<Chromosome, CombinedRegion> copyNumbers = copyNumbers(firstCN, secondCN, thirdCN, forthCN, fifthCN); final StructuralVariantImplied victim = new StructuralVariantImplied(100, 2, PURE); final List<CombinedRegion> result = victim.svImpliedCopyNumber(svs, copyNumbers).get(CHROMOSOME); assertEquals(4, result.size()); assertEquals(40.00, result.get(0).tumorCopyNumber(), EPSILON); assertEquals(33.75, result.get(1).tumorCopyNumber(), EPSILON); assertEquals(03.75, result.get(2).tumorCopyNumber(), EPSILON); assertEquals(10.00, result.get(3).tumorCopyNumber(), EPSILON); }