Search in sources :

Example 6 with RecalibrationArgumentCollection

use of org.broadinstitute.hellbender.utils.recalibration.RecalibrationArgumentCollection in project gatk by broadinstitute.

the class CycleCovariateUnitTest method init.

@BeforeClass
public void init() {
    RAC = new RecalibrationArgumentCollection();
    covariate = new CycleCovariate(RAC);
    illuminaReadGroup = new SAMReadGroupRecord("MY.ID");
    illuminaReadGroup.setPlatform("illumina");
}
Also used : RecalibrationArgumentCollection(org.broadinstitute.hellbender.utils.recalibration.RecalibrationArgumentCollection) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with RecalibrationArgumentCollection

use of org.broadinstitute.hellbender.utils.recalibration.RecalibrationArgumentCollection in project gatk by broadinstitute.

the class ReadCovariatesUnitTest method testCovariateGeneration.

@Test
public void testCovariateGeneration() {
    final RecalibrationArgumentCollection RAC = new RecalibrationArgumentCollection();
    final String[] readGroups = { "RG1", "RG2", "RGbla" };
    ReadGroupCovariate rgCov = new ReadGroupCovariate(RAC, Arrays.asList(readGroups));
    QualityScoreCovariate qsCov = new QualityScoreCovariate(RAC);
    ContextCovariate coCov = new ContextCovariate(RAC);
    CycleCovariate cyCov = new CycleCovariate(RAC);
    StandardCovariateList covariates = new StandardCovariateList(RAC, Arrays.asList(readGroups));
    final int NUM_READS = 100;
    final Random rnd = Utils.getRandomGenerator();
    final CovariateKeyCache keyCache = new CovariateKeyCache();
    for (int idx = 0; idx < NUM_READS; idx++) {
        for (final String readGroupID : readGroups) {
            final SAMReadGroupRecord readGroupRecord = new SAMReadGroupRecord(readGroupID);
            readGroupRecord.setPlatform("illumina");
            final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeaderWithReadGroup(readGroupRecord);
            // random read length, at least 10 bp long
            final int length = 10 + rnd.nextInt(100);
            final GATKRead read = ArtificialReadUtils.createRandomRead(header, length, false);
            read.setIsReverseStrand(rnd.nextBoolean());
            read.setReadGroup(readGroupID);
            final byte[] mQuals = read.getBaseQualities();
            final byte[] iQuals = ReadUtils.getBaseInsertionQualities(read);
            final byte[] dQuals = ReadUtils.getBaseDeletionQualities(read);
            ReadCovariates rc = RecalUtils.computeCovariates(read, header, covariates, true, keyCache);
            // check that the length is correct
            Assert.assertEquals(rc.getMismatchesKeySet().length, length);
            Assert.assertEquals(rc.getInsertionsKeySet().length, length);
            Assert.assertEquals(rc.getDeletionsKeySet().length, length);
            for (int i = 0; i < length; i++) {
                // check that read group is always the same
                Assert.assertEquals(rgCov.formatKey(rc.getMismatchesKeySet(i)[0]), readGroupID);
                Assert.assertEquals(rgCov.formatKey(rc.getInsertionsKeySet(i)[0]), readGroupID);
                Assert.assertEquals(rgCov.formatKey(rc.getDeletionsKeySet(i)[0]), readGroupID);
                // check quality score
                Assert.assertEquals(qsCov.formatKey(rc.getMismatchesKeySet(i)[1]), String.valueOf(mQuals[i]));
                Assert.assertEquals(qsCov.formatKey(rc.getInsertionsKeySet(i)[1]), String.valueOf(iQuals[i]));
                Assert.assertEquals(qsCov.formatKey(rc.getDeletionsKeySet(i)[1]), String.valueOf(dQuals[i]));
                // check context
                Assert.assertEquals(coCov.formatKey(rc.getMismatchesKeySet(i)[2]), ContextCovariateUnitTest.expectedContext(read, i, RAC.MISMATCHES_CONTEXT_SIZE, RAC.LOW_QUAL_TAIL), "read: " + idx + " readGroup:" + readGroupID + " context mismatch key at position:" + i);
                Assert.assertEquals(coCov.formatKey(rc.getInsertionsKeySet(i)[2]), ContextCovariateUnitTest.expectedContext(read, i, RAC.INDELS_CONTEXT_SIZE, RAC.LOW_QUAL_TAIL), "read: " + idx + " readGroup:" + readGroupID + " context insertion key at position:" + i);
                Assert.assertEquals(coCov.formatKey(rc.getDeletionsKeySet(i)[2]), ContextCovariateUnitTest.expectedContext(read, i, RAC.INDELS_CONTEXT_SIZE, RAC.LOW_QUAL_TAIL), "read: " + idx + " readGroup:" + readGroupID + " context deletion key at position:" + i);
                // check cycle
                final int expectedCycleMismatch = CycleCovariateUnitTest.expectedCycle(read, i, false, RAC.MAXIMUM_CYCLE_VALUE);
                final int expectedCycleIndel = CycleCovariateUnitTest.expectedCycle(read, i, true, RAC.MAXIMUM_CYCLE_VALUE);
                Assert.assertEquals(cyCov.formatKey(rc.getMismatchesKeySet(i)[3]), String.valueOf(expectedCycleMismatch), "read: " + idx + " cycle mismatch key at position:" + i);
                Assert.assertEquals(cyCov.formatKey(rc.getInsertionsKeySet(i)[3]), String.valueOf(expectedCycleIndel), "read: " + idx + " cycle insertion key at position:" + i);
                Assert.assertEquals(cyCov.formatKey(rc.getDeletionsKeySet(i)[3]), String.valueOf(expectedCycleIndel), "read: " + idx + " cycle deletion key at position:" + i);
            }
        }
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) RecalibrationArgumentCollection(org.broadinstitute.hellbender.utils.recalibration.RecalibrationArgumentCollection) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) Random(java.util.Random) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 8 with RecalibrationArgumentCollection

use of org.broadinstitute.hellbender.utils.recalibration.RecalibrationArgumentCollection in project gatk by broadinstitute.

the class ReadGroupCovariateUnitTest method testMissingReadGroup.

@Test(expectedExceptions = IllegalStateException.class)
public void testMissingReadGroup() {
    final String id = "MY.ID";
    final String expected = "SAMPLE.1";
    final ReadGroupCovariate covariate = new ReadGroupCovariate(new RecalibrationArgumentCollection(), Arrays.asList(expected));
    final int key = covariate.keyFromValue("fred");
}
Also used : RecalibrationArgumentCollection(org.broadinstitute.hellbender.utils.recalibration.RecalibrationArgumentCollection) Test(org.testng.annotations.Test)

Example 9 with RecalibrationArgumentCollection

use of org.broadinstitute.hellbender.utils.recalibration.RecalibrationArgumentCollection in project gatk by broadinstitute.

the class ReadGroupCovariateUnitTest method testReadGroupNames.

@Test
public void testReadGroupNames() {
    final String id = "MY.ID";
    final String expected = "SAMPLE.1";
    final ReadGroupCovariate covariate = new ReadGroupCovariate(new RecalibrationArgumentCollection(), Arrays.asList(expected));
    final SAMFileHeader headerWithGroups = ArtificialReadUtils.createArtificialSamHeaderWithGroups(1, 0, 100, 2);
    final List<String> rgs = Arrays.asList("rg1", "rg2");
    Assert.assertEquals(ReadGroupCovariate.getReadGroupIDs(headerWithGroups), headerWithGroups.getReadGroups().stream().map(rg -> ReadGroupCovariate.getID(rg)).collect(Collectors.toList()));
}
Also used : RecalibrationArgumentCollection(org.broadinstitute.hellbender.utils.recalibration.RecalibrationArgumentCollection) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Test(org.testng.annotations.Test)

Aggregations

RecalibrationArgumentCollection (org.broadinstitute.hellbender.utils.recalibration.RecalibrationArgumentCollection)9 Test (org.testng.annotations.Test)7 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)5 SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 BeforeClass (org.testng.annotations.BeforeClass)2 Random (java.util.Random)1 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)1 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)1