ReadContextFactory { @NotNull public ReadContext createInsertContext(@NotNull final String alt, int refPosition, int readIndex, @NotNull final SAMRecord record, final IndexedBases refBases) { int refIndex = refBases.index(refPosition); final MicrohomologyContext microhomologyContext = microhomologyAtInsert(readIndex, alt.length(), record.getReadBases()); final MicrohomologyContext microhomologyContextWithRepeats = expandMicrohomologyRepeats(microhomologyContext); int startIndex = microhomologyContextWithRepeats.position() - MIN_CORE_DISTANCE; int length = Math.max(microhomologyContextWithRepeats.length() + 1, alt.length()); int endIndex = Math.max(microhomologyContextWithRepeats.position() + MIN_CORE_DISTANCE, microhomologyContextWithRepeats.position() + length); final Optional<RepeatContext> refRepeatContext = RepeatContextFactory.repeats(refIndex + 1, refBases.bases()); if (refRepeatContext.filter(x -> x.count() >= MIN_REPEAT_COUNT).isPresent()) { final RepeatContext repeat = refRepeatContext.get(); int repeatStartIndexInReadSpace = repeat.startIndex() - refIndex + readIndex; int repeatEndIndexInReadSpace = repeat.endIndex() - refIndex + readIndex; startIndex = Math.min(startIndex, repeatStartIndexInReadSpace - 1); endIndex = Math.max(endIndex, repeatEndIndexInReadSpace + 1); } final Optional<RepeatContext> readRepeatContext = RepeatContextFactory.repeats(readIndex + 1, record.getReadBases()); if (readRepeatContext.filter(x -> x.count() >= MIN_REPEAT_COUNT).isPresent()) { final RepeatContext repeat = readRepeatContext.get(); startIndex = Math.min(startIndex, repeat.startIndex() - 1); endIndex = Math.max(endIndex, repeat.endIndex() + 1); } return new ReadContext(microhomologyContext.toString(), readRepeatContext.map(RepeatContext::count).orElse(0), readRepeatContext.map(RepeatContext::sequence).orElse(Strings.EMPTY), refPosition, readIndex, startIndex, endIndex, flankSize, refBases, record); } ReadContextFactory(final int flankSize); @NotNull ReadContext createDelContext(@NotNull final String ref, int refPosition, int readIndex, @NotNull final SAMRecord record,
            final IndexedBases refBases); @NotNull ReadContext createInsertContext(@NotNull final String alt, int refPosition, int readIndex,
            @NotNull final SAMRecord record, final IndexedBases refBases); @NotNull ReadContext createSNVContext(int refPosition, int readIndex, @NotNull final SAMRecord record, final IndexedBases refBases); @NotNull ReadContext createMNVContext(int refPosition, int readIndex, int length, @NotNull final SAMRecord record,
            final IndexedBases refBases);  }
@Test public void testSimpleInsert() { String refSequence = "GATCATCTAGG"; String readSequence = "GAGGCTCATCTAGG"; IndexedBases refBases = new IndexedBases(1000, 0, refSequence.getBytes()); SAMRecord record = buildSamRecord("2M3I9M", readSequence); ReadContext victim = this.victim.createInsertContext("AGGC", 1000, 1, record, refBases); assertEquals("GAGGCT", victim.centerBases()); }
@Test public void testInsertInRepeat() { String refSequence = "TGAAAAAAAATCT"; String readSequence = "TGAAAAAAAAATCT"; IndexedBases refBases = new IndexedBases(1000, 0, refSequence.getBytes()); SAMRecord record = buildSamRecord("2M1I11M", readSequence); ReadContext victim = this.victim.createInsertContext("GA", 1000, 1, record, refBases); assertEquals("TGAAAAAAAAAT", victim.centerBases()); }
@Test public void testInsertAtHomology() { String refSequence = "GATCATCTG"; String readSequence = "GATCATCATCTG"; IndexedBases refBases = new IndexedBases(1000, 0, refSequence.getBytes()); SAMRecord record = buildSamRecord("1M3I8M", readSequence); ReadContext victim = this.victim.createInsertContext("ATCA", 1000, 1, record, refBases); assertEquals("GATCATCATCT", victim.centerBases()); }
@Test public void testInsertAtHomologyRepeat() { String refSequence = "GATCATCATCTG"; String readSequence = "GATCATCATCATCTG"; IndexedBases refBases = new IndexedBases(1000, 0, refSequence.getBytes()); SAMRecord record = buildSamRecord("1M3I10M", readSequence); ReadContext victim = this.victim.createInsertContext("ATCA", 1000, 1, record, refBases); assertEquals("GATCATCATCATCT", victim.centerBases()); }
@Test public void testInsertAtHomologyWithAdditionalBases() { String refSequence = "ATGCGATCTTCC"; String readSequence = "ATGCGATCAATCTTCC"; IndexedBases refBases = new IndexedBases(1000, 0, refSequence.getBytes()); SAMRecord record = buildSamRecord("5M4I7M", readSequence); ReadContext victim = this.victim.createInsertContext("GATCA", 1000, 4, record, refBases); assertEquals("GCGATCAA", victim.centerBases()); }