Search in sources :

Example 46 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class SampleCollectionUnitTest method testReadGroupIndexByReadWithNullReadGroup.

@Test(dataProvider = "samFileHeaderData", dependsOnMethods = "testCreation")
public void testReadGroupIndexByReadWithNullReadGroup(final SAMFileHeader header) {
    final SampleCollection sampleCollection = new SampleCollection(header);
    final GATKRead read = ArtificialReadUtils.createRandomRead(header, 100);
    read.setReadGroup(null);
    Assert.assertEquals(sampleCollection.readGroupIndexByRead(read), -1);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 47 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class SampleCollectionUnitTest method testReadGroupIndexByReadWithReadGroupWithoutSample.

@Test(dataProvider = "samFileHeaderData", dependsOnMethods = "testCreation")
public void testReadGroupIndexByReadWithReadGroupWithoutSample(final SAMFileHeader header) {
    final String readGroup = header.getReadGroups().stream().filter(rg -> rg.getSample() == null).map(SAMReadGroupRecord::getId).findFirst().orElse(null);
    if (readGroup == null)
        return;
    final SampleCollection sampleCollection = new SampleCollection(header);
    final GATKRead read = ArtificialReadUtils.createRandomRead(header, 100);
    read.setReadGroup(readGroup);
    Assert.assertEquals(sampleCollection.readGroupIndexByRead(read), sampleCollection.readGroupIndexById(readGroup));
}
Also used : java.util(java.util) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) ArtificialReadUtils(org.broadinstitute.hellbender.utils.read.ArtificialReadUtils) Assert(org.testng.Assert) DataProvider(org.testng.annotations.DataProvider) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) BeforeClass(org.testng.annotations.BeforeClass) Test(org.testng.annotations.Test) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Collectors(java.util.stream.Collectors) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 48 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class ReadPosRankSumTestUnitTest method makeRead.

private GATKRead makeRead(final int start, final int mq) {
    Cigar cigar = TextCigarCodec.decode("10M");
    final GATKRead read = ArtificialReadUtils.createArtificialRead(cigar);
    read.setMappingQuality(mq);
    read.setPosition(CONTIG, start);
    return read;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Cigar(htsjdk.samtools.Cigar)

Example 49 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class ReadPosRankSumTestUnitTest method testReadPos_Raw.

@Test
public void testReadPos_Raw() {
    final AS_RankSumTest ann = new AS_ReadPosRankSumTest();
    final String key1 = GATKVCFConstants.AS_RAW_READ_POS_RANK_SUM_KEY;
    final String key2 = GATKVCFConstants.AS_READ_POS_RANK_SUM_KEY;
    final int[] startAlts = { 3, 4 };
    final int[] startRefs = { 1, 2 };
    final int readLength = 10;
    final List<GATKRead> refReads = Arrays.asList(makeRead(startRefs[0], 30), makeRead(startRefs[1], 30));
    final List<GATKRead> altReads = Arrays.asList(makeRead(startAlts[0], 30), makeRead(startAlts[1], 30));
    final ReadLikelihoods<Allele> likelihoods = AnnotationArtificialData.makeLikelihoods(sample1, refReads, altReads, -100.0, -100.0, REF, ALT);
    Assert.assertEquals(ann.getDescriptions().size(), 1);
    Assert.assertEquals(ann.getDescriptions().get(0).getID(), key1);
    Assert.assertEquals(ann.getKeyNames().size(), 1);
    Assert.assertEquals(ann.getKeyNames().get(0), key2);
    final ReferenceContext ref = null;
    //middle of the read
    final long position = 5L;
    final VariantContext vc = makeVC(position);
    final Map<String, Object> annotateRaw = ann.annotateRawData(ref, vc, likelihoods);
    final Map<String, Object> annotateNonRaw = ann.annotate(ref, vc, likelihoods);
    final String expected = startAlts[0] + ",1," + startAlts[1] + ",1" + AS_RankSumTest.PRINT_DELIM + startRefs[0] + ",1," + startRefs[1] + ",1";
    Assert.assertEquals(annotateRaw.get(key1), expected);
    Assert.assertEquals(annotateNonRaw.get(key1), expected);
    //past middle
    final long positionEnd = 8L;
    final VariantContext vcEnd = makeVC(positionEnd);
    //Note: past the middle of the read we compute the position from the end.
    final Map<String, Object> annotateEndRaw = ann.annotateRawData(ref, vcEnd, likelihoods);
    final Map<String, Object> annotateEndNonRaw = ann.annotate(ref, vcEnd, likelihoods);
    final String refS = (startRefs[0] + readLength - positionEnd - 1) + ",1," + (startRefs[1] + readLength - positionEnd - 1) + ",1";
    final String altS = (positionEnd - startAlts[1]) + ",1," + (positionEnd - startAlts[0]) + ",1";
    Assert.assertEquals(annotateEndRaw.get(key1), refS + AS_RankSumTest.PRINT_DELIM + altS);
    Assert.assertEquals(annotateEndNonRaw.get(key1), refS + AS_RankSumTest.PRINT_DELIM + altS);
    //past middle
    final long positionPastEnd = 20L;
    final VariantContext vcPastEnd = makeVC(positionPastEnd);
    //Note: past the end of the read, there's nothing
    final Map<String, Object> annotatePastEndRaw = ann.annotateRawData(ref, vcPastEnd, likelihoods);
    final Map<String, Object> annotatePastEndNonRaw = ann.annotate(ref, vcPastEnd, likelihoods);
    Assert.assertTrue(annotatePastEndRaw.isEmpty());
    Assert.assertTrue(annotatePastEndNonRaw.isEmpty());
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) AS_ReadPosRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_ReadPosRankSumTest) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest) AS_ReadPosRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_ReadPosRankSumTest)

Example 50 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class ReadPosRankSumTestUnitTest method testIsUsableRead.

@Test(dataProvider = "dataIsUsableRead")
public void testIsUsableRead(final String cigarString, final int mappingQuality, final int start, final int refLoc, final boolean isUsable) {
    final ReadPosRankSumTest readPosRankSumTest = new ReadPosRankSumTest();
    final Cigar cigar = TextCigarCodec.decode(cigarString);
    final GATKRead read = ArtificialReadUtils.createArtificialRead(cigar);
    read.setMappingQuality(mappingQuality);
    read.setPosition(CONTIG, start);
    Assert.assertEquals(readPosRankSumTest.isUsableRead(read, refLoc), isUsable);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Cigar(htsjdk.samtools.Cigar) AS_ReadPosRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_ReadPosRankSumTest) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest) AS_ReadPosRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_ReadPosRankSumTest)

Aggregations

GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)457 Test (org.testng.annotations.Test)286 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)163 SAMFileHeader (htsjdk.samtools.SAMFileHeader)87 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)59 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)40 ArrayList (java.util.ArrayList)34 Collectors (java.util.stream.Collectors)34 List (java.util.List)30 Cigar (htsjdk.samtools.Cigar)29 File (java.io.File)28 java.util (java.util)28 DataProvider (org.testng.annotations.DataProvider)28 JavaRDD (org.apache.spark.api.java.JavaRDD)26 Haplotype (org.broadinstitute.hellbender.utils.haplotype.Haplotype)26 Assert (org.testng.Assert)25 ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)24 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)22 Argument (org.broadinstitute.barclay.argparser.Argument)18 UserException (org.broadinstitute.hellbender.exceptions.UserException)18