diff --git a/java/src/org/broadinstitute/sting/gatk/contexts/AlignmentContext.java b/java/src/org/broadinstitute/sting/gatk/contexts/AlignmentContext.java index e40948a7d..4298ad628 100755 --- a/java/src/org/broadinstitute/sting/gatk/contexts/AlignmentContext.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/AlignmentContext.java @@ -46,6 +46,7 @@ import java.util.*; public class AlignmentContext { protected GenomeLoc loc = null; protected ReadBackedPileup basePileup = null; + protected boolean hasPileupBeenDownsampled; /** * The number of bases we've skipped over in the reference since the last map invocation. @@ -53,40 +54,19 @@ public class AlignmentContext { */ private long skippedBases = 0; - /** - * Default constructor for AlignmentContext object - * since private objects are already set to null we - * don't need to do anything - */ - public AlignmentContext() { /* private objects already set to null */ } - - /** - * Create a new AlignmentContext object - * - * @param loc - * @param reads - * @param offsets - */ - @Deprecated - public AlignmentContext(GenomeLoc loc, List reads, List offsets) { - this(loc, reads, offsets, 0); - } - - @Deprecated - public AlignmentContext(GenomeLoc loc, List reads, List offsets, long skippedBases ) { - if ( loc == null ) throw new StingException("BUG: GenomeLoc in Alignment context is null"); - if ( skippedBases < 0 ) throw new StingException("BUG: skippedBases is -1 in Alignment context"); - - this.loc = loc; - this.basePileup = new ReadBackedPileupImpl(loc, reads, offsets); - this.skippedBases = skippedBases; - } - public AlignmentContext(GenomeLoc loc, ReadBackedPileup basePileup) { - this(loc, basePileup, 0); + this(loc, basePileup, 0, false); } - public AlignmentContext(GenomeLoc loc, ReadBackedPileup basePileup, long skippedBases ) { + public AlignmentContext(GenomeLoc loc, ReadBackedPileup basePileup, boolean hasPileupBeenDownsampled) { + this(loc, basePileup, 0, hasPileupBeenDownsampled); + } + + public AlignmentContext(GenomeLoc loc, ReadBackedPileup basePileup, long skippedBases) { + this(loc, basePileup, skippedBases, false); + } + + public AlignmentContext(GenomeLoc loc, ReadBackedPileup basePileup, long skippedBases,boolean hasPileupBeenDownsampled ) { if ( loc == null ) throw new StingException("BUG: GenomeLoc in Alignment context is null"); if ( basePileup == null ) throw new StingException("BUG: ReadBackedPileup in Alignment context is null"); if ( skippedBases < 0 ) throw new StingException("BUG: skippedBases is -1 in Alignment context"); @@ -94,6 +74,7 @@ public class AlignmentContext { this.loc = loc; this.basePileup = basePileup; this.skippedBases = skippedBases; + this.hasPileupBeenDownsampled = hasPileupBeenDownsampled; } /** Returns base pileup over the current genomic location. Deprectated. Use getBasePileup() to make your intentions @@ -136,6 +117,12 @@ public class AlignmentContext { */ public boolean hasExtendedEventPileup() { return basePileup instanceof ReadBackedExtendedEventPileup; } + /** + * Returns true if any reads have been filtered out of the pileup due to excess DoC. + * @return True if reads have been filtered out. False otherwise. + */ + public boolean hasPileupBeenDownsampled() { return hasPileupBeenDownsampled; } + /** * get all of the reads within this context * @@ -178,6 +165,7 @@ public class AlignmentContext { public void downsampleToCoverage(int coverage) { basePileup = basePileup.getDownsampledPileup(coverage); + hasPileupBeenDownsampled = true; } /** diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/providers/AllLocusView.java b/java/src/org/broadinstitute/sting/gatk/datasources/providers/AllLocusView.java index 9a7cf87ba..2aad7242e 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/providers/AllLocusView.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/providers/AllLocusView.java @@ -8,6 +8,7 @@ import org.broadinstitute.sting.gatk.iterators.GenomeLocusIterator; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.utils.GenomeLoc; import net.sf.samtools.SAMRecord; +import org.broadinstitute.sting.utils.pileup.ReadBackedPileupImpl; /** * User: hanna * Date: May 13, 2009 @@ -95,7 +96,7 @@ public class AllLocusView extends LocusView { * @param site Site at which to create the blank locus context. * @return empty context. */ - private AlignmentContext createEmptyLocus( GenomeLoc site ) { - return new AlignmentContext(site, new ArrayList(), new ArrayList()); + private AlignmentContext createEmptyLocus( GenomeLoc site ) { + return new AlignmentContext(site,new ReadBackedPileupImpl(site,new ArrayList(), new ArrayList())); } } diff --git a/java/src/org/broadinstitute/sting/gatk/iterators/LocusIteratorByState.java b/java/src/org/broadinstitute/sting/gatk/iterators/LocusIteratorByState.java index 3ac312630..4d475b84a 100755 --- a/java/src/org/broadinstitute/sting/gatk/iterators/LocusIteratorByState.java +++ b/java/src/org/broadinstitute/sting/gatk/iterators/LocusIteratorByState.java @@ -358,10 +358,11 @@ public class LocusIteratorByState extends LocusIterator { // are associated with the *previous* reference base GenomeLoc loc = GenomeLocParser.incPos(our1stState.getLocation(),-1); + boolean hasBeenSampled = false; for(String sampleName: sampleNames) { Iterator iterator = readStates.iteratorForSample(sampleName); ArrayList indelPile = new ArrayList(readStates.size()); - boolean hasBeenSampled = loc.getStart() <= readStates.readStatesBySample.get(sampleName).getDownsamplingExtent(); + hasBeenSampled |= loc.getStart() <= readStates.readStatesBySample.get(sampleName).getDownsamplingExtent(); size = 0; nDeletions = 0; @@ -414,21 +415,22 @@ public class LocusIteratorByState extends LocusIterator { nMQ0Reads++; } } - if( indelPile.size() != 0 ) fullExtendedEventPileup.put(sampleName,new ReadBackedExtendedEventPileupImpl(loc,indelPile,size,maxDeletionLength,nInsertions,nDeletions,nMQ0Reads,hasBeenSampled)); + 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); // for ( ExtendedEventPileupElement pe : indelPile ) { if ( pe.isIndel() ) System.out.println(" "+pe.toString()); } - nextAlignmentContext = new AlignmentContext(loc, new ReadBackedExtendedEventPileupImpl(loc, fullExtendedEventPileup)); + nextAlignmentContext = new AlignmentContext(loc, new ReadBackedExtendedEventPileupImpl(loc, fullExtendedEventPileup), hasBeenSampled); } else { GenomeLoc location = getLocation(); Map fullPileup = new HashMap(); // todo -- performance problem -- should be lazy, really + boolean hasBeenSampled = false; for(String sampleName: sampleNames) { Iterator iterator = readStates.iteratorForSample(sampleName); ArrayList pile = new ArrayList(readStates.size()); - boolean hasBeenSampled = location.getStart() <= readStates.readStatesBySample.get(sampleName).getDownsamplingExtent(); + hasBeenSampled |= location.getStart() <= readStates.readStatesBySample.get(sampleName).getDownsamplingExtent(); size = 0; nDeletions = 0; @@ -458,12 +460,12 @@ public class LocusIteratorByState extends LocusIterator { nMQ0Reads++; } } - if( pile.size() != 0 ) fullPileup.put(sampleName,new ReadBackedPileupImpl(location,pile,size,nDeletions,nMQ0Reads,hasBeenSampled)); + if( pile.size() != 0 ) fullPileup.put(sampleName,new ReadBackedPileupImpl(location,pile,size,nDeletions,nMQ0Reads)); } updateReadStates(); // critical - must be called after we get the current state offsets and location // if we got reads with non-D/N over the current position, we are done - if ( !fullPileup.isEmpty() ) nextAlignmentContext = new AlignmentContext(location, new ReadBackedPileupImpl(location,fullPileup)); + if ( !fullPileup.isEmpty() ) nextAlignmentContext = new AlignmentContext(location, new ReadBackedPileupImpl(location,fullPileup),hasBeenSampled); } } } diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/SnpCallRateByCoverageWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/SnpCallRateByCoverageWalker.java index 83d050078..d9941f2ff 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/SnpCallRateByCoverageWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/SnpCallRateByCoverageWalker.java @@ -37,9 +37,11 @@ import org.broadinstitute.sting.gatk.walkers.genotyper.UnifiedArgumentCollection import org.broadinstitute.sting.gatk.walkers.genotyper.UnifiedGenotyperEngine; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.MathUtils; +import org.broadinstitute.sting.utils.pileup.ReadBackedPileupImpl; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; + import java.util.ArrayList; import java.util.List; import java.util.Collection; @@ -114,7 +116,7 @@ public class SnpCallRateByCoverageWalker extends LocusWalker, Strin List sub_reads = MathUtils.sliceListByIndices(subset_indices, reads); List sub_offsets = MathUtils.sliceListByIndices(subset_indices, offsets); - AlignmentContext subContext = new AlignmentContext(context.getLocation(), sub_reads, sub_offsets); + AlignmentContext subContext = new AlignmentContext(context.getLocation(), new ReadBackedPileupImpl(context.getLocation(),sub_reads, sub_offsets)); VariantCallContext calls = UG.runGenotyper(tracker, ref, subContext); diff --git a/java/src/org/broadinstitute/sting/utils/pileup/AbstractReadBackedPileup.java b/java/src/org/broadinstitute/sting/utils/pileup/AbstractReadBackedPileup.java index 39cb534f8..924fd0b0a 100644 --- a/java/src/org/broadinstitute/sting/utils/pileup/AbstractReadBackedPileup.java +++ b/java/src/org/broadinstitute/sting/utils/pileup/AbstractReadBackedPileup.java @@ -46,7 +46,6 @@ public abstract class AbstractReadBackedPileup pileup, int size, int nDeletions, int nMQ0Reads, boolean hasPileupBeenDownsampled ) { + public AbstractReadBackedPileup(GenomeLoc loc, List pileup, int size, int nDeletions, int nMQ0Reads) { if ( loc == null ) throw new StingException("Illegal null genomeloc in UnifiedReadBackedPileup"); if ( pileup == null ) throw new StingException("Illegal null pileup in UnifiedReadBackedPileup"); @@ -105,7 +104,6 @@ public abstract class AbstractReadBackedPileup implements ReadBackedExtendedEventPileup { private int nInsertions; private int maxDeletionLength; // cached value of the length of the longest deletion observed at the site - /** - * True if this pileup has been downsampled due to excessive coverage depth. False otherwise. - */ - private boolean hasBeenDownsampled; public ReadBackedExtendedEventPileupImpl(GenomeLoc loc, List pileupElements) { super(loc,pileupElements); @@ -53,8 +49,8 @@ public class ReadBackedExtendedEventPileupImpl extends AbstractReadBackedPileup< * @param pileup */ public ReadBackedExtendedEventPileupImpl(GenomeLoc loc, List pileup, int size, - int maxDeletionLength, int nInsertions, int nDeletions, int nMQ0Reads, boolean hasPileupBeenDownsampled ) { - super(loc,pileup,size,nDeletions,nMQ0Reads,hasPileupBeenDownsampled); + int maxDeletionLength, int nInsertions, int nDeletions, int nMQ0Reads) { + super(loc,pileup,size,nDeletions,nMQ0Reads); this.maxDeletionLength = maxDeletionLength; this.nInsertions = nInsertions; } diff --git a/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileup.java b/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileup.java index ccac2a908..9454adfd7 100644 --- a/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileup.java +++ b/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileup.java @@ -115,12 +115,6 @@ public interface ReadBackedPileup extends Iterable { */ public ReadBackedPileup getDownsampledPileup(int desiredCoverage); - /** - * Returns true if any reads have been filtered out of the pileup due to excess DoC. - * @return True if reads have been filtered out. False otherwise. - */ - public boolean hasPileupBeenDownsampled(); - /** * Gets a collection of all the read groups represented in this pileup. * @return A collection of all the read group ids represented in this pileup. diff --git a/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileupImpl.java b/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileupImpl.java index 03db78320..4ebb13ea4 100644 --- a/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileupImpl.java +++ b/java/src/org/broadinstitute/sting/utils/pileup/ReadBackedPileupImpl.java @@ -56,8 +56,8 @@ public class ReadBackedPileupImpl extends AbstractReadBackedPileup pileup, int size, int nDeletions, int nMQ0Reads, boolean hasPileupBeenDownsampled ) { - super(loc,pileup,size,nDeletions,nMQ0Reads,hasPileupBeenDownsampled); + public ReadBackedPileupImpl(GenomeLoc loc, List pileup, int size, int nDeletions, int nMQ0Reads) { + super(loc,pileup,size,nDeletions,nMQ0Reads); } protected ReadBackedPileupImpl(GenomeLoc loc, PileupElementTracker tracker) {