Search in sources :

Example 31 with ReferenceContext

use of org.broadinstitute.hellbender.engine.ReferenceContext in project gatk by broadinstitute.

the class MappingQualityZeroUnitTest method testLikelihoods.

@Test
public void testLikelihoods() {
    final Allele REF = Allele.create("T", true);
    final Allele ALT = Allele.create("A");
    final int refDepth = 5;
    final int altDepth = 3;
    final int refMQ = 10;
    final int altMQ = 0;
    final List<GATKRead> refReads = IntStream.range(0, refDepth).mapToObj(i -> makeRead(refMQ)).collect(Collectors.toList());
    final List<GATKRead> altReads = IntStream.range(0, altDepth).mapToObj(i -> makeRead(altMQ)).collect(Collectors.toList());
    final ReadLikelihoods<Allele> likelihoods = AnnotationArtificialData.makeLikelihoods("sample1", refReads, altReads, -1.0, -1.0, REF, ALT);
    final VariantContext vc = makeVC();
    final ReferenceContext referenceContext = null;
    final Map<String, Object> annotate = new MappingQualityZero().annotate(referenceContext, vc, likelihoods);
    Assert.assertEquals(annotate.size(), 1, "size");
    Assert.assertEquals(annotate.keySet(), Collections.singleton(VCFConstants.MAPPING_QUALITY_ZERO_KEY), "annots");
    Assert.assertEquals(annotate.get(VCFConstants.MAPPING_QUALITY_ZERO_KEY), String.valueOf(altDepth));
}
Also used : IntStream(java.util.stream.IntStream) Allele(htsjdk.variant.variantcontext.Allele) Arrays(java.util.Arrays) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.testng.annotations.Test) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Collectors(java.util.stream.Collectors) GenotypesContext(htsjdk.variant.variantcontext.GenotypesContext) ReadLikelihoods(org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods) List(java.util.List) Assert(org.testng.Assert) Map(java.util.Map) AlleleList(org.broadinstitute.hellbender.utils.genotyper.AlleleList) IndexedAlleleList(org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList) VariantContext(htsjdk.variant.variantcontext.VariantContext) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) Collections(java.util.Collections) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) VCFConstants(htsjdk.variant.vcf.VCFConstants) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Allele(htsjdk.variant.variantcontext.Allele) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) VariantContext(htsjdk.variant.variantcontext.VariantContext) Test(org.testng.annotations.Test)

Example 32 with ReferenceContext

use of org.broadinstitute.hellbender.engine.ReferenceContext in project gatk by broadinstitute.

the class RMSMappingQualityUnitTest method testAllNull.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testAllNull() throws Exception {
    final VariantContext vc = null;
    final ReferenceContext referenceContext = null;
    final InfoFieldAnnotation cov = new RMSMappingQuality();
    //vc can't be null
    cov.annotate(referenceContext, vc, null);
}
Also used : ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) AS_RMSMappingQuality(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RMSMappingQuality) Test(org.testng.annotations.Test)

Example 33 with ReferenceContext

use of org.broadinstitute.hellbender.engine.ReferenceContext in project gatk-protected by broadinstitute.

the class HaplotypeCallerGenotypingEngine method makeAnnotatedCall.

protected VariantContext makeAnnotatedCall(byte[] ref, SimpleInterval refLoc, FeatureContext tracker, SAMFileHeader header, VariantContext mergedVC, ReadLikelihoods<Allele> readAlleleLikelihoods, VariantContext call) {
    final SimpleInterval locus = new SimpleInterval(mergedVC.getContig(), mergedVC.getStart(), mergedVC.getEnd());
    final SimpleInterval refLocInterval = new SimpleInterval(refLoc);
    final ReferenceDataSource refData = new ReferenceMemorySource(new ReferenceBases(ref, refLocInterval), header.getSequenceDictionary());
    final ReferenceContext referenceContext = new ReferenceContext(refData, locus, refLocInterval);
    final VariantContext untrimmedResult = annotationEngine.annotateContext(call, tracker, referenceContext, readAlleleLikelihoods, a -> true);
    return call.getAlleles().size() == mergedVC.getAlleles().size() ? untrimmedResult : GATKVariantContextUtils.reverseTrimAlleles(untrimmedResult);
}
Also used : ReferenceBases(org.broadinstitute.hellbender.utils.reference.ReferenceBases) ReferenceDataSource(org.broadinstitute.hellbender.engine.ReferenceDataSource) ReferenceMemorySource(org.broadinstitute.hellbender.engine.ReferenceMemorySource) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval)

Example 34 with ReferenceContext

use of org.broadinstitute.hellbender.engine.ReferenceContext in project gatk by broadinstitute.

the class AnnotateVcfWithExpectedAlleleFraction method apply.

@Override
public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext refContext, final FeatureContext fc) {
    final double[] weights = vc.getGenotypes().stream().mapToDouble(g -> weight(g)).toArray();
    final double expectedAlleleFraction = MathUtils.sum(MathArrays.ebeMultiply(weights, mixingFractionsInSampleOrder));
    vcfWriter.add(new VariantContextBuilder(vc).attribute(EXPECTED_ALLELE_FRACTION_NAME, expectedAlleleFraction).make());
}
Also used : Genotype(htsjdk.variant.variantcontext.Genotype) VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) DocumentedFeature(org.broadinstitute.barclay.help.DocumentedFeature) CommandLineProgramProperties(org.broadinstitute.barclay.argparser.CommandLineProgramProperties) VCFHeader(htsjdk.variant.vcf.VCFHeader) MathArrays(org.apache.commons.math3.util.MathArrays) Argument(org.broadinstitute.barclay.argparser.Argument) StandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions) VariantProgramGroup(org.broadinstitute.hellbender.cmdline.programgroups.VariantProgramGroup) HashSet(java.util.HashSet) Map(java.util.Map) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) FeatureContext(org.broadinstitute.hellbender.engine.FeatureContext) VCFHeaderLineType(htsjdk.variant.vcf.VCFHeaderLineType) VariantWalker(org.broadinstitute.hellbender.engine.VariantWalker) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) MathUtils(org.broadinstitute.hellbender.utils.MathUtils) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) VCFInfoHeaderLine(htsjdk.variant.vcf.VCFInfoHeaderLine) VariantContext(htsjdk.variant.variantcontext.VariantContext) ReadsContext(org.broadinstitute.hellbender.engine.ReadsContext) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder)

Example 35 with ReferenceContext

use of org.broadinstitute.hellbender.engine.ReferenceContext in project gatk by broadinstitute.

the class TandemRepeatUnitTest method testUsingVC.

@Test
public void testUsingVC() {
    // - [ref] / ATC from 20-20
    final String insLoc = "chr1";
    final int insLocStart = 2;
    final int insLocStop = 2;
    final byte[] refBytes = "GTATCATCATCGGA".getBytes();
    final Allele nullR = Allele.create("A", true);
    final Allele atc = Allele.create("AATC", false);
    // A*,ATC, context = ATC ATC ATC : (ATC)3 -> (ATC)4
    final VariantContext vc = new VariantContextBuilder("foo", insLoc, insLocStart, insLocStop, Arrays.asList(nullR, atc)).make();
    // we test that the interval from which the ReferenceContext is constructed does not need to exactly overlap
    // the VariantContext.  The annotation should be able to handle this.
    final SimpleInterval interval = new SimpleInterval(insLoc, insLocStart + 3, insLocStop + 4);
    final SimpleInterval interval1 = new SimpleInterval(insLoc, 1, refBytes.length);
    final ReferenceBases ref1 = new ReferenceBases(refBytes, interval1);
    final SAMSequenceDictionary dict = new SAMSequenceDictionary(Arrays.asList(new SAMSequenceRecord(insLoc, refBytes.length)));
    final ReferenceContext ref = new ReferenceContext(ReferenceDataSource.of(ref1, dict), interval, 20, 20);
    final InfoFieldAnnotation ann = new TandemRepeat();
    final Map<String, Object> a = ann.annotate(ref, vc, null);
    Assert.assertEquals(a.size(), 3);
    Assert.assertEquals(a.get(GATKVCFConstants.STR_PRESENT_KEY), true);
    Assert.assertEquals(a.get(GATKVCFConstants.REPEAT_UNIT_KEY), "ATC");
    //3 repeats in the reference, 4 in the variant
    Assert.assertEquals(a.get(GATKVCFConstants.REPEATS_PER_ALLELE_KEY), Arrays.asList(3, 4));
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) ReferenceBases(org.broadinstitute.hellbender.utils.reference.ReferenceBases) Allele(htsjdk.variant.variantcontext.Allele) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

ReferenceContext (org.broadinstitute.hellbender.engine.ReferenceContext)41 Test (org.testng.annotations.Test)30 VariantContext (htsjdk.variant.variantcontext.VariantContext)17 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)17 ReadLikelihoods (org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods)15 Collectors (java.util.stream.Collectors)13 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)12 Allele (htsjdk.variant.variantcontext.Allele)10 GATKVCFConstants (org.broadinstitute.hellbender.utils.variant.GATKVCFConstants)10 VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)9 htsjdk.variant.variantcontext (htsjdk.variant.variantcontext)8 java.util (java.util)8 List (java.util.List)8 AS_RMSMappingQuality (org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RMSMappingQuality)8 Assert (org.testng.Assert)8 VCFConstants (htsjdk.variant.vcf.VCFConstants)7 Map (java.util.Map)7 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 MannWhitneyU (org.broadinstitute.hellbender.utils.MannWhitneyU)6