ReportableGeneDisruptionFactory { @NotNull static List<ReportableGeneDisruption> convert(@NotNull List<LinxBreakend> disruptions) { List<ReportableGeneDisruption> reportableDisruptions = Lists.newArrayList(); Map<SvAndGeneKey, Pair<LinxBreakend, LinxBreakend>> pairedMap = mapDisruptionsPerStructuralVariant(disruptions); for (Pair<LinxBreakend, LinxBreakend> pairedDisruption : pairedMap.values()) { LinxBreakend primaryDisruptionLeft = pairedDisruption.getLeft(); LinxBreakend primaryDisruptionRight = pairedDisruption.getRight(); if (primaryDisruptionRight != null) { double lowestUndisruptedCopyNumber = Math.min(primaryDisruptionLeft.undisruptedCopyNumber(), primaryDisruptionRight.undisruptedCopyNumber()); Double copyNumberLeft = primaryDisruptionLeft.junctionCopyNumber(); Double copyNumberRight = primaryDisruptionRight.junctionCopyNumber(); if (copyNumberLeft != null && copyNumberRight != null && !Doubles.equal(copyNumberLeft, copyNumberRight)) { LOGGER.warn("The disrupted copy number of a paired sv is not the same on {}", primaryDisruptionLeft.gene()); } reportableDisruptions.add(ImmutableReportableGeneDisruption.builder() .location(primaryDisruptionLeft.chromosome() + primaryDisruptionLeft.chrBand()) .gene(primaryDisruptionLeft.gene()) .type(primaryDisruptionLeft.type()) .range(rangeField(pairedDisruption)) .junctionCopyNumber(primaryDisruptionLeft.junctionCopyNumber()) .undisruptedCopyNumber(Math.max(0, lowestUndisruptedCopyNumber)) .firstAffectedExon(primaryDisruptionLeft.exonUp()) .build()); } else { reportableDisruptions.add(ImmutableReportableGeneDisruption.builder() .location(primaryDisruptionLeft.chromosome() + primaryDisruptionLeft.chrBand()) .gene(primaryDisruptionLeft.gene()) .type(primaryDisruptionLeft.type()) .range(rangeField(pairedDisruption)) .junctionCopyNumber(primaryDisruptionLeft.junctionCopyNumber()) .undisruptedCopyNumber(Math.max(0, primaryDisruptionLeft.undisruptedCopyNumber())) .firstAffectedExon(primaryDisruptionLeft.exonUp()) .build()); } } LOGGER.debug("Generated {} reportable disruptions based on {} disruptions", reportableDisruptions.size(), disruptions.size()); return reportableDisruptions; } private  ReportableGeneDisruptionFactory();   }
@Test public void canConvertPairedDisruption() { ImmutableLinxBreakend.Builder pairedDisruptionBuilder = createTestDisruptionBuilder().svId(1).gene("ROPN1B").chromosome("3").chrBand("p12").type("INV").junctionCopyNumber(1.12); List<LinxBreakend> pairedDisruptions = Lists.newArrayList(pairedDisruptionBuilder.exonUp(3).exonDown(4).undisruptedCopyNumber(4.3).build(), pairedDisruptionBuilder.exonUp(8).exonDown(9).undisruptedCopyNumber(2.1).build()); List<ReportableGeneDisruption> reportableDisruptions = ReportableGeneDisruptionFactory.convert(pairedDisruptions); assertEquals(1, reportableDisruptions.size()); ReportableGeneDisruption disruption = reportableDisruptions.get(0); assertEquals("INV", disruption.type()); assertEquals("3p12", disruption.location()); assertEquals("ROPN1B", disruption.gene()); assertEquals("Intron 3 -> Intron 8", disruption.range()); assertEquals(3, disruption.firstAffectedExon()); assertEquals(2.1, disruption.undisruptedCopyNumber(), EPSILON); Double copyNumber = disruption.junctionCopyNumber(); assertNotNull(copyNumber); assertEquals(1.12, copyNumber, EPSILON); }
@Test public void doesNotPairDisruptionsOnDifferentGenes() { ImmutableLinxBreakend.Builder pairedDisruptionBuilder = createTestDisruptionBuilder().svId(1); List<LinxBreakend> pairedDisruptions = Lists.newArrayList(pairedDisruptionBuilder.gene("ROPN1B") .svId(1) .junctionCopyNumber(1.0) .undisruptedCopyNumber(1.0) .build(), pairedDisruptionBuilder.gene("SETD2").svId(1).junctionCopyNumber(1.0).undisruptedCopyNumber(2.3).build(), pairedDisruptionBuilder.gene("SETD2").svId(1).junctionCopyNumber(1.0).undisruptedCopyNumber(1.7).build()); List<ReportableGeneDisruption> reportableDisruptions = ReportableGeneDisruptionFactory.convert(pairedDisruptions); assertEquals(2, reportableDisruptions.size()); }