Search in sources :

Example 46 with SAMReadGroupRecord

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");
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)46 Test (org.testng.annotations.Test)30 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)26 SAMFileHeader (htsjdk.samtools.SAMFileHeader)22 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)20 BeforeClass (org.testng.annotations.BeforeClass)9 ArrayList (java.util.ArrayList)7 java.util (java.util)6 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)6 DataProvider (org.testng.annotations.DataProvider)6 Locatable (htsjdk.samtools.util.Locatable)5 UserException (org.broadinstitute.hellbender.exceptions.UserException)5 RecalibrationArgumentCollection (org.broadinstitute.hellbender.utils.recalibration.RecalibrationArgumentCollection)5 SAMRecord (htsjdk.samtools.SAMRecord)4 SamReader (htsjdk.samtools.SamReader)4 HashMap (java.util.HashMap)4 ArtificialReadUtils (org.broadinstitute.hellbender.utils.read.ArtificialReadUtils)4 Assert (org.testng.Assert)4 CigarElement (htsjdk.samtools.CigarElement)3 CigarOperator (htsjdk.samtools.CigarOperator)3