Search in sources :

Example 6 with StructuralVariantLeg

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

the class StructuralVariantLegsFactory method reduce.

@NotNull
@VisibleForTesting
static StructuralVariantLeg reduce(@NotNull final List<StructuralVariantLeg> legs) {
    double maxPositive = 0;
    double maxNegative = 0;
    for (StructuralVariantLeg leg : legs) {
        if (leg.orientation() == 1) {
            maxPositive = Math.max(maxPositive, leg.alleleFrequency());
        } else {
            maxNegative = Math.max(maxNegative, leg.alleleFrequency());
        }
    }
    if (Doubles.isZero(maxNegative)) {
        for (StructuralVariantLeg leg : legs) {
            if (Doubles.equal(maxPositive, leg.alleleFrequency())) {
                return leg;
            }
        }
    }
    if (Doubles.isZero(maxPositive)) {
        for (StructuralVariantLeg leg : legs) {
            if (Doubles.equal(maxNegative, leg.alleleFrequency())) {
                return leg;
            }
        }
    }
    byte orientation = (byte) (Doubles.greaterThan(maxPositive, maxNegative) ? 1 : -1);
    double vaf = Math.abs(maxPositive - maxNegative);
    return ImmutableStructuralVariantLegImpl.builder().from(legs.get(0)).orientation(orientation).alleleFrequency(vaf).build();
}
Also used : StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with StructuralVariantLeg

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

the class StructuralVariantLegsFactory method createLegs.

@NotNull
private static List<ModifiableStructuralVariantLegs> createLegs(boolean allowInserts, @NotNull final List<StructuralVariant> variants) {
    final List<ModifiableStructuralVariantLegs> result = Lists.newArrayList();
    for (StructuralVariant variant : variants) {
        if (allowInserts || variant.type() != StructuralVariantType.INS) {
            final Optional<StructuralVariantLeg> start = Optional.of(variant.start()).filter(x -> x.alleleFrequency() != null);
            final Optional<StructuralVariantLeg> end = Optional.of(variant.end()).filter(x -> x.alleleFrequency() != null);
            if (start.isPresent() || end.isPresent()) {
                final ModifiableStructuralVariantLegs legs = ModifiableStructuralVariantLegs.create().setStart(start).setEnd(end);
                result.add(legs);
            }
        }
    }
    return result;
}
Also used : StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with StructuralVariantLeg

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

the class StructuralVariantLegsFactory method create.

@NotNull
static List<StructuralVariantLegs> create(@NotNull final List<StructuralVariant> variants) {
    final List<ModifiableStructuralVariantLegs> result = createLegs(false, variants);
    final Multimap<GenomePosition, ModifiableStructuralVariantLegs> duplicates = findDuplicates(result);
    for (GenomePosition duplicatePosition : duplicates.keySet()) {
        final StructuralVariantLeg approvedLeg = reduce(duplicatePosition, duplicates.get(duplicatePosition));
        boolean match = false;
        for (ModifiableStructuralVariantLegs legs : duplicates.get(duplicatePosition)) {
            Optional<StructuralVariantLeg> start = legs.start();
            if (start.filter(x -> isDuplicate(duplicatePosition, x)).isPresent()) {
                assert start.isPresent();
                if (start.get().equals(approvedLeg)) {
                    match = true;
                } else {
                    legs.setStart(Optional.empty());
                }
            }
            Optional<StructuralVariantLeg> end = legs.end();
            if (end.filter(x -> isDuplicate(duplicatePosition, x)).isPresent()) {
                assert end.isPresent();
                if (end.get().equals(approvedLeg)) {
                    match = true;
                } else {
                    legs.setEnd(Optional.empty());
                }
            }
        }
        if (!match) {
            result.add(ModifiableStructuralVariantLegs.create().setStart(approvedLeg).setEnd(Optional.empty()));
        }
    }
    return new ArrayList<>(result);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap) Collection(java.util.Collection) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) ArrayList(java.util.ArrayList) List(java.util.List) Lists(com.google.common.collect.Lists) GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) Doubles(com.hartwig.hmftools.common.numeric.Doubles) ImmutableStructuralVariantLegImpl(com.hartwig.hmftools.common.variant.structural.ImmutableStructuralVariantLegImpl) Optional(java.util.Optional) StructuralVariantType(com.hartwig.hmftools.common.variant.structural.StructuralVariantType) 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) StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with StructuralVariantLeg

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

the class StructuralVariantLegsFactoryTest method assertReduce.

private void assertReduce(@NotNull final StructuralVariantLeg expected, @NotNull final List<StructuralVariantLeg> legs) {
    final StructuralVariantLeg result = reduce(legs);
    assertEquals(expected.alleleFrequency(), result.alleleFrequency(), EPSILON);
    assertEquals(expected.orientation(), result.orientation());
}
Also used : StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg)

Example 10 with StructuralVariantLeg

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

the class StructuralVariantLegsFactoryTest method testReduce.

@Test
public void testReduce() {
    final StructuralVariantLeg largePositive = createLeg(1, 0.9);
    final StructuralVariantLeg smallPositive = createLeg(1, 0.1);
    final StructuralVariantLeg largeNegative = createLeg(-1, 0.8);
    final StructuralVariantLeg smallNegative = createLeg(-1, 0.2);
    assertReduce(largePositive, Lists.newArrayList(largePositive, smallPositive));
    assertReduce(largePositive, Lists.newArrayList(smallPositive, largePositive));
    assertReduce(largeNegative, Lists.newArrayList(largeNegative, smallNegative));
    assertReduce(largeNegative, Lists.newArrayList(smallNegative, largeNegative));
    assertReduce(createLeg(1, 0.7), Lists.newArrayList(smallNegative, largePositive));
    assertReduce(createLeg(1, 0.1), Lists.newArrayList(largeNegative, largePositive));
    assertReduce(createLeg(-1, 0.7), Lists.newArrayList(largeNegative, smallPositive));
}
Also used : StructuralVariantLeg(com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg) Test(org.junit.Test) PurpleDatamodelTest(com.hartwig.hmftools.common.purple.PurpleDatamodelTest)

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