Change interface to VCFWriter add() method to take only 1 byte from reference (since that's the only thing it needs), to prevent bugs like having people call it with ref.addBases() which is wrong (since it provides bases starting from the left of reference context window).

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3868 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
delangel 2010-07-23 20:24:03 +00:00
parent b3fd145161
commit 4fc1db7aaf
25 changed files with 42 additions and 44 deletions

View File

@ -171,8 +171,8 @@ public class VariantContextUtils {
UNION, INTERSECT UNION, INTERSECT
} }
public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs, byte[] refBases) { public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs, byte refBase) {
return simpleMerge(unsortedVCs, null, VariantMergeType.INTERSECT, GenotypeMergeType.UNSORTED, false, false, refBases); return simpleMerge(unsortedVCs, null, VariantMergeType.INTERSECT, GenotypeMergeType.UNSORTED, false, false, refBase);
} }
@ -189,14 +189,14 @@ public class VariantContextUtils {
*/ */
public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs, List<String> priorityListOfVCs, public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs, List<String> priorityListOfVCs,
VariantMergeType variantMergeOptions, GenotypeMergeType genotypeMergeOptions, VariantMergeType variantMergeOptions, GenotypeMergeType genotypeMergeOptions,
boolean annotateOrigin, boolean printMessages, byte[] inputRefBases ) { boolean annotateOrigin, boolean printMessages, byte inputRefBase ) {
return simpleMerge(unsortedVCs, priorityListOfVCs, variantMergeOptions, genotypeMergeOptions, annotateOrigin, printMessages, inputRefBases, "set"); return simpleMerge(unsortedVCs, priorityListOfVCs, variantMergeOptions, genotypeMergeOptions, annotateOrigin, printMessages, inputRefBase, "set");
} }
public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs, List<String> priorityListOfVCs, public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs, List<String> priorityListOfVCs,
VariantMergeType variantMergeOptions, GenotypeMergeType genotypeMergeOptions, VariantMergeType variantMergeOptions, GenotypeMergeType genotypeMergeOptions,
boolean annotateOrigin, boolean printMessages, byte[] inputRefBases, String setKey ) { boolean annotateOrigin, boolean printMessages, byte inputRefBase, String setKey ) {
if ( unsortedVCs == null || unsortedVCs.size() == 0 ) if ( unsortedVCs == null || unsortedVCs.size() == 0 )
return null; return null;
@ -213,7 +213,7 @@ public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs,
List<VariantContext> VCs = new ArrayList<VariantContext>(); List<VariantContext> VCs = new ArrayList<VariantContext>();
for (VariantContext vc : prepaddedVCs) { for (VariantContext vc : prepaddedVCs) {
VCs.add(createVariantContextWithPaddedAlleles(vc,inputRefBases)); VCs.add(createVariantContextWithPaddedAlleles(vc,inputRefBase));
} }
@ -479,7 +479,7 @@ public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs,
} }
public static VariantContext createVariantContextWithPaddedAlleles(VariantContext inputVC, byte[] inputRefBase) { public static VariantContext createVariantContextWithPaddedAlleles(VariantContext inputVC, byte inputRefBase) {
Allele refAllele = inputVC.getReference(); Allele refAllele = inputVC.getReference();
@ -501,8 +501,8 @@ public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs,
Map<String,Object> attributes = inputVC.getAttributes(); Map<String,Object> attributes = inputVC.getAttributes();
if (BaseUtils.isRegularBase(inputRefBase[0])) if (BaseUtils.isRegularBase(inputRefBase))
refByte = inputRefBase[0]; refByte = inputRefBase;
else if (attributes.containsKey(VariantContext.REFERENCE_BASE_FOR_INDEL_KEY)) else if (attributes.containsKey(VariantContext.REFERENCE_BASE_FOR_INDEL_KEY))
refByte = (Byte)attributes.get(VariantContext.REFERENCE_BASE_FOR_INDEL_KEY); refByte = (Byte)attributes.get(VariantContext.REFERENCE_BASE_FOR_INDEL_KEY);
else else

View File

@ -129,7 +129,7 @@ public class VariantsToVCF extends RodWalker<Integer, Integer> {
} }
vc = VariantContextUtils.purgeUnallowedGenotypeAttributes(vc, allowedGenotypeFormatStrings); vc = VariantContextUtils.purgeUnallowedGenotypeAttributes(vc, allowedGenotypeFormatStrings);
vcfwriter.add(vc, new byte[]{ref}); vcfwriter.add(vc,ref);
} }
public Integer reduceInit() { public Integer reduceInit() {

View File

@ -202,12 +202,12 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> {
if ( ! indelsOnly ) { if ( ! indelsOnly ) {
for ( VariantContext annotatedVC : annotatedVCs ) for ( VariantContext annotatedVC : annotatedVCs )
vcfWriter.add(annotatedVC, new byte[]{ref.getBase()}); vcfWriter.add(annotatedVC, ref.getBase());
} else { } else {
// check to see if the buffered context is different (in location) this context // check to see if the buffered context is different (in location) this context
if ( indelBufferContext != null && ! indelBufferContext.iterator().next().getLocation().equals(annotatedVCs.iterator().next().getLocation()) ) { if ( indelBufferContext != null && ! indelBufferContext.iterator().next().getLocation().equals(annotatedVCs.iterator().next().getLocation()) ) {
for ( VariantContext annotatedVC : indelBufferContext ) for ( VariantContext annotatedVC : indelBufferContext )
vcfWriter.add(annotatedVC, new byte[]{ref.getBase()}); vcfWriter.add(annotatedVC, ref.getBase());
indelBufferContext = annotatedVCs; indelBufferContext = annotatedVCs;
} else { } else {
indelBufferContext = annotatedVCs; indelBufferContext = annotatedVCs;

View File

@ -216,7 +216,7 @@ public class VariantFiltrationWalker extends RodWalker<Integer, Integer> {
private void writeVCF(VariantContext vc, byte ref) { private void writeVCF(VariantContext vc, byte ref) {
if ( writer == null ) if ( writer == null )
initializeVcfWriter(vc); initializeVcfWriter(vc);
writer.add(vc, new byte[]{ref}); writer.add(vc, ref);
} }
public Integer reduce(Integer value, Integer sum) { public Integer reduce(Integer value, Integer sum) {

View File

@ -148,7 +148,7 @@ public class BatchedCallsMerger extends LocusWalker<VariantContext, Integer> imp
} }
// merge the variant contexts // merge the variant contexts
return VariantContextUtils.simpleMerge(calls, ref.getBases()); return VariantContextUtils.simpleMerge(calls, ref.getBase());
} }
private AlignmentContext filterForSamples(ReadBackedPileup pileup, Set<String> samples) { private AlignmentContext filterForSamples(ReadBackedPileup pileup, Set<String> samples) {

View File

@ -160,7 +160,7 @@ public class SequenomValidationConverter extends RodWalker<Pair<VariantContext,
vcfWriter.writeHeader(header); vcfWriter.writeHeader(header);
for ( Pair<VariantContext, Byte> record : records ) for ( Pair<VariantContext, Byte> record : records )
vcfWriter.add(record.first, new byte[]{record.second}); vcfWriter.add(record.first, record.second);
vcfWriter.close(); vcfWriter.close();
} }

View File

@ -554,7 +554,7 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> {
wroteHeader = true; wroteHeader = true;
} }
writer.add(mvc, new byte[]{ref}); writer.add(mvc, ref);
//interestingReasons.clear(); //interestingReasons.clear();
} }
} }

View File

@ -150,7 +150,7 @@ public class ApplyVariantCuts extends RodWalker<Integer, Integer> {
vc = new VariantContext(vc.getName(), vc.getLocation(), vc.getAlleles(), vc.getGenotypes(), vc.getNegLog10PError(), filters, vc.getAttributes()); vc = new VariantContext(vc.getName(), vc.getLocation(), vc.getAlleles(), vc.getGenotypes(), vc.getNegLog10PError(), filters, vc.getAttributes());
} }
} }
vcfWriter.add( vc, new byte[]{ref.getBase()} ); vcfWriter.add( vc, ref.getBase() );
} }
} }

View File

@ -194,10 +194,10 @@ public class VariantRecalibrator extends RodWalker<ExpandingArrayList<VariantDat
filters.add(VCFConstants.PASSES_FILTERS_v4); filters.add(VCFConstants.PASSES_FILTERS_v4);
VariantContext newVC = new VariantContext(vc.getName(), vc.getLocation(), vc.getAlleles(), vc.getGenotypes(), variantDatum.qual / 10.0, filters, attrs); VariantContext newVC = new VariantContext(vc.getName(), vc.getLocation(), vc.getAlleles(), vc.getGenotypes(), variantDatum.qual / 10.0, filters, attrs);
vcfWriter.add( newVC, new byte[]{ref.getBase()} ); vcfWriter.add( newVC, ref.getBase() );
} else { // not a SNP or is filtered so just dump it out to the VCF file } else { // not a SNP or is filtered so just dump it out to the VCF file
vcfWriter.add( vc, new byte[]{ref.getBase()} ); vcfWriter.add( vc, ref.getBase() );
} }
} }

View File

@ -116,14 +116,14 @@ public class CombineVariants extends RodWalker<Integer, Integer> {
// Need to provide reference bases to simpleMerge starting at current locus // Need to provide reference bases to simpleMerge starting at current locus
Collection<VariantContext> vcs = tracker.getAllVariantContexts(ref, context.getLocation()); Collection<VariantContext> vcs = tracker.getAllVariantContexts(ref, context.getLocation());
VariantContext mergedVC = VariantContextUtils.simpleMerge(vcs, priority, variantMergeOption, VariantContext mergedVC = VariantContextUtils.simpleMerge(vcs, priority, variantMergeOption,
genotypeMergeOption, true, printComplexMerges, ref.getBasesAtLocus(1), SET_KEY); genotypeMergeOption, true, printComplexMerges, ref.getBase(), SET_KEY);
//out.printf(" merged => %s%nannotated => %s%n", mergedVC, annotatedMergedVC); //out.printf(" merged => %s%nannotated => %s%n", mergedVC, annotatedMergedVC);
if ( mergedVC != null ) { // only operate at the start of events if ( mergedVC != null ) { // only operate at the start of events
VariantContext annotatedMergedVC = engine.annotateContext(tracker, ref, mergedVC); VariantContext annotatedMergedVC = engine.annotateContext(tracker, ref, mergedVC);
vcfWriter.add(annotatedMergedVC, ref.getBasesAtLocus(1)); vcfWriter.add(annotatedMergedVC, ref.getBase());
} }
return vcs.isEmpty() ? 0 : 1; return vcs.isEmpty() ? 0 : 1;

View File

@ -64,7 +64,7 @@ public class FilterLiftedVariants extends RodWalker<Integer, Integer> {
if ( recordRef != ref ) { if ( recordRef != ref ) {
failedLocs++; failedLocs++;
} else { } else {
writer.add(vc, new byte[]{ref}); writer.add(vc, ref);
} }
} }

View File

@ -86,7 +86,7 @@ public class LiftoverVariants extends RodWalker<Integer, Integer> {
if ( toInterval != null ) { if ( toInterval != null ) {
vc = VariantContextUtils.modifyLocation(vc, GenomeLocParser.createGenomeLoc(toInterval.getSequence(), toInterval.getStart(), toInterval.getEnd())); vc = VariantContextUtils.modifyLocation(vc, GenomeLocParser.createGenomeLoc(toInterval.getSequence(), toInterval.getStart(), toInterval.getEnd()));
writer.add(vc, new byte[]{ref.getBase()}); writer.add(vc, ref.getBase());
successfulIntervals++; successfulIntervals++;
} else { } else {
failedIntervals++; failedIntervals++;

View File

@ -109,7 +109,7 @@ public class IndelAnnotator extends RodWalker<Integer,Long>{
Map<String, Object> attrs = new HashMap<String, Object>(vc.getAttributes()); Map<String, Object> attrs = new HashMap<String, Object>(vc.getAttributes());
attrs.put("type",annotationString); attrs.put("type",annotationString);
vc = VariantContextUtils.modifyAttributes(vc, attrs); vc = VariantContextUtils.modifyAttributes(vc, attrs);
vcfWriter.add(vc, new byte[]{ref.getBase()}); vcfWriter.add(vc, ref.getBase());
return 1; return 1;
} }

View File

@ -142,12 +142,12 @@ public class IndelDBRateWalker extends RodWalker<OverlapTable,OverlapTabulator>
if ( vcfWriter != null ) { if ( vcfWriter != null ) {
int i = 0; int i = 0;
while ( i < compContexts.size() && compContexts.get(i).getLocation().isBefore(evalContexts.get(0).getLocation())) { while ( i < compContexts.size() && compContexts.get(i).getLocation().isBefore(evalContexts.get(0).getLocation())) {
vcfWriter.add(compContexts.get(i), new byte[]{compContexts.get(i).getReference().getBases()[0]}); vcfWriter.add(compContexts.get(i),compContexts.get(i).getReference().getBases()[0]);
i++; i++;
} }
vcfWriter.add(evalContexts.get(0), new byte[]{ref.getBase()}); vcfWriter.add(evalContexts.get(0), ref.getBase());
while ( i < compContexts.size() && compContexts.get(i).getLocation().distance(evalContexts.get(0).getLocation()) <= indelWindow) { while ( i < compContexts.size() && compContexts.get(i).getLocation().distance(evalContexts.get(0).getLocation()) <= indelWindow) {
vcfWriter.add(compContexts.get(i), new byte[]{compContexts.get(i).getReference().getBases()[0]}); vcfWriter.add(compContexts.get(i), compContexts.get(i).getReference().getBases()[0]);
i++; i++;
} }
} }

View File

@ -601,7 +601,7 @@ public class MendelianViolationClassifier extends LocusWalker<MendelianViolation
public VCFWriter reduce(MendelianViolation variant, VCFWriter writer) { public VCFWriter reduce(MendelianViolation variant, VCFWriter writer) {
if ( variant != null ) { if ( variant != null ) {
trioStructure.updateHomozygosityRegions(variant,bedOutput); trioStructure.updateHomozygosityRegions(variant,bedOutput);
writer.add(variant.toVariantContext(), new byte[]{variant.getRefBase()}); writer.add(variant.toVariantContext(),variant.getRefBase());
} }
return writer; return writer;

View File

@ -77,7 +77,7 @@ public class TestVariantContextWalker extends RodWalker<Integer, Integer> {
wroteHeader = true; wroteHeader = true;
} }
writer.add(vc, new byte[]{ref.getBase()}); writer.add(vc, ref.getBase());
} }
n++; n++;

View File

@ -126,7 +126,7 @@ public class VCF4WriterTestWalker extends RodWalker<Integer, Integer> {
return 0; return 0;
// Write directly variant context to VCF4.0 format. // Write directly variant context to VCF4.0 format.
vcfWriter.add(vc, ref.getBases()); vcfWriter.add(vc, ref.getBase());
return 1; return 1;
} }

View File

@ -317,7 +317,7 @@ public class BeagleOutputToVCFWalker extends RodWalker<Integer, Integer> {
vcfWriter.add(VariantContextUtils.modifyAttributes(filteredVC, attributes), new byte[]{ref.getBase()}); vcfWriter.add(VariantContextUtils.modifyAttributes(filteredVC, attributes), ref.getBase());
return 1; return 1;

View File

@ -179,7 +179,7 @@ public class TrioGenotyperWalker extends RefWalker<VariantContext, Integer>{
if ( a == 0 ) if ( a == 0 )
writer.writeHeader(VariantContextAdaptors.createVCFHeader(null, vc)); writer.writeHeader(VariantContextAdaptors.createVCFHeader(null, vc));
writer.add(vc, new byte[]{(byte)'.'}); writer.add(vc, (byte)'.');
a++; a++;
} }

View File

@ -303,7 +303,7 @@ public class GenomicAnnotator extends RodWalker<LinkedList<VariantContext>, Link
} else { } else {
//write results to disk immediately //write results to disk immediately
for(VariantContext annotatedVC : annotatedVCs ) { for(VariantContext annotatedVC : annotatedVCs ) {
vcfWriter.add(annotatedVC, new byte[]{ref.getBase()}); vcfWriter.add(annotatedVC,ref.getBase());
} }
} }
@ -346,7 +346,7 @@ public class GenomicAnnotator extends RodWalker<LinkedList<VariantContext>, Link
if(multiThreadedMode) { if(multiThreadedMode) {
//finally write results to disk //finally write results to disk
for(VariantContext vc : totalOutputRecords ) { for(VariantContext vc : totalOutputRecords ) {
vcfWriter.add(vc, vc.getReference().getBases()); vcfWriter.add(vc, vc.getReference().getBases()[0]);
} }
} }

View File

@ -139,7 +139,7 @@ public class VariantSelect extends RodWalker<Integer, Integer> {
} }
if ( someoneMatched ) if ( someoneMatched )
writer.add(vc, new byte[]{ref.getBase()}); writer.add(vc, ref.getBase());
return 1; return 1;
} }

View File

@ -73,7 +73,7 @@ public class VariantSubset extends RodWalker<Integer, Integer> {
if ( (vc.isPolymorphic() || INCLUDE_NON_VARIANTS) && if ( (vc.isPolymorphic() || INCLUDE_NON_VARIANTS) &&
(!subset.isFiltered() || INCLUDE_FILTERED) ) (!subset.isFiltered() || INCLUDE_FILTERED) )
writer.add(subset, new byte[]{ref.getBase()}); writer.add(subset, ref.getBase());
} }
return 1; return 1;

View File

@ -63,7 +63,7 @@ public class VCFGenotypeWriterAdapter extends VCFWriter implements VCFGenotypeWr
public void addCall(VariantContext vc, byte ref) { public void addCall(VariantContext vc, byte ref) {
vc = VariantContextUtils.purgeUnallowedGenotypeAttributes(vc, allowedGenotypeFormatKeys); vc = VariantContextUtils.purgeUnallowedGenotypeAttributes(vc, allowedGenotypeFormatKeys);
add(vc, new byte[]{ref}); add(vc, ref);
} }
public void writeHeader(VCFHeader header) { public void writeHeader(VCFHeader header) {
@ -112,7 +112,7 @@ public class VCFGenotypeWriterAdapter extends VCFWriter implements VCFGenotypeWr
while ( iterator.hasNext() ) { while ( iterator.hasNext() ) {
VariantContext vc = iterator.next(); VariantContext vc = iterator.next();
vc = VariantContextUtils.purgeUnallowedGenotypeAttributes(vc, allowedGenotypeFormatKeys); vc = VariantContextUtils.purgeUnallowedGenotypeAttributes(vc, allowedGenotypeFormatKeys);
add(vc, new byte[]{vc.getReferenceBaseForIndel()}); add(vc, vc.getReferenceBaseForIndel());
} }
vcfReader.close(); vcfReader.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {

View File

@ -133,15 +133,13 @@ public class VCFWriter {
} }
} }
public void add(VariantContext vc, byte[] refBases) { public void add(VariantContext vc, byte refBase) {
if ( mHeader == null ) if ( mHeader == null )
throw new IllegalStateException("The VCF Header must be written before records can be added"); throw new IllegalStateException("The VCF Header must be written before records can be added");
if ( refBases == null || refBases.length < 1 )
throw new IllegalArgumentException("The reference base must be provided to write VCF records");
try { try {
vc = VariantContextUtils.createVariantContextWithPaddedAlleles(vc, refBases); vc = VariantContextUtils.createVariantContextWithPaddedAlleles(vc, refBase);
GenomeLoc loc = vc.getLocation(); GenomeLoc loc = vc.getLocation();
Map<Allele, String> alleleMap = new HashMap<Allele, String>(vc.getAlleles().size()); Map<Allele, String> alleleMap = new HashMap<Allele, String>(vc.getAlleles().size());

View File

@ -47,8 +47,8 @@ public class VCFWriterUnitTest extends BaseTest {
VCFHeader header = createFakeHeader(metaData,additionalColumns); VCFHeader header = createFakeHeader(metaData,additionalColumns);
VCFWriter writer = new VCFWriter(fakeVCFFile); VCFWriter writer = new VCFWriter(fakeVCFFile);
writer.writeHeader(header); writer.writeHeader(header);
writer.add(createVC(header),"A".getBytes()); writer.add(createVC(header),new Byte("A"));
writer.add(createVC(header),"A".getBytes()); writer.add(createVC(header),new Byte("A"));
writer.close(); writer.close();
VCFCodec reader = new VCFCodec(); VCFCodec reader = new VCFCodec();
AsciiLineReader lineReader; AsciiLineReader lineReader;