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:
parent
b3fd145161
commit
4fc1db7aaf
|
|
@ -171,8 +171,8 @@ public class VariantContextUtils {
|
|||
UNION, INTERSECT
|
||||
}
|
||||
|
||||
public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs, byte[] refBases) {
|
||||
return simpleMerge(unsortedVCs, null, VariantMergeType.INTERSECT, GenotypeMergeType.UNSORTED, false, false, refBases);
|
||||
public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs, byte refBase) {
|
||||
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,
|
||||
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,
|
||||
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 )
|
||||
return null;
|
||||
|
||||
|
|
@ -213,7 +213,7 @@ public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs,
|
|||
List<VariantContext> VCs = new ArrayList<VariantContext>();
|
||||
|
||||
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();
|
||||
|
||||
|
||||
|
|
@ -501,8 +501,8 @@ public static VariantContext simpleMerge(Collection<VariantContext> unsortedVCs,
|
|||
|
||||
Map<String,Object> attributes = inputVC.getAttributes();
|
||||
|
||||
if (BaseUtils.isRegularBase(inputRefBase[0]))
|
||||
refByte = inputRefBase[0];
|
||||
if (BaseUtils.isRegularBase(inputRefBase))
|
||||
refByte = inputRefBase;
|
||||
else if (attributes.containsKey(VariantContext.REFERENCE_BASE_FOR_INDEL_KEY))
|
||||
refByte = (Byte)attributes.get(VariantContext.REFERENCE_BASE_FOR_INDEL_KEY);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ public class VariantsToVCF extends RodWalker<Integer, Integer> {
|
|||
}
|
||||
|
||||
vc = VariantContextUtils.purgeUnallowedGenotypeAttributes(vc, allowedGenotypeFormatStrings);
|
||||
vcfwriter.add(vc, new byte[]{ref});
|
||||
vcfwriter.add(vc,ref);
|
||||
}
|
||||
|
||||
public Integer reduceInit() {
|
||||
|
|
|
|||
|
|
@ -202,12 +202,12 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> {
|
|||
|
||||
if ( ! indelsOnly ) {
|
||||
for ( VariantContext annotatedVC : annotatedVCs )
|
||||
vcfWriter.add(annotatedVC, new byte[]{ref.getBase()});
|
||||
vcfWriter.add(annotatedVC, ref.getBase());
|
||||
} else {
|
||||
// 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()) ) {
|
||||
for ( VariantContext annotatedVC : indelBufferContext )
|
||||
vcfWriter.add(annotatedVC, new byte[]{ref.getBase()});
|
||||
vcfWriter.add(annotatedVC, ref.getBase());
|
||||
indelBufferContext = annotatedVCs;
|
||||
} else {
|
||||
indelBufferContext = annotatedVCs;
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ public class VariantFiltrationWalker extends RodWalker<Integer, Integer> {
|
|||
private void writeVCF(VariantContext vc, byte ref) {
|
||||
if ( writer == null )
|
||||
initializeVcfWriter(vc);
|
||||
writer.add(vc, new byte[]{ref});
|
||||
writer.add(vc, ref);
|
||||
}
|
||||
|
||||
public Integer reduce(Integer value, Integer sum) {
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ public class BatchedCallsMerger extends LocusWalker<VariantContext, Integer> imp
|
|||
}
|
||||
|
||||
// merge the variant contexts
|
||||
return VariantContextUtils.simpleMerge(calls, ref.getBases());
|
||||
return VariantContextUtils.simpleMerge(calls, ref.getBase());
|
||||
}
|
||||
|
||||
private AlignmentContext filterForSamples(ReadBackedPileup pileup, Set<String> samples) {
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ public class SequenomValidationConverter extends RodWalker<Pair<VariantContext,
|
|||
vcfWriter.writeHeader(header);
|
||||
|
||||
for ( Pair<VariantContext, Byte> record : records )
|
||||
vcfWriter.add(record.first, new byte[]{record.second});
|
||||
vcfWriter.add(record.first, record.second);
|
||||
vcfWriter.close();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -554,7 +554,7 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> {
|
|||
wroteHeader = true;
|
||||
}
|
||||
|
||||
writer.add(mvc, new byte[]{ref});
|
||||
writer.add(mvc, ref);
|
||||
//interestingReasons.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
vcfWriter.add( vc, new byte[]{ref.getBase()} );
|
||||
vcfWriter.add( vc, ref.getBase() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,10 +194,10 @@ public class VariantRecalibrator extends RodWalker<ExpandingArrayList<VariantDat
|
|||
filters.add(VCFConstants.PASSES_FILTERS_v4);
|
||||
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
|
||||
vcfWriter.add( vc, new byte[]{ref.getBase()} );
|
||||
vcfWriter.add( vc, ref.getBase() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,14 +116,14 @@ public class CombineVariants extends RodWalker<Integer, Integer> {
|
|||
// Need to provide reference bases to simpleMerge starting at current locus
|
||||
Collection<VariantContext> vcs = tracker.getAllVariantContexts(ref, context.getLocation());
|
||||
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);
|
||||
|
||||
if ( mergedVC != null ) { // only operate at the start of events
|
||||
VariantContext annotatedMergedVC = engine.annotateContext(tracker, ref, mergedVC);
|
||||
vcfWriter.add(annotatedMergedVC, ref.getBasesAtLocus(1));
|
||||
vcfWriter.add(annotatedMergedVC, ref.getBase());
|
||||
}
|
||||
|
||||
return vcs.isEmpty() ? 0 : 1;
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class FilterLiftedVariants extends RodWalker<Integer, Integer> {
|
|||
if ( recordRef != ref ) {
|
||||
failedLocs++;
|
||||
} else {
|
||||
writer.add(vc, new byte[]{ref});
|
||||
writer.add(vc, ref);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class LiftoverVariants extends RodWalker<Integer, Integer> {
|
|||
|
||||
if ( toInterval != null ) {
|
||||
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++;
|
||||
} else {
|
||||
failedIntervals++;
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ public class IndelAnnotator extends RodWalker<Integer,Long>{
|
|||
Map<String, Object> attrs = new HashMap<String, Object>(vc.getAttributes());
|
||||
attrs.put("type",annotationString);
|
||||
vc = VariantContextUtils.modifyAttributes(vc, attrs);
|
||||
vcfWriter.add(vc, new byte[]{ref.getBase()});
|
||||
vcfWriter.add(vc, ref.getBase());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,12 +142,12 @@ public class IndelDBRateWalker extends RodWalker<OverlapTable,OverlapTabulator>
|
|||
if ( vcfWriter != null ) {
|
||||
int i = 0;
|
||||
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++;
|
||||
}
|
||||
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) {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -601,7 +601,7 @@ public class MendelianViolationClassifier extends LocusWalker<MendelianViolation
|
|||
public VCFWriter reduce(MendelianViolation variant, VCFWriter writer) {
|
||||
if ( variant != null ) {
|
||||
trioStructure.updateHomozygosityRegions(variant,bedOutput);
|
||||
writer.add(variant.toVariantContext(), new byte[]{variant.getRefBase()});
|
||||
writer.add(variant.toVariantContext(),variant.getRefBase());
|
||||
}
|
||||
|
||||
return writer;
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public class TestVariantContextWalker extends RodWalker<Integer, Integer> {
|
|||
wroteHeader = true;
|
||||
}
|
||||
|
||||
writer.add(vc, new byte[]{ref.getBase()});
|
||||
writer.add(vc, ref.getBase());
|
||||
}
|
||||
|
||||
n++;
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public class VCF4WriterTestWalker extends RodWalker<Integer, Integer> {
|
|||
return 0;
|
||||
|
||||
// Write directly variant context to VCF4.0 format.
|
||||
vcfWriter.add(vc, ref.getBases());
|
||||
vcfWriter.add(vc, ref.getBase());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ public class TrioGenotyperWalker extends RefWalker<VariantContext, Integer>{
|
|||
if ( a == 0 )
|
||||
writer.writeHeader(VariantContextAdaptors.createVCFHeader(null, vc));
|
||||
|
||||
writer.add(vc, new byte[]{(byte)'.'});
|
||||
writer.add(vc, (byte)'.');
|
||||
a++;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ public class GenomicAnnotator extends RodWalker<LinkedList<VariantContext>, Link
|
|||
} else {
|
||||
//write results to disk immediately
|
||||
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) {
|
||||
//finally write results to disk
|
||||
for(VariantContext vc : totalOutputRecords ) {
|
||||
vcfWriter.add(vc, vc.getReference().getBases());
|
||||
vcfWriter.add(vc, vc.getReference().getBases()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ public class VariantSelect extends RodWalker<Integer, Integer> {
|
|||
}
|
||||
|
||||
if ( someoneMatched )
|
||||
writer.add(vc, new byte[]{ref.getBase()});
|
||||
writer.add(vc, ref.getBase());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class VariantSubset extends RodWalker<Integer, Integer> {
|
|||
|
||||
if ( (vc.isPolymorphic() || INCLUDE_NON_VARIANTS) &&
|
||||
(!subset.isFiltered() || INCLUDE_FILTERED) )
|
||||
writer.add(subset, new byte[]{ref.getBase()});
|
||||
writer.add(subset, ref.getBase());
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class VCFGenotypeWriterAdapter extends VCFWriter implements VCFGenotypeWr
|
|||
|
||||
public void addCall(VariantContext vc, byte ref) {
|
||||
vc = VariantContextUtils.purgeUnallowedGenotypeAttributes(vc, allowedGenotypeFormatKeys);
|
||||
add(vc, new byte[]{ref});
|
||||
add(vc, ref);
|
||||
}
|
||||
|
||||
public void writeHeader(VCFHeader header) {
|
||||
|
|
@ -112,7 +112,7 @@ public class VCFGenotypeWriterAdapter extends VCFWriter implements VCFGenotypeWr
|
|||
while ( iterator.hasNext() ) {
|
||||
VariantContext vc = iterator.next();
|
||||
vc = VariantContextUtils.purgeUnallowedGenotypeAttributes(vc, allowedGenotypeFormatKeys);
|
||||
add(vc, new byte[]{vc.getReferenceBaseForIndel()});
|
||||
add(vc, vc.getReferenceBaseForIndel());
|
||||
}
|
||||
vcfReader.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
|
|
|
|||
|
|
@ -133,15 +133,13 @@ public class VCFWriter {
|
|||
}
|
||||
}
|
||||
|
||||
public void add(VariantContext vc, byte[] refBases) {
|
||||
public void add(VariantContext vc, byte refBase) {
|
||||
if ( mHeader == null )
|
||||
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 {
|
||||
|
||||
vc = VariantContextUtils.createVariantContextWithPaddedAlleles(vc, refBases);
|
||||
vc = VariantContextUtils.createVariantContextWithPaddedAlleles(vc, refBase);
|
||||
|
||||
GenomeLoc loc = vc.getLocation();
|
||||
Map<Allele, String> alleleMap = new HashMap<Allele, String>(vc.getAlleles().size());
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ public class VCFWriterUnitTest extends BaseTest {
|
|||
VCFHeader header = createFakeHeader(metaData,additionalColumns);
|
||||
VCFWriter writer = new VCFWriter(fakeVCFFile);
|
||||
writer.writeHeader(header);
|
||||
writer.add(createVC(header),"A".getBytes());
|
||||
writer.add(createVC(header),"A".getBytes());
|
||||
writer.add(createVC(header),new Byte("A"));
|
||||
writer.add(createVC(header),new Byte("A"));
|
||||
writer.close();
|
||||
VCFCodec reader = new VCFCodec();
|
||||
AsciiLineReader lineReader;
|
||||
|
|
|
|||
Loading…
Reference in New Issue