Search in sources :

Example 91 with GATKRead

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

the class MappingQualityRankSumTestUnitTest method testMQ.

@Test
public void testMQ() {
    final InfoFieldAnnotation ann = new MappingQualityRankSumTest();
    final String key = GATKVCFConstants.MAP_QUAL_RANK_SUM_KEY;
    final MannWhitneyU mannWhitneyU = new MannWhitneyU();
    final int[] altMappingQualities = { 10, 20 };
    final int[] refMappingQualities = { 100, 110 };
    final List<GATKRead> refReads = Arrays.stream(refMappingQualities).mapToObj(i -> makeRead(i)).collect(Collectors.toList());
    final List<GATKRead> altReads = Arrays.stream(altMappingQualities).mapToObj(i -> makeRead(i)).collect(Collectors.toList());
    final ReadLikelihoods<Allele> likelihoods = AnnotationArtificialData.makeLikelihoods(sample1, refReads, altReads, -100.0, -100.0, REF, ALT);
    final VariantContext vc = makeVC(REF, ALT);
    final Map<String, Object> annotate = ann.annotate(null, vc, likelihoods);
    final double zScore = mannWhitneyU.test(new double[] { altMappingQualities[0], altMappingQualities[1] }, new double[] { refMappingQualities[0], refMappingQualities[1] }, MannWhitneyU.TestType.FIRST_DOMINATES).getZ();
    final String zScoreStr = String.format("%.3f", zScore);
    Assert.assertEquals(annotate.get(key), zScoreStr);
    Assert.assertEquals(ann.getDescriptions().size(), 1);
    Assert.assertEquals(ann.getDescriptions().get(0).getID(), key);
    Assert.assertEquals(ann.getKeyNames().size(), 1);
    Assert.assertEquals(ann.getKeyNames().get(0), key);
}
Also used : TextCigarCodec(htsjdk.samtools.TextCigarCodec) Cigar(htsjdk.samtools.Cigar) AS_MappingQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_MappingQualityRankSumTest) Arrays(java.util.Arrays) GATKVCFConstants(org.broadinstitute.hellbender.utils.variant.GATKVCFConstants) Test(org.testng.annotations.Test) htsjdk.variant.variantcontext(htsjdk.variant.variantcontext) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Collectors(java.util.stream.Collectors) ReadLikelihoods(org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest) List(java.util.List) ArtificialReadUtils(org.broadinstitute.hellbender.utils.read.ArtificialReadUtils) Assert(org.testng.Assert) Map(java.util.Map) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) MannWhitneyU(org.broadinstitute.hellbender.utils.MannWhitneyU) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) AS_MappingQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_MappingQualityRankSumTest) MannWhitneyU(org.broadinstitute.hellbender.utils.MannWhitneyU) AS_MappingQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_MappingQualityRankSumTest) Test(org.testng.annotations.Test) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest)

Example 92 with GATKRead

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

the class MappingQualityRankSumTestUnitTest method testAS_MQRaw.

@Test
public void testAS_MQRaw() {
    final AS_RankSumTest ann = new AS_MappingQualityRankSumTest();
    final String key1 = GATKVCFConstants.AS_RAW_MAP_QUAL_RANK_SUM_KEY;
    final String key2 = GATKVCFConstants.AS_MAP_QUAL_RANK_SUM_KEY;
    final int[] altMappingQualities = { 10, 20 };
    final int[] refMappingQualities = { 100, 110 };
    final List<GATKRead> refReads = Arrays.stream(refMappingQualities).mapToObj(i -> makeRead(i)).collect(Collectors.toList());
    final List<GATKRead> altReads = Arrays.stream(altMappingQualities).mapToObj(i -> makeRead(i)).collect(Collectors.toList());
    final ReadLikelihoods<Allele> likelihoods = AnnotationArtificialData.makeLikelihoods(sample1, refReads, altReads, -100.0, -100.0, REF, ALT);
    final ReferenceContext ref = null;
    final VariantContext vc = makeVC(REF, ALT);
    final Map<String, Object> annotateRaw = ann.annotateRawData(ref, vc, likelihoods);
    final Map<String, Object> annotate = ann.annotate(ref, vc, likelihoods);
    final String expected = refMappingQualities[0] + ",1," + refMappingQualities[1] + ",1" + AS_RankSumTest.PRINT_DELIM + altMappingQualities[0] + ",1," + altMappingQualities[1] + ",1";
    Assert.assertEquals(annotate.get(key1), expected);
    Assert.assertEquals(annotateRaw.get(key1), expected);
    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);
}
Also used : TextCigarCodec(htsjdk.samtools.TextCigarCodec) Cigar(htsjdk.samtools.Cigar) AS_MappingQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_MappingQualityRankSumTest) Arrays(java.util.Arrays) GATKVCFConstants(org.broadinstitute.hellbender.utils.variant.GATKVCFConstants) Test(org.testng.annotations.Test) htsjdk.variant.variantcontext(htsjdk.variant.variantcontext) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Collectors(java.util.stream.Collectors) ReadLikelihoods(org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest) List(java.util.List) ArtificialReadUtils(org.broadinstitute.hellbender.utils.read.ArtificialReadUtils) Assert(org.testng.Assert) Map(java.util.Map) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) MannWhitneyU(org.broadinstitute.hellbender.utils.MannWhitneyU) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest) AS_MappingQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_MappingQualityRankSumTest) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) AS_MappingQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_MappingQualityRankSumTest) Test(org.testng.annotations.Test) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest)

Example 93 with GATKRead

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

the class MappingQualityZeroUnitTest method testEmptyLikelihoods.

@Test
public void testEmptyLikelihoods() throws Exception {
    final List<GATKRead> reads = Collections.emptyList();
    final Map<String, List<GATKRead>> readsBySample = ImmutableMap.of("sample1", reads);
    final org.broadinstitute.hellbender.utils.genotyper.SampleList sampleList = new IndexedSampleList(Arrays.asList("sample1"));
    final AlleleList<Allele> alleleList = new IndexedAlleleList<>(Arrays.asList(Allele.create("A")));
    final ReadLikelihoods<Allele> likelihoods = new ReadLikelihoods<>(sampleList, alleleList, readsBySample);
    final VariantContext vc = makeVC();
    final ReferenceContext referenceContext = null;
    final Map<String, Object> annotate = new MappingQualityZero().annotate(referenceContext, vc, likelihoods);
    //strangely,  MappingQualityZero returns 0 if likelihoods is empty
    final int n = 0;
    Assert.assertEquals(annotate.get(VCFConstants.MAPPING_QUALITY_ZERO_KEY), String.valueOf(n));
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) VariantContext(htsjdk.variant.variantcontext.VariantContext) IndexedAlleleList(org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList) ReadLikelihoods(org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods) Allele(htsjdk.variant.variantcontext.Allele) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) List(java.util.List) AlleleList(org.broadinstitute.hellbender.utils.genotyper.AlleleList) IndexedAlleleList(org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) Test(org.testng.annotations.Test)

Example 94 with GATKRead

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

the class BaseQualityUnitTest method test.

@Test
public void test() {
    final SAMFileHeader SAM_HEADER = ArtificialReadUtils.createArtificialSamHeader(10, 0, 1000);
    final List<Allele> alleles = Arrays.asList(Allele.create((byte) 'A', true), Allele.create((byte) 'C', false));
    final AlleleList<Allele> alleleList = new IndexedAlleleList<>(alleles);
    // variant is a SNP at position 20
    final int chromosomeIndex = 5;
    final int variantSite = 20;
    final VariantContext vc = new VariantContextBuilder("source", Integer.toString(chromosomeIndex), variantSite, variantSite, alleles).make();
    final org.broadinstitute.hellbender.utils.genotyper.SampleList sampleList = new IndexedSampleList("SAMPLE");
    //7 reads of length = 3 -- the middle base is at the variant position
    final Map<String, List<GATKRead>> readMap = new LinkedHashMap<>();
    final List<GATKRead> reads = new ArrayList<>();
    final byte[] quals = new byte[] { 30, 30, 30, 30, 25, 25, 25 };
    for (int r = 0; r < quals.length; r++) {
        final GATKRead read = ArtificialReadUtils.createArtificialRead(SAM_HEADER, "RRR00" + r, chromosomeIndex, 19, "ACG".getBytes(), new byte[] { 4, quals[r], 55 }, "3M");
        read.setMappingQuality(60);
        reads.add(read);
    }
    readMap.put("SAMPLE", reads);
    final ReadLikelihoods<Allele> likelihoods = new ReadLikelihoods<>(sampleList, alleleList, readMap);
    //we will make the first four reads ref (median position = 2) and the last three alt (median position 10, hence
    // median distance from end = 1)
    final LikelihoodMatrix<Allele> matrix = likelihoods.sampleMatrix(0);
    // log likelihoods are initialized to 0, so we can "turn on" a read for a particular allele by setting the
    // (allele, read) entry to 10
    matrix.set(0, 0, 10);
    matrix.set(0, 1, 10);
    matrix.set(0, 2, 10);
    matrix.set(0, 3, 10);
    matrix.set(1, 4, 10);
    matrix.set(1, 5, 10);
    matrix.set(1, 6, 10);
    final BaseQuality bq = new BaseQuality();
    final GenotypeBuilder gb = new GenotypeBuilder(DUMMY_GENOTYPE);
    bq.annotate(null, vc, DUMMY_GENOTYPE, gb, likelihoods);
    final Genotype g = gb.make();
    final int[] medianRefAndAltQuals = (int[]) g.getExtendedAttribute(BaseQuality.KEY);
    Assert.assertEquals(medianRefAndAltQuals[0], 30);
    Assert.assertEquals(medianRefAndAltQuals[1], 25);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) org.broadinstitute.hellbender.utils.genotyper(org.broadinstitute.hellbender.utils.genotyper) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Test(org.testng.annotations.Test)

Example 95 with GATKRead

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

the class ClippingRankSumTestUnitTest method makeRead.

private static GATKRead makeRead(final int hardClip) {
    Cigar cigar = hardClip == 0 ? TextCigarCodec.decode("10M") : TextCigarCodec.decode("10M" + hardClip + "H");
    final GATKRead read = ArtificialReadUtils.createArtificialRead(cigar);
    read.setMappingQuality(30);
    return read;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Cigar(htsjdk.samtools.Cigar)

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