Fixed bug in the filtering of lifted over variants where a deletion at the end of a contig could cause it to error out.
Added a unit test.
This commit is contained in:
parent
418fbdfbab
commit
400e7c1404
|
|
@ -77,32 +77,49 @@ public class FilterLiftedVariants extends RodWalker<Integer, Integer> {
|
|||
writer.writeHeader(vcfHeader);
|
||||
}
|
||||
|
||||
private void filterAndWrite(byte[] ref, VariantContext vc) {
|
||||
/**
|
||||
* Determines whether records should be filtered; if not, writes them to the output
|
||||
*
|
||||
* @param ref the reference context
|
||||
* @param vc the VariantContext to process
|
||||
* @return true if the record is not filtered, false otherwise
|
||||
*/
|
||||
protected boolean filterOrWrite(final byte[] ref, final VariantContext vc) {
|
||||
if ( ref == null ) throw new IllegalArgumentException("Cannot filter based on a null reference array");
|
||||
if ( vc == null ) throw new IllegalArgumentException("Cannot filter a null Variant Context");
|
||||
|
||||
totalLocs++;
|
||||
|
||||
boolean failed = false;
|
||||
byte[] recordRef = vc.getReference().getBases();
|
||||
for (int i = 0; i < recordRef.length && i < MAX_VARIANT_SIZE; i++) {
|
||||
if ( recordRef[i] != ref[i] ) {
|
||||
failed = true;
|
||||
break;
|
||||
boolean filter = false;
|
||||
final byte[] recordRef = vc.getReference().getBases();
|
||||
|
||||
// this can happen for records that get placed at the ends of chromosomes
|
||||
if ( recordRef.length > ref.length ) {
|
||||
filter = true;
|
||||
} else {
|
||||
for (int i = 0; i < recordRef.length && i < MAX_VARIANT_SIZE; i++) {
|
||||
if ( recordRef[i] != ref[i] ) {
|
||||
filter = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( failed )
|
||||
if ( filter )
|
||||
failedLocs++;
|
||||
else
|
||||
writer.add(vc);
|
||||
|
||||
return !filter;
|
||||
}
|
||||
|
||||
public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
|
||||
if ( tracker == null )
|
||||
return 0;
|
||||
|
||||
Collection<VariantContext> VCs = tracker.getValues(variantCollection.variants, context.getLocation());
|
||||
for ( VariantContext vc : VCs )
|
||||
filterAndWrite(ref.getBases(), vc);
|
||||
final Collection<VariantContext> VCs = tracker.getValues(variantCollection.variants, context.getLocation());
|
||||
for ( final VariantContext vc : VCs )
|
||||
filterOrWrite(ref.getBases(), vc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -114,4 +131,4 @@ public class FilterLiftedVariants extends RodWalker<Integer, Integer> {
|
|||
public void onTraversalDone(Integer result) {
|
||||
System.out.println("Filtered " + failedLocs + " records out of " + totalLocs + " total records.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2012 The Broad Institute
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.gatk.walkers.variantutils;
|
||||
|
||||
import org.broadinstitute.sting.BaseTest;
|
||||
import org.broadinstitute.variant.variantcontext.Allele;
|
||||
import org.broadinstitute.variant.variantcontext.VariantContext;
|
||||
import org.broadinstitute.variant.variantcontext.VariantContextBuilder;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class FilterLiftedVariantsUnitTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testIndelAtEndOfContig() {
|
||||
|
||||
final List<Allele> alleles = new ArrayList<>(2);
|
||||
alleles.add(Allele.create("AAAAA", true));
|
||||
alleles.add(Allele.create("A", false));
|
||||
final VariantContext vc = new VariantContextBuilder("test", "1", 10, 14, alleles).make();
|
||||
|
||||
final FilterLiftedVariants filter = new FilterLiftedVariants();
|
||||
|
||||
Assert.assertFalse(filter.filterOrWrite(new byte[]{'A'}, vc));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue