CopyNumberChange { CopyNumberChange(@NotNull final List<StructuralVariantLegPloidy> structuralVariants) { assert (!structuralVariants.isEmpty()); final StructuralVariantLegPloidy template = structuralVariants.get(0); double copyNumberDifference = copyNumberDifference(template); int upCount = 0; int downCount = 0; double upPloidy = 0; double downPloidy = 0; double minPloidy = Double.MAX_VALUE; StructuralVariantLegPloidy minPloidyVariant = null; for (StructuralVariantLegPloidy structuralVariant : structuralVariants) { double ploidy = ploidy(structuralVariant); if (isPositive(structuralVariant)) { downCount++; downPloidy += ploidy; } else { upCount++; upPloidy += ploidy; } if (Doubles.lessThan(ploidy, minPloidy)) { minPloidy = ploidy; minPloidyVariant = structuralVariant; } } downScale = (upPloidy - copyNumberDifference) / (upPloidy + downPloidy); upScale = 1 - downScale; if (upCount > 0 && downCount > 0 && minPloidyVariant != null) { double targetDownPloidy = Math.min(template.leftCopyNumber().orElse(0d), downPloidy); double targetUpPloidy = Math.min(template.rightCopyNumber().orElse(0d), upPloidy); double targetPloidy = targetUpPloidy + targetDownPloidy; double explainedPloidy = downScale * downPloidy + upScale * upPloidy; double offsetRequired = (targetPloidy - explainedPloidy); downOffset = offsetRequired / (2 * downCount); upOffset = downOffset * downCount / upCount; } else { downOffset = 0; upOffset = 0; } } CopyNumberChange(@NotNull final List<StructuralVariantLegPloidy> structuralVariants);   }
@Test public void testTwoPositiveOrientationsHaveLargeCopyNumberChange() { final StructuralVariantLegPloidy leg1 = svPloidy(1, 1, 4, 1); final StructuralVariantLegPloidy leg2 = svPloidy(1, 1.5, 4, 1); final List<StructuralVariantLegPloidy> legList = Lists.newArrayList(leg1, leg2); assertPloidy(3, legList); assertCopyNumberChange(-3, legList); final CopyNumberChange victim = new CopyNumberChange(legList); assertEquals(1.2, victim.copyNumberChange(leg1), EPSILON); assertEquals(1.8, victim.copyNumberChange(leg2), EPSILON); }
@Test public void testTwoPositiveOrientationsIncreaseCopyNumber() { final StructuralVariantLegPloidy leg1 = svPloidy(1, 1, 3, 4.5); final StructuralVariantLegPloidy leg2 = svPloidy(1, 1.5, 3, 4.5); final List<StructuralVariantLegPloidy> legList = Lists.newArrayList(leg1, leg2); assertPloidy(-1.5, legList); assertCopyNumberChange(1.5, legList); final CopyNumberChange victim = new CopyNumberChange(legList); assertEquals(-0.6, victim.copyNumberChange(leg1), EPSILON); assertEquals(-0.9, victim.copyNumberChange(leg2), EPSILON); }
@Test public void testTwoNegativeOrientationsGivePositiveCopyNumberChange() { final StructuralVariantLegPloidy leg1 = svPloidy(-1, 1, 1, 4); final StructuralVariantLegPloidy leg2 = svPloidy(-1, 1.5, 1, 4); final List<StructuralVariantLegPloidy> legList = Lists.newArrayList(leg1, leg2); assertPloidy(3, legList); assertCopyNumberChange(3, legList); final CopyNumberChange victim = new CopyNumberChange(legList); assertEquals(1.2, victim.copyNumberChange(leg1), EPSILON); assertEquals(1.8, victim.copyNumberChange(leg2), EPSILON); }
@Test public void testTwoNegativeOrientationsGiveNegativeCopyNumberChange() { final StructuralVariantLegPloidy leg1 = svPloidy(-1, 1, 4, 1); final StructuralVariantLegPloidy leg2 = svPloidy(-1, 1.5, 4, 1); final List<StructuralVariantLegPloidy> legList = Lists.newArrayList(leg1, leg2); assertPloidy(-3, legList); assertCopyNumberChange(-3, legList); final CopyNumberChange victim = new CopyNumberChange(legList); assertEquals(-1.2, victim.copyNumberChange(leg1), EPSILON); assertEquals(-1.8, victim.copyNumberChange(leg2), EPSILON); }
@Test public void testTwoDifferentDirections() { final StructuralVariantLegPloidy leg1 = svPloidy(-1, 1, 2, 1.6); final StructuralVariantLegPloidy leg2 = svPloidy(1, 1.5, 2, 1.6); final List<StructuralVariantLegPloidy> legList = Lists.newArrayList(leg1, leg2); assertPloidy(2.5, legList); assertCopyNumberChange(-0.4, legList); final CopyNumberChange victim = new CopyNumberChange(legList); assertEquals(1.05, victim.copyNumberChange(leg1), EPSILON); assertEquals(1.45, victim.copyNumberChange(leg2), EPSILON); }
@Test public void testTwoDifferentDirectionsThroughZero() { final StructuralVariantLegPloidy leg1 = svPloidy(-1, 1, 1, 0.6); final StructuralVariantLegPloidy leg2 = svPloidy(1, 1.5, 1, 0.6); final List<StructuralVariantLegPloidy> legList = Lists.newArrayList(leg1, leg2); assertPloidy(1.6, legList); assertCopyNumberChange(-0.4, legList); final CopyNumberChange victim = new CopyNumberChange(legList); assertEquals(0.6, victim.copyNumberChange(leg1), EPSILON); assertEquals(1, victim.copyNumberChange(leg2), EPSILON); }
@Test public void testMultipleInDifferentDirection() { final StructuralVariantLegPloidy leg1 = svPloidy(-1, 1, 2, 1.4); final StructuralVariantLegPloidy leg2 = svPloidy(1, 0.7, 2, 1.4); final StructuralVariantLegPloidy leg3 = svPloidy(1, 0.8, 2, 1.4); final List<StructuralVariantLegPloidy> legList = Lists.newArrayList(leg1, leg2, leg3); assertPloidy(2.5, legList); assertCopyNumberChange(-0.6, legList); final CopyNumberChange victim = new CopyNumberChange(legList); assertEquals(0.95, victim.copyNumberChange(leg1), EPSILON); assertEquals(0.743, victim.copyNumberChange(leg2), EPSILON); assertEquals(0.807, victim.copyNumberChange(leg3), EPSILON); }
@Test public void testMultipleInDifferentDirectionPositive() { final StructuralVariantLegPloidy leg1 = svPloidy(-1, 0.6, 2, 2.5); final StructuralVariantLegPloidy leg2 = svPloidy(1, 1, 2, 2.5); final StructuralVariantLegPloidy leg3 = svPloidy(1, 1, 2, 2.5); final List<StructuralVariantLegPloidy> legList = Lists.newArrayList(leg1, leg2, leg3); assertPloidy(2.6, legList); assertCopyNumberChange(0.5, legList); final CopyNumberChange victim = new CopyNumberChange(legList); assertEquals(1.55, victim.copyNumberChange(leg1), EPSILON); assertEquals(0.525, victim.copyNumberChange(leg2), EPSILON); assertEquals(0.525, victim.copyNumberChange(leg3), EPSILON); }
@Test public void testNoCopyNumberChange() { final StructuralVariantLegPloidy leg1 = svPloidy(-1, 1, 2, 2); final StructuralVariantLegPloidy leg2 = svPloidy(1, 0.75, 2, 2); final List<StructuralVariantLegPloidy> legList = Lists.newArrayList(leg1, leg2); final CopyNumberChange victim = new CopyNumberChange(legList); assertPloidy(1.75, legList); assertCopyNumberChange(0, legList); assertEquals(0.875, victim.copyNumberChange(leg1), EPSILON); assertEquals(0.875, victim.copyNumberChange(leg2), EPSILON); }
@Test public void testNoCopyNumberChangeThroughZero() { final StructuralVariantLegPloidy leg1 = svPloidy(-1, 1, 0.8, 0.8); final StructuralVariantLegPloidy leg2 = svPloidy(1, 0.75, 0.8, 0.8); final List<StructuralVariantLegPloidy> legList = Lists.newArrayList(leg1, leg2); final CopyNumberChange victim = new CopyNumberChange(legList); assertPloidy(1.55, legList); assertCopyNumberChange(0, legList); assertEquals(0.775, victim.copyNumberChange(leg1), EPSILON); assertEquals(0.775, victim.copyNumberChange(leg2), EPSILON); }
@Test public void testTwoPositiveOrientationsHaveNoCopyNumberChange() { final StructuralVariantLegPloidy leg1 = svPloidy(1, 1, 2, 2); final StructuralVariantLegPloidy leg2 = svPloidy(1, 1.5, 2, 2); final List<StructuralVariantLegPloidy> legList = Lists.newArrayList(leg1, leg2); assertPloidy(0, legList); assertCopyNumberChange(0, legList); final CopyNumberChange victim = new CopyNumberChange(legList); assertEquals(0, victim.copyNumberChange(leg1), EPSILON); assertEquals(0, victim.copyNumberChange(leg2), EPSILON); }
@Test public void testTwoPositiveOrientationsHaveSmallCopyNumberChange() { final StructuralVariantLegPloidy leg1 = svPloidy(1, 1, 3, 2); final StructuralVariantLegPloidy leg2 = svPloidy(1, 1.5, 3, 2); final List<StructuralVariantLegPloidy> legList = Lists.newArrayList(leg1, leg2); assertPloidy(1, legList); assertCopyNumberChange(-1, legList); final CopyNumberChange victim = new CopyNumberChange(legList); assertEquals(0.4, victim.copyNumberChange(leg1), EPSILON); assertEquals(0.6, victim.copyNumberChange(leg2), EPSILON); }