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();
}
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;
}
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);
}
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());
}
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));
}
Aggregations