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