use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk-protected by broadinstitute.
the class ReferenceConfidenceModel method getPileupsOverReference.
/**
* Get a list of pileups that span the entire active region span, in order, one for each position
*/
private List<ReadPileup> getPileupsOverReference(final Haplotype refHaplotype, final Collection<Haplotype> calledHaplotypes, final SimpleInterval paddedReferenceLoc, final AssemblyRegion activeRegion, final SimpleInterval activeRegionSpan, final ReadLikelihoods<Haplotype> readLikelihoods) {
Utils.validateArg(calledHaplotypes.contains(refHaplotype), "calledHaplotypes must contain the refHaplotype");
Utils.validateArg(readLikelihoods.numberOfSamples() == 1, () -> "readLikelihoods must contain exactly one sample but it contained " + readLikelihoods.numberOfSamples());
final List<GATKRead> reads = activeRegion.getReads();
final LocusIteratorByState libs = new LocusIteratorByState(reads.iterator(), LocusIteratorByState.NO_DOWNSAMPLING, false, samples.asSetOfSamples(), activeRegion.getHeader(), true);
final int startPos = activeRegionSpan.getStart();
final List<ReadPileup> pileups = new ArrayList<>(activeRegionSpan.getEnd() - startPos);
AlignmentContext next = libs.advanceToLocus(startPos, true);
for (int curPos = startPos; curPos <= activeRegionSpan.getEnd(); curPos++) {
if (next != null && next.getLocation().getStart() == curPos) {
pileups.add(next.getBasePileup());
next = libs.hasNext() ? libs.next() : null;
} else {
// no data, so we create empty pileups
pileups.add(new ReadPileup(new SimpleInterval(activeRegionSpan.getContig(), curPos, curPos)));
}
}
return pileups;
}
use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.
the class ReferenceConfidenceModel method getPileupsOverReference.
/**
* Get a list of pileups that span the entire active region span, in order, one for each position
*/
private List<ReadPileup> getPileupsOverReference(final Haplotype refHaplotype, final Collection<Haplotype> calledHaplotypes, final SimpleInterval paddedReferenceLoc, final AssemblyRegion activeRegion, final SimpleInterval activeRegionSpan, final ReadLikelihoods<Haplotype> readLikelihoods) {
Utils.validateArg(calledHaplotypes.contains(refHaplotype), "calledHaplotypes must contain the refHaplotype");
Utils.validateArg(readLikelihoods.numberOfSamples() == 1, () -> "readLikelihoods must contain exactly one sample but it contained " + readLikelihoods.numberOfSamples());
final List<GATKRead> reads = activeRegion.getReads();
final LocusIteratorByState libs = new LocusIteratorByState(reads.iterator(), LocusIteratorByState.NO_DOWNSAMPLING, false, samples.asSetOfSamples(), activeRegion.getHeader(), true);
final int startPos = activeRegionSpan.getStart();
final List<ReadPileup> pileups = new ArrayList<>(activeRegionSpan.getEnd() - startPos);
AlignmentContext next = libs.advanceToLocus(startPos, true);
for (int curPos = startPos; curPos <= activeRegionSpan.getEnd(); curPos++) {
if (next != null && next.getLocation().getStart() == curPos) {
pileups.add(next.getBasePileup());
next = libs.hasNext() ? libs.next() : null;
} else {
// no data, so we create empty pileups
pileups.add(new ReadPileup(new SimpleInterval(activeRegionSpan.getContig(), curPos, curPos)));
}
}
return pileups;
}
use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.
the class PileupSpark method pileupFunction.
private static Function<LocusWalkerContext, String> pileupFunction(List<FeatureInput<Feature>> metadata, boolean outputInsertLength, boolean showVerbose) {
return (Function<LocusWalkerContext, String>) context -> {
AlignmentContext alignmentContext = context.getAlignmentContext();
ReferenceContext referenceContext = context.getReferenceContext();
FeatureContext featureContext = context.getFeatureContext();
final String features = getFeaturesString(featureContext, metadata);
final ReadPileup basePileup = alignmentContext.getBasePileup();
final StringBuilder s = new StringBuilder();
s.append(String.format("%s %s", basePileup.getPileupString((referenceContext.hasBackingDataSource()) ? (char) referenceContext.getBase() : 'N'), features));
if (outputInsertLength) {
s.append(" ").append(insertLengthOutput(basePileup));
}
if (showVerbose) {
s.append(" ").append(createVerboseOutput(basePileup));
}
s.append("\n");
return s.toString();
};
}
use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.
the class IntervalAlignmentContextIterator method next.
@Override
public AlignmentContext next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
final boolean isOverlaps = currentInterval.overlaps(currentAlignmentContext);
AlignmentContext result;
// Get ready to return result and determine what should go the next time next() is called.
if (isOverlaps) {
result = currentAlignmentContext;
advanceIntervalLocus();
advanceAlignmentContextToCurrentInterval();
} else {
result = createEmptyAlignmentContext(currentInterval);
advanceIntervalLocus();
if (currentInterval != null) {
final int comparison = IntervalUtils.compareLocatables(currentInterval, currentAlignmentContext, dictionary);
// Interval is after the next alignment context when comparison is greater than zero.
if (comparison > 0) {
advanceAlignmentContextToCurrentInterval();
}
}
}
return result;
}
use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.
the class IntervalAlignmentContextIteratorUnitTest method testCoveredOnly.
@Test
public void testCoveredOnly() {
// This test is good at finding places where the alignment contexts start behind the interval.
// Totally covered
final SimpleInterval record_20_9999910_9999913 = new SimpleInterval("20:9999910-9999913");
final List<SimpleInterval> locusIntervals = new ArrayList<>(1);
locusIntervals.add(record_20_9999910_9999913);
final List<AlignmentContext> allAlignmentContexts = getAlignmentContexts(locusIntervals, BAM_FILE_NAME);
Assert.assertEquals(allAlignmentContexts.size(), 4);
Assert.assertTrue(allAlignmentContexts.stream().allMatch(ac -> ac != null));
}
Aggregations