use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.
the class CigarUtils method hasConsecutiveIndels.
/**
* Checks if cigar has consecutive I/D elements.
*/
private static boolean hasConsecutiveIndels(final List<CigarElement> elems) {
boolean prevIndel = false;
for (final CigarElement elem : elems) {
final CigarOperator op = elem.getOperator();
final boolean isIndel = (op == CigarOperator.INSERTION || op == CigarOperator.DELETION);
if (prevIndel && isIndel) {
return true;
}
prevIndel = isIndel;
}
return false;
}
use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.
the class LocusIteratorByStateUnitTest method makeIndelLengthAndBasesTest.
/////////////////////////////////////////////
// get event length and bases calculations //
/////////////////////////////////////////////
@DataProvider(name = "IndelLengthAndBasesTest")
public Object[][] makeIndelLengthAndBasesTest() {
final String EVENT_BASES = "ACGTACGTACGT";
final List<Object[]> tests = new LinkedList<>();
for (int eventSize = 1; eventSize < 10; eventSize++) {
for (final CigarOperator indel : Arrays.asList(CigarOperator.D, CigarOperator.I)) {
final String cigar = String.format("2M%d%s1M", eventSize, indel.toString());
final String eventBases = indel == CigarOperator.D ? "" : EVENT_BASES.substring(0, eventSize);
final int readLength = 3 + eventBases.length();
final GATKRead read = ArtificialReadUtils.createArtificialRead(header, "read", 0, 1, readLength);
read.setBases(("TT" + eventBases + "A").getBytes());
final byte[] quals = new byte[readLength];
for (int i = 0; i < readLength; i++) quals[i] = (byte) (i % QualityUtils.MAX_SAM_QUAL_SCORE);
read.setBaseQualities(quals);
read.setCigar(cigar);
tests.add(new Object[] { read, indel, eventSize, eventBases.equals("") ? null : eventBases });
}
}
return tests.toArray(new Object[][] {});
}
use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.
the class PileupElementUnitTest method makePrevAndNextTest_simple.
@DataProvider(name = "PrevAndNextTest_simple")
public Object[][] makePrevAndNextTest_simple() {
final List<Object[]> tests = new LinkedList<>();
for (final CigarOperator firstOp : Arrays.asList(M)) {
for (final CigarOperator lastOp : Arrays.asList(M)) {
for (final CigarOperator middleOp : Arrays.asList(CigarOperator.I, CigarOperator.P, CigarOperator.S)) {
final int readLength = 3;
final GATKRead read = ArtificialReadUtils.createArtificialRead(header, "read", 0, 1, readLength);
read.setBases(Utils.dupBytes((byte) 'A', readLength));
read.setBaseQualities(Utils.dupBytes((byte) 30, readLength));
String cigar = "1" + firstOp;
cigar += "1" + middleOp;
cigar += "1" + lastOp;
read.setCigar(cigar);
tests.add(new Object[] { read, middleOp });
}
}
}
return tests.toArray(new Object[][] {});
}
use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.
the class PileupElementUnitTest method testIsImmediatelyAfter_afterLastM.
@Test
public void testIsImmediatelyAfter_afterLastM() {
final GATKRead read = ArtificialReadUtils.createArtificialRead("10M10D10M");
final PileupElement pe = PileupElement.createPileupForReadAndOffset(read, 9);
Assert.assertFalse(pe.atStartOfCurrentCigar(), "atStartOfCurrentCigar");
Assert.assertTrue(pe.atEndOfCurrentCigar(), "atEndOfCurrentCigar");
for (final CigarOperator op : CigarOperator.values()) {
Assert.assertFalse(pe.isImmediatelyAfter(op), "isImmediatelyAfter " + op);
}
Assert.assertTrue(pe.isImmediatelyBefore(D));
for (final CigarOperator op : CigarOperator.values()) {
if (op != D) {
Assert.assertFalse(pe.isImmediatelyBefore(op), "isImmediatelyBefore " + op);
}
}
}
use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.
the class PileupElementUnitTest method testAdjacentElements.
@Test(dataProvider = "adjacentElementTestData")
public void testAdjacentElements(GATKRead read, int goodOffset, boolean atStartOfCurrentCigar, boolean atEndOfCurrentCigar, CigarOperator prev, CigarOperator next) throws Exception {
final PileupElement pe = PileupElement.createPileupForReadAndOffset(read, goodOffset);
Assert.assertEquals(pe.atStartOfCurrentCigar(), atStartOfCurrentCigar, "atStartOfCurrentCigar");
Assert.assertEquals(pe.atEndOfCurrentCigar(), atEndOfCurrentCigar, "atEndOfCurrentCigar");
Assert.assertEquals(pe.getAdjacentOperator(PileupElement.Direction.PREV), prev, "prev");
Assert.assertEquals(pe.getAdjacentOperator(PileupElement.Direction.NEXT), next, "next");
for (final CigarOperator op : CigarOperator.values()) {
Assert.assertEquals(pe.isImmediatelyAfter(op), atStartOfCurrentCigar && op == prev);
Assert.assertEquals(pe.isImmediatelyBefore(op), atEndOfCurrentCigar && op == next);
}
}
Aggregations