Search in sources :

Example 1 with StructuralVariantLeg

use of com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg in project hmftools by hartwigmedical.

the class ClusterVariantLegFactory method create.

@NotNull
public static List<ClusterVariantLeg> create(@NotNull final List<StructuralVariant> variants) {
    final List<ClusterVariantLeg> positions = Lists.newArrayList();
    for (StructuralVariant variant : variants) {
        if (variant.type() != StructuralVariantType.INS) {
            final StructuralVariantLeg start = variant.start();
            positions.add(ImmutableClusterVariantLeg.builder().from(start).type(variant.type()).build());
            final StructuralVariantLeg end = variant.end();
            positions.add(ImmutableClusterVariantLeg.builder().from(end).type(variant.type()).build());
        }
    }
    Collections.sort(positions);
    return positions;
}
Also used : StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with StructuralVariantLeg

use of com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg in project hmftools by hartwigmedical.

the class StructuralVariantPloidyFactoryTest method testBothLegsValid.

@Test
public void testBothLegsValid() {
    final StructuralVariantLeg start = createLeg(1001, 1, 0.25);
    final StructuralVariantLeg end = createLeg(2001, -1, 0.25);
    final PurpleCopyNumber left = copyNumber(1, 1000, 4);
    final PurpleCopyNumber middle = copyNumber(1001, 2000, 3);
    final PurpleCopyNumber right = copyNumber(2001, 3000, 4);
    final StructuralVariantLegs legs = ImmutableStructuralVariantLegs.builder().start(start).end(end).build();
    final ListMultimap<String, PurpleCopyNumber> copyNumbers = copyNumbers(left, middle, right);
    final List<StructuralVariantLegPloidy> ploidies = PURE_PLOIDY_FACTORY.create(legs, copyNumbers);
    assertEquals(2, ploidies.size());
    for (StructuralVariantLegPloidy ploidy : ploidies) {
        assertEquals(1d, ploidy.averageImpliedPloidy(), EPSILON);
        assertEquals(2d, ploidy.weight(), EPSILON);
    }
}
Also used : StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) Test(org.junit.Test) PurpleDatamodelTest(com.hartwig.hmftools.common.purple.PurpleDatamodelTest)

Example 3 with StructuralVariantLeg

use of com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg in project hmftools by hartwigmedical.

the class StructuralVariantPloidyFactoryTest method testExcludeInfiniteVAF.

@Test
public void testExcludeInfiniteVAF() {
    final StructuralVariantLeg leg = createLeg(1001, -1, 1);
    final PurpleCopyNumber left = copyNumber(1, 1000, 3);
    assertFalse(PURE_PLOIDY_FACTORY.create(leg, GenomeRegionSelectorFactory.create(singleton(left))).isPresent());
}
Also used : StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) Test(org.junit.Test) PurpleDatamodelTest(com.hartwig.hmftools.common.purple.PurpleDatamodelTest)

Example 4 with StructuralVariantLeg

use of com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg in project hmftools by hartwigmedical.

the class StructuralVariantPloidyFactoryTest method testSelectCorrectOrAlternativeCopyNumberForLeg.

@Test
public void testSelectCorrectOrAlternativeCopyNumberForLeg() {
    final StructuralVariantLeg positiveLeg = createLeg(1001, 1, 0.25);
    final StructuralVariantLeg negativeLeg = createLeg(2001, -1, 0.25);
    final PurpleCopyNumber left = copyNumber(1, 1000, 4);
    final PurpleCopyNumber middle = copyNumber(1001, 2000, 3);
    final PurpleCopyNumber right = copyNumber(2001, 3000, 4);
    assertPloidy(1, false, PURE_PLOIDY_FACTORY.create(positiveLeg, GenomeRegionSelectorFactory.create(singleton(left))));
    assertPloidy(1, true, PURE_PLOIDY_FACTORY.create(positiveLeg, GenomeRegionSelectorFactory.create(singleton(middle))));
    assertPloidy(1, true, PURE_PLOIDY_FACTORY.create(negativeLeg, GenomeRegionSelectorFactory.create(singleton(middle))));
    assertPloidy(1, false, PURE_PLOIDY_FACTORY.create(negativeLeg, GenomeRegionSelectorFactory.create(singleton(right))));
}
Also used : StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) Test(org.junit.Test) PurpleDatamodelTest(com.hartwig.hmftools.common.purple.PurpleDatamodelTest)

Example 5 with StructuralVariantLeg

use of com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg 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

StructuralVariantLeg (com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg)13 PurpleDatamodelTest (com.hartwig.hmftools.common.purple.PurpleDatamodelTest)7 Test (org.junit.Test)7 PurpleCopyNumber (com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber)6 NotNull (org.jetbrains.annotations.NotNull)5 StructuralVariant (com.hartwig.hmftools.common.variant.structural.StructuralVariant)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 Lists (com.google.common.collect.Lists)2 Multimap (com.google.common.collect.Multimap)2 Doubles (com.hartwig.hmftools.common.numeric.Doubles)2 GenomePosition (com.hartwig.hmftools.common.position.GenomePosition)2 GenomePositions (com.hartwig.hmftools.common.position.GenomePositions)2 PurityAdjuster (com.hartwig.hmftools.common.purple.PurityAdjuster)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ListMultimap (com.google.common.collect.ListMultimap)1 GenomeRegion (com.hartwig.hmftools.common.region.GenomeRegion)1 GenomeRegionSelector (com.hartwig.hmftools.common.region.GenomeRegionSelector)1