Add some missing methods to the pileup architecture.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3588 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2010-06-18 15:03:08 +00:00
parent 5050b19457
commit 52477bd9e6
6 changed files with 82 additions and 0 deletions

View File

@ -29,6 +29,7 @@ import org.broadinstitute.sting.utils.collections.Pair;
import java.util.Iterator;
import java.util.List;
import java.util.Collection;
import net.sf.samtools.SAMRecord;
@ -58,6 +59,19 @@ public interface ReadBackedExtendedEventPileup extends Iterable<ExtendedEventPil
*/
public ReadBackedExtendedEventPileup getDownsampledPileup(int desiredCoverage);
/**
* Gets a list of all the samples stored in this pileup.
* @return List of samples in this pileup.
*/
public Collection<String> getSamples();
/**
* Gets the particular subset of this pileup with the given sample name.
* @param sampleName Name of the sample to use.
* @return A subset of this pileup containing only reads with the given sample.
*/
public ReadBackedExtendedEventPileup getPileupForSample(String sampleName);
/**
* Returns the number of deletion events in this pileup
*

View File

@ -29,6 +29,7 @@ import org.broadinstitute.sting.gatk.iterators.IterableIterator;
import net.sf.samtools.SAMRecord;
import java.util.List;
import java.util.Collection;
/**
* A data retrieval interface for accessing parts of the pileup.
@ -95,6 +96,12 @@ public interface ReadBackedPileup extends Iterable<PileupElement> {
*/
public ReadBackedPileup getDownsampledPileup(int desiredCoverage);
/**
* Gets a collection of all the samples stored in this pileup.
* @return Collection of samples in this pileup.
*/
public Collection<String> getSamples();
/**
* Gets the particular subset of this pileup with the given sample name.
* @param sampleName Name of the sample to use.

View File

@ -151,6 +151,24 @@ public class SampleSplitReadBackedExtendedEventPileup implements ReadBackedExten
return downsampledPileup;
}
/**
* Gets a list of all the samples stored in this pileup.
* @return List of samples in this pileup.
*/
public Collection<String> getSamples() {
return pileupBySample.keySet();
}
/**
* Gets the particular subset of this pileup with the given sample name.
* @param sampleName Name of the sample to use.
* @return A subset of this pileup containing only reads with the given sample.
*/
public ReadBackedExtendedEventPileup getPileupForSample(String sampleName) {
return pileupBySample.get(sampleName);
}
@Override
public Iterator<ExtendedEventPileupElement> iterator() {
return new ExtendedEventCastingIterator(new MergingPileupElementIterator(pileupBySample));

View File

@ -226,6 +226,10 @@ public class SampleSplitReadBackedPileup implements ReadBackedPileup {
return downsampledPileup;
}
public Collection<String> getSamples() {
return pileupBySample.keySet();
}
@Override
public ReadBackedPileup getPileupForSample(String sampleName) {
return pileupBySample.containsKey(sampleName) ? pileupBySample.get(sampleName) : null;

View File

@ -194,6 +194,34 @@ public class UnifiedReadBackedExtendedEventPileup implements ReadBackedExtendedE
return new UnifiedReadBackedExtendedEventPileup(getLocation(), downsampledPileup);
}
@Override
public Collection<String> getSamples() {
Collection<String> sampleNames = new HashSet<String>();
for(PileupElement p: this) {
SAMRecord read = p.getRead();
String sampleName = read.getReadGroup() != null ? read.getReadGroup().getSample() : null;
sampleNames.add(sampleName);
}
return sampleNames;
}
@Override
public ReadBackedExtendedEventPileup getPileupForSample(String sampleName) {
List<ExtendedEventPileupElement> filteredPileup = new ArrayList<ExtendedEventPileupElement>();
for(ExtendedEventPileupElement p: this) {
SAMRecord read = p.getRead();
if(sampleName != null) {
if(read.getReadGroup() != null && sampleName.equals(read.getReadGroup().getSample()))
filteredPileup.add(p);
}
else {
if(read.getReadGroup() == null || read.getReadGroup().getSample() == null)
filteredPileup.add(p);
}
}
return filteredPileup.size()>0 ? new UnifiedReadBackedExtendedEventPileup(loc,filteredPileup) : null;
}
// --------------------------------------------------------
//
// iterators

View File

@ -299,6 +299,17 @@ public class UnifiedReadBackedPileup implements ReadBackedPileup {
return new UnifiedReadBackedPileup(getLocation(), downsampledPileup);
}
@Override
public Collection<String> getSamples() {
Collection<String> sampleNames = new HashSet<String>();
for(PileupElement p: this) {
SAMRecord read = p.getRead();
String sampleName = read.getReadGroup() != null ? read.getReadGroup().getSample() : null;
sampleNames.add(sampleName);
}
return sampleNames;
}
@Override
public ReadBackedPileup getPileupForSample(String sampleName) {
List<PileupElement> filteredPileup = new ArrayList<PileupElement>();