Search in sources :

Example 1 with ReferenceDataSource

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

the class BaseRecalibratorSparkFn method apply.

public static RecalibrationReport apply(final JavaPairRDD<GATKRead, ReadContextData> readsWithContext, final SAMFileHeader header, final SAMSequenceDictionary referenceDictionary, final RecalibrationArgumentCollection recalArgs) {
    JavaRDD<RecalibrationTables> unmergedTables = readsWithContext.mapPartitions(readWithContextIterator -> {
        final BaseRecalibrationEngine bqsr = new BaseRecalibrationEngine(recalArgs, header);
        bqsr.logCovariatesUsed();
        while (readWithContextIterator.hasNext()) {
            final Tuple2<GATKRead, ReadContextData> readWithData = readWithContextIterator.next();
            Iterable<GATKVariant> variants = readWithData._2().getOverlappingVariants();
            final ReferenceBases refBases = readWithData._2().getOverlappingReferenceBases();
            ReferenceDataSource refDS = new ReferenceMemorySource(refBases, referenceDictionary);
            bqsr.processRead(readWithData._1(), refDS, variants);
        }
        return Arrays.asList(bqsr.getRecalibrationTables()).iterator();
    });
    final RecalibrationTables emptyRecalibrationTable = new RecalibrationTables(new StandardCovariateList(recalArgs, header));
    final RecalibrationTables combinedTables = unmergedTables.treeAggregate(emptyRecalibrationTable, RecalibrationTables::inPlaceCombine, RecalibrationTables::inPlaceCombine, Math.max(1, (int) (Math.log(unmergedTables.partitions().size()) / Math.log(2))));
    BaseRecalibrationEngine.finalizeRecalibrationTables(combinedTables);
    final QuantizationInfo quantizationInfo = new QuantizationInfo(combinedTables, recalArgs.QUANTIZING_LEVELS);
    final StandardCovariateList covariates = new StandardCovariateList(recalArgs, header);
    return RecalUtils.createRecalibrationReport(recalArgs.generateReportTable(covariates.covariateNames()), quantizationInfo.generateReportTable(), RecalUtils.generateReportTables(combinedTables, covariates));
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) GATKVariant(org.broadinstitute.hellbender.utils.variant.GATKVariant) ReferenceDataSource(org.broadinstitute.hellbender.engine.ReferenceDataSource) ReferenceMemorySource(org.broadinstitute.hellbender.engine.ReferenceMemorySource) StandardCovariateList(org.broadinstitute.hellbender.utils.recalibration.covariates.StandardCovariateList) ReadContextData(org.broadinstitute.hellbender.engine.ReadContextData) ReferenceBases(org.broadinstitute.hellbender.utils.reference.ReferenceBases)

Example 2 with ReferenceDataSource

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

the class BaseRecalibrationEngineUnitTest method testCalculateIsIndel.

@Test(dataProvider = "CalculateIsIndelData")
public void testCalculateIsIndel(final String cigar, final boolean negStrand, final EventType mode, final int[] expected) {
    final GATKRead read = ArtificialReadUtils.createArtificialRead(TextCigarCodec.decode(cigar));
    read.setIsReverseStrand(negStrand);
    // Fake reference data, since the indel calculation does not use the reference at all.
    final ReferenceDataSource refSource = new ReferenceMemorySource(new ReferenceBases(Utils.repeatBytes((byte) 'A', read.getEnd() - read.getStart() + 1), new SimpleInterval(read)), ArtificialReadUtils.createArtificialSamHeader().getSequenceDictionary());
    int[] isSNP = new int[read.getLength()];
    int[] isInsertion = new int[isSNP.length];
    int[] isDeletion = new int[isSNP.length];
    BaseRecalibrationEngine.calculateIsSNPOrIndel(read, refSource, isSNP, isInsertion, isDeletion);
    final int[] actual = (mode == EventType.BASE_INSERTION ? isInsertion : isDeletion);
    Assert.assertEquals(actual, expected, "calculateIsSNPOrIndel() failed with " + mode + " and cigar " + cigar + " Expected " + Arrays.toString(expected) + " but got " + Arrays.toString(actual));
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReferenceBases(org.broadinstitute.hellbender.utils.reference.ReferenceBases) ReferenceDataSource(org.broadinstitute.hellbender.engine.ReferenceDataSource) ReferenceMemorySource(org.broadinstitute.hellbender.engine.ReferenceMemorySource) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Test(org.testng.annotations.Test)

Example 3 with ReferenceDataSource

use of org.broadinstitute.hellbender.engine.ReferenceDataSource in project gatk 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 4 with ReferenceDataSource

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

the class BAQUnitTest method testBAQOverwritesExistingTagWithNull.

@Test
public void testBAQOverwritesExistingTagWithNull() {
    final File referenceFile = new File(hg19_chr1_1M_Reference);
    final ReferenceDataSource rds = new ReferenceFileSource(referenceFile);
    // create a read with a single base off the end of the contig, which cannot be BAQed
    final GATKRead read = ArtificialReadUtils.createArtificialRead(createHeader(), "foo", 0, rds.getSequenceDictionary().getSequence("1").getSequenceLength() + 1, 1);
    read.setBases(new byte[] { (byte) 'A' });
    read.setBaseQualities(new byte[] { (byte) 20 });
    read.setCigar("1M");
    read.setAttribute("BQ", "A");
    // try to BAQ and tell it to RECALCULATE AND ADD_TAG
    final BAQ baq = new BAQ(1.0e-3, 0.1, 7, (byte) 4);
    baq.baqRead(read, rds, BAQ.CalculationMode.RECALCULATE, BAQ.QualityMode.ADD_TAG);
    // did we remove the existing tag?
    Assert.assertFalse(read.hasAttribute("BQ"));
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReferenceDataSource(org.broadinstitute.hellbender.engine.ReferenceDataSource) File(java.io.File) ReferenceFileSource(org.broadinstitute.hellbender.engine.ReferenceFileSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 5 with ReferenceDataSource

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

the class ReferenceBasesUnitTest method test.

@Test
public void test() {
    final File refFasta = new File(b37_reference_20_21);
    final ReferenceDataSource refDataSource = new ReferenceFileSource(refFasta);
    final ReferenceContext ref = new ReferenceContext(refDataSource, new SimpleInterval("20", 10_000_000, 10_000_200));
    final VariantContext vc = new VariantContextBuilder("source", "20", 10_000_100, 10_000_100, Collections.singleton(Allele.create((byte) 'A', true))).make();
    final String refBases = (String) new ReferenceBases().annotate(ref, vc, null).get(ReferenceBases.REFERENCE_BASES_KEY);
    Assert.assertEquals(refBases, "ACTGCATCCCTTGCATTTCC");
}
Also used : VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) ReferenceDataSource(org.broadinstitute.hellbender.engine.ReferenceDataSource) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) VariantContext(htsjdk.variant.variantcontext.VariantContext) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) File(java.io.File) ReferenceFileSource(org.broadinstitute.hellbender.engine.ReferenceFileSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

ReferenceDataSource (org.broadinstitute.hellbender.engine.ReferenceDataSource)8 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)6 ReferenceMemorySource (org.broadinstitute.hellbender.engine.ReferenceMemorySource)5 ReferenceBases (org.broadinstitute.hellbender.utils.reference.ReferenceBases)5 ReferenceContext (org.broadinstitute.hellbender.engine.ReferenceContext)4 Test (org.testng.annotations.Test)4 File (java.io.File)3 ReferenceFileSource (org.broadinstitute.hellbender.engine.ReferenceFileSource)3 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)3 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)3 VariantContext (htsjdk.variant.variantcontext.VariantContext)2 VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)2 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)1 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)1 ArrayList (java.util.ArrayList)1 ReadContextData (org.broadinstitute.hellbender.engine.ReadContextData)1 StandardCovariateList (org.broadinstitute.hellbender.utils.recalibration.covariates.StandardCovariateList)1 GATKVariant (org.broadinstitute.hellbender.utils.variant.GATKVariant)1 DataProvider (org.testng.annotations.DataProvider)1