use of org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine in project gatk by broadinstitute.
the class CalculateMixingFractions method apply.
@Override
public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext refContext, final FeatureContext fc) {
if (!isBiallelicSingletonHetSnp(vc)) {
return;
}
final Optional<String> variantSample = StreamSupport.stream(vc.getGenotypes().spliterator(), false).filter(genotype -> genotype.isHet()).map(genotype -> genotype.getSampleName()).findFirst();
if (!variantSample.isPresent()) {
return;
}
final List<GATKRead> reads = new ArrayList<>();
final List<Integer> offsets = new ArrayList<>();
for (final GATKRead read : readsContext) {
if (read.failsVendorQualityCheck()) {
continue;
}
final AlignmentStateMachine asm = new AlignmentStateMachine(read);
while (asm.stepForwardOnGenome() != null && asm.getGenomePosition() < vc.getStart()) {
}
if (asm.getGenomePosition() == vc.getStart()) {
reads.add(read);
offsets.add(asm.getReadOffset());
}
}
final ReadPileup pileup = new ReadPileup(vc, reads, offsets);
final byte altBase = vc.getAlternateAllele(0).getBases()[0];
final long altCount = StreamSupport.stream(pileup.spliterator(), false).filter(pe -> pe.getBase() == altBase).count();
final long totalCount = pileup.size();
sampleCounts.get(variantSample.get()).addCounts(altCount, totalCount);
}
use of org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine in project gatk-protected by broadinstitute.
the class CalculateMixingFractions method apply.
@Override
public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext refContext, final FeatureContext fc) {
if (!isBiallelicSingletonHetSnp(vc)) {
return;
}
final Optional<String> variantSample = StreamSupport.stream(vc.getGenotypes().spliterator(), false).filter(genotype -> genotype.isHet()).map(genotype -> genotype.getSampleName()).findFirst();
if (!variantSample.isPresent()) {
return;
}
final List<GATKRead> reads = new ArrayList<>();
final List<Integer> offsets = new ArrayList<>();
for (final GATKRead read : readsContext) {
if (read.failsVendorQualityCheck()) {
continue;
}
final AlignmentStateMachine asm = new AlignmentStateMachine(read);
while (asm.stepForwardOnGenome() != null && asm.getGenomePosition() < vc.getStart()) {
}
if (asm.getGenomePosition() == vc.getStart()) {
reads.add(read);
offsets.add(asm.getReadOffset());
}
}
final ReadPileup pileup = new ReadPileup(vc, reads, offsets);
final byte altBase = vc.getAlternateAllele(0).getBases()[0];
final long altCount = StreamSupport.stream(pileup.spliterator(), false).filter(pe -> pe.getBase() == altBase).count();
final long totalCount = pileup.size();
sampleCounts.get(variantSample.get()).addCounts(altCount, totalCount);
}
use of org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine in project gatk by broadinstitute.
the class PileupElement method createPileupForReadAndOffset.
/**
* Create a pileup element for read at offset.
*
* offset must correspond to a valid read offset given the read's cigar, or an IllegalStateException will be throw
*
* @param read a read
* @param offset the offset into the bases we'd like to use in the pileup
* @return a valid PileupElement with read and at offset
*/
public static PileupElement createPileupForReadAndOffset(final GATKRead read, final int offset) {
Utils.nonNull(read, "read is null");
Utils.validIndex(offset, read.getLength());
final AlignmentStateMachine stateMachine = new AlignmentStateMachine(read);
while (stateMachine.stepForwardOnGenome() != null) {
if (stateMachine.getReadOffset() == offset) {
return stateMachine.makePileupElement();
}
}
throw new IllegalStateException("Tried to create a pileup for read " + read + " with offset " + offset + " but we never saw such an offset in the alignment state machine");
}
use of org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine in project gatk by broadinstitute.
the class PileupElementUnitTest method testPrevAndNextTest.
@Test(dataProvider = "PrevAndNextTest")
public void testPrevAndNextTest(final GATKRead read, final CigarOperator firstOp, final CigarOperator lastOp, final List<CigarOperator> ops) {
final AlignmentStateMachine state = new AlignmentStateMachine(read);
//before the first 'op' from the list
state.stepForwardOnGenome();
final PileupElement pe = state.makePileupElement();
Assert.assertEquals(pe.getBetweenNextPosition().size(), ops.size());
Assert.assertEquals(pe.getBetweenPrevPosition().size(), 0);
assertEqualsOperators(pe.getBetweenNextPosition(), ops);
Assert.assertEquals(pe.getPreviousOnGenomeCigarElement(), null);
Assert.assertNotNull(pe.getNextOnGenomeCigarElement());
Assert.assertEquals(pe.getNextOnGenomeCigarElement().getOperator(), lastOp);
//after the first 'op' from the list
state.stepForwardOnGenome();
final PileupElement pe2 = state.makePileupElement();
Assert.assertEquals(pe2.getBetweenPrevPosition().size(), ops.size());
Assert.assertEquals(pe2.getBetweenNextPosition().size(), 0);
assertEqualsOperators(pe2.getBetweenPrevPosition(), ops);
Assert.assertNotNull(pe2.getPreviousOnGenomeCigarElement());
Assert.assertEquals(pe2.getPreviousOnGenomeCigarElement().getOperator(), firstOp);
Assert.assertEquals(pe2.getNextOnGenomeCigarElement(), null);
}
use of org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine in project gatk by broadinstitute.
the class PileupElementUnitTest method testImmediateBeforeAndAfterTest_simple.
@Test(dataProvider = "PrevAndNextTest_simple")
public void testImmediateBeforeAndAfterTest_simple(final GATKRead read, final CigarOperator middleOp) {
final AlignmentStateMachine state = new AlignmentStateMachine(read);
state.stepForwardOnGenome();
//before the 'middleOp'
final PileupElement pe1 = state.makePileupElement();
Assert.assertEquals(pe1.getAdjacentOperator(PileupElement.Direction.PREV), null, "PREV");
Assert.assertEquals(pe1.getAdjacentOperator(PileupElement.Direction.NEXT), middleOp, "NEXT");
for (final CigarOperator op : CigarOperator.values()) {
Assert.assertEquals(pe1.isImmediatelyBefore(op), middleOp == op, op.toString());
Assert.assertFalse(pe1.isImmediatelyAfter(op), op.toString());
}
state.stepForwardOnGenome();
//after the 'middleOp'
final PileupElement pe2 = state.makePileupElement();
Assert.assertEquals(pe2.getAdjacentOperator(PileupElement.Direction.PREV), middleOp, "PREV");
Assert.assertEquals(pe2.getAdjacentOperator(PileupElement.Direction.NEXT), null, "NEXT");
for (final CigarOperator op : CigarOperator.values()) {
Assert.assertFalse(pe2.isImmediatelyBefore(op), op.toString());
Assert.assertEquals(pe2.isImmediatelyAfter(op), op == middleOp, op.toString());
}
}
Aggregations