use of com.hartwig.hmftools.common.purple.copynumber.sv.StructuralVariantLegPloidy in project hmftools by hartwigmedical.
the class StructuralVariantImpliedTest method testImpliedCopyNumber.
@Test
public void testImpliedCopyNumber() {
final StructuralVariantLegPloidy left = create(1, Optional.of(4d), Optional.empty());
final StructuralVariantLegPloidy right = create(-1, Optional.empty(), Optional.of(5d));
final double bothKnown = StructuralVariantImplied.inferCopyNumberFromStructuralVariants(Optional.of(left), Optional.of(right));
assertEquals(3.5, bothKnown, EPSILON);
final double leftKnown = StructuralVariantImplied.inferCopyNumberFromStructuralVariants(Optional.of(left), Optional.empty());
assertEquals(3, leftKnown, EPSILON);
final double rightKnown = StructuralVariantImplied.inferCopyNumberFromStructuralVariants(Optional.empty(), Optional.of(right));
assertEquals(4, rightKnown, EPSILON);
}
use of com.hartwig.hmftools.common.purple.copynumber.sv.StructuralVariantLegPloidy in project hmftools by hartwigmedical.
the class StructuralVariantImplied method svImpliedCopyNumber.
@NotNull
ListMultimap<String, CombinedRegion> svImpliedCopyNumber(final List<StructuralVariant> structuralVariants, @NotNull final ListMultimap<String, CombinedRegion> copyNumbers) {
long previousMissingCopyNumbers = copyNumbers.size();
long currentMissingCopyNumbers = missingCopyNumberCount(copyNumbers);
while (currentMissingCopyNumbers < previousMissingCopyNumbers && currentMissingCopyNumbers > 0) {
final GenomePositionSelector<StructuralVariantLegPloidy> selector = GenomePositionSelectorFactory.create(createPloidies(structuralVariants, copyNumbers));
for (Chromosome chromosome : HumanChromosome.values()) {
final String chromosomeName = chromosome.toString();
final List<CombinedRegion> chromosomeCopyNumbers = copyNumbers.get(chromosomeName);
boolean svInferred = false;
for (final CombinedRegion copyNumber : chromosomeCopyNumbers) {
if (implyCopyNumberFromSV(copyNumber)) {
final Optional<StructuralVariantLegPloidy> optionalStart = selector.select(GenomePositions.create(chromosomeName, copyNumber.start()));
final Optional<StructuralVariantLegPloidy> optionalEnd = selector.select(GenomePositions.create(chromosomeName, copyNumber.end() + 1));
if (optionalStart.isPresent() || optionalEnd.isPresent()) {
svInferred = true;
inferCopyNumberFromStructuralVariants(copyNumber, optionalStart, optionalEnd);
}
}
}
// JOBA: Extend structural variant segments
if (svInferred) {
ExtendStructuralVariant.extendStructuralVariants(chromosomeCopyNumbers);
}
}
previousMissingCopyNumbers = currentMissingCopyNumbers;
currentMissingCopyNumbers = missingCopyNumberCount(copyNumbers);
}
return copyNumbers;
}
use of com.hartwig.hmftools.common.purple.copynumber.sv.StructuralVariantLegPloidy in project hmftools by hartwigmedical.
the class EnrichedStructuralVariantFactory method enrich.
@NotNull
public static List<EnrichedStructuralVariant> enrich(@NotNull final List<StructuralVariant> variants, @NotNull final PurityAdjuster purityAdjuster, @NotNull final Multimap<String, PurpleCopyNumber> copyNumbers) {
final StructuralVariantLegPloidyFactory<PurpleCopyNumber> ploidyFactory = new StructuralVariantLegPloidyFactory<>(purityAdjuster, PurpleCopyNumber::averageTumorCopyNumber);
final List<EnrichedStructuralVariant> result = Lists.newArrayList();
for (final StructuralVariant variant : variants) {
final ImmutableEnrichedStructuralVariant.Builder builder = ImmutableEnrichedStructuralVariant.builder().from(variant);
final ImmutableEnrichedStructuralVariantLeg.Builder startBuilder = ImmutableEnrichedStructuralVariantLeg.builder().from(variant.start());
final ImmutableEnrichedStructuralVariantLeg.Builder endBuilder = ImmutableEnrichedStructuralVariantLeg.builder().from(variant.end());
final List<StructuralVariantLegPloidy> ploidies = ploidyFactory.create(variant, copyNumbers);
if (!ploidies.isEmpty()) {
Double roundedPloidy = round(ploidies.get(0).averageImpliedPloidy());
builder.ploidy(roundedPloidy);
}
if (ploidies.size() == 2) {
final StructuralVariantLegPloidy start = ploidies.get(0);
final StructuralVariantLegPloidy end = ploidies.get(1);
startBuilder.adjustedAlleleFrequency(round(adjustedVAF(purityAdjuster, start)));
startBuilder.adjustedCopyNumber(round(adjustedCopyNumber(start)));
startBuilder.adjustedCopyNumberChange(round(adjustedCopyNumberChange(start)));
endBuilder.adjustedAlleleFrequency(round(adjustedVAF(purityAdjuster, end)));
endBuilder.adjustedCopyNumber(round(adjustedCopyNumber(end)));
endBuilder.adjustedCopyNumberChange(round(adjustedCopyNumberChange(end)));
}
result.add(builder.start(startBuilder.build()).end(endBuilder.build()).build());
}
return result;
}
Aggregations