use of org.broadinstitute.hellbender.utils.read.ReadConstants.NO_MAPPING_QUALITY in project gatk by broadinstitute.
the class ReadPileupUnitTest method testSimplePileup.
@Test
public void testSimplePileup() {
final int readlength = 10;
final byte[] bases1 = Utils.repeatChars('A', readlength);
final byte[] quals1 = Utils.repeatBytes((byte) 10, readlength);
final String cigar1 = "10M";
final byte[] bases2 = Utils.repeatChars('C', readlength);
final byte[] quals2 = Utils.repeatBytes((byte) 20, readlength);
final String cigar2 = "5M3I2M";
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
final GATKRead read1 = ArtificialReadUtils.createArtificialRead(header, bases1, quals1, cigar1);
read1.setName("read1");
final GATKRead read2 = ArtificialReadUtils.createArtificialRead(header, bases2, quals2, cigar2);
read1.setName("read2");
final List<GATKRead> reads = Arrays.asList(read1, read2);
final ReadPileup pu = new ReadPileup(loc, reads, 1);
//checking non-blowup. We're not making any claims about the format of toString
Assert.assertNotNull(pu.toString());
Assert.assertEquals(pu.getPileupString('N'), String.format("%s %s N %s%s %s%s", // the position
loc.getContig(), // the position
loc.getStart(), // the bases
(char) read1.getBase(0), // the bases
(char) read2.getBase(0), // base quality in FASTQ format
SAMUtils.phredToFastq(read1.getBaseQuality(0)), // base quality in FASTQ format
SAMUtils.phredToFastq(read2.getBaseQuality(0))));
Assert.assertEquals(pu.getBases(), new byte[] { (byte) 'A', (byte) 'C' });
Assert.assertFalse(pu.isEmpty());
Assert.assertEquals(pu.size(), 2, "size");
Assert.assertEquals(pu.getBaseCounts(), new int[] { 1, 1, 0, 0 });
Assert.assertEquals(pu.getBaseQuals(), new byte[] { 10, 20 });
Assert.assertEquals(pu.getLocation(), loc);
Assert.assertEquals(pu.getMappingQuals(), new int[] { NO_MAPPING_QUALITY, NO_MAPPING_QUALITY });
Assert.assertEquals(pu.makeFilteredPileup(p -> p.getQual() >= 12).makeFilteredPileup(p -> p.getMappingQual() >= 0).size(), 1, "getBaseAndMappingFilteredPileup");
Assert.assertEquals(pu.makeFilteredPileup(r -> r.getQual() >= 12).size(), 1, "getBaseFilteredPileup");
Assert.assertEquals(pu.getNumberOfElements(p -> true), 2);
Assert.assertEquals(pu.getNumberOfElements(p -> false), 0);
Assert.assertEquals(pu.getNumberOfElements(p -> p.isDeletion()), 0);
Assert.assertEquals(pu.getNumberOfElements(p -> p.isBeforeDeletionStart()), 0);
Assert.assertEquals(pu.getNumberOfElements(p -> p.isBeforeInsertion()), 0);
Assert.assertEquals(pu.getNumberOfElements(p -> p.getRead().getMappingQuality() == 0), 2);
Assert.assertEquals(pu.getOffsets(), Arrays.asList(1, 1), "getOffsets");
Assert.assertEquals(pu.getReadGroupIDs(), Arrays.asList(new SAMReadGroupRecord[] { null }), "getReadGroups");
Assert.assertEquals(pu.getReads(), Arrays.asList(read1, read2), "getReads");
Assert.assertEquals(pu.getSamples(header), Arrays.asList(new String[] { null }), "getSamples");
Assert.assertTrue(pu.getPileupForLane("fred").isEmpty());
Assert.assertTrue(pu.makeFilteredPileup(r -> r.getMappingQual() >= 10).isEmpty());
}
use of org.broadinstitute.hellbender.utils.read.ReadConstants.NO_MAPPING_QUALITY in project gatk by broadinstitute.
the class ReadPileupUnitTest method testSimplePileupWithOffset.
@Test
public void testSimplePileupWithOffset() {
final int readlength = 10;
final byte[] bases1 = Utils.repeatChars('A', readlength);
final byte[] quals1 = Utils.repeatBytes((byte) 10, readlength);
final String cigar1 = "10M";
final byte[] bases2 = Utils.repeatChars('C', readlength);
final byte[] quals2 = Utils.repeatBytes((byte) 20, readlength);
final String cigar2 = "10M";
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
final GATKRead read1 = ArtificialReadUtils.createArtificialRead(header, bases1, quals1, cigar1);
read1.setName("read1");
final GATKRead read2 = ArtificialReadUtils.createArtificialRead(header, bases2, quals2, cigar2);
read1.setName("read2");
final List<GATKRead> reads = Arrays.asList(read1, read2);
final int off = 6;
final ReadPileup pu = new ReadPileup(loc, reads, off);
Assert.assertEquals(pu.getBases(), new byte[] { (byte) 'A', (byte) 'C' });
//checking non-blowup. We're not making any claims about the format of toString
Assert.assertNotNull(pu.toString());
Assert.assertEquals(pu.getPileupString('N'), String.format("%s %s N %s%s %s%s", // the position
loc.getContig(), // the position
loc.getStart(), // the bases
(char) read1.getBase(off), // the bases
(char) read2.getBase(off), // base quality in FASTQ format
SAMUtils.phredToFastq(read1.getBaseQuality(off)), // base quality in FASTQ format
SAMUtils.phredToFastq(read2.getBaseQuality(off))));
Assert.assertFalse(pu.isEmpty());
Assert.assertEquals(pu.size(), 2, "size");
Assert.assertEquals(pu.getBaseCounts(), new int[] { 1, 1, 0, 0 });
Assert.assertEquals(pu.getBaseQuals(), new byte[] { 10, 20 });
Assert.assertEquals(pu.getLocation(), loc);
Assert.assertEquals(pu.getMappingQuals(), new int[] { NO_MAPPING_QUALITY, NO_MAPPING_QUALITY });
Assert.assertTrue(pu.makeFilteredPileup(r -> r.getRead().isReverseStrand()).isEmpty(), "getReverseStrandPileup");
Assert.assertEquals(pu.makeFilteredPileup(r -> !r.getRead().isReverseStrand()).size(), 2, "getForwardStrandPileup");
Assert.assertEquals(pu.makeFilteredPileup(p -> p.getQual() >= 12).makeFilteredPileup(p -> p.getMappingQual() >= 0).size(), 1, "getBaseAndMappingFilteredPileup");
Assert.assertEquals(pu.makeFilteredPileup(p -> p.getQual() >= 12).size(), 1, "getBaseFilteredPileup");
Assert.assertEquals(pu.getNumberOfElements(p -> true), 2);
Assert.assertEquals(pu.getNumberOfElements(p -> false), 0);
Assert.assertEquals(pu.getNumberOfElements(p -> p.isDeletion()), 0);
Assert.assertEquals(pu.getNumberOfElements(p -> p.isBeforeDeletionStart()), 0);
Assert.assertEquals(pu.getNumberOfElements(p -> p.isBeforeInsertion()), 0);
Assert.assertEquals(pu.getNumberOfElements(p -> p.getRead().getMappingQuality() == 0), 2);
Assert.assertEquals(pu.getOffsets(), Arrays.asList(off, off), "getOffsets");
Assert.assertEquals(pu.getReadGroupIDs(), Arrays.asList(new SAMReadGroupRecord[] { null }), "getReadGroups");
Assert.assertEquals(pu.getReads(), Arrays.asList(read1, read2), "getReads");
Assert.assertEquals(pu.getSamples(header), Arrays.asList(new String[] { null }), "getSamples");
Assert.assertTrue(pu.getPileupForLane("fred").isEmpty());
Assert.assertTrue(pu.makeFilteredPileup(p -> p.getMappingQual() >= 10).isEmpty());
}
use of org.broadinstitute.hellbender.utils.read.ReadConstants.NO_MAPPING_QUALITY in project gatk by broadinstitute.
the class ReadPileupUnitTest method testSimplePileupWithIndelsOffset.
@Test
public void testSimplePileupWithIndelsOffset() {
final int readlength = 10;
final byte[] bases1 = Utils.repeatChars('A', readlength);
final byte[] quals1 = Utils.repeatBytes((byte) 10, readlength);
final String cigar1 = "10M";
final byte[] bases2 = Utils.repeatChars('C', readlength);
final byte[] quals2 = Utils.repeatBytes((byte) 20, readlength);
final String cigar2 = "5M3I2M";
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
final GATKRead read1 = ArtificialReadUtils.createArtificialRead(header, bases1, quals1, cigar1);
read1.setName("read1");
final GATKRead read2 = ArtificialReadUtils.createArtificialRead(header, bases2, quals2, cigar2);
read1.setName("read2");
final List<GATKRead> reads = Arrays.asList(read1, read2);
final int offset = 4;
final ReadPileup pu = new ReadPileup(loc, reads, offset);
final PileupElement firstElem = pu.getElementForRead(read1);
Assert.assertNull(firstElem.getAdjacentOperator(PileupElement.Direction.NEXT));
Assert.assertNull(firstElem.getAdjacentOperator(PileupElement.Direction.PREV));
final PileupElement secondElem = pu.getElementForRead(read2);
Assert.assertEquals(secondElem.getAdjacentOperator(PileupElement.Direction.NEXT), CigarOperator.I);
Assert.assertNull(secondElem.getAdjacentOperator(PileupElement.Direction.PREV));
//checking non-blowup. We're not making any claims about the format of toString
Assert.assertNotNull(pu.toString());
Assert.assertEquals(pu.getPileupString('N'), String.format("%s %s N %s%s %s%s", // the position
loc.getContig(), // the position
loc.getStart(), // the bases
(char) read1.getBase(0), // the bases
(char) read2.getBase(0), // base quality in FASTQ format
SAMUtils.phredToFastq(read1.getBaseQuality(0)), // base quality in FASTQ format
SAMUtils.phredToFastq(read2.getBaseQuality(0))));
Assert.assertEquals(pu.getBases(), new byte[] { (byte) 'A', (byte) 'C' });
Assert.assertFalse(pu.isEmpty());
Assert.assertEquals(pu.size(), 2, "size");
Assert.assertEquals(pu.getBaseCounts(), new int[] { 1, 1, 0, 0 });
Assert.assertEquals(pu.getBaseQuals(), new byte[] { 10, 20 });
Assert.assertEquals(pu.getLocation(), loc);
Assert.assertEquals(pu.getMappingQuals(), new int[] { NO_MAPPING_QUALITY, NO_MAPPING_QUALITY });
Assert.assertEquals(pu.makeFilteredPileup(p -> p.getQual() >= 12).makeFilteredPileup(p -> p.getMappingQual() >= 0).size(), 1, "getBaseAndMappingFilteredPileup");
Assert.assertEquals(pu.makeFilteredPileup(r -> r.getQual() >= 12).size(), 1, "getBaseFilteredPileup");
Assert.assertEquals(pu.getNumberOfElements(p -> true), 2);
Assert.assertEquals(pu.getNumberOfElements(p -> false), 0);
Assert.assertEquals(pu.getNumberOfElements(p -> p.isDeletion()), 0);
Assert.assertEquals(pu.getNumberOfElements(p -> p.isBeforeDeletionStart()), 0);
Assert.assertEquals(pu.getNumberOfElements(p -> p.isBeforeInsertion()), 1);
Assert.assertEquals(pu.getNumberOfElements(p -> p.getRead().getMappingQuality() == 0), 2);
Assert.assertEquals(pu.getOffsets(), Arrays.asList(offset, offset), "getOffsets");
Assert.assertEquals(pu.getReadGroupIDs(), Arrays.asList(new SAMReadGroupRecord[] { null }), "getReadGroups");
Assert.assertEquals(pu.getReads(), Arrays.asList(read1, read2), "getReads");
Assert.assertEquals(pu.getSamples(header), Arrays.asList(new String[] { null }), "getSamples");
Assert.assertTrue(pu.getPileupForLane("fred").isEmpty());
Assert.assertTrue(pu.makeFilteredPileup(r -> r.getMappingQual() >= 10).isEmpty());
}
Aggregations