diff --git a/public/java/src/org/broadinstitute/sting/gatk/refdata/VariantContextAdaptors.java b/public/java/src/org/broadinstitute/sting/gatk/refdata/VariantContextAdaptors.java index c4ba5d6d1..523da7492 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/refdata/VariantContextAdaptors.java +++ b/public/java/src/org/broadinstitute/sting/gatk/refdata/VariantContextAdaptors.java @@ -194,7 +194,7 @@ public class VariantContextAdaptors { return null; // we weren't given enough reference context to create the VariantContext Byte refBaseForIndel = new Byte(ref.getBases()[index]); - GenotypeMap genotypes = null; + GenotypeCollection genotypes = null; VariantContext vc = new VariantContext(name, dbsnp.getChr(), dbsnp.getStart() - (sawNullAllele ? 1 : 0), dbsnp.getEnd() - (refAllele.isNull() ? 1 : 0), alleles, genotypes, VariantContext.NO_NEG_LOG_10PERROR, null, attributes, refBaseForIndel); return vc; } else @@ -324,7 +324,7 @@ public class VariantContextAdaptors { String[] samples = hapmap.getSampleIDs(); String[] genotypeStrings = hapmap.getGenotypes(); - GenotypeMap genotypes = GenotypeMap.create(samples.length); + GenotypeCollection genotypes = GenotypeCollection.create(samples.length); for ( int i = 0; i < samples.length; i++ ) { // ignore bad genotypes if ( genotypeStrings[i].contains("N") ) diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/AlleleBalance.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/AlleleBalance.java index 297490172..c345c8741 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/AlleleBalance.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/AlleleBalance.java @@ -35,7 +35,7 @@ import org.broadinstitute.sting.utils.codecs.vcf.VCFHeaderLineType; import org.broadinstitute.sting.utils.codecs.vcf.VCFInfoHeaderLine; import org.broadinstitute.sting.utils.pileup.ReadBackedExtendedEventPileup; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.util.Arrays; @@ -55,18 +55,18 @@ public class AlleleBalance extends InfoFieldAnnotation { if ( !vc.isBiallelic() ) return null; - final GenotypeMap genotypes = vc.getGenotypes(); + final GenotypeCollection genotypes = vc.getGenotypes(); if ( !vc.hasGenotypes() ) return null; double ratio = 0.0; double totalWeights = 0.0; - for ( Map.Entry genotype : genotypes.entrySet() ) { + for ( Genotype genotype : genotypes ) { // we care only about het calls - if ( !genotype.getValue().isHet() ) + if ( !genotype.isHet() ) continue; - AlignmentContext context = stratifiedContexts.get(genotype.getKey()); + AlignmentContext context = stratifiedContexts.get(genotype.getSampleName()); if ( context == null ) continue; @@ -85,8 +85,8 @@ public class AlleleBalance extends InfoFieldAnnotation { continue; // weight the allele balance by genotype quality so that e.g. mis-called homs don't affect the ratio too much - ratio += genotype.getValue().getNegLog10PError() * ((double)refCount / (double)(refCount + altCount)); - totalWeights += genotype.getValue().getNegLog10PError(); + ratio += genotype.getNegLog10PError() * ((double)refCount / (double)(refCount + altCount)); + totalWeights += genotype.getNegLog10PError(); } else if ( vc.isIndel() && context.hasExtendedEventPileup() ) { final ReadBackedExtendedEventPileup indelPileup = context.getExtendedEventPileup(); if ( indelPileup == null ) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HardyWeinberg.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HardyWeinberg.java index 6352fcf2a..164c77d1c 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HardyWeinberg.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HardyWeinberg.java @@ -11,7 +11,7 @@ import org.broadinstitute.sting.utils.QualityUtils; import org.broadinstitute.sting.utils.codecs.vcf.VCFHeaderLineType; import org.broadinstitute.sting.utils.codecs.vcf.VCFInfoHeaderLine; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.util.Arrays; @@ -31,16 +31,14 @@ public class HardyWeinberg extends InfoFieldAnnotation implements WorkInProgress public Map annotate(RefMetaDataTracker tracker, AnnotatorCompatibleWalker walker, ReferenceContext ref, Map stratifiedContexts, VariantContext vc) { - final GenotypeMap genotypes = vc.getGenotypes(); + final GenotypeCollection genotypes = vc.getGenotypes(); if ( genotypes == null || genotypes.size() < MIN_SAMPLES ) return null; int refCount = 0; int hetCount = 0; int homCount = 0; - for ( Map.Entry genotype : genotypes.entrySet() ) { - Genotype g = genotype.getValue(); - + for ( final Genotype g : genotypes ) { if ( g.isNoCall() ) continue; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/InbreedingCoeff.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/InbreedingCoeff.java index 9935eced9..a21d7106c 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/InbreedingCoeff.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/InbreedingCoeff.java @@ -10,7 +10,7 @@ import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.utils.codecs.vcf.VCFHeaderLineType; import org.broadinstitute.sting.utils.codecs.vcf.VCFInfoHeaderLine; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.util.Arrays; @@ -33,7 +33,7 @@ public class InbreedingCoeff extends InfoFieldAnnotation implements StandardAnno public Map annotate(RefMetaDataTracker tracker, AnnotatorCompatibleWalker walker, ReferenceContext ref, Map stratifiedContexts, VariantContext vc) { - final GenotypeMap genotypes = vc.getGenotypes(); + final GenotypeCollection genotypes = vc.getGenotypes(); if ( genotypes == null || genotypes.size() < MIN_SAMPLES ) return null; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/QualByDepth.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/QualByDepth.java index e34ef5d45..dae041155 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/QualByDepth.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/QualByDepth.java @@ -9,7 +9,7 @@ import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.StandardAnnota import org.broadinstitute.sting.utils.codecs.vcf.VCFHeaderLineType; import org.broadinstitute.sting.utils.codecs.vcf.VCFInfoHeaderLine; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.util.Arrays; @@ -29,7 +29,7 @@ public class QualByDepth extends InfoFieldAnnotation implements StandardAnnotati if ( stratifiedContexts.size() == 0 ) return null; - final GenotypeMap genotypes = vc.getGenotypes(); + final GenotypeCollection genotypes = vc.getGenotypes(); if ( genotypes == null || genotypes.size() == 0 ) return null; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/RankSumTest.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/RankSumTest.java index f75997d57..8182747f4 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/RankSumTest.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/RankSumTest.java @@ -13,7 +13,7 @@ import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.util.ArrayList; @@ -33,7 +33,7 @@ public abstract class RankSumTest extends InfoFieldAnnotation implements Standar if ( stratifiedContexts.size() == 0 ) return null; - final GenotypeMap genotypes = vc.getGenotypes(); + final GenotypeCollection genotypes = vc.getGenotypes(); if ( genotypes == null || genotypes.size() == 0 ) return null; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java index 87b1366cf..9fb25d605 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java @@ -34,7 +34,7 @@ import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.*; import org.broadinstitute.sting.utils.codecs.vcf.*; import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.util.*; @@ -217,11 +217,11 @@ public class VariantAnnotatorEngine { } } - private GenotypeMap annotateGenotypes(RefMetaDataTracker tracker, ReferenceContext ref, Map stratifiedContexts, VariantContext vc) { + private GenotypeCollection annotateGenotypes(RefMetaDataTracker tracker, ReferenceContext ref, Map stratifiedContexts, VariantContext vc) { if ( requestedGenotypeAnnotations.size() == 0 ) return vc.getGenotypes(); - GenotypeMap genotypes = GenotypeMap.create(vc.getNSamples()); + GenotypeCollection genotypes = GenotypeCollection.create(vc.getNSamples()); for ( Map.Entry g : vc.getGenotypes().entrySet() ) { Genotype genotype = g.getValue(); AlignmentContext context = stratifiedContexts.get(g.getKey()); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/BeagleOutputToVCFWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/BeagleOutputToVCFWalker.java index 352b1790e..89dd114cc 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/BeagleOutputToVCFWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/BeagleOutputToVCFWalker.java @@ -187,7 +187,7 @@ public class BeagleOutputToVCFWalker extends RodWalker { byte refByte = ref.getBase(); // make new Genotypes based on Beagle results - GenotypeMap genotypes = GenotypeMap.create(vc_input.getGenotypes().size()); + GenotypeCollection genotypes = GenotypeCollection.create(vc_input.getGenotypes().size()); // for each genotype, create a new object with Beagle information on it @@ -196,7 +196,7 @@ public class BeagleOutputToVCFWalker extends RodWalker { Double alleleFrequencyH = 0.0; int beagleVarCounts = 0; - GenotypeMap hapmapGenotypes = null; + GenotypeCollection hapmapGenotypes = null; if (vc_comp != null) { hapmapGenotypes = vc_comp.getGenotypes(); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java index 9428fd7ee..c1fbc9ac6 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java @@ -37,7 +37,7 @@ import org.broadinstitute.sting.utils.SampleUtils; import org.broadinstitute.sting.utils.codecs.vcf.*; import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import org.broadinstitute.sting.utils.variantcontext.VariantContextUtils; @@ -283,11 +283,11 @@ public class VariantFiltrationWalker extends RodWalker { VariantContext vc = context.getVariantContext(); // make new Genotypes based on filters - GenotypeMap genotypes; + GenotypeCollection genotypes; if ( genotypeFilterExps.size() == 0 ) { genotypes = null; } else { - genotypes = GenotypeMap.create(vc.getGenotypes().size()); + genotypes = GenotypeCollection.create(vc.getGenotypes().size()); // for each genotype, check filters then create a new object for ( Map.Entry genotype : vc.getGenotypes().entrySet() ) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/AlleleFrequencyCalculationModel.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/AlleleFrequencyCalculationModel.java index 2bee98879..d0f45092b 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/AlleleFrequencyCalculationModel.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/AlleleFrequencyCalculationModel.java @@ -26,17 +26,14 @@ package org.broadinstitute.sting.gatk.walkers.genotyper; import org.apache.log4j.Logger; -import org.broadinstitute.sting.gatk.contexts.ReferenceContext; -import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.utils.variantcontext.Allele; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.io.PrintStream; import java.util.List; import java.util.Map; -import java.util.Set; /** @@ -86,7 +83,7 @@ public abstract class AlleleFrequencyCalculationModel implements Cloneable { * * @return calls */ - protected abstract GenotypeMap assignGenotypes(VariantContext vc, + protected abstract GenotypeCollection assignGenotypes(VariantContext vc, double[] log10AlleleFrequencyPosteriors, int AFofMaxLikelihood); } \ No newline at end of file diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/ExactAFCalculationModel.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/ExactAFCalculationModel.java index 0e3062cfc..bb2516f7c 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/ExactAFCalculationModel.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/ExactAFCalculationModel.java @@ -26,14 +26,12 @@ package org.broadinstitute.sting.gatk.walkers.genotyper; import org.apache.log4j.Logger; -import org.broadinstitute.sting.gatk.contexts.ReferenceContext; -import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.variantcontext.Allele; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.io.PrintStream; @@ -269,14 +267,14 @@ public class ExactAFCalculationModel extends AlleleFrequencyCalculationModel { * * @return calls */ - public GenotypeMap assignGenotypes(VariantContext vc, + public GenotypeCollection assignGenotypes(VariantContext vc, double[] log10AlleleFrequencyPosteriors, int AFofMaxLikelihood) { if ( !vc.isVariant() ) throw new UserException("The VCF record passed in does not contain an ALT allele at " + vc.getChr() + ":" + vc.getStart()); - GenotypeMap GLs = vc.getGenotypes(); + GenotypeCollection GLs = vc.getGenotypes(); double[][] pathMetricArray = new double[GLs.size()+1][AFofMaxLikelihood+1]; int[][] tracebackArray = new int[GLs.size()+1][AFofMaxLikelihood+1]; @@ -343,7 +341,7 @@ public class ExactAFCalculationModel extends AlleleFrequencyCalculationModel { } } - GenotypeMap calls = GenotypeMap.create(); + GenotypeCollection calls = GenotypeCollection.create(); int startIdx = AFofMaxLikelihood; for (int k = sampleIdx; k > 0; k--) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GridSearchAFEstimation.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GridSearchAFEstimation.java index bb31045a7..48df8dcb9 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GridSearchAFEstimation.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GridSearchAFEstimation.java @@ -26,15 +26,13 @@ package org.broadinstitute.sting.gatk.walkers.genotyper; import org.apache.log4j.Logger; -import org.broadinstitute.sting.gatk.contexts.ReferenceContext; -import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.variantcontext.Allele; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.io.PrintStream; @@ -90,7 +88,7 @@ public class GridSearchAFEstimation extends AlleleFrequencyCalculationModel { * * @return calls */ - protected GenotypeMap assignGenotypes(VariantContext vc, + protected GenotypeCollection assignGenotypes(VariantContext vc, double[] log10AlleleFrequencyPosteriors, int AFofMaxLikelihood) { if ( !vc.isVariant() ) @@ -98,7 +96,7 @@ public class GridSearchAFEstimation extends AlleleFrequencyCalculationModel { Allele refAllele = vc.getReference(); Allele altAllele = vc.getAlternateAllele(0); - GenotypeMap calls = GenotypeMap.create(); + GenotypeCollection calls = GenotypeCollection.create(); // first, the potential alt calls for ( String sample : AFMatrix.getSamples() ) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UGCallVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UGCallVariants.java index c54089350..81310f15a 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UGCallVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UGCallVariants.java @@ -36,7 +36,7 @@ import org.broadinstitute.sting.utils.SampleUtils; import org.broadinstitute.sting.utils.codecs.vcf.*; import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import org.broadinstitute.sting.utils.variantcontext.VariantContextUtils; @@ -129,7 +129,7 @@ public class UGCallVariants extends RodWalker { return null; VariantContext variantVC = null; - GenotypeMap genotypes = GenotypeMap.create(); + GenotypeCollection genotypes = GenotypeCollection.create(); for ( VariantContext vc : VCs ) { if ( variantVC == null && vc.isVariant() ) variantVC = vc; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyperEngine.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyperEngine.java index 10bd7c8ae..72b88100b 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyperEngine.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyperEngine.java @@ -265,7 +265,7 @@ public class UnifiedGenotyperEngine { alleles.add(refAllele); boolean addedAltAlleles = false; - GenotypeMap genotypes = GenotypeMap.create(); + GenotypeCollection genotypes = GenotypeCollection.create(); for ( MultiallelicGenotypeLikelihoods GL : GLs.values() ) { if ( !addedAltAlleles ) { addedAltAlleles = true; @@ -354,7 +354,7 @@ public class UnifiedGenotyperEngine { } // create the genotypes - GenotypeMap genotypes = afcm.get().assignGenotypes(vc, log10AlleleFrequencyPosteriors.get(), bestAFguess); + GenotypeCollection genotypes = afcm.get().assignGenotypes(vc, log10AlleleFrequencyPosteriors.get(), bestAFguess); // print out stats if we have a writer if ( verboseWriter != null ) @@ -491,7 +491,7 @@ public class UnifiedGenotyperEngine { } // create the genotypes - GenotypeMap genotypes = afcm.get().assignGenotypes(vc, log10AlleleFrequencyPosteriors.get(), bestAFguess); + GenotypeCollection genotypes = afcm.get().assignGenotypes(vc, log10AlleleFrequencyPosteriors.get(), bestAFguess); // *** note that calculating strand bias involves overwriting data structures, so we do that last HashMap attributes = new HashMap(); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/indels/SomaticIndelDetectorWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/indels/SomaticIndelDetectorWalker.java index ee5562ba2..7425258d4 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/indels/SomaticIndelDetectorWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/indels/SomaticIndelDetectorWalker.java @@ -60,7 +60,7 @@ import org.broadinstitute.sting.utils.sam.AlignmentUtils; import org.broadinstitute.sting.utils.sam.GATKSAMRecord; import org.broadinstitute.sting.utils.variantcontext.Allele; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.io.*; @@ -1058,7 +1058,7 @@ public class SomaticIndelDetectorWalker extends ReadWalker { stop += event_length; } - GenotypeMap genotypes = GenotypeMap.create(); + GenotypeCollection genotypes = GenotypeCollection.create(); for ( String sample : normalSamples ) { @@ -1148,7 +1148,7 @@ public class SomaticIndelDetectorWalker extends ReadWalker { homRefAlleles.add( alleles.get(0)); homRefAlleles.add( alleles.get(0)); - GenotypeMap genotypes = GenotypeMap.create(); + GenotypeCollection genotypes = GenotypeCollection.create(); for ( String sample : normalSamples ) { genotypes.put(sample,new Genotype(sample, homRefN ? homRefAlleles : alleles,Genotype.NO_NEG_LOG_10PERROR,null,attrsNormal,false)); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/PhaseByTransmission.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/PhaseByTransmission.java index 6b52fcf62..b35c54f94 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/PhaseByTransmission.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/PhaseByTransmission.java @@ -293,7 +293,7 @@ public class PhaseByTransmission extends RodWalker { if (tracker != null) { VariantContext vc = tracker.getFirstValue(variantCollection.variants, context.getLocation()); - GenotypeMap genotypeMap = vc.getGenotypes(); + GenotypeCollection genotypeCollection = vc.getGenotypes(); for (Trio trio : trios) { Genotype mother = vc.getGenotype(trio.getMother()); @@ -306,12 +306,12 @@ public class PhaseByTransmission extends RodWalker { Genotype phasedFather = trioGenotypes.get(1); Genotype phasedChild = trioGenotypes.get(2); - genotypeMap.put(phasedMother.getSampleName(), phasedMother); - genotypeMap.put(phasedFather.getSampleName(), phasedFather); - genotypeMap.put(phasedChild.getSampleName(), phasedChild); + genotypeCollection.put(phasedMother.getSampleName(), phasedMother); + genotypeCollection.put(phasedFather.getSampleName(), phasedFather); + genotypeCollection.put(phasedChild.getSampleName(), phasedChild); } - VariantContext newvc = VariantContext.modifyGenotypes(vc, genotypeMap); + VariantContext newvc = VariantContext.modifyGenotypes(vc, genotypeCollection); vcfWriter.add(newvc); } diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/ReadBackedPhasingWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/ReadBackedPhasingWalker.java index 2aa96379c..132ed1582 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/ReadBackedPhasingWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/ReadBackedPhasingWalker.java @@ -352,7 +352,7 @@ public class ReadBackedPhasingWalker extends RodWalker samplePhaseStats = new TreeMap(); for (Map.Entry sampGtEntry : sampGenotypes.entrySet()) { String samp = sampGtEntry.getKey(); @@ -1123,7 +1123,7 @@ public class ReadBackedPhasingWalker extends RodWalker alleles; - private GenotypeMap genotypes; + private GenotypeCollection genotypes; private double negLog10PError; private Set filters; private Map attributes; @@ -1134,7 +1134,7 @@ public class ReadBackedPhasingWalker extends RodWalker(vc.getAttributes()); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/evaluators/GenotypePhasingEvaluator.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/evaluators/GenotypePhasingEvaluator.java index ad9ad62b3..08d62154d 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/evaluators/GenotypePhasingEvaluator.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/evaluators/GenotypePhasingEvaluator.java @@ -14,7 +14,7 @@ import org.broadinstitute.sting.gatk.walkers.varianteval.util.TableType; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.util.HashMap; @@ -92,13 +92,13 @@ public class GenotypePhasingEvaluator extends VariantEvaluator { Set allSamples = new HashSet(); - GenotypeMap compSampGenotypes = null; + GenotypeCollection compSampGenotypes = null; if (isRelevantToPhasing(comp)) { allSamples.addAll(comp.getSampleNames()); compSampGenotypes = comp.getGenotypes(); } - GenotypeMap evalSampGenotypes = null; + GenotypeCollection evalSampGenotypes = null; if (isRelevantToPhasing(eval)) { allSamples.addAll(eval.getSampleNames()); evalSampGenotypes = eval.getGenotypes(); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariants.java index 64f54e611..f87ec5d3b 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariants.java @@ -40,7 +40,7 @@ import org.broadinstitute.sting.utils.codecs.vcf.*; import org.broadinstitute.sting.utils.sam.AlignmentUtils; import org.broadinstitute.sting.utils.variantcontext.Allele; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.util.*; @@ -211,7 +211,7 @@ public class LeftAlignVariants extends RodWalker { } // create new Genotype objects - GenotypeMap newGenotypes = GenotypeMap.create(vc.getNSamples()); + GenotypeCollection newGenotypes = GenotypeCollection.create(vc.getNSamples()); for ( Map.Entry genotype : vc.getGenotypes().entrySet() ) { List newAlleles = new ArrayList(); for ( Allele allele : genotype.getValue().getAlleles() ) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariants.java index 3c5a55134..3764a9998 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariants.java @@ -24,10 +24,8 @@ package org.broadinstitute.sting.gatk.walkers.variantutils; -import org.apache.poi.hpsf.Variant; import org.broadinstitute.sting.commandline.*; import org.broadinstitute.sting.gatk.arguments.StandardVariantContextInputArgumentCollection; -import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.utils.codecs.vcf.*; import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.text.XReadLines; @@ -558,7 +556,7 @@ public class SelectVariants extends RodWalker { return (compVCs == null || compVCs.isEmpty()); // check if we find it in the variant rod - GenotypeMap genotypes = vc.getGenotypes(samples); + GenotypeCollection genotypes = vc.getGenotypes(samples); for (Genotype g : genotypes.values()) { if (sampleHasVariant(g)) { // There is a variant called (or filtered with not exclude filtered option set) that is not HomRef for at least one of the samples. diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToVCF.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToVCF.java index 7f1fc9d16..ff7fb3434 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToVCF.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToVCF.java @@ -130,7 +130,7 @@ public class VariantsToVCF extends RodWalker { // set the appropriate sample name if necessary if ( sampleName != null && vc.hasGenotypes() && vc.hasGenotype(variants.getName()) ) { Genotype g = Genotype.modifyName(vc.getGenotype(variants.getName()), sampleName); - GenotypeMap genotypes = GenotypeMap.create(1); + GenotypeCollection genotypes = GenotypeCollection.create(1); genotypes.put(sampleName, g); vc = VariantContext.modifyGenotypes(vc, genotypes); } diff --git a/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/AbstractVCFCodec.java b/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/AbstractVCFCodec.java index c285a9f68..ad14e059b 100755 --- a/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/AbstractVCFCodec.java +++ b/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/AbstractVCFCodec.java @@ -11,8 +11,7 @@ import org.broad.tribble.util.ParsingUtils; import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.variantcontext.Allele; -import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.io.*; @@ -77,7 +76,7 @@ public abstract class AbstractVCFCodec implements FeatureCodec, NameAwareCodec, * @param pos position * @return a mapping of sample name to genotype object */ - public abstract GenotypeMap createGenotypeMap(String str, List alleles, String chr, int pos); + public abstract GenotypeCollection createGenotypeMap(String str, List alleles, String chr, int pos); /** diff --git a/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCF3Codec.java b/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCF3Codec.java index fcfc0c6fc..302b93da7 100755 --- a/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCF3Codec.java +++ b/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCF3Codec.java @@ -5,11 +5,10 @@ import org.broad.tribble.readers.LineReader; import org.broad.tribble.util.ParsingUtils; import org.broadinstitute.sting.utils.variantcontext.Allele; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.util.*; @@ -119,13 +118,13 @@ public class VCF3Codec extends AbstractVCFCodec { * @param pos position * @return a mapping of sample name to genotype object */ - public GenotypeMap createGenotypeMap(String str, List alleles, String chr, int pos) { + public GenotypeCollection createGenotypeMap(String str, List alleles, String chr, int pos) { if (genotypeParts == null) genotypeParts = new String[header.getColumnCount() - NUM_STANDARD_FIELDS]; int nParts = ParsingUtils.split(str, genotypeParts, VCFConstants.FIELD_SEPARATOR_CHAR); - GenotypeMap genotypes = GenotypeMap.create(nParts); + GenotypeCollection genotypes = GenotypeCollection.create(nParts); // get the format keys int nGTKeys = ParsingUtils.split(genotypeParts[0], genotypeKeyArray, VCFConstants.GENOTYPE_FIELD_SEPARATOR_CHAR); diff --git a/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCFCodec.java b/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCFCodec.java index eefb929bb..8256c9cac 100755 --- a/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCFCodec.java +++ b/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCFCodec.java @@ -5,11 +5,10 @@ import org.broad.tribble.readers.LineReader; import org.broad.tribble.util.ParsingUtils; import org.broadinstitute.sting.utils.variantcontext.Allele; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.util.*; @@ -146,13 +145,13 @@ public class VCFCodec extends AbstractVCFCodec { * @param alleles the list of alleles * @return a mapping of sample name to genotype object */ - public GenotypeMap createGenotypeMap(String str, List alleles, String chr, int pos) { + public GenotypeCollection createGenotypeMap(String str, List alleles, String chr, int pos) { if (genotypeParts == null) genotypeParts = new String[header.getColumnCount() - NUM_STANDARD_FIELDS]; int nParts = ParsingUtils.split(str, genotypeParts, VCFConstants.FIELD_SEPARATOR_CHAR); - GenotypeMap genotypes = GenotypeMap.create(nParts); + GenotypeCollection genotypes = GenotypeCollection.create(nParts); // get the format keys int nGTKeys = ParsingUtils.split(genotypeParts[0], genotypeKeyArray, VCFConstants.GENOTYPE_FIELD_SEPARATOR_CHAR); diff --git a/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCFParser.java b/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCFParser.java index 2887c5360..86dd5d4f7 100755 --- a/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCFParser.java +++ b/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCFParser.java @@ -1,11 +1,9 @@ package org.broadinstitute.sting.utils.codecs.vcf; import org.broadinstitute.sting.utils.variantcontext.Allele; -import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import java.util.List; -import java.util.Map; /** @@ -21,6 +19,6 @@ public interface VCFParser { * @param pos position * @return a mapping of sample name to genotype object */ - public GenotypeMap createGenotypeMap(String str, List alleles, String chr, int pos); + public GenotypeCollection createGenotypeMap(String str, List alleles, String chr, int pos); } diff --git a/public/java/src/org/broadinstitute/sting/utils/gcf/GCF.java b/public/java/src/org/broadinstitute/sting/utils/gcf/GCF.java index 7f15b4f5e..9a900d734 100644 --- a/public/java/src/org/broadinstitute/sting/utils/gcf/GCF.java +++ b/public/java/src/org/broadinstitute/sting/utils/gcf/GCF.java @@ -28,7 +28,7 @@ import org.broadinstitute.sting.utils.codecs.vcf.StandardVCFWriter; import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.variantcontext.Allele; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import java.io.*; @@ -146,16 +146,16 @@ public class GCF { Map attributes = new HashMap(); attributes.put("INFO", info); Byte refPadByte = refPad == 0 ? null : refPad; - GenotypeMap genotypes = decodeGenotypes(header); + GenotypeCollection genotypes = decodeGenotypes(header); return new VariantContext(source, contig, start, stop, alleleMap, genotypes, negLog10PError, filters, attributes, refPadByte); } - private GenotypeMap decodeGenotypes(final GCFHeader header) { + private GenotypeCollection decodeGenotypes(final GCFHeader header) { if ( genotypes.isEmpty() ) return VariantContext.NO_GENOTYPES; else { - GenotypeMap map = GenotypeMap.create(); + GenotypeCollection map = GenotypeCollection.create(); for ( int i = 0; i < genotypes.size(); i++ ) { final String sampleName = header.getSample(i); diff --git a/public/java/src/org/broadinstitute/sting/utils/variantcontext/GenotypeCollection.java b/public/java/src/org/broadinstitute/sting/utils/variantcontext/GenotypeCollection.java new file mode 100644 index 000000000..a83356647 --- /dev/null +++ b/public/java/src/org/broadinstitute/sting/utils/variantcontext/GenotypeCollection.java @@ -0,0 +1,325 @@ +/* + * Copyright (c) 2011, The Broad Institute + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.broadinstitute.sting.utils.variantcontext; + +import java.util.*; + +/** + * + */ +public class GenotypeCollection implements List { + public final static GenotypeCollection NO_GENOTYPES = new GenotypeCollection(); + + Map sampleNameToOffset = null; + boolean cacheIsInvalid = true; + final ArrayList genotypes; + boolean immutable = false; + + // --------------------------------------------------------------------------- + // + // private constructors -- you have to use static create methods to make these classes + // + // --------------------------------------------------------------------------- + + private GenotypeCollection() { + this(10, false); + } + + private GenotypeCollection(final int n, final boolean immutable) { + this(new ArrayList(n), immutable); + } + + private GenotypeCollection(final ArrayList genotypes, final boolean immutable) { + this.genotypes = genotypes; + this.immutable = immutable; + } + + // --------------------------------------------------------------------------- + // + // public static factory methods + // + // --------------------------------------------------------------------------- + + public static final GenotypeCollection create() { + return new GenotypeCollection(); + } + + public static final GenotypeCollection create(final int nGenotypes) { + return new GenotypeCollection(nGenotypes, true); + } + + // todo -- differentiate between empty constructor and copy constructor + // todo -- create constructor (Genotype ... genotypes) + + public static final GenotypeCollection create(final ArrayList genotypes) { + return new GenotypeCollection(genotypes, true); + } + + public static final GenotypeCollection copy(final GenotypeCollection toCopy) { + return create(toCopy.genotypes); + } + +// public static final GenotypeMap create(final Collection genotypes) { +// if ( genotypes == null ) +// return null; // todo -- really should return an empty map +// else { +// GenotypeMap genotypeMap = new GenotypeMap(genotypes.size(), false); +// for ( final Genotype g : genotypes ) { +// if ( genotypeMap.containsKey(g.getSampleName() ) ) +// throw new IllegalArgumentException("Duplicate genotype added to VariantContext: " + g); +// genotypeMap.put(g.getSampleName(), g); +// } +// +// //return genotypeMap.immutable(); // todo enable when we have time to dive into mutability issue +// return genotypeMap; +// } +// } + + // --------------------------------------------------------------------------- + // + // Mutability methods + // + // --------------------------------------------------------------------------- + + public final GenotypeCollection mutable() { + immutable = false; + return this; + } + + public final GenotypeCollection immutable() { + immutable = true; + return this; + } + + public boolean isMutable() { + return ! immutable; + } + + public final void checkImmutability() { + if ( immutable ) + throw new IllegalAccessError("GenotypeMap is currently immutable, but a mutator method was invoked on it"); + } + + // --------------------------------------------------------------------------- + // + // caches + // + // --------------------------------------------------------------------------- + + private void invalidateCaches() { + cacheIsInvalid = true; + if ( sampleNameToOffset != null ) sampleNameToOffset.clear(); + } + + private void buildCache() { + cacheIsInvalid = false; + + if ( sampleNameToOffset == null ) + sampleNameToOffset = new HashMap(genotypes.size()); + + for ( int i = 0; i < genotypes.size(); i++ ) + sampleNameToOffset.put(genotypes.get(i).getSampleName(), i); + } + + + // --------------------------------------------------------------------------- + // + // Map methods + // + // --------------------------------------------------------------------------- + + @Override + public void clear() { + checkImmutability(); + genotypes.clear(); + } + + @Override + public int size() { + return genotypes.size(); + } + + @Override + public boolean isEmpty() { + return genotypes.isEmpty(); + } + + @Override + public boolean add(final Genotype genotype) { + checkImmutability(); + invalidateCaches(); + return genotypes.add(genotype); + } + + @Override + public void add(final int i, final Genotype genotype) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(final Collection genotypes) { + checkImmutability(); + invalidateCaches(); + return this.genotypes.addAll(genotypes); + } + + @Override + public boolean addAll(final int i, final Collection genotypes) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean contains(final Object o) { + return this.genotypes.contains(o); + } + + @Override + public boolean containsAll(final Collection objects) { + return this.genotypes.containsAll(objects); + } + + @Override + public Genotype get(final int i) { + return genotypes.get(i); + } + + public Genotype get(final String sampleName) { + buildCache(); + Integer offset = sampleNameToOffset.get(sampleName); + if ( offset == null ) + throw new IllegalArgumentException("Sample " + sampleName + " not found in this GenotypeCollection"); + return genotypes.get(offset); + } + + + @Override + public int indexOf(final Object o) { + return genotypes.indexOf(o); + } + + @Override + public Iterator iterator() { + return genotypes.iterator(); + } + + @Override + public int lastIndexOf(final Object o) { + return genotypes.lastIndexOf(o); + } + + @Override + public ListIterator listIterator() { + // todo -- must be immutable + return genotypes.listIterator(); + } + + @Override + public ListIterator listIterator(final int i) { + // todo -- must be immutable + return genotypes.listIterator(i); + } + + @Override + public Genotype remove(final int i) { + checkImmutability(); + invalidateCaches(); + return genotypes.remove(i); + } + + @Override + public boolean remove(final Object o) { + checkImmutability(); + invalidateCaches(); + return genotypes.remove(o); + } + + @Override + public boolean removeAll(final Collection objects) { + checkImmutability(); + invalidateCaches(); + return genotypes.removeAll(objects); + } + + @Override + public boolean retainAll(final Collection objects) { + checkImmutability(); + invalidateCaches(); + return genotypes.retainAll(objects); + } + + @Override + public Genotype set(final int i, final Genotype genotype) { + checkImmutability(); + invalidateCaches(); + return genotypes.set(i, genotype); + } + + @Override + public List subList(final int i, final int i1) { + return genotypes.subList(i, i1); + } + + @Override + public Object[] toArray() { + return genotypes.toArray(); + } + + @Override + public T[] toArray(final T[] ts) { + return genotypes.toArray(ts); + } + + public Iterable iterateInOrder(final Iterable sampleNamesInOrder) { + return new Iterable() { + @Override + public Iterator iterator() { + return new InOrderIterator(sampleNamesInOrder.iterator()); + } + }; + } + + private final class InOrderIterator implements Iterator { + final Iterator sampleNamesInOrder; + + private InOrderIterator(final Iterator sampleNamesInOrder) { + this.sampleNamesInOrder = sampleNamesInOrder; + } + + @Override + public boolean hasNext() { + return sampleNamesInOrder.hasNext(); + } + + @Override + public Genotype next() { + return get(sampleNamesInOrder.next()); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + } +} diff --git a/public/java/src/org/broadinstitute/sting/utils/variantcontext/GenotypeMap.java b/public/java/src/org/broadinstitute/sting/utils/variantcontext/GenotypeMap.java deleted file mode 100644 index cb7250bdb..000000000 --- a/public/java/src/org/broadinstitute/sting/utils/variantcontext/GenotypeMap.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (c) 2011, The Broad Institute - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.broadinstitute.sting.utils.variantcontext; - -import java.util.*; - -/** - * - */ -public class GenotypeMap implements Map { - final TreeMap genotypes; - boolean immutable = false; - public final static GenotypeMap NO_GENOTYPES = new GenotypeMap(); - - // --------------------------------------------------------------------------- - // - // private constructors -- you have to use static create methods to make these classes - // - // --------------------------------------------------------------------------- - - private GenotypeMap() { - this(false); - } - - private GenotypeMap(boolean immutable) { - this(new TreeMap(), immutable); - } - - private GenotypeMap(final TreeMap genotypes, final boolean immutable) { - this.genotypes = genotypes; - this.immutable = immutable; - } - - // --------------------------------------------------------------------------- - // - // public static factory methods - // - // --------------------------------------------------------------------------- - - public static final GenotypeMap create() { - return new GenotypeMap(); - } - - public static final GenotypeMap create(final int nGenotypes) { - return new GenotypeMap(); - } - - public static final GenotypeMap create(final GenotypeMap genotypes) { - return create(genotypes.values()); - } - - // todo -- differentiate between empty constructor and copy constructor - // todo -- create constructor (Genotype ... genotypes) - - public static final GenotypeMap create(final Map genotypes) { - return create(genotypes.values()); - } - - public static final GenotypeMap create(final Collection genotypes) { - if ( genotypes == null ) - return null; // todo -- really should return an empty map - else { - GenotypeMap genotypeMap = new GenotypeMap().mutable(); - for ( final Genotype g : genotypes ) { - if ( genotypeMap.containsKey(g.getSampleName() ) ) - throw new IllegalArgumentException("Duplicate genotype added to VariantContext: " + g); - genotypeMap.put(g.getSampleName(), g); - } - - //return genotypeMap.immutable(); // todo enable when we have time to dive into mutability issue - return genotypeMap; - } - } - - // --------------------------------------------------------------------------- - // - // Mutability methods - // - // --------------------------------------------------------------------------- - - public final GenotypeMap mutable() { - immutable = false; - return this; - } - - public final GenotypeMap immutable() { - immutable = true; - return this; - } - - public boolean isMutable() { - return ! immutable; - } - - public final void checkImmutability() { - if ( immutable ) - throw new IllegalAccessError("GenotypeMap is currently immutable, but a mutator method was invoked on it"); - } - - // --------------------------------------------------------------------------- - // - // Map methods - // - // --------------------------------------------------------------------------- - - @Override - public void clear() { - checkImmutability(); - genotypes.clear(); - } - - @Override - public int size() { - return genotypes.size(); - } - - @Override - public boolean isEmpty() { - return genotypes.isEmpty(); - } - - @Override - public boolean containsKey(final Object o) { - return genotypes.containsKey(o); - } - - @Override - public boolean containsValue(final Object o) { - return genotypes.containsValue(o); - } - - @Override - public Genotype get(final Object o) { - return genotypes.get(o); - } - - @Override - public Genotype put(final String s, final Genotype genotype) { - checkImmutability(); - return genotypes.put(s, genotype); - } - - @Override - public Genotype remove(final Object o) { - checkImmutability(); - return genotypes.remove(o); - } - - @Override - public void putAll(final Map map) { - checkImmutability(); - genotypes.putAll(map); - } - - @Override - public Set keySet() { - return Collections.unmodifiableSet(genotypes.keySet()); - } - - @Override - public Collection values() { - return genotypes.values(); - } - - @Override - public Set> entrySet() { - return genotypes.entrySet(); - } -} diff --git a/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantContext.java b/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantContext.java index 47b792e0b..5bd29a0ce 100755 --- a/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantContext.java +++ b/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantContext.java @@ -184,12 +184,12 @@ public class VariantContext implements Feature { // to enable tribble intergrati final protected List alleles; /** A mapping from sampleName -> genotype objects for all genotypes associated with this context */ - protected GenotypeMap genotypes = null; + protected GenotypeCollection genotypes = null; /** Counts for each of the possible Genotype types in this context */ protected int[] genotypeCounts = null; - public final static GenotypeMap NO_GENOTYPES = GenotypeMap.NO_GENOTYPES; + public final static GenotypeCollection NO_GENOTYPES = GenotypeCollection.NO_GENOTYPES; // a fast cached access point to the ref / alt alleles for biallelic case private Allele REF = null; @@ -222,7 +222,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati * @param attributes attributes * @param referenceBaseForIndel padded reference base */ - public VariantContext(String source, String contig, long start, long stop, Collection alleles, GenotypeMap genotypes, double negLog10PError, Set filters, Map attributes, Byte referenceBaseForIndel) { + public VariantContext(String source, String contig, long start, long stop, Collection alleles, GenotypeCollection genotypes, double negLog10PError, Set filters, Map attributes, Byte referenceBaseForIndel) { this(source, contig, start, stop, alleles, genotypes, negLog10PError, filters, attributes, referenceBaseForIndel, false); } @@ -239,7 +239,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati * @param filters filters: use null for unfiltered and empty set for passes filters * @param attributes attributes */ - public VariantContext(String source, String contig, long start, long stop, Collection alleles, GenotypeMap genotypes, double negLog10PError, Set filters, Map attributes) { + public VariantContext(String source, String contig, long start, long stop, Collection alleles, GenotypeCollection genotypes, double negLog10PError, Set filters, Map attributes) { this(source, contig, start, stop, alleles, genotypes, negLog10PError, filters, attributes, null, false); } @@ -279,7 +279,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati */ public VariantContext(String source, String contig, long start, long stop, Collection alleles, Collection genotypes, double negLog10PError, Set filters, Map attributes) { this(source, contig, start, stop, alleles, - GenotypeMap.create(genotypes), + GenotypeCollection.create(genotypes), negLog10PError, filters, attributes, null, false); } @@ -335,7 +335,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati * @param genotypesAreUnparsed true if the genotypes have not yet been parsed */ private VariantContext(String source, String contig, long start, long stop, - Collection alleles, GenotypeMap genotypes, + Collection alleles, GenotypeCollection genotypes, double negLog10PError, Set filters, Map attributes, Byte referenceBaseForIndel, boolean genotypesAreUnparsed) { if ( contig == null ) { throw new IllegalArgumentException("Contig cannot be null"); } @@ -383,7 +383,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati // // --------------------------------------------------------------------------------------------------------- - public static VariantContext modifyGenotypes(VariantContext vc, GenotypeMap genotypes) { + public static VariantContext modifyGenotypes(VariantContext vc, GenotypeCollection genotypes) { return new VariantContext(vc.getSource(), vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles(), genotypes, vc.getNegLog10PError(), vc.filtersWereApplied() ? vc.getFilters() : null, new HashMap(vc.getAttributes()), vc.getReferenceBaseForIndel(), false); } @@ -458,7 +458,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati */ public VariantContext subContextFromGenotypes(Collection genotypes, Collection alleles) { return new VariantContext(getSource(), contig, start, stop, alleles, - GenotypeMap.create(genotypes), + GenotypeCollection.create(genotypes), getNegLog10PError(), filtersWereApplied() ? getFilters() : null, getAttributes(), @@ -890,7 +890,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati /** * @return set of all Genotypes associated with this context */ - public GenotypeMap getGenotypes() { + public GenotypeCollection getGenotypes() { loadGenotypes(); return genotypes; } @@ -909,7 +909,7 @@ public class VariantContext implements Feature { // to enable tribble intergrati * @return * @throws IllegalArgumentException if sampleName isn't bound to a genotype */ - public GenotypeMap getGenotypes(String sampleName) { + public GenotypeCollection getGenotypes(String sampleName) { return getGenotypes(Arrays.asList(sampleName)); } @@ -921,8 +921,8 @@ public class VariantContext implements Feature { // to enable tribble intergrati * @return * @throws IllegalArgumentException if sampleName isn't bound to a genotype */ - public GenotypeMap getGenotypes(Collection sampleNames) { - GenotypeMap map = GenotypeMap.create(sampleNames.size()); + public GenotypeCollection getGenotypes(Collection sampleNames) { + GenotypeCollection map = GenotypeCollection.create(sampleNames.size()); for ( String name : sampleNames ) { if ( map.containsKey(name) ) throw new IllegalArgumentException("Duplicate names detected in requested samples " + sampleNames); @@ -1465,8 +1465,8 @@ public class VariantContext implements Feature { // to enable tribble intergrati Byte refByte = inputVC.getReferenceBaseForIndel(); List alleles = new ArrayList(); - GenotypeMap genotypes = GenotypeMap.create(); - GenotypeMap inputGenotypes = inputVC.getGenotypes(); + GenotypeCollection genotypes = GenotypeCollection.create(); + GenotypeCollection inputGenotypes = inputVC.getGenotypes(); for (Allele a : inputVC.getAlleles()) { // get bases for current allele and create a new one with trimmed bases 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 37d8acbe2..89db22bd6 100755 --- a/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantContextUtils.java +++ b/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantContextUtils.java @@ -70,7 +70,7 @@ public class VariantContextUtils { * @return VariantContext object */ public static VariantContext toVC(String name, GenomeLoc loc, Collection alleles, Collection genotypes, double negLog10PError, Set filters, Map attributes) { - return new VariantContext(name, loc.getContig(), loc.getStart(), loc.getStop(), alleles, GenotypeMap.create(genotypes), negLog10PError, filters, attributes); + return new VariantContext(name, loc.getContig(), loc.getStart(), loc.getStop(), alleles, GenotypeCollection.create(genotypes), negLog10PError, filters, attributes); } /** @@ -350,7 +350,7 @@ public class VariantContextUtils { if ( vc.hasID() ) attributes.put(VariantContext.ID_KEY, vc.getID()); // Genotypes - final GenotypeMap genotypes = GenotypeMap.create(vc.getNSamples()); + final GenotypeCollection genotypes = GenotypeCollection.create(vc.getNSamples()); for ( final Genotype g : vc.getGenotypes().values() ) { Map genotypeAttributes = subsetAttributes(g.commonInfo, keysToPreserve); genotypes.put(g.getSampleName(), @@ -458,7 +458,7 @@ public class VariantContextUtils { final Map attributesWithMaxAC = new TreeMap(); double negLog10PError = -1; VariantContext vcWithMaxAC = null; - GenotypeMap genotypes = GenotypeMap.create(); + GenotypeCollection genotypes = GenotypeCollection.create(); // counting the number of filtered and variant VCs int nFiltered = 0; @@ -648,7 +648,7 @@ public class VariantContextUtils { // nothing to do if we don't need to trim bases if (trimVC) { List alleles = new ArrayList(); - GenotypeMap genotypes = GenotypeMap.create(); + GenotypeCollection genotypes = GenotypeCollection.create(); // set the reference base for indels in the attributes Map attributes = new TreeMap(inputVC.getAttributes()); @@ -702,8 +702,8 @@ public class VariantContextUtils { return inputVC; } - public static GenotypeMap stripPLs(GenotypeMap genotypes) { - GenotypeMap newGs = GenotypeMap.create(genotypes.size()); + public static GenotypeCollection stripPLs(GenotypeCollection genotypes) { + GenotypeCollection newGs = GenotypeCollection.create(genotypes.size()); for ( Map.Entry g : genotypes.entrySet() ) { newGs.put(g.getKey(), g.getValue().hasLikelihoods() ? removePLs(g.getValue()) : g.getValue()); @@ -883,7 +883,7 @@ public class VariantContextUtils { } } - private static void mergeGenotypes(GenotypeMap mergedGenotypes, VariantContext oneVC, AlleleMapper alleleMapping, boolean uniqifySamples) { + private static void mergeGenotypes(GenotypeCollection mergedGenotypes, VariantContext oneVC, AlleleMapper alleleMapping, boolean uniqifySamples) { for ( Genotype g : oneVC.getGenotypes().values() ) { String name = mergedSampleName(oneVC.getSource(), g.getSampleName(), uniqifySamples); if ( ! mergedGenotypes.containsKey(name) ) { @@ -923,7 +923,7 @@ public class VariantContextUtils { } // create new Genotype objects - GenotypeMap newGenotypes = GenotypeMap.create(vc.getNSamples()); + GenotypeCollection newGenotypes = GenotypeCollection.create(vc.getNSamples()); for ( Map.Entry genotype : vc.getGenotypes().entrySet() ) { List newAlleles = new ArrayList(); for ( Allele allele : genotype.getValue().getAlleles() ) { @@ -943,7 +943,7 @@ public class VariantContextUtils { if ( allowedAttributes == null ) return vc; - GenotypeMap newGenotypes = GenotypeMap.create(vc.getNSamples()); + GenotypeCollection newGenotypes = GenotypeCollection.create(vc.getNSamples()); for ( Map.Entry genotype : vc.getGenotypes().entrySet() ) { Map attrs = new HashMap(); for ( Map.Entry attr : genotype.getValue().getAttributes().entrySet() ) { @@ -1022,7 +1022,7 @@ public class VariantContextUtils { } MergedAllelesData mergeData = new MergedAllelesData(intermediateBases, vc1, vc2); // ensures that the reference allele is added - GenotypeMap mergedGenotypes = GenotypeMap.create(); + GenotypeCollection mergedGenotypes = GenotypeCollection.create(); for (Map.Entry gt1Entry : vc1.getGenotypes().entrySet()) { String sample = gt1Entry.getKey(); Genotype gt1 = gt1Entry.getValue(); diff --git a/public/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java b/public/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java index b658da1d3..d698d12a3 100644 --- a/public/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java +++ b/public/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java @@ -4,7 +4,7 @@ import org.broad.tribble.Tribble; import org.broad.tribble.readers.AsciiLineReader; import org.broadinstitute.sting.utils.variantcontext.Allele; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.GenotypeMap; +import org.broadinstitute.sting.utils.variantcontext.GenotypeCollection; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import org.broadinstitute.sting.utils.codecs.vcf.*; import org.broadinstitute.sting.utils.exceptions.UserException; @@ -122,7 +122,7 @@ public class VCFWriterUnitTest extends BaseTest { List alleles = new ArrayList(); Set filters = null; Map attributes = new HashMap(); - GenotypeMap genotypes = GenotypeMap.create(); + GenotypeCollection genotypes = GenotypeCollection.create(); alleles.add(Allele.create("-",true)); alleles.add(Allele.create("CC",false)); diff --git a/public/java/test/org/broadinstitute/sting/utils/variantcontext/VariantContextUtilsUnitTest.java b/public/java/test/org/broadinstitute/sting/utils/variantcontext/VariantContextUtilsUnitTest.java index 48ddb7efc..f5e485587 100644 --- a/public/java/test/org/broadinstitute/sting/utils/variantcontext/VariantContextUtilsUnitTest.java +++ b/public/java/test/org/broadinstitute/sting/utils/variantcontext/VariantContextUtilsUnitTest.java @@ -99,7 +99,7 @@ public class VariantContextUtilsUnitTest extends BaseTest { int start = 10; int stop = start; // alleles.contains(ATC) ? start + 3 : start; return new VariantContext(source, "1", start, stop, alleles, - GenotypeMap.create(genotypes), 1.0, filters, null, Cref.getBases()[0]); + GenotypeCollection.create(genotypes), 1.0, filters, null, Cref.getBases()[0]); } // --------------------------------------------------------------------------------