Better algorithm for merging genotypes in CombineVariants

This commit is contained in:
Mark DePristo 2011-11-16 15:17:33 -05:00
parent 101ffc4dfd
commit caf6080402
1 changed files with 5 additions and 3 deletions

View File

@ -401,6 +401,7 @@ public class VariantContextUtils {
final Map<String, Object> attributesWithMaxAC = new TreeMap<String, Object>(); final Map<String, Object> attributesWithMaxAC = new TreeMap<String, Object>();
double negLog10PError = -1; double negLog10PError = -1;
VariantContext vcWithMaxAC = null; VariantContext vcWithMaxAC = null;
Set<String> addedSamples = new HashSet<String>(first.getNSamples());
GenotypeCollection genotypes = GenotypeCollection.create(); GenotypeCollection genotypes = GenotypeCollection.create();
// counting the number of filtered and variant VCs // counting the number of filtered and variant VCs
@ -425,7 +426,7 @@ public class VariantContextUtils {
alleles.addAll(alleleMapping.values()); 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); 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<String> addedSamples, VariantContext oneVC, AlleleMapper alleleMapping, boolean uniqifySamples) {
for ( Genotype g : oneVC.getGenotypes() ) { for ( Genotype g : oneVC.getGenotypes() ) {
String name = mergedSampleName(oneVC.getSource(), g.getSampleName(), uniqifySamples); String name = mergedSampleName(oneVC.getSource(), g.getSampleName(), uniqifySamples);
if ( ! mergedGenotypes.containsSample(name) ) { if ( ! addedSamples.contains(name) ) {
// only add if the name is new // only add if the name is new
Genotype newG = g; Genotype newG = g;
@ -837,6 +838,7 @@ public class VariantContextUtils {
} }
mergedGenotypes.add(newG); mergedGenotypes.add(newG);
addedSamples.add(name);
} }
} }
} }