diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java index 29ee8f045..056136b1f 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java @@ -3,6 +3,7 @@ package org.broadinstitute.sting.gatk.walkers.annotator; import org.broadinstitute.sting.gatk.contexts.*; import org.broadinstitute.sting.gatk.refdata.*; import org.broadinstitute.sting.gatk.walkers.*; +import org.broadinstitute.sting.gatk.datasources.simpleDataSources.ReferenceOrderedDataSource; import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.utils.genotype.vcf.*; import org.broadinstitute.sting.utils.genotype.*; @@ -41,6 +42,9 @@ public class VariantAnnotator extends LocusWalker { private ArrayList requestedAnnotations; + // should we annotate dbsnp? + private boolean annotateDbsnp = false; + // mapping from class name to class private static HashMap allAnnotations = null; private static HashMap standardAnnotations = null; @@ -115,12 +119,24 @@ public class VariantAnnotator extends LocusWalker { } } + // check to see whether a dbsnp rod was included + List dataSources = getToolkit().getRodDataSources(); + for ( ReferenceOrderedDataSource source : dataSources ) { + ReferenceOrderedData rod = source.getReferenceOrderedData(); + if ( rod.getType().equals(rodDbSNP.class) ) { + annotateDbsnp = true; + break; + } + } + // setup the header fields Set hInfo = new HashSet(); hInfo.addAll(VCFUtils.getHeaderFields(getToolkit())); hInfo.add(new VCFHeaderLine("source", "VariantAnnotator")); hInfo.add(new VCFHeaderLine("annotatorReference", getToolkit().getArguments().referenceFile.getName())); hInfo.addAll(getVCFAnnotationDescriptions(requestedAnnotations)); + if ( annotateDbsnp ) + hInfo.add(new VCFInfoHeaderLine(VCFRecord.DBSNP_KEY, 1, VCFInfoHeaderLine.INFO_TYPE.Integer, "dbSNP membership")); vcfWriter = new VCFWriter(VCF_OUT); vcfHeader = new VCFHeader(hInfo, samples); @@ -166,7 +182,7 @@ public class VariantAnnotator extends LocusWalker { if ( BaseUtils.simpleBaseToBaseIndex(ref.getBase()) != -1 ) { Map stratifiedContexts = StratifiedAlignmentContext.splitContextBySample(context.getBasePileup()); if ( stratifiedContexts != null ) - annotations = getAnnotations(tracker, ref, stratifiedContexts, variant, requestedAnnotations); + annotations = getAnnotations(tracker, ref, stratifiedContexts, variant, requestedAnnotations, annotateDbsnp); } writeVCF(tracker, ref, context, variant, annotations); @@ -208,24 +224,30 @@ public class VariantAnnotator extends LocusWalker { } // option #1: don't specify annotations to be used: standard annotations are used by default - public static Map getAnnotations(RefMetaDataTracker tracker, ReferenceContext ref, Map stratifiedContexts, Variation variation) { + public static Map getAnnotations(RefMetaDataTracker tracker, ReferenceContext ref, Map stratifiedContexts, Variation variation, boolean annotateDbsnp) { if ( standardAnnotations == null ) determineAllAnnotations(); - return getAnnotations(tracker, ref, stratifiedContexts, variation, standardAnnotations.values()); + return getAnnotations(tracker, ref, stratifiedContexts, variation, standardAnnotations.values(), annotateDbsnp); } // option #2: specify that all possible annotations be used - public static Map getAllAnnotations(RefMetaDataTracker tracker, ReferenceContext ref, Map stratifiedContexts, Variation variation) { + public static Map getAllAnnotations(RefMetaDataTracker tracker, ReferenceContext ref, Map stratifiedContexts, Variation variation, boolean annotateDbsnp) { if ( allAnnotations == null ) determineAllAnnotations(); - return getAnnotations(tracker, ref, stratifiedContexts, variation, allAnnotations.values()); + return getAnnotations(tracker, ref, stratifiedContexts, variation, allAnnotations.values(), annotateDbsnp); } // option #3: specify the exact annotations to be used - public static Map getAnnotations(RefMetaDataTracker tracker, ReferenceContext ref, Map stratifiedContexts, Variation variation, Collection annotations) { + public static Map getAnnotations(RefMetaDataTracker tracker, ReferenceContext ref, Map stratifiedContexts, Variation variation, Collection annotations, boolean annotateDbsnp) { HashMap results = new HashMap(); + // annotate dbsnp occurrence + if ( annotateDbsnp ) { + rodDbSNP dbsnp = rodDbSNP.getFirstRealSNP(tracker.getTrackData("dbsnp", null)); + results.put(VCFRecord.DBSNP_KEY, dbsnp == null ? "0" : "1"); + } + for ( VariantAnnotation annotator : annotations) { String annot = annotator.annotate(tracker, ref, stratifiedContexts, variation); if ( annot != null ) { @@ -236,13 +258,12 @@ public class VariantAnnotator extends LocusWalker { return results; } - private void writeVCF(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context, VariationRod variant, Map annotations) { VCFRecord rec = getVCFRecord(tracker, ref, context, variant); if ( rec != null ) { rec.addInfoFields(annotations); // also, annotate dbsnp id if available and not already there - if ( rec.getID() == null || rec.getID().equals(".") ) { + if ( annotateDbsnp && (rec.getID() == null || rec.getID().equals(".")) ) { rodDbSNP dbsnp = rodDbSNP.getFirstRealSNP(tracker.getTrackData("dbsnp", null)); if ( dbsnp != null ) rec.setID(dbsnp.getRS_ID()); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java index 0ec370edc..2d50bc00c 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java @@ -26,8 +26,11 @@ package org.broadinstitute.sting.gatk.walkers.genotyper; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; +import org.broadinstitute.sting.gatk.datasources.simpleDataSources.ReferenceOrderedDataSource; import org.broadinstitute.sting.gatk.contexts.*; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; +import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedData; +import org.broadinstitute.sting.gatk.refdata.rodDbSNP; import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.walkers.annotator.VariantAnnotator; import org.broadinstitute.sting.utils.*; @@ -66,7 +69,10 @@ public class UnifiedGenotyper extends LocusWalker samples = new HashSet(); - /** Enable deletions in the pileup **/ + // should we annotate dbsnp? + private boolean annotateDbsnp = false; + + // Enable deletions in the pileup public boolean includeReadsWithDeletionAtLoci() { return true; } /** @@ -162,6 +168,16 @@ public class UnifiedGenotyper extends LocusWalker dataSources = getToolkit().getRodDataSources(); + for ( ReferenceOrderedDataSource source : dataSources ) { + ReferenceOrderedData rod = source.getReferenceOrderedData(); + if ( rod.getType().equals(rodDbSNP.class) ) { + annotateDbsnp = true; + break; + } + } + // *** If we were called by another walker, then we don't *** // *** want to do any of the other initialization steps. *** if ( writer == null ) @@ -192,6 +208,8 @@ public class UnifiedGenotyper extends LocusWalker annotations; if ( UAC.ALL_ANNOTATIONS ) - annotations = VariantAnnotator.getAllAnnotations(tracker, refContext, stratifiedContexts, call.variation); + annotations = VariantAnnotator.getAllAnnotations(tracker, refContext, stratifiedContexts, call.variation, annotateDbsnp); else - annotations = VariantAnnotator.getAnnotations(tracker, refContext, stratifiedContexts, call.variation); + annotations = VariantAnnotator.getAnnotations(tracker, refContext, stratifiedContexts, call.variation, annotateDbsnp); ((ArbitraryFieldsBacked)call.variation).setFields(annotations); }