From 6231bba2888a62d4dfd2b99e3988777b54f4a887 Mon Sep 17 00:00:00 2001 From: rpoplin Date: Sun, 12 Jun 2011 20:10:16 +0000 Subject: [PATCH] Bug fix for mergeInfoWithMaxAC git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5978 348d0f76-0448-11de-a6fe-93d51630548a --- .../variantcontext/VariantContextUtils.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 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 fbfcd91f3..c848a300b 100755 --- a/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantContextUtils.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantContextUtils.java @@ -483,7 +483,8 @@ public class VariantContextUtils { String rsID = null; int depth = 0; int maxAC = -1; - Map maxACAttributes = new TreeMap(); + Map attributesWithMaxAC = new TreeMap(); + VariantContext vcWithMaxAC = null; // counting the number of filtered and variant VCs int nFiltered = 0, nVariant = 0; @@ -532,14 +533,14 @@ public class VariantContextUtils { final int ac = Integer.valueOf(alleleCount.trim()); if (ac > maxAC) { maxAC = ac; - maxACAttributes = vc.getAttributes(); + vcWithMaxAC = vc; } } } else { final int ac = Integer.valueOf(rawAlleleCounts); if (ac > maxAC) { maxAC = ac; - maxACAttributes = vc.getAttributes(); + vcWithMaxAC = vc; } } } @@ -565,6 +566,11 @@ public class VariantContextUtils { } } + // take the VC with the maxAC and pull the attributes into a modifiable map + if ( mergeInfoWithMaxAC && vcWithMaxAC != null ) { + attributesWithMaxAC.putAll(vcWithMaxAC.getAttributes()); + } + // if at least one record was unfiltered and we want a union, clear all of the filters if ( filteredRecordMergeType == FilteredRecordMergeType.KEEP_IF_ANY_UNFILTERED && nFiltered != VCs.size() ) filters.clear(); @@ -588,7 +594,7 @@ public class VariantContextUtils { if ( setKey != null ) { attributes.put(setKey, setValue); - if( mergeInfoWithMaxAC ) { maxACAttributes.put(setKey, setValue); } + if( mergeInfoWithMaxAC && vcWithMaxAC != null ) { attributesWithMaxAC.put(setKey, vcWithMaxAC.getSource()); } } } @@ -597,7 +603,7 @@ public class VariantContextUtils { if ( rsID != null ) attributes.put(VariantContext.ID_KEY, rsID); - VariantContext merged = new VariantContext(name, loc.getContig(), loc.getStart(), loc.getStop(), alleles, genotypes, negLog10PError, filters, (mergeInfoWithMaxAC ? maxACAttributes : attributes) ); + VariantContext merged = new VariantContext(name, loc.getContig(), loc.getStart(), loc.getStop(), alleles, genotypes, negLog10PError, filters, (mergeInfoWithMaxAC ? attributesWithMaxAC : attributes) ); // Trim the padded bases of all alleles if necessary merged = AbstractVCFCodec.createVariantContextWithTrimmedAlleles(merged);