From caf60804028bfcd17ca0234ce3a07678e3ec722c Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Wed, 16 Nov 2011 15:17:33 -0500 Subject: [PATCH] Better algorithm for merging genotypes in CombineVariants --- .../sting/utils/variantcontext/VariantContextUtils.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantContextUtils.java b/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantContextUtils.java index 161800009..238cf4b3b 100755 --- a/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantContextUtils.java +++ b/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantContextUtils.java @@ -401,6 +401,7 @@ public class VariantContextUtils { final Map attributesWithMaxAC = new TreeMap(); double negLog10PError = -1; VariantContext vcWithMaxAC = null; + Set addedSamples = new HashSet(first.getNSamples()); GenotypeCollection genotypes = GenotypeCollection.create(); // counting the number of filtered and variant VCs @@ -425,7 +426,7 @@ public class VariantContextUtils { alleles.addAll(alleleMapping.values()); - mergeGenotypes(genotypes, vc, alleleMapping, genotypeMergeOptions == GenotypeMergeType.UNIQUIFY); + mergeGenotypes(genotypes, addedSamples, vc, alleleMapping, genotypeMergeOptions == GenotypeMergeType.UNIQUIFY); negLog10PError = Math.max(negLog10PError, vc.isVariant() ? vc.getNegLog10PError() : -1); @@ -824,10 +825,10 @@ public class VariantContextUtils { } } - private static void mergeGenotypes(GenotypeCollection mergedGenotypes, VariantContext oneVC, AlleleMapper alleleMapping, boolean uniqifySamples) { + private static void mergeGenotypes(GenotypeCollection mergedGenotypes, Set addedSamples, VariantContext oneVC, AlleleMapper alleleMapping, boolean uniqifySamples) { for ( Genotype g : oneVC.getGenotypes() ) { String name = mergedSampleName(oneVC.getSource(), g.getSampleName(), uniqifySamples); - if ( ! mergedGenotypes.containsSample(name) ) { + if ( ! addedSamples.contains(name) ) { // only add if the name is new Genotype newG = g; @@ -837,6 +838,7 @@ public class VariantContextUtils { } mergedGenotypes.add(newG); + addedSamples.add(name); } } }