Search in sources :

Example 86 with SAMFileHeader

use of htsjdk.samtools.SAMFileHeader in project gatk by broadinstitute.

the class ReadUtilsUnitTest method testGetSamplesFromHeaderNoSamples.

@Test
public void testGetSamplesFromHeaderNoSamples() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(5, 1, 100);
    header.setReadGroups(Arrays.asList(new SAMReadGroupRecord("ReadGroup1")));
    Assert.assertEquals(header.getReadGroups().size(), 1);
    Assert.assertNull(header.getReadGroups().get(0).getSample());
    Assert.assertTrue(ReadUtils.getSamplesFromHeader(header).isEmpty(), "Non-empty Set returned from ReadUtils.getSamplesFromHeader() for a header with no samples");
}
Also used : SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 87 with SAMFileHeader

use of htsjdk.samtools.SAMFileHeader in project gatk by broadinstitute.

the class ReadUtilsUnitTest method testReadWithNsRefAfterDeletion.

@Test
public void testReadWithNsRefAfterDeletion() throws FileNotFoundException {
    final IndexedFastaSequenceFile seq = new CachingIndexedFastaSequenceFile(new File(exampleReference));
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(seq.getSequenceDictionary());
    final int readLength = 76;
    final GATKRead read = ArtificialReadUtils.createArtificialRead(header, "myRead", 0, 8975, readLength);
    read.setBases(Utils.dupBytes((byte) 'A', readLength));
    read.setBaseQualities(Utils.dupBytes((byte) 30, readLength));
    read.setCigar("3M414N1D73M");
    final int result = ReadUtils.getReadCoordinateForReferenceCoordinateUpToEndOfRead(read, 9393, ReadUtils.ClippingTail.LEFT_TAIL);
    Assert.assertEquals(result, 3);
}
Also used : CachingIndexedFastaSequenceFile(org.broadinstitute.hellbender.utils.fasta.CachingIndexedFastaSequenceFile) SAMFileHeader(htsjdk.samtools.SAMFileHeader) CachingIndexedFastaSequenceFile(org.broadinstitute.hellbender.utils.fasta.CachingIndexedFastaSequenceFile) File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) CachingIndexedFastaSequenceFile(org.broadinstitute.hellbender.utils.fasta.CachingIndexedFastaSequenceFile) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 88 with SAMFileHeader

use of htsjdk.samtools.SAMFileHeader in project gatk by broadinstitute.

the class ReadUtilsUnitTest method testGetSamplesFromHeader.

@Test
public void testGetSamplesFromHeader() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(5, 1, 100);
    final List<SAMReadGroupRecord> readGroups = new ArrayList<>();
    for (int i = 1; i <= 5; ++i) {
        SAMReadGroupRecord readGroup = new SAMReadGroupRecord("ReadGroup" + i);
        readGroup.setSample("Sample" + i);
        readGroups.add(readGroup);
    }
    header.setReadGroups(readGroups);
    final Set<String> samples = ReadUtils.getSamplesFromHeader(header);
    Assert.assertEquals(samples.size(), 5, "Wrong number of samples returned from ReadUtils.getSamplesFromHeader()");
    for (int i = 1; i <= 5; ++i) {
        Assert.assertTrue(samples.contains("Sample" + i), "Missing Sample" + i + " in samples returned from ReadUtils.getSamplesFromHeader()");
    }
}
Also used : SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 89 with SAMFileHeader

use of htsjdk.samtools.SAMFileHeader in project gatk by broadinstitute.

the class CycleCovariateUnitTest method testMoreThanMaxCycleFails.

@Test(expectedExceptions = { UserException.class })
public void testMoreThanMaxCycleFails() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeaderWithReadGroup(illuminaReadGroup);
    int readLength = RAC.MAXIMUM_CYCLE_VALUE + 1;
    GATKRead read = ArtificialReadUtils.createRandomRead(readLength);
    read.setIsPaired(true);
    read.setReadGroup(illuminaReadGroup.getReadGroupId());
    ReadCovariates readCovariates = new ReadCovariates(read.getLength(), 1, new CovariateKeyCache());
    covariate.recordValues(read, header, readCovariates, true);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 90 with SAMFileHeader

use of htsjdk.samtools.SAMFileHeader 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)

Aggregations

SAMFileHeader (htsjdk.samtools.SAMFileHeader)148 Test (org.testng.annotations.Test)89 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)85 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)71 File (java.io.File)23 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)22 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)17 DataProvider (org.testng.annotations.DataProvider)17 java.util (java.util)15 UserException (org.broadinstitute.hellbender.exceptions.UserException)15 ArrayList (java.util.ArrayList)14 List (java.util.List)12 Collectors (java.util.stream.Collectors)12 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)12 SAMRecord (htsjdk.samtools.SAMRecord)11 Locatable (htsjdk.samtools.util.Locatable)11 BeforeClass (org.testng.annotations.BeforeClass)11 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)10 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)10 ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)10