diff --git a/ivy.xml b/ivy.xml
index b7ca65406..1802c1627 100644
--- a/ivy.xml
+++ b/ivy.xml
@@ -61,6 +61,7 @@
+
@@ -82,7 +83,7 @@
-
+
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/downsampling/AlleleBiasedDownsamplingUtils.java b/protected/java/src/org/broadinstitute/sting/gatk/downsampling/AlleleBiasedDownsamplingUtils.java
index a7bb58d0c..02821ab50 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/downsampling/AlleleBiasedDownsamplingUtils.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/downsampling/AlleleBiasedDownsamplingUtils.java
@@ -47,7 +47,6 @@
package org.broadinstitute.sting.gatk.downsampling;
import net.sf.samtools.SAMReadGroupRecord;
-import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.utils.*;
import org.broadinstitute.sting.utils.pileup.*;
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
@@ -78,30 +77,15 @@ public class AlleleBiasedDownsamplingUtils {
for ( int i = 0; i < 4; i++ )
alleleStratifiedElements[i] = new ArrayList();
- // keep all of the reduced reads
- final ArrayList reducedReadPileups = new ArrayList();
-
// start by stratifying the reads by the alleles they represent at this position
- for( final PileupElement pe : pileup ) {
+ for ( final PileupElement pe : pileup ) {
// we do not want to remove a reduced read
- if ( pe.getRead().isReducedRead() )
- reducedReadPileups.add(pe);
-
- final int baseIndex = BaseUtils.simpleBaseToBaseIndex(pe.getBase());
- if ( baseIndex != -1 )
- alleleStratifiedElements[baseIndex].add(pe);
- }
-
- // Unfortunately, we need to maintain the original pileup ordering of reads or FragmentUtils will complain later.
- int numReadsToRemove = (int)(pileup.getNumberOfElements() * downsamplingFraction); // floor
- final TreeSet elementsToKeep = new TreeSet(new Comparator() {
- @Override
- public int compare(PileupElement element1, PileupElement element2) {
- final int difference = element1.getRead().getAlignmentStart() - element2.getRead().getAlignmentStart();
- return difference != 0 ? difference : element1.getRead().getReadName().compareTo(element2.getRead().getReadName());
+ if ( !pe.getRead().isReducedRead() ) {
+ final int baseIndex = BaseUtils.simpleBaseToBaseIndex(pe.getBase());
+ if ( baseIndex != -1 )
+ alleleStratifiedElements[baseIndex].add(pe);
}
- });
- elementsToKeep.addAll(reducedReadPileups);
+ }
// make a listing of allele counts
final int[] alleleCounts = new int[4];
@@ -109,22 +93,30 @@ public class AlleleBiasedDownsamplingUtils {
alleleCounts[i] = alleleStratifiedElements[i].size();
// do smart down-sampling
+ int numReadsToRemove = (int)(pileup.getNumberOfElements() * downsamplingFraction); // floor
final int[] targetAlleleCounts = runSmartDownsampling(alleleCounts, numReadsToRemove);
+ final HashSet readsToRemove = new HashSet(numReadsToRemove);
for ( int i = 0; i < 4; i++ ) {
final ArrayList alleleList = alleleStratifiedElements[i];
- // if we don't need to remove any reads, keep them all
- if ( alleleList.size() <= targetAlleleCounts[i] )
- elementsToKeep.addAll(alleleList);
- else
- elementsToKeep.addAll(downsampleElements(alleleList, alleleList.size() - targetAlleleCounts[i], log));
+ // if we don't need to remove any reads, then don't
+ if ( alleleList.size() > targetAlleleCounts[i] )
+ readsToRemove.addAll(downsampleElements(alleleList, alleleList.size() - targetAlleleCounts[i], log));
}
// clean up pointers so memory can be garbage collected if needed
for ( int i = 0; i < 4; i++ )
alleleStratifiedElements[i].clear();
- return new ReadBackedPileupImpl(pileup.getLocation(), new ArrayList(elementsToKeep));
+ // we need to keep the reads sorted because the FragmentUtils code will expect them in coordinate order and will fail otherwise
+ final List readsToKeep = new ArrayList(pileup.getNumberOfElements() - numReadsToRemove);
+ for ( final PileupElement pe : pileup ) {
+ if ( !readsToRemove.contains(pe) ) {
+ readsToKeep.add(pe);
+ }
+ }
+
+ return new ReadBackedPileupImpl(pileup.getLocation(), new ArrayList(readsToKeep));
}
private static int scoreAlleleCounts(final int[] alleleCounts) {
@@ -188,37 +180,43 @@ public class AlleleBiasedDownsamplingUtils {
}
/**
- * Performs allele biased down-sampling on a pileup and computes the list of elements to keep
+ * Performs allele biased down-sampling on a pileup and computes the list of elements to remove
*
* @param elements original list of records
* @param numElementsToRemove the number of records to remove
* @param log logging output
- * @return the list of pileup elements TO KEEP
+ * @return the list of pileup elements TO REMOVE
*/
- private static List downsampleElements(final ArrayList elements, final int numElementsToRemove, final PrintStream log) {
- if ( numElementsToRemove == 0 )
- return elements;
+ private static List downsampleElements(final List elements, final int numElementsToRemove, final PrintStream log) {
+ ArrayList elementsToRemove = new ArrayList(numElementsToRemove);
+ // are there no elements to remove?
+ if ( numElementsToRemove == 0 )
+ return elementsToRemove;
+
+ // should we remove all of the elements?
final int pileupSize = elements.size();
if ( numElementsToRemove == pileupSize ) {
logAllElements(elements, log);
- return new ArrayList(0);
+ elementsToRemove.addAll(elements);
+ return elementsToRemove;
}
+ // create a bitset describing which elements to remove
final BitSet itemsToRemove = new BitSet(pileupSize);
for ( Integer selectedIndex : MathUtils.sampleIndicesWithoutReplacement(pileupSize, numElementsToRemove) ) {
itemsToRemove.set(selectedIndex);
}
- ArrayList elementsToKeep = new ArrayList(pileupSize - numElementsToRemove);
for ( int i = 0; i < pileupSize; i++ ) {
- if ( itemsToRemove.get(i) )
- logRead(elements.get(i).getRead(), log);
- else
- elementsToKeep.add(elements.get(i));
+ if ( itemsToRemove.get(i) ) {
+ final T element = elements.get(i);
+ logElement(element, log);
+ elementsToRemove.add(element);
+ }
}
- return elementsToKeep;
+ return elementsToRemove;
}
/**
@@ -252,65 +250,30 @@ public class AlleleBiasedDownsamplingUtils {
final List alleleBin = alleleReadMap.get(alleles.get(i));
if ( alleleBin.size() > targetAlleleCounts[i] ) {
- readsToRemove.addAll(downsampleReads(alleleBin, alleleBin.size() - targetAlleleCounts[i], log));
+ readsToRemove.addAll(downsampleElements(alleleBin, alleleBin.size() - targetAlleleCounts[i], log));
}
}
return readsToRemove;
}
- /**
- * Performs allele biased down-sampling on a pileup and computes the list of elements to remove
- *
- * @param reads original list of records
- * @param numElementsToRemove the number of records to remove
- * @param log logging output
- * @return the list of pileup elements TO REMOVE
- */
- private static List downsampleReads(final List reads, final int numElementsToRemove, final PrintStream log) {
- final ArrayList readsToRemove = new ArrayList(numElementsToRemove);
-
- if ( numElementsToRemove == 0 )
- return readsToRemove;
-
- final int pileupSize = reads.size();
- if ( numElementsToRemove == pileupSize ) {
- logAllReads(reads, log);
- return reads;
- }
-
- final BitSet itemsToRemove = new BitSet(pileupSize);
- for ( Integer selectedIndex : MathUtils.sampleIndicesWithoutReplacement(pileupSize, numElementsToRemove) ) {
- itemsToRemove.set(selectedIndex);
- }
-
- for ( int i = 0; i < pileupSize; i++ ) {
- if ( itemsToRemove.get(i) ) {
- final GATKSAMRecord read = reads.get(i);
- readsToRemove.add(read);
- logRead(read, log);
+ private static void logAllElements(final List elements, final PrintStream log) {
+ if ( log != null ) {
+ for ( final T obj : elements ) {
+ logElement(obj, log);
}
}
-
- return readsToRemove;
}
- private static void logAllElements(final List elements, final PrintStream log) {
+ private static void logElement(final T obj, final PrintStream log) {
if ( log != null ) {
- for ( final PileupElement p : elements )
- logRead(p.getRead(), log);
- }
- }
- private static void logAllReads(final List reads, final PrintStream log) {
- if ( log != null ) {
- for ( final GATKSAMRecord read : reads )
- logRead(read, log);
- }
- }
+ final GATKSAMRecord read;
+ if ( obj instanceof PileupElement )
+ read = ((PileupElement)obj).getRead();
+ else
+ read = (GATKSAMRecord)obj;
- private static void logRead(final SAMRecord read, final PrintStream log) {
- if ( log != null ) {
final SAMReadGroupRecord readGroup = read.getReadGroup();
log.println(String.format("%s\t%s\t%s\t%s", read.getReadName(), readGroup.getSample(), readGroup.getLibrary(), readGroup.getPlatformUnit()));
}
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthOfCoverage.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthOfCoverage.java
index aeec36c18..4adb2ca71 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthOfCoverage.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthOfCoverage.java
@@ -99,7 +99,7 @@ public class DepthOfCoverage extends InfoFieldAnnotation implements StandardAnno
for (PerReadAlleleLikelihoodMap maps : perReadAlleleLikelihoodMap.values() ) {
for (Map.Entry> el : maps.getLikelihoodReadMap().entrySet()) {
final GATKSAMRecord read = el.getKey();
- depth += (read.isReducedRead() ? read.getReducedCount(ReadUtils.getReadCoordinateForReferenceCoordinate(read, vc.getStart(), ReadUtils.ClippingTail.RIGHT_TAIL)) : 1);
+ depth += (read.isReducedRead() ? read.getReducedCount(ReadUtils.getReadCoordinateForReferenceCoordinateUpToEndOfRead(read, vc.getStart(), ReadUtils.ClippingTail.RIGHT_TAIL)) : 1);
}
}
}
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthPerAlleleBySample.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthPerAlleleBySample.java
index a194fe323..5acea12f6 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthPerAlleleBySample.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/DepthPerAlleleBySample.java
@@ -144,7 +144,7 @@ public class DepthPerAlleleBySample extends GenotypeAnnotation implements Standa
continue; // read is non-informative
if (!vc.getAlleles().contains(a))
continue; // sanity check - shouldn't be needed
- alleleCounts.put(a, alleleCounts.get(a) + (read.isReducedRead() ? read.getReducedCount(ReadUtils.getReadCoordinateForReferenceCoordinate(read, vc.getStart(), ReadUtils.ClippingTail.RIGHT_TAIL)) : 1));
+ alleleCounts.put(a, alleleCounts.get(a) + (read.isReducedRead() ? read.getReducedCount(ReadUtils.getReadCoordinateForReferenceCoordinateUpToEndOfRead(read, vc.getStart(), ReadUtils.ClippingTail.RIGHT_TAIL)) : 1));
}
final int[] counts = new int[alleleCounts.size()];
counts[0] = alleleCounts.get(vc.getReference());
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/FisherStrand.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/FisherStrand.java
index 167e5df63..ff3d7940f 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/FisherStrand.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/FisherStrand.java
@@ -116,8 +116,8 @@ public class FisherStrand extends InfoFieldAnnotation implements StandardAnnotat
else if (table1 == null)
return annotationForOneTable(pValueForContingencyTable(table2));
else { // take the one with the best (i.e., least significant pvalue)
- double pvalue1 = Math.max(pValueForContingencyTable(table1), MIN_PVALUE);
- double pvalue2 = Math.max(pValueForContingencyTable(table2), MIN_PVALUE);
+ double pvalue1 = pValueForContingencyTable(table1);
+ double pvalue2 = pValueForContingencyTable(table2);
return annotationForOneTable(Math.max(pvalue1, pvalue2));
}
}
@@ -129,7 +129,7 @@ public class FisherStrand extends InfoFieldAnnotation implements StandardAnnotat
* @return a hash map from FS -> phred-scaled pValue
*/
private Map annotationForOneTable(final double pValue) {
- final Object value = String.format("%.3f", QualityUtils.phredScaleErrorRate(pValue));
+ final Object value = String.format("%.3f", QualityUtils.phredScaleErrorRate(Math.max(pValue, MIN_PVALUE))); // prevent INFINITYs
return Collections.singletonMap(FS, value);
// Map map = new HashMap();
// map.put(FS, String.format("%.3f", QualityUtils.phredScaleErrorRate(pValue)));
@@ -265,24 +265,16 @@ public class FisherStrand extends InfoFieldAnnotation implements StandardAnnotat
for (PerReadAlleleLikelihoodMap maps : stratifiedPerReadAlleleLikelihoodMap.values() ) {
for (Map.Entry> el : maps.getLikelihoodReadMap().entrySet()) {
- final boolean matchesRef = PerReadAlleleLikelihoodMap.getMostLikelyAllele(el.getValue()).equals(ref,true);
- final boolean matchesAlt = PerReadAlleleLikelihoodMap.getMostLikelyAllele(el.getValue()).equals(alt,true);
-
- if ( !matchesRef && !matchesAlt )
- continue;
-
- boolean isFW = el.getKey().getReadNegativeStrandFlag();
-
- int row = matchesRef ? 0 : 1;
- int column = isFW ? 0 : 1;
-
+ final Allele mostLikelyAllele = PerReadAlleleLikelihoodMap.getMostLikelyAllele(el.getValue());
final GATKSAMRecord read = el.getKey();
- table[row][column] += (read.isReducedRead() ? read.getReducedCount(ReadUtils.getReadCoordinateForReferenceCoordinate(read, vc.getStart(), ReadUtils.ClippingTail.RIGHT_TAIL)) : 1);
+ final int representativeCount = read.isReducedRead() ? read.getReducedCount(ReadUtils.getReadCoordinateForReferenceCoordinateUpToEndOfRead(read, vc.getStart(), ReadUtils.ClippingTail.RIGHT_TAIL)) : 1;
+ updateTable(table, mostLikelyAllele, read, ref, alt, representativeCount);
}
}
return table;
}
+
/**
Allocate and fill a 2x2 strand contingency table. In the end, it'll look something like this:
* fw rc
@@ -299,31 +291,36 @@ public class FisherStrand extends InfoFieldAnnotation implements StandardAnnotat
for ( Map.Entry sample : stratifiedContexts.entrySet() ) {
for (PileupElement p : sample.getValue().getBasePileup()) {
- // ignore reduced reads because they are always on the forward strand!
- // TODO -- when het compression is enabled in RR, we somehow need to allow those reads through into the Fisher test
- if ( p.getRead().isReducedRead() )
- continue;
-
if ( ! RankSumTest.isUsableBase(p, false) ) // ignore deletions
continue;
if ( p.getQual() < minQScoreToConsider || p.getMappingQual() < minQScoreToConsider )
continue;
- final Allele base = Allele.create(p.getBase(), false);
- final boolean isFW = !p.getRead().getReadNegativeStrandFlag();
-
- final boolean matchesRef = ref.equals(base, true);
- final boolean matchesAlt = alt.equals(base, true);
- if ( matchesRef || matchesAlt ) {
- int row = matchesRef ? 0 : 1;
- int column = isFW ? 0 : 1;
-
- table[row][column] += p.getRepresentativeCount();
- }
+ updateTable(table, Allele.create(p.getBase(), false), p.getRead(), ref, alt, p.getRepresentativeCount());
}
}
return table;
}
+
+ private static void updateTable(final int[][] table, final Allele allele, final GATKSAMRecord read, final Allele ref, final Allele alt, final int representativeCount) {
+ // ignore reduced reads because they are always on the forward strand!
+ // TODO -- when het compression is enabled in RR, we somehow need to allow those reads through into the Fisher test
+ if ( read.isReducedRead() )
+ return;
+
+ final boolean matchesRef = allele.equals(ref, true);
+ final boolean matchesAlt = allele.equals(alt, true);
+
+ if ( matchesRef || matchesAlt ) {
+
+ final boolean isFW = !read.getReadNegativeStrandFlag();
+
+ int row = matchesRef ? 0 : 1;
+ int column = isFW ? 0 : 1;
+
+ table[row][column] += representativeCount;
+ }
+ }
}
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/GCContent.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/GCContent.java
index 3bb3d7d5a..2b3290595 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/GCContent.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/GCContent.java
@@ -95,9 +95,9 @@ public class GCContent extends InfoFieldAnnotation implements ExperimentalAnnota
for ( byte base : ref.getBases() ) {
int baseIndex = BaseUtils.simpleBaseToBaseIndex(base);
- if ( baseIndex == BaseUtils.gIndex || baseIndex == BaseUtils.cIndex )
+ if ( baseIndex == BaseUtils.Base.G.ordinal() || baseIndex == BaseUtils.Base.C.ordinal() )
gc++;
- else if ( baseIndex == BaseUtils.aIndex || baseIndex == BaseUtils.tIndex )
+ else if ( baseIndex == BaseUtils.Base.A.ordinal() || baseIndex == BaseUtils.Base.T.ordinal() )
at++;
else
; // ignore
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HaplotypeScore.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HaplotypeScore.java
index fe4075117..3acba48ae 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HaplotypeScore.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HaplotypeScore.java
@@ -56,7 +56,6 @@ import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.InfoFieldAnnot
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.StandardAnnotation;
import org.broadinstitute.sting.utils.genotyper.PerReadAlleleLikelihoodMap;
import org.broadinstitute.variant.utils.BaseUtils;
-import org.broadinstitute.sting.utils.Haplotype;
import org.broadinstitute.sting.utils.MathUtils;
import org.broadinstitute.sting.utils.QualityUtils;
import org.broadinstitute.variant.vcf.VCFHeaderLineType;
@@ -236,8 +235,8 @@ public class HaplotypeScore extends InfoFieldAnnotation implements StandardAnnot
final byte[] haplotypeBases = new byte[contextSize];
Arrays.fill(haplotypeBases, (byte) REGEXP_WILDCARD);
- final double[] baseQualities = new double[contextSize];
- Arrays.fill(baseQualities, 0.0);
+ final byte[] baseQualities = new byte[contextSize];
+ Arrays.fill(baseQualities, (byte)0);
byte[] readBases = read.getReadBases();
readBases = AlignmentUtils.readToAlignmentByteArray(read.getCigar(), readBases); // Adjust the read bases based on the Cigar string
@@ -267,7 +266,7 @@ public class HaplotypeScore extends InfoFieldAnnotation implements StandardAnnot
readQuals[baseOffset] = (byte) 0;
} // quals less than 5 are used as codes and don't have actual probabilistic meaning behind them
haplotypeBases[i] = readBases[baseOffset];
- baseQualities[i] = (double) readQuals[baseOffset];
+ baseQualities[i] = readQuals[baseOffset];
}
return new Haplotype(haplotypeBases, baseQualities);
@@ -286,10 +285,10 @@ public class HaplotypeScore extends InfoFieldAnnotation implements StandardAnnot
final int length = a.length;
final byte[] consensusChars = new byte[length];
- final double[] consensusQuals = new double[length];
+ final int[] consensusQuals = new int[length];
- final double[] qualsA = haplotypeA.getQuals();
- final double[] qualsB = haplotypeB.getQuals();
+ final int[] qualsA = haplotypeA.getQuals();
+ final int[] qualsB = haplotypeB.getQuals();
for (int i = 0; i < length; i++) {
chA = a[i];
@@ -300,7 +299,7 @@ public class HaplotypeScore extends InfoFieldAnnotation implements StandardAnnot
if ((chA == wc) && (chB == wc)) {
consensusChars[i] = wc;
- consensusQuals[i] = 0.0;
+ consensusQuals[i] = 0;
} else if ((chA == wc)) {
consensusChars[i] = chB;
consensusQuals[i] = qualsB[i];
@@ -433,7 +432,6 @@ public class HaplotypeScore extends InfoFieldAnnotation implements StandardAnnot
}
-
public List getKeyNames() {
return Arrays.asList("HaplotypeScore");
}
@@ -441,4 +439,46 @@ public class HaplotypeScore extends InfoFieldAnnotation implements StandardAnnot
public List getDescriptions() {
return Arrays.asList(new VCFInfoHeaderLine("HaplotypeScore", 1, VCFHeaderLineType.Float, "Consistency of the site with at most two segregating haplotypes"));
}
+
+ private static class Haplotype {
+ private final byte[] bases;
+ private final int[] quals;
+ private int qualitySum = -1;
+
+ public Haplotype( final byte[] bases, final int[] quals ) {
+ this.bases = bases;
+ this.quals = quals;
+ }
+
+ public Haplotype( final byte[] bases, final int qual ) {
+ this.bases = bases;
+ quals = new int[bases.length];
+ Arrays.fill(quals, qual);
+ }
+
+ public Haplotype( final byte[] bases, final byte[] quals ) {
+ this.bases = bases;
+ this.quals = new int[quals.length];
+ for ( int i = 0 ; i < quals.length; i++ )
+ this.quals[i] = (int)quals[i];
+ }
+
+ public double getQualitySum() {
+ if ( qualitySum == -1 ) {
+ qualitySum = 0;
+ for ( final int qual : quals ) {
+ qualitySum += qual;
+ }
+ }
+ return qualitySum;
+ }
+
+ public int[] getQuals() {
+ return quals.clone();
+ }
+
+ public byte[] getBases() {
+ return bases.clone();
+ }
+ }
}
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/RankSumTest.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/RankSumTest.java
index 959a26fba..ec107512a 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/RankSumTest.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/RankSumTest.java
@@ -169,8 +169,7 @@ public abstract class RankSumTest extends InfoFieldAnnotation implements ActiveR
* @return true if this base is part of a meaningful read for comparison, false otherwise
*/
public static boolean isUsableBase(final PileupElement p, final boolean allowDeletions) {
- return !(p.isInsertionAtBeginningOfRead() ||
- (! allowDeletions && p.isDeletion()) ||
+ return !((! allowDeletions && p.isDeletion()) ||
p.getMappingQual() == 0 ||
p.getMappingQual() == QualityUtils.MAPPING_QUALITY_UNAVAILABLE ||
((int) p.getQual()) < QualityUtils.MIN_USABLE_Q_SCORE); // need the unBAQed quality score here
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java
index 99dadea54..f03a25c04 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java
@@ -52,6 +52,7 @@ import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.*;
+import org.broadinstitute.sting.utils.GenomeLoc;
import org.broadinstitute.sting.utils.genotyper.PerReadAlleleLikelihoodMap;
import org.broadinstitute.variant.vcf.*;
import org.broadinstitute.sting.utils.exceptions.UserException;
@@ -214,10 +215,10 @@ public class VariantAnnotatorEngine {
Map infoAnnotations = new LinkedHashMap(vc.getAttributes());
// annotate db occurrences
- vc = annotateDBs(tracker, ref, vc, infoAnnotations);
+ vc = annotateDBs(tracker, ref.getLocus(), vc, infoAnnotations);
// annotate expressions where available
- annotateExpressions(tracker, ref, infoAnnotations);
+ annotateExpressions(tracker, ref.getLocus(), infoAnnotations);
// go through all the requested info annotationTypes
for ( InfoFieldAnnotation annotationType : requestedInfoAnnotations ) {
@@ -254,10 +255,22 @@ public class VariantAnnotatorEngine {
return builder.genotypes(annotateGenotypes(null, null, null, vc, perReadAlleleLikelihoodMap)).make();
}
- private VariantContext annotateDBs(RefMetaDataTracker tracker, ReferenceContext ref, VariantContext vc, Map infoAnnotations) {
+ public VariantContext annotateDBs(final RefMetaDataTracker tracker, final GenomeLoc loc, VariantContext vc) {
+ final Map newInfoAnnotations = new HashMap(0);
+ vc = annotateDBs(tracker, loc, vc, newInfoAnnotations);
+
+ if ( !newInfoAnnotations.isEmpty() ) {
+ final VariantContextBuilder builder = new VariantContextBuilder(vc).attributes(newInfoAnnotations);
+ vc = builder.make();
+ }
+
+ return vc;
+ }
+
+ private VariantContext annotateDBs(final RefMetaDataTracker tracker, final GenomeLoc loc, VariantContext vc, final Map infoAnnotations) {
for ( Map.Entry, String> dbSet : dbAnnotations.entrySet() ) {
if ( dbSet.getValue().equals(VCFConstants.DBSNP_KEY) ) {
- final String rsID = VCFUtils.rsIDOfFirstRealVariant(tracker.getValues(dbSet.getKey(), ref.getLocus()), vc.getType());
+ final String rsID = VCFUtils.rsIDOfFirstRealVariant(tracker.getValues(dbSet.getKey(), loc), vc.getType());
// add the ID if appropriate
if ( rsID != null ) {
@@ -273,7 +286,7 @@ public class VariantAnnotatorEngine {
}
} else {
boolean overlapsComp = false;
- for ( VariantContext comp : tracker.getValues(dbSet.getKey(), ref.getLocus()) ) {
+ for ( VariantContext comp : tracker.getValues(dbSet.getKey(), loc) ) {
if ( !comp.isFiltered() && ( !requireStrictAlleleMatch || comp.getAlleles().equals(vc.getAlleles()) ) ) {
overlapsComp = true;
break;
@@ -287,9 +300,9 @@ public class VariantAnnotatorEngine {
return vc;
}
- private void annotateExpressions(RefMetaDataTracker tracker, ReferenceContext ref, Map infoAnnotations) {
+ private void annotateExpressions(final RefMetaDataTracker tracker, final GenomeLoc loc, final Map infoAnnotations) {
for ( VAExpression expression : requestedExpressions ) {
- Collection VCs = tracker.getValues(expression.binding, ref.getLocus());
+ Collection VCs = tracker.getValues(expression.binding, loc);
if ( VCs.size() == 0 )
continue;
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverage.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverage.java
index 1e4c55e0d..b10daab58 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverage.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverage.java
@@ -938,7 +938,7 @@ public class DepthOfCoverage extends LocusWalker