Allele extends Locus { public Allele merge(final Allele right, final long minimumOverlap) throws IllegalSymbolException, IndexOutOfBoundsException, IllegalAlphabetException, AlleleException { Allele.Builder builder = Allele.builder(); Locus overlap = intersection(right); if (overlap.length() < minimumOverlap) { return builder.reset().build(); } Allele bit = builder .withContig(overlap.getContig()) .withStart(overlap.getStart()) .withEnd(overlap.getEnd()) .withSequence(SymbolList.EMPTY_LIST) .withLesion(Lesion.UNKNOWN) .build(); Allele a = bit.doubleCrossover(right); Allele b = bit.doubleCrossover(this); if (a.sequence.seqString().equals(b.sequence.seqString())) { Locus union = union(right); return builder .withName(right.getName()) .withContig(union.getContig()) .withStart(union.getStart()) .withEnd(union.getEnd()) .withSequence(SymbolList.EMPTY_LIST) .withLesion(Lesion.UNKNOWN) .build() .doubleCrossover(right) .doubleCrossover(this); } return builder.reset().build(); } Allele(final String name, final String contig, final int start, final int end, final SymbolList sequence, final Lesion lesion); String getName(); void setName(final String name); static Builder builder(); @Override boolean equals(final Object right); @Override int hashCode(); Allele doubleCrossover(final Allele right); Allele merge(final Allele right, final long minimumOverlap); Allele leftHardClip(final String pattern); Allele rightHardClip(final String pattern); final SymbolList sequence; final Lesion lesion; }
@Test public void testMerge() { try { temp = allele5.merge(allele4, 0); assertEquals(temp.getStart(), 5); assertEquals(temp.getEnd(), 20); assertEquals(temp.sequence.seqString(), "cccccaaaaattttt"); temp = allele4.merge(allele5, 0); assertEquals(temp.getStart(), 5); assertEquals(temp.getEnd(), 20); assertEquals(temp.sequence.seqString(), "cccccaaaaattttt"); temp = allele2.merge(allele4, 0); assertEquals(temp.getStart(), 10); assertEquals(temp.getEnd(), 20); assertEquals(temp.sequence.seqString(), "aaaaattttt"); temp = allele2.merge(allele4, 5); assertEquals(temp.getStart(), 10); assertEquals(temp.getEnd(), 20); assertEquals(temp.sequence.seqString(), "aaaaattttt"); temp = allele2.merge(allele4, 6); assertTrue(temp.isEmpty()); } catch(Exception e) { fail(); } }