use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.
the class StrandOddsRatioUnitTest method makeRead.
private GATKRead makeRead(final boolean forward) {
Cigar cigar = TextCigarCodec.decode("10M");
final GATKRead read = ArtificialReadUtils.createArtificialRead(cigar);
read.setIsReverseStrand(!forward);
return read;
}
use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.
the class VariantAnnotatorEngineUnitTest method makeReadLikelihoods.
private ReadLikelihoods<Allele> makeReadLikelihoods(final int ref, final int alt, final Allele refAllele, final Allele altAllele, final String contig, final int position) {
final List<GATKRead> reads = new ArrayList<>();
for (int i = 0; i < alt; i++) {
final GATKRead read = ArtificialReadUtils.createUniqueArtificialRead("10M");
read.setPosition(contig, position);
reads.add(read);
}
for (int i = 0; i < ref; i++) {
final GATKRead read = ArtificialReadUtils.createUniqueArtificialRead("10M");
read.setPosition(contig, position);
reads.add(read);
}
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(refAllele, altAllele));
final ReadLikelihoods<Allele> likelihoods = new ReadLikelihoods<>(sampleList, alleleList, readsBySample);
// modify likelihoods in-place
final LikelihoodMatrix<Allele> matrix = likelihoods.sampleMatrix(0);
int n = 0;
for (int i = 0; i < alt; i++) {
matrix.set(0, n, -100.0);
matrix.set(1, n, -1.0);
n++;
}
for (int i = 0; i < ref; i++) {
matrix.set(0, n, -1.0);
matrix.set(1, n, -100.0);
n++;
}
return likelihoods;
}
use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.
the class RMSMappingQualityUnitTest method testLikelihoods.
@Test
public void testLikelihoods() {
final Allele REF = Allele.create("A", true);
final Allele ALT = Allele.create("C", true);
final int[] MQs = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, QualityUtils.MAPPING_QUALITY_UNAVAILABLE };
final List<Integer> MQsList = Arrays.asList(ArrayUtils.toObject(MQs));
//MQ 255 are excluded from the calculations, we test it here.
final List<Integer> MQsListOK = new ArrayList<>(MQsList);
//NOTE: if we just call remove(i), Java thinks i is an index.
//A workaround for this overloading bogosity to to call removeAll and pass a collection
//(casting i to (Object) would work too but it's more error prone)
MQsListOK.removeAll(Collections.singleton(QualityUtils.MAPPING_QUALITY_UNAVAILABLE));
final List<GATKRead> reads = Arrays.stream(MQs).mapToObj(mq -> AnnotationArtificialData.makeRead(20, mq)).collect(Collectors.toList());
final ReadLikelihoods<Allele> likelihoods = AnnotationArtificialData.makeLikelihoods("sample1", reads, -1.0, REF, ALT);
final VariantContext vc = makeVC();
final ReferenceContext referenceContext = null;
final Map<String, Object> annotate = new RMSMappingQuality().annotate(referenceContext, vc, likelihoods);
Assert.assertEquals(annotate.size(), 1, "size");
Assert.assertEquals(annotate.keySet(), Collections.singleton(GATKVCFConstants.RAW_RMS_MAPPING_QUALITY_KEY), "annots");
//only those are MQ0
final double rms = MathUtils.sumOfSquares(MQsListOK);
Assert.assertNull(annotate.get(VCFConstants.RMS_MAPPING_QUALITY_KEY));
Assert.assertEquals(annotate.get(GATKVCFConstants.RAW_RMS_MAPPING_QUALITY_KEY), String.format("%.2f", rms));
}
use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.
the class RMSMappingQualityUnitTest method testLikelihoodsEmpty_AS.
@Test
public void testLikelihoodsEmpty_AS() 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 AS_RMSMappingQuality().annotate(referenceContext, vc, likelihoods);
final String[] split = ((String) annotate.get(GATKVCFConstants.AS_RAW_RMS_MAPPING_QUALITY_KEY)).split(AS_RMSMappingQuality.SPLIT_DELIM);
Assert.assertEquals(split.length, 2);
Assert.assertEquals(split[0], String.format("%.2f", 0.0));
Assert.assertEquals(split[1], String.format("%.2f", 0.0));
}
use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.
the class RMSMappingQualityUnitTest method testLikelihoods_AS.
@Test
public void testLikelihoods_AS() {
final Allele REF = Allele.create("A", true);
final Allele ALT = Allele.create("C");
final int[] MQs = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, QualityUtils.MAPPING_QUALITY_UNAVAILABLE };
final List<Integer> MQsList = Arrays.asList(ArrayUtils.toObject(MQs));
//MQ 255 are excluded from the calculations, we test it here.
final List<Integer> MQsListOK = new ArrayList<>(MQsList);
//NOTE: if we just call remove(i), Java thinks i is an index.
//A workaround for this overloading bogosity to to call removeAll and pass a collection
//(casting i to (Object) would work too but it's more error prone)
MQsListOK.removeAll(Collections.singleton(QualityUtils.MAPPING_QUALITY_UNAVAILABLE));
final List<GATKRead> reads = Arrays.stream(MQs).mapToObj(mq -> AnnotationArtificialData.makeRead(30, mq)).collect(Collectors.toList());
final ReadLikelihoods<Allele> likelihoods = AnnotationArtificialData.makeLikelihoods("sample1", reads, -10.0, REF, ALT);
final VariantContext vc = makeVC();
final ReferenceContext referenceContext = null;
final Map<String, Object> annotate = new AS_RMSMappingQuality().annotateRawData(referenceContext, vc, likelihoods);
Assert.assertEquals(annotate.size(), 1, "size");
Assert.assertEquals(annotate.keySet(), Collections.singleton(GATKVCFConstants.AS_RAW_RMS_MAPPING_QUALITY_KEY), "annots");
//only those are MQ0
final double rms = MathUtils.sumOfSquares(MQsListOK);
final String[] split = ((String) annotate.get(GATKVCFConstants.AS_RAW_RMS_MAPPING_QUALITY_KEY)).split(AS_RMSMappingQuality.SPLIT_DELIM);
Assert.assertEquals(split.length, 2);
Assert.assertEquals(split[0], String.format("%.2f", rms));
Assert.assertEquals(split[1], String.format("%.2f", 0.0));
}
Aggregations