diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/AlleleBalanceBySample.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/AlleleBalanceBySample.java index 06e91bf26..7fe56a1ef 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/AlleleBalanceBySample.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/AlleleBalanceBySample.java @@ -11,6 +11,7 @@ import org.broadinstitute.sting.utils.codecs.vcf.VCFFormatHeaderLine; import org.broadinstitute.sting.utils.codecs.vcf.VCFHeaderLineType; import org.broadinstitute.sting.utils.variantcontext.Allele; import org.broadinstitute.sting.utils.variantcontext.Genotype; +import org.broadinstitute.sting.utils.variantcontext.GenotypeBuilder; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.util.*; @@ -21,15 +22,12 @@ import java.util.*; */ public class AlleleBalanceBySample extends GenotypeAnnotation implements ExperimentalAnnotation { - public Map annotate(RefMetaDataTracker tracker, AnnotatorCompatibleWalker walker, ReferenceContext ref, AlignmentContext stratifiedContext, VariantContext vc, Genotype g) { + public void annotate(RefMetaDataTracker tracker, AnnotatorCompatibleWalker walker, ReferenceContext ref, AlignmentContext stratifiedContext, VariantContext vc, Genotype g, final GenotypeBuilder gb) { Double ratio = annotateSNP(stratifiedContext, vc, g); if (ratio == null) - return null; - - Map map = new HashMap(); - map.put(getKeyNames().get(0), String.format("%.2f", ratio.doubleValue())); - return map; + return; + gb.attribute(getKeyNames().get(0), Double.valueOf(String.format("%.2f", ratio.doubleValue()))); } private Double annotateSNP(AlignmentContext stratifiedContext, VariantContext vc, Genotype g) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthPerAlleleBySample.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthPerAlleleBySample.java index dc3e7c6f0..a8bbebec9 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthPerAlleleBySample.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthPerAlleleBySample.java @@ -15,6 +15,7 @@ import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import org.broadinstitute.sting.utils.variantcontext.Allele; import org.broadinstitute.sting.utils.variantcontext.Genotype; +import org.broadinstitute.sting.utils.variantcontext.GenotypeBuilder; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.util.*; @@ -45,22 +46,20 @@ public class DepthPerAlleleBySample extends GenotypeAnnotation implements Standa private static final String DEL = "DEL"; // constant, for speed: no need to create a key string for deletion allele every time - public Map annotate(RefMetaDataTracker tracker, AnnotatorCompatibleWalker walker, ReferenceContext ref, AlignmentContext stratifiedContext, VariantContext vc, Genotype g) { + public void annotate(RefMetaDataTracker tracker, AnnotatorCompatibleWalker walker, ReferenceContext ref, AlignmentContext stratifiedContext, VariantContext vc, Genotype g, GenotypeBuilder gb) { if ( g == null || !g.isCalled() ) - return null; + return; if ( vc.isSNP() ) - return annotateSNP(stratifiedContext, vc); - if ( vc.isIndel() ) - return annotateIndel(stratifiedContext, vc); - - return null; + annotateSNP(stratifiedContext, vc, gb); + else if ( vc.isIndel() ) + annotateIndel(stratifiedContext, vc, gb); } - private Map annotateSNP(AlignmentContext stratifiedContext, VariantContext vc) { + private void annotateSNP(AlignmentContext stratifiedContext, VariantContext vc, GenotypeBuilder gb) { if ( ! stratifiedContext.hasBasePileup() ) - return null; + return; HashMap alleleCounts = new HashMap(); for ( Allele allele : vc.getAlleles() ) @@ -78,17 +77,16 @@ public class DepthPerAlleleBySample extends GenotypeAnnotation implements Standa for (int i = 0; i < vc.getAlternateAlleles().size(); i++) counts[i+1] = alleleCounts.get(vc.getAlternateAllele(i).getBases()[0]); - return toADAnnotation(counts); + gb.AD(counts); } - private Map annotateIndel(AlignmentContext stratifiedContext, VariantContext vc) { - + private void annotateIndel(AlignmentContext stratifiedContext, VariantContext vc, GenotypeBuilder gb) { if ( ! stratifiedContext.hasBasePileup() ) - return null; + return; ReadBackedPileup pileup = stratifiedContext.getBasePileup(); if ( pileup == null ) - return null; + return; final HashMap alleleCounts = new HashMap(); alleleCounts.put(REF_ALLELE, 0); @@ -129,11 +127,7 @@ public class DepthPerAlleleBySample extends GenotypeAnnotation implements Standa for (int i = 0; i < vc.getAlternateAlleles().size(); i++) counts[i+1] = alleleCounts.get( getAlleleRepresentation(vc.getAlternateAllele(i)) ); - return toADAnnotation(counts); - } - - private final Map toADAnnotation(final int[] counts) { - return Collections.singletonMap(getKeyNames().get(0), (Object)counts); + gb.AD(counts); } private String getAlleleRepresentation(Allele allele) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/MappingQualityZeroBySample.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/MappingQualityZeroBySample.java index b1c037ba3..b2615411a 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/MappingQualityZeroBySample.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/MappingQualityZeroBySample.java @@ -36,6 +36,7 @@ import org.broadinstitute.sting.utils.codecs.vcf.VCFHeaderLineType; import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import org.broadinstitute.sting.utils.variantcontext.Genotype; +import org.broadinstitute.sting.utils.variantcontext.GenotypeBuilder; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.util.Arrays; @@ -47,10 +48,11 @@ import java.util.Map; * Count for each sample of mapping quality zero reads */ public class MappingQualityZeroBySample extends GenotypeAnnotation { - public Map annotate(RefMetaDataTracker tracker, - AnnotatorCompatibleWalker walker, ReferenceContext ref, AlignmentContext context, VariantContext vc, Genotype g) { + public void annotate(RefMetaDataTracker tracker, + AnnotatorCompatibleWalker walker, ReferenceContext ref, AlignmentContext context, + VariantContext vc, Genotype g, GenotypeBuilder gb) { if ( g == null || !g.isCalled() ) - return null; + return; int mq0 = 0; if ( context.hasBasePileup() ) { @@ -60,9 +62,8 @@ public class MappingQualityZeroBySample extends GenotypeAnnotation { mq0++; } } - Map map = new HashMap(); - map.put(getKeyNames().get(0), String.format("%d", mq0)); - return map; + + gb.attribute(getKeyNames().get(0), mq0); } public List getKeyNames() { return Arrays.asList(VCFConstants.MAPPING_QUALITY_ZERO_KEY); } diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java index 14077ca44..f31957123 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java @@ -261,24 +261,22 @@ public class VariantAnnotatorEngine { } private GenotypesContext annotateGenotypes(RefMetaDataTracker tracker, ReferenceContext ref, Map stratifiedContexts, VariantContext vc) { - if ( requestedGenotypeAnnotations.size() == 0 ) + if ( requestedGenotypeAnnotations.isEmpty() ) return vc.getGenotypes(); - GenotypesContext genotypes = GenotypesContext.create(vc.getNSamples()); + final GenotypesContext genotypes = GenotypesContext.create(vc.getNSamples()); for ( final Genotype genotype : vc.getGenotypes() ) { AlignmentContext context = stratifiedContexts.get(genotype.getSampleName()); + if ( context == null ) { genotypes.add(genotype); - continue; + } else { + final GenotypeBuilder gb = new GenotypeBuilder(genotype); + for ( final GenotypeAnnotation annotation : requestedGenotypeAnnotations ) { + annotation.annotate(tracker, walker, ref, context, vc, genotype, gb); + } + genotypes.add(gb.make()); } - - Map genotypeAnnotations = new HashMap(genotype.getExtendedAttributes()); - for ( GenotypeAnnotation annotation : requestedGenotypeAnnotations ) { - Map result = annotation.annotate(tracker, walker, ref, context, vc, genotype); - if ( result != null ) - genotypeAnnotations.putAll(result); - } - genotypes.add(new GenotypeBuilder(genotype).attributes(genotypeAnnotations).make()); } return genotypes; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/interfaces/GenotypeAnnotation.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/interfaces/GenotypeAnnotation.java index f87f0e310..c44c834de 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/interfaces/GenotypeAnnotation.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/interfaces/GenotypeAnnotation.java @@ -5,6 +5,7 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.utils.codecs.vcf.VCFFormatHeaderLine; import org.broadinstitute.sting.utils.variantcontext.Genotype; +import org.broadinstitute.sting.utils.variantcontext.GenotypeBuilder; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.util.List; @@ -13,8 +14,9 @@ import java.util.Map; public abstract class GenotypeAnnotation extends VariantAnnotatorAnnotation { // return annotations for the given contexts/genotype split by sample - public abstract Map annotate(RefMetaDataTracker tracker, AnnotatorCompatibleWalker walker, - ReferenceContext ref, AlignmentContext stratifiedContext, VariantContext vc, Genotype g); + public abstract void annotate(RefMetaDataTracker tracker, AnnotatorCompatibleWalker walker, + ReferenceContext ref, AlignmentContext stratifiedContext, + VariantContext vc, Genotype g, GenotypeBuilder gb ); // return the descriptions used for the VCF FORMAT meta field public abstract List getDescriptions();