Merge pull request #529 from broadinstitute/eb_fix_gvcf_writer_missing_blocks
Fixing a bug in the GVCF writer.
This commit is contained in:
commit
132e2429c8
|
|
@ -84,6 +84,7 @@ public class GVCFWriter implements VariantContextWriter {
|
|||
|
||||
/** fields updated on the fly during GVCFWriter operation */
|
||||
int nextAvailableStart = -1;
|
||||
String contigOfNextAvailableStart = null;
|
||||
private String sampleName = null;
|
||||
private HomRefBlock currentBlock = null;
|
||||
|
||||
|
|
@ -187,10 +188,17 @@ public class GVCFWriter implements VariantContextWriter {
|
|||
* @return a VariantContext to be emitted, or null if non is appropriate
|
||||
*/
|
||||
protected VariantContext addHomRefSite(final VariantContext vc, final Genotype g) {
|
||||
if ( nextAvailableStart != -1 && vc.getStart() <= nextAvailableStart ) {
|
||||
if ( nextAvailableStart != -1 ) {
|
||||
// don't create blocks while the hom-ref site falls before nextAvailableStart (for deletions)
|
||||
return null;
|
||||
} else if ( currentBlock == null ) {
|
||||
if ( vc.getStart() <= nextAvailableStart && vc.getChr().equals(contigOfNextAvailableStart) ) {
|
||||
return null;
|
||||
}
|
||||
// otherwise, reset to non-relevant
|
||||
nextAvailableStart = -1;
|
||||
contigOfNextAvailableStart = null;
|
||||
}
|
||||
|
||||
if ( currentBlock == null ) {
|
||||
currentBlock = createNewBlock(vc, g);
|
||||
return null;
|
||||
} else if ( currentBlock.withinBounds(g.getGQ()) ) {
|
||||
|
|
@ -302,6 +310,7 @@ public class GVCFWriter implements VariantContextWriter {
|
|||
// g is variant, so flush the bands and emit vc
|
||||
emitCurrentBlock();
|
||||
nextAvailableStart = vc.getEnd();
|
||||
contigOfNextAvailableStart = vc.getChr();
|
||||
underlyingWriter.add(vc);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -202,6 +202,37 @@ public class GVCFWriterUnitTest extends BaseTest {
|
|||
assertGoodVC(mockWriter.emitted.get(1), "21", 3, 3, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCrossingContigBoundaryToLowerPositionsRef() {
|
||||
final GVCFWriter writer = new GVCFWriter(mockWriter, standardPartition);
|
||||
|
||||
writer.add(makeHomRef("20", 30, 30));
|
||||
writer.add(makeHomRef("20", 31, 30));
|
||||
Assert.assertEquals(mockWriter.emitted.size(), 0);
|
||||
writer.add(makeHomRef("21", 10, 30));
|
||||
Assert.assertEquals(mockWriter.emitted.size(), 1);
|
||||
assertGoodVC(mockWriter.emitted.get(0), "20", 30, 31, false);
|
||||
writer.add(makeNonRef("21", 11, 30));
|
||||
Assert.assertEquals(mockWriter.emitted.size(), 3);
|
||||
assertGoodVC(mockWriter.emitted.get(1), "21", 10, 10, false);
|
||||
assertGoodVC(mockWriter.emitted.get(2), "21", 11, 11, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCrossingContigBoundaryFromNonRefToLowerPositionsRef() {
|
||||
final GVCFWriter writer = new GVCFWriter(mockWriter, standardPartition);
|
||||
|
||||
writer.add(makeNonRef("20", 20, 30));
|
||||
Assert.assertEquals(mockWriter.emitted.size(), 1);
|
||||
writer.add(makeHomRef("21", 10, 30));
|
||||
Assert.assertEquals(mockWriter.emitted.size(), 1);
|
||||
assertGoodVC(mockWriter.emitted.get(0), "20", 20, 20, true);
|
||||
writer.add(makeNonRef("21", 11, 30));
|
||||
Assert.assertEquals(mockWriter.emitted.size(), 3);
|
||||
assertGoodVC(mockWriter.emitted.get(1), "21", 10, 10, false);
|
||||
assertGoodVC(mockWriter.emitted.get(2), "21", 11, 11, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCrossingContigBoundaryNonRef() {
|
||||
final GVCFWriter writer = new GVCFWriter(mockWriter, standardPartition);
|
||||
|
|
|
|||
Loading…
Reference in New Issue