From ab5c4064edb2ade90da3fef96c10df5cd5a2d430 Mon Sep 17 00:00:00 2001 From: aaron Date: Wed, 6 Apr 2011 05:36:52 +0000 Subject: [PATCH] quick bug fix for variant context utils: only calculate the max AC if we're using the mergeInfoWithMaxAC flag, and if so deal with sites that have multiple alternate alleles correctly. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5582 348d0f76-0448-11de-a6fe-93d51630548a --- .../variantcontext/VariantContextUtils.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantContextUtils.java b/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantContextUtils.java index de6b4cfdd..17a918028 100755 --- a/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantContextUtils.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantContextUtils.java @@ -489,18 +489,33 @@ public class VariantContextUtils { // // special case DP (add it up) and ID (just preserve it) // - if ( vc.hasAttribute(VCFConstants.DEPTH_KEY) ) + if (vc.hasAttribute(VCFConstants.DEPTH_KEY)) depth += Integer.valueOf(vc.getAttributeAsString(VCFConstants.DEPTH_KEY)); - if ( rsID == null && vc.hasID() ) + if (rsID == null && vc.hasID()) rsID = vc.getID(); - if ( vc.hasAttribute(VCFConstants.ALLELE_COUNT_KEY) ) { - final int ac = Integer.valueOf(vc.getAttributeAsString(VCFConstants.ALLELE_COUNT_KEY)); - if( ac > maxAC ) { maxAC = ac; maxACAttributes = vc.getAttributes(); } + if (mergeInfoWithMaxAC && vc.hasAttribute(VCFConstants.ALLELE_COUNT_KEY)) { + String rawAlleleCounts = vc.getAttributeAsString(VCFConstants.ALLELE_COUNT_KEY); + // lets see if the string contains a , separator + if (rawAlleleCounts.contains(VCFConstants.INFO_FIELD_ARRAY_SEPARATOR)) { + List alleleCountArray = Arrays.asList(rawAlleleCounts.substring(1, rawAlleleCounts.length() - 1).split(VCFConstants.INFO_FIELD_ARRAY_SEPARATOR)); + for (String alleleCount : alleleCountArray) { + final int ac = Integer.valueOf(alleleCount.trim()); + if (ac > maxAC) { + maxAC = ac; + maxACAttributes = vc.getAttributes(); + } + } + } else { + final int ac = Integer.valueOf(rawAlleleCounts); + if (ac > maxAC) { + maxAC = ac; + maxACAttributes = vc.getAttributes(); + } + } } - for ( Map.Entry p : vc.getAttributes().entrySet() ) { + for (Map.Entry p : vc.getAttributes().entrySet()) { String key = p.getKey(); - // if we don't like the key already, don't go anywhere if ( ! inconsistentAttributes.contains(key) ) { boolean alreadyFound = attributes.containsKey(key);