Moved hasPileupBeenDownsampled() based on Eric's request. Also eliminated

@Deprecated constructors from AlignmentContext.


git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4142 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2010-08-27 16:12:05 +00:00
parent 427a2f85e9
commit de5ccfb0b1
8 changed files with 38 additions and 63 deletions

View File

@ -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<SAMRecord> reads, List<Integer> offsets) {
this(loc, reads, offsets, 0);
}
@Deprecated
public AlignmentContext(GenomeLoc loc, List<SAMRecord> reads, List<Integer> 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;
}
/**

View File

@ -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<SAMRecord>(), new ArrayList<Integer>());
private AlignmentContext createEmptyLocus( GenomeLoc site ) {
return new AlignmentContext(site,new ReadBackedPileupImpl(site,new ArrayList<SAMRecord>(), new ArrayList<Integer>()));
}
}

View File

@ -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<SAMRecordState> iterator = readStates.iteratorForSample(sampleName);
ArrayList<ExtendedEventPileupElement> indelPile = new ArrayList<ExtendedEventPileupElement>(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<String,ReadBackedPileupImpl> fullPileup = new HashMap<String,ReadBackedPileupImpl>();
// todo -- performance problem -- should be lazy, really
boolean hasBeenSampled = false;
for(String sampleName: sampleNames) {
Iterator<SAMRecordState> iterator = readStates.iteratorForSample(sampleName);
ArrayList<PileupElement> pile = new ArrayList<PileupElement>(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);
}
}
}

View File

@ -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<List<String>, Strin
List<SAMRecord> sub_reads = MathUtils.sliceListByIndices(subset_indices, reads);
List<Integer> 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);

View File

@ -46,7 +46,6 @@ public abstract class AbstractReadBackedPileup<RBP extends AbstractReadBackedPil
protected int size = 0; // cached value of the size of the pileup
protected int nDeletions = 0; // cached value of the number of deletions
protected int nMQ0Reads = 0; // cached value of the number of MQ0 reads
protected boolean hasPileupBeenDownsampled;
/**
* Create a new version of a read backed pileup at loc, using the reads and their corresponding
@ -96,7 +95,7 @@ public abstract class AbstractReadBackedPileup<RBP extends AbstractReadBackedPil
* @param loc
* @param pileup
*/
public AbstractReadBackedPileup(GenomeLoc loc, List<PE> pileup, int size, int nDeletions, int nMQ0Reads, boolean hasPileupBeenDownsampled ) {
public AbstractReadBackedPileup(GenomeLoc loc, List<PE> 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<RBP extends AbstractReadBackedPil
this.size = size;
this.nDeletions = nDeletions;
this.nMQ0Reads = nMQ0Reads;
this.hasPileupBeenDownsampled = hasPileupBeenDownsampled;
}
@ -150,7 +148,6 @@ public abstract class AbstractReadBackedPileup<RBP extends AbstractReadBackedPil
size += pileup.size();
nDeletions += pileup.getNumberOfDeletions();
nMQ0Reads += pileup.getNumberOfMappingQualityZeroReads();
hasPileupBeenDownsampled |= pileup.hasPileupBeenDownsampled();
}
/**
@ -675,11 +672,6 @@ public abstract class AbstractReadBackedPileup<RBP extends AbstractReadBackedPil
return loc;
}
@Override
public boolean hasPileupBeenDownsampled() {
return hasPileupBeenDownsampled;
}
/**
* Somewhat expensive routine that returns true if any base in the pileup has secondary bases annotated
* @return

View File

@ -34,10 +34,6 @@ import net.sf.samtools.SAMRecord;
public class ReadBackedExtendedEventPileupImpl extends AbstractReadBackedPileup<ReadBackedExtendedEventPileupImpl,ExtendedEventPileupElement> 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<ExtendedEventPileupElement> pileupElements) {
super(loc,pileupElements);
@ -53,8 +49,8 @@ public class ReadBackedExtendedEventPileupImpl extends AbstractReadBackedPileup<
* @param pileup
*/
public ReadBackedExtendedEventPileupImpl(GenomeLoc loc, List<ExtendedEventPileupElement> 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;
}

View File

@ -115,12 +115,6 @@ public interface ReadBackedPileup extends Iterable<PileupElement> {
*/
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.

View File

@ -56,8 +56,8 @@ public class ReadBackedPileupImpl extends AbstractReadBackedPileup<ReadBackedPil
* @param loc
* @param pileup
*/
public ReadBackedPileupImpl(GenomeLoc loc, List<PileupElement> pileup, int size, int nDeletions, int nMQ0Reads, boolean hasPileupBeenDownsampled ) {
super(loc,pileup,size,nDeletions,nMQ0Reads,hasPileupBeenDownsampled);
public ReadBackedPileupImpl(GenomeLoc loc, List<PileupElement> pileup, int size, int nDeletions, int nMQ0Reads) {
super(loc,pileup,size,nDeletions,nMQ0Reads);
}
protected ReadBackedPileupImpl(GenomeLoc loc, PileupElementTracker<PileupElement> tracker) {