From 0aef5c0074318610f0bbbb64cd93751ad02440b6 Mon Sep 17 00:00:00 2001 From: delangel Date: Mon, 30 May 2011 14:05:39 +0000 Subject: [PATCH] Totaly experimental, possibly useless annotation that logs # of MQ0 reads / total depth, TBD if VQSR can use it. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5905 348d0f76-0448-11de-a6fe-93d51630548a --- .../annotator/MappingQualityZeroFraction.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 java/src/org/broadinstitute/sting/gatk/walkers/annotator/MappingQualityZeroFraction.java diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/MappingQualityZeroFraction.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/MappingQualityZeroFraction.java new file mode 100755 index 000000000..46beed71d --- /dev/null +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/MappingQualityZeroFraction.java @@ -0,0 +1,60 @@ +package org.broadinstitute.sting.gatk.walkers.annotator; + +import org.broad.tribble.util.variantcontext.VariantContext; +import org.broad.tribble.vcf.VCFConstants; +import org.broad.tribble.vcf.VCFHeaderLineType; +import org.broad.tribble.vcf.VCFInfoHeaderLine; +import org.broadinstitute.sting.gatk.contexts.AlignmentContext; +import org.broadinstitute.sting.gatk.contexts.ReferenceContext; +import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; +import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.ExperimentalAnnotation; +import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.InfoFieldAnnotation; +import org.broadinstitute.sting.utils.pileup.PileupElement; +import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + + +public class MappingQualityZeroFraction implements InfoFieldAnnotation, ExperimentalAnnotation { + + public Map annotate(RefMetaDataTracker tracker, ReferenceContext ref, Map stratifiedContexts, VariantContext vc) { + if ( stratifiedContexts.size() == 0 ) + return null; + + int mq0 = 0; + int depth = 0; + for ( Map.Entry sample : stratifiedContexts.entrySet() ) { + AlignmentContext context = sample.getValue(); + depth += context.size(); + ReadBackedPileup pileup = null; + if (context.hasExtendedEventPileup()) + pileup = context.getExtendedEventPileup(); + else if (context.hasBasePileup()) + pileup = context.getBasePileup(); + + if (pileup != null) { + for (PileupElement p : pileup ) { + if ( p.getMappingQual() == 0 ) + mq0++; + } + } + } + if (depth > 0) { + double mq0f = (double)mq0 / (double )depth; + + Map map = new HashMap(); + map.put(getKeyNames().get(0), String.format("%1.4f", mq0f)); + return map; + } + else + return null; + } + + public List getKeyNames() { return Arrays.asList("MQ0Fraction"); } + + public List getDescriptions() { return Arrays.asList(new VCFInfoHeaderLine(getKeyNames().get(0), 1, VCFHeaderLineType.Integer, "Fraction of Mapping Quality Zero Reads")); } +} \ No newline at end of file