use of htsjdk.samtools.SAMReadGroupRecord in project gatk by broadinstitute.
the class ReadPileupUnitTest method testSplitByReadGroup.
/**
* Ensure that basic read group splitting works.
*/
@Test
public void testSplitByReadGroup() {
final SAMReadGroupRecord readGroupOne = new SAMReadGroupRecord("rg1");
final SAMReadGroupRecord readGroupTwo = new SAMReadGroupRecord("rg2");
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(1, 1, 1000);
header.addReadGroup(readGroupOne);
header.addReadGroup(readGroupTwo);
final GATKRead read1 = ArtificialReadUtils.createArtificialRead(header, "read1", 0, 1, 10);
read1.setReadGroup(readGroupOne.getId());
final GATKRead read2 = ArtificialReadUtils.createArtificialRead(header, "read2", 0, 1, 10);
read2.setReadGroup(readGroupTwo.getId());
final GATKRead read3 = ArtificialReadUtils.createArtificialRead(header, "read3", 0, 1, 10);
read3.setReadGroup(readGroupOne.getId());
final GATKRead read4 = ArtificialReadUtils.createArtificialRead(header, "read4", 0, 1, 10);
read4.setReadGroup(readGroupTwo.getId());
final GATKRead read5 = ArtificialReadUtils.createArtificialRead(header, "read5", 0, 1, 10);
read5.setReadGroup(readGroupTwo.getId());
final GATKRead read6 = ArtificialReadUtils.createArtificialRead(header, "read6", 0, 1, 10);
read6.setReadGroup(readGroupOne.getId());
final GATKRead read7 = ArtificialReadUtils.createArtificialRead(header, "read7", 0, 1, 10);
read7.setReadGroup(readGroupOne.getId());
final ReadPileup pileup = new ReadPileup(loc, Arrays.asList(read1, read2, read3, read4, read5, read6, read7), 1);
final ReadPileup rg1Pileup = pileup.makeFilteredPileup(pe -> "rg1".equals(pe.getRead().getReadGroup()));
final List<GATKRead> rg1Reads = rg1Pileup.getReads();
Assert.assertEquals(rg1Reads.size(), 4, "Wrong number of reads in read group rg1");
Assert.assertEquals(rg1Reads.get(0), read1, "Read " + read1.getName() + " should be in rg1 but isn't");
Assert.assertEquals(rg1Reads.get(1), read3, "Read " + read3.getName() + " should be in rg1 but isn't");
Assert.assertEquals(rg1Reads.get(2), read6, "Read " + read6.getName() + " should be in rg1 but isn't");
Assert.assertEquals(rg1Reads.get(3), read7, "Read " + read7.getName() + " should be in rg1 but isn't");
final ReadPileup rg2Pileup = pileup.makeFilteredPileup(pe -> "rg2".equals(pe.getRead().getReadGroup()));
final List<GATKRead> rg2Reads = rg2Pileup.getReads();
Assert.assertEquals(rg2Reads.size(), 3, "Wrong number of reads in read group rg2");
Assert.assertEquals(rg2Reads.get(0), read2, "Read " + read2.getName() + " should be in rg2 but isn't");
Assert.assertEquals(rg2Reads.get(1), read4, "Read " + read4.getName() + " should be in rg2 but isn't");
Assert.assertEquals(rg2Reads.get(2), read5, "Read " + read5.getName() + " should be in rg2 but isn't");
}
Aggregations