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);
}
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);
}
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));
}
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);
}
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;
}
Aggregations