diff --git a/java/src/org/broadinstitute/sting/gatk/filters/BadMateFilter.java b/java/src/org/broadinstitute/sting/gatk/filters/BadMateFilter.java index 15f1f4846..43dc6a6de 100755 --- a/java/src/org/broadinstitute/sting/gatk/filters/BadMateFilter.java +++ b/java/src/org/broadinstitute/sting/gatk/filters/BadMateFilter.java @@ -37,6 +37,11 @@ import net.sf.samtools.SAMRecord; public class BadMateFilter implements SamRecordFilter { public boolean filterOut(final SAMRecord rec) { - return (rec.getReadPairedFlag() && !rec.getMateUnmappedFlag() && rec.getMateReferenceIndex() != rec.getReferenceIndex()); + return hasBadMate(rec); } + + public static boolean hasBadMate(final SAMRecord rec) { + return (rec.getReadPairedFlag() && !rec.getMateUnmappedFlag() && !rec.getReferenceIndex().equals(rec.getMateReferenceIndex())); + } + } \ No newline at end of file diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthOfCoverage.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthOfCoverage.java index 3f5190bdf..43afe2db3 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthOfCoverage.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthOfCoverage.java @@ -22,8 +22,8 @@ public class DepthOfCoverage implements InfoFieldAnnotation, StandardAnnotation return null; int depth = 0; - for ( String sample : stratifiedContexts.keySet() ) - depth += stratifiedContexts.get(sample).getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE).size(); + for ( Map.Entry sample : stratifiedContexts.entrySet() ) + depth += sample.getValue().getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE).size(); Map map = new HashMap(); map.put(getKeyNames().get(0), String.format("%d", depth)); return map; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HaplotypeScore.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HaplotypeScore.java index 719ab8fe0..763401fac 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HaplotypeScore.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HaplotypeScore.java @@ -237,7 +237,7 @@ public class HaplotypeScore implements InfoFieldAnnotation, StandardAnnotation { public String toString() { return new String(this.bases); } } - private class BaseQual extends Pair { + private static class BaseQual extends Pair { public BaseQual(byte base, byte qual) { super(base, qual); } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/LowMQ.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/LowMQ.java index fcd87c3ec..f10b2f70b 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/LowMQ.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/LowMQ.java @@ -25,9 +25,9 @@ public class LowMQ implements InfoFieldAnnotation { double mq0 = 0; double mq10 = 0; double total = 0; - for ( String sample : stratifiedContexts.keySet() ) + for ( Map.Entry sample : stratifiedContexts.entrySet() ) { - ReadBackedPileup pileup = stratifiedContexts.get(sample).getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE).getBasePileup(); + ReadBackedPileup pileup = sample.getValue().getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE).getBasePileup(); for (PileupElement p : pileup ) { if ( p.getMappingQual() == 0 ) { mq0 += 1; } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/MappingQualityZero.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/MappingQualityZero.java index a7ee2ae2b..555d8823b 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/MappingQualityZero.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/MappingQualityZero.java @@ -24,8 +24,8 @@ public class MappingQualityZero implements InfoFieldAnnotation, StandardAnnotati return null; int mq0 = 0; - for ( String sample : stratifiedContexts.keySet() ) { - ReadBackedPileup pileup = stratifiedContexts.get(sample).getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE).getBasePileup(); + for ( Map.Entry sample : stratifiedContexts.entrySet() ) { + ReadBackedPileup pileup = sample.getValue().getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE).getBasePileup(); for (PileupElement p : pileup ) { if ( p.getMappingQual() == 0 ) mq0++; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/RMSMappingQuality.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/RMSMappingQuality.java index bf3c98116..433713faa 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/RMSMappingQuality.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/RMSMappingQuality.java @@ -23,8 +23,8 @@ public class RMSMappingQuality implements InfoFieldAnnotation, StandardAnnotatio return null; ArrayList qualities = new ArrayList(); - for ( String sample : stratifiedContexts.keySet() ) { - ReadBackedPileup pileup = stratifiedContexts.get(sample).getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE).getBasePileup(); + for ( Map.Entry sample : stratifiedContexts.entrySet() ) { + ReadBackedPileup pileup = sample.getValue().getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE).getBasePileup(); for (PileupElement p : pileup ) qualities.add(p.getRead().getMappingQuality()); } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/SpanningDeletions.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/SpanningDeletions.java index 49c5bb533..e40f7df8e 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/SpanningDeletions.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/SpanningDeletions.java @@ -24,8 +24,8 @@ public class SpanningDeletions implements InfoFieldAnnotation, StandardAnnotatio int deletions = 0; int depth = 0; - for ( String sample : stratifiedContexts.keySet() ) { - ReadBackedPileup pileup = stratifiedContexts.get(sample).getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE).getBasePileup(); + for ( Map.Entry sample : stratifiedContexts.entrySet() ) { + ReadBackedPileup pileup = sample.getValue().getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE).getBasePileup(); deletions += pileup.getNumberOfDeletions(); depth += pileup.size(); } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/DiploidGenotypeCalculationModel.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/DiploidGenotypeCalculationModel.java index 7a9b609fc..53d3e6607 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/DiploidGenotypeCalculationModel.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/DiploidGenotypeCalculationModel.java @@ -69,15 +69,14 @@ public class DiploidGenotypeCalculationModel extends JointEstimateGenotypeCalcul // use flat priors for GLs DiploidGenotypePriors priors = new DiploidGenotypePriors(); - for ( String sample : contexts.keySet() ) { - StratifiedAlignmentContext context = contexts.get(sample); - ReadBackedPileup pileup = context.getContext(contextType).getBasePileup(); + for ( Map.Entry sample : contexts.entrySet() ) { + ReadBackedPileup pileup = sample.getValue().getContext(contextType).getBasePileup(); // create the GenotypeLikelihoods object GenotypeLikelihoods GL = new GenotypeLikelihoods(UAC.baseModel, priors, UAC.defaultPlatform); GL.add(pileup, true, UAC.CAP_BASE_QUALITY); - GLs.put(sample, GL); + GLs.put(sample.getKey(), GL); double[] posteriors = GL.getPosteriors(); @@ -87,7 +86,7 @@ public class DiploidGenotypeCalculationModel extends JointEstimateGenotypeCalcul if ( alt != ref ) { DiploidGenotype hetGenotype = DiploidGenotype.createDiploidGenotype(ref, alt); DiploidGenotype homGenotype = DiploidGenotype.createHomGenotype(alt); - AFMatrixMap.get(alt).setLikelihoods(posteriors[refGenotype.ordinal()], posteriors[hetGenotype.ordinal()], posteriors[homGenotype.ordinal()], sample); + AFMatrixMap.get(alt).setLikelihoods(posteriors[refGenotype.ordinal()], posteriors[hetGenotype.ordinal()], posteriors[homGenotype.ordinal()], sample.getKey()); } } } @@ -171,7 +170,7 @@ public class DiploidGenotypeCalculationModel extends JointEstimateGenotypeCalcul } - protected class AlleleFrequencyMatrix { + protected static class AlleleFrequencyMatrix { private double[][] matrix; // allele frequency matrix private int[] indexes; // matrix to maintain which genotype is active diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/DiploidGenotypePriors.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/DiploidGenotypePriors.java index cce076d92..9c6bf62a9 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/DiploidGenotypePriors.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/DiploidGenotypePriors.java @@ -57,7 +57,7 @@ public class DiploidGenotypePriors { private double[] priors = null; // todo -- fix me when this issue is resolved - public static boolean RequirePriorSumToOne = false; + public static final boolean requirePriorSumToOne = false; /** * Create a new DiploidGenotypePriors object with flat priors for each diploid genotype @@ -124,7 +124,7 @@ public class DiploidGenotypePriors { public boolean validate(boolean throwException) { try { - if ( RequirePriorSumToOne && MathUtils.compareDoubles(MathUtils.sumLog10(priors), 1.0) != 0 ) { + if ( requirePriorSumToOne && MathUtils.compareDoubles(MathUtils.sumLog10(priors), 1.0) != 0 ) { throw new IllegalStateException(String.format("Priors don't sum to 1: sum=%f %s", MathUtils.sumLog10(priors), Arrays.toString(priors))); } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/EmpiricalSubstitutionProbabilities.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/EmpiricalSubstitutionProbabilities.java index cc4773688..b0d74695b 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/EmpiricalSubstitutionProbabilities.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/EmpiricalSubstitutionProbabilities.java @@ -101,7 +101,7 @@ public class EmpiricalSubstitutionProbabilities extends FourBaseProbabilities { double logP = log10pTrueGivenMiscall.get(pl)[i][j]; if ( logP == 0.0 ) - throw new RuntimeException(String.format("Bad miscall base request miscalled=%c true=%b", miscalledBase, trueBase)); + throw new RuntimeException(String.format("Bad miscall base request miscalled=%c true=%c", miscalledBase, trueBase)); else return logP; } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/FourBaseProbabilitiesFactory.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/FourBaseProbabilitiesFactory.java index 5b427c423..3031d69a5 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/FourBaseProbabilitiesFactory.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/FourBaseProbabilitiesFactory.java @@ -6,11 +6,7 @@ public class FourBaseProbabilitiesFactory { //private FourBaseProbabilitiesFactory() {} // cannot be instantiated public static BaseMismatchModel getBaseMismatchModel(final String name) { - BaseMismatchModel m = valueOf(name); - if ( m == null ) - throw new RuntimeException("Unexpected BaseMismatchModel " + name); - else - return m; + return valueOf(name); } public static BaseMismatchModel getBaseMismatchModel(final FourBaseProbabilities m) { diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypeCalculationModelFactory.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypeCalculationModelFactory.java index d66d45266..cbc6950e4 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypeCalculationModelFactory.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypeCalculationModelFactory.java @@ -37,11 +37,7 @@ public class GenotypeCalculationModelFactory { //private GenotypeCalculationModelFactory() {} // cannot be instantiated public static GenotypeCalculationModel.Model getGenotypeCalculationModel(final String name) { - GenotypeCalculationModel.Model m = valueOf(name); - if ( m == null ) - throw new RuntimeException("Unexpected GenotypeCalculationModel " + name); - else - return m; + return valueOf(name); } /** diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypeLikelihoods.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypeLikelihoods.java index f9b280ba8..04cec3f8a 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypeLikelihoods.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypeLikelihoods.java @@ -499,7 +499,7 @@ public class GenotypeLikelihoods implements Cloneable { // // Constant static data // - protected final static double[] zeros = new double[DiploidGenotype.values().length]; + final static double[] zeros = new double[DiploidGenotype.values().length]; static { for ( DiploidGenotype g : DiploidGenotype.values() ) { diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/JointEstimateGenotypeCalculationModel.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/JointEstimateGenotypeCalculationModel.java index e44bfea8b..101cd1ea9 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/JointEstimateGenotypeCalculationModel.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/JointEstimateGenotypeCalculationModel.java @@ -13,8 +13,8 @@ public abstract class JointEstimateGenotypeCalculationModel extends GenotypeCalc // for use in optimizing the P(D|AF) calculations: // how much off from the max likelihoods do we need to be before we can quit calculating? - protected static final Double LOG10_OPTIMIZATION_EPSILON = 8.0; - protected static final Double VALUE_NOT_CALCULATED = -1.0 * Double.MAX_VALUE; + protected static final double LOG10_OPTIMIZATION_EPSILON = 8.0; + protected static final double VALUE_NOT_CALCULATED = -1.0 * Double.MAX_VALUE; private int minAlleleFrequencyToTest; // because the null allele frequencies are constant for a given N, @@ -107,11 +107,9 @@ public abstract class JointEstimateGenotypeCalculationModel extends GenotypeCalc protected void initializeBestAlternateAllele(byte ref, Map contexts) { int[] qualCounts = new int[4]; - for ( String sample : contexts.keySet() ) { - AlignmentContext context = contexts.get(sample).getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE); - + for ( Map.Entry sample : contexts.entrySet() ) { // calculate the sum of quality scores for each base - ReadBackedPileup pileup = context.getBasePileup(); + ReadBackedPileup pileup = sample.getValue().getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE).getBasePileup(); for ( PileupElement p : pileup ) { // ignore deletions if ( p.isDeletion() ) @@ -409,7 +407,7 @@ public abstract class JointEstimateGenotypeCalculationModel extends GenotypeCalc strandScore *= 10.0; //logger.debug(String.format("SLOD=%f", strandScore)); - attributes.put("SB", new Double(strandScore)); + attributes.put("SB", Double.valueOf(strandScore)); } VariantContext vc = new VariantContext("UG_SNP_call", loc, alleles, genotypes, phredScaledConfidence/10.0, passesCallThreshold(phredScaledConfidence) ? null : filter, attributes); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/SimpleIndelCalculationModel.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/SimpleIndelCalculationModel.java index 35db3ea45..4c61f38c3 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/SimpleIndelCalculationModel.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/SimpleIndelCalculationModel.java @@ -92,8 +92,8 @@ public class SimpleIndelCalculationModel extends GenotypeCalculationModel { protected void initializeAlleles(byte[] ref, Map contexts) { - for ( String sample : contexts.keySet() ) { - AlignmentContext context = contexts.get(sample).getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE); + for ( Map.Entry sample : contexts.entrySet() ) { + AlignmentContext context = sample.getValue().getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE); totalCoverage += context.size(); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java index 3a25f3678..85e82bf5c 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java @@ -82,7 +82,7 @@ public class UnifiedGenotyper extends LocusWalker { read.getReadFailsVendorQualityCheckFlag() || read.getMappingQuality() == 0 || read.getAlignmentStart() == SAMRecord.NO_ALIGNMENT_START || - (!REALIGN_BADLY_MATED_READS && read.getReadPairedFlag() && !read.getMateUnmappedFlag() && read.getMateReferenceIndex() != read.getReferenceIndex()); + (!REALIGN_BADLY_MATED_READS && BadMateFilter.hasBadMate(read)); } private void cleanAndCallMap(ReferenceContext ref, SAMRecord read, ReadMetaDataTracker metaDataTracker, GenomeLoc readLoc) { @@ -510,7 +511,9 @@ public class IndelRealigner extends ReadWalker { statsOutput.write(Double.toString(improvement)); statsOutput.write("\n"); statsOutput.flush(); - } catch (Exception e) {} + } catch (Exception e) { + throw new StingException(e.getMessage()); + } } } else { //logger.debug("CLEAN: " + bestConsensus.cigar + " " + bestConsensus.str.toString() + " " + bestConsensus.cigar.numCigarElements() ); @@ -535,7 +538,9 @@ public class IndelRealigner extends ReadWalker { try { indelOutput.write(str.toString()); indelOutput.flush(); - } catch (Exception e) {} + } catch (Exception e) { + throw new StingException(e.getMessage()); + } } if ( statsOutput != null ) { try { @@ -547,7 +552,9 @@ public class IndelRealigner extends ReadWalker { statsOutput.write(Double.toString(improvement)); statsOutput.write("\n"); statsOutput.flush(); - } catch (Exception e) {} + } catch (Exception e) { + throw new StingException(e.getMessage()); + } } // finish cleaning the appropriate reads @@ -571,7 +578,9 @@ public class IndelRealigner extends ReadWalker { statsOutput.write(String.format("%s\tFAIL\t%.1f%n", readsToClean.getLocation().toString(), improvement)); statsOutput.flush(); - } catch (Exception e) {} + } catch (Exception e) { + throw new StingException(e.getMessage()); + } } } @@ -999,7 +1008,9 @@ public class IndelRealigner extends ReadWalker { try { snpsOutput.write(sb.toString()); snpsOutput.flush(); - } catch (Exception e) {} + } catch (Exception e) { + throw new StingException(e.getMessage()); + } } return reduces; } @@ -1200,7 +1211,7 @@ public class IndelRealigner extends ReadWalker { } } - private class Consensus { + private static class Consensus { public final byte[] str; public final ArrayList> readIndexes; public final int positionOnReference; @@ -1230,7 +1241,7 @@ public class IndelRealigner extends ReadWalker { } } - private class ReadBin { + private static class ReadBin { private final ArrayList reads = new ArrayList(); private byte[] reference = null; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java b/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java index 773965643..5bbed58c7 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java @@ -25,12 +25,12 @@ package org.broadinstitute.sting.gatk.walkers.indels; -import net.sf.samtools.SAMRecord; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContext; import org.broadinstitute.sting.gatk.filters.Platform454Filter; import org.broadinstitute.sting.gatk.filters.ZeroMappingQualityReadFilter; +import org.broadinstitute.sting.gatk.filters.BadMateFilter; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.utils.GenomeLoc; @@ -91,7 +91,7 @@ public class RealignerTargetCreator extends RodWalker 0 ) { hasIndel = hasInsertion = true; @@ -119,6 +119,8 @@ public class RealignerTargetCreator extends RodWalker