diff --git a/java/src/org/broadinstitute/sting/gatk/iterators/DownsamplingLocusIteratorByState.java b/java/src/org/broadinstitute/sting/gatk/iterators/DownsamplingLocusIteratorByState.java index 4e866a136..72a05a34e 100755 --- a/java/src/org/broadinstitute/sting/gatk/iterators/DownsamplingLocusIteratorByState.java +++ b/java/src/org/broadinstitute/sting/gatk/iterators/DownsamplingLocusIteratorByState.java @@ -359,7 +359,8 @@ public class DownsamplingLocusIteratorByState extends LocusIterator { // In this case, the subsequent call to next() will emit the normal pileup at the current base // and shift the position. if (readInfo.generateExtendedEvents() && hasExtendedEvents) { - Map> fullExtendedEventPileup = new HashMap>(); + Map> fullExtendedEventPileup = + new HashMap>(); SAMRecordState our1stState = readStates.getFirst(); // get current location on the reference and decrement it by 1: the indels we just stepped over @@ -411,9 +412,8 @@ public class DownsamplingLocusIteratorByState extends LocusIterator { if ( state.getRead().getMappingQuality() == 0 ) { nMQ0Reads++; } - // TODO: sample split! - if( indelPile.size() != 0 ) fullExtendedEventPileup.put(sampleName,new ReadBackedExtendedEventPileupImpl(loc,indelPile,size,maxDeletionLength,nDeletions,nInsertions,nMQ0Reads)); } + if( indelPile.size() != 0 ) fullExtendedEventPileup.put(sampleName,new ReadBackedExtendedEventPileupImpl(loc,indelPile,size,maxDeletionLength,nInsertions,nDeletions,nMQ0Reads)); } hasExtendedEvents = false; // we are done with extended events prior to current ref base // System.out.println("Indel(s) at "+loc); @@ -421,7 +421,7 @@ public class DownsamplingLocusIteratorByState extends LocusIterator { nextAlignmentContext = new AlignmentContext(loc, new ReadBackedExtendedEventPileupImpl(loc, fullExtendedEventPileup)); } else { GenomeLoc location = getLocation(); - Map> fullPileup = new HashMap>(); + Map> fullPileup = new HashMap>(); // todo -- performance problem -- should be lazy, really for(String sampleName: sampleNames) { diff --git a/java/src/org/broadinstitute/sting/utils/pileup/AbstractReadBackedPileup.java b/java/src/org/broadinstitute/sting/utils/pileup/AbstractReadBackedPileup.java index b8dd2ed36..6d980932d 100644 --- a/java/src/org/broadinstitute/sting/utils/pileup/AbstractReadBackedPileup.java +++ b/java/src/org/broadinstitute/sting/utils/pileup/AbstractReadBackedPileup.java @@ -113,6 +113,16 @@ public abstract class AbstractReadBackedPileup> pileupsBySample) { + this.loc = loc; + PerSamplePileupElementTracker tracker = new PerSamplePileupElementTracker(); + for(Map.Entry> pileupEntry: pileupsBySample.entrySet()) { + tracker.addElements(pileupEntry.getKey(),pileupEntry.getValue().pileupElementTracker); + addPileupToCumulativeStats(pileupEntry.getValue()); + } + this.pileupElementTracker = tracker; + } + /** * Calculate cached sizes, nDeletion, and base counts for the pileup. This calculation is done upfront, * so you pay the cost at the start, but it's more efficient to do this rather than pay the cost of calling @@ -134,6 +144,12 @@ public abstract class AbstractReadBackedPileup pileup) { + size += pileup.size(); + nDeletions += pileup.getNumberOfDeletions(); + nMQ0Reads += pileup.getNumberOfMappingQualityZeroReads(); + } + /** * Helper routine for converting reads and offset lists to a PileupElement list. * diff --git a/java/src/org/broadinstitute/sting/utils/pileup/MergingPileupElementIterator.java b/java/src/org/broadinstitute/sting/utils/pileup/MergingPileupElementIterator.java index d41cecdb9..212fbb42a 100644 --- a/java/src/org/broadinstitute/sting/utils/pileup/MergingPileupElementIterator.java +++ b/java/src/org/broadinstitute/sting/utils/pileup/MergingPileupElementIterator.java @@ -44,7 +44,7 @@ class MergingPileupElementIterator implements Iterator for(String sampleName: tracker.getSamples()) { PileupElementTracker trackerPerSample = tracker.getElements(sampleName); if(trackerPerSample.size() != 0) - perSampleIterators.add(new PeekableIterator(tracker.iterator())); + perSampleIterators.add(new PeekableIterator(trackerPerSample.iterator())); } } diff --git a/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedExtendedEventPileupImpl.java b/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedExtendedEventPileupImpl.java index b7f1e418a..078f58012 100644 --- a/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedExtendedEventPileupImpl.java +++ b/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedExtendedEventPileupImpl.java @@ -32,8 +32,8 @@ import java.util.*; import net.sf.samtools.SAMRecord; public class ReadBackedExtendedEventPileupImpl extends AbstractReadBackedPileup implements ReadBackedExtendedEventPileup { - private int nInsertions = 0; - private int maxDeletionLength = 0; // cached value of the length of the longest deletion observed at the site + private int nInsertions; + private int maxDeletionLength; // cached value of the length of the longest deletion observed at the site public ReadBackedExtendedEventPileupImpl(GenomeLoc loc, List pileupElements) { super(loc,pileupElements); @@ -55,8 +55,8 @@ public class ReadBackedExtendedEventPileupImpl extends AbstractReadBackedPileup< this.nInsertions = nInsertions; } - public ReadBackedExtendedEventPileupImpl(GenomeLoc loc, Map> pileupElementsBySample) { - super(loc,new PerSamplePileupElementTracker(pileupElementsBySample)); + public ReadBackedExtendedEventPileupImpl(GenomeLoc loc, Map> pileupElementsBySample) { + super(loc,pileupElementsBySample); } /** @@ -68,15 +68,26 @@ public class ReadBackedExtendedEventPileupImpl extends AbstractReadBackedPileup< protected void calculateCachedData() { super.calculateCachedData(); - nDeletions = 0; - maxDeletionLength = 0; - for ( ExtendedEventPileupElement p : this.toExtendedIterable()) { + nInsertions = 0; + nMQ0Reads = 0; + + for ( ExtendedEventPileupElement p : this.toExtendedIterable() ) { + if ( p.isDeletion() ) { - nDeletions++; maxDeletionLength = Math.max(maxDeletionLength, p.getEventLength()); + } else { + if ( p.isInsertion() ) nInsertions++; } } - } + } + + @Override + protected void addPileupToCumulativeStats(AbstractReadBackedPileup pileup) { + super.addPileupToCumulativeStats(pileup); + ReadBackedExtendedEventPileup extendedEventPileup = ((ReadBackedExtendedEventPileup)pileup); + this.nInsertions += extendedEventPileup.getNumberOfInsertions(); + this.maxDeletionLength += extendedEventPileup.getMaxDeletionLength(); + } @Override protected ReadBackedExtendedEventPileup createNewPileup(GenomeLoc loc, PileupElementTracker tracker) { diff --git a/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileupImpl.java b/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileupImpl.java index b32fb8f06..145e2f5e6 100644 --- a/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileupImpl.java +++ b/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileupImpl.java @@ -47,8 +47,8 @@ public class ReadBackedPileupImpl extends AbstractReadBackedPileup> pileupElementsBySample) { - super(loc,new PerSamplePileupElementTracker(pileupElementsBySample)); + public ReadBackedPileupImpl(GenomeLoc loc, Map> pileupElementsBySample) { + super(loc,pileupElementsBySample); } /**