Search in sources :

Example 1 with ReadTransformer

use of org.broadinstitute.hellbender.transformers.ReadTransformer in project gatk by broadinstitute.

the class BaseRecalibrationEngine method processRead.

/**
     * For each read at this locus get the various covariate values and increment that location in the map based on
     * whether or not the base matches the reference at this particular location
     */
public void processRead(final GATKRead originalRead, final ReferenceDataSource refDS, final Iterable<? extends Locatable> knownSites) {
    final ReadTransformer transform = makeReadTransform();
    final GATKRead read = transform.apply(originalRead);
    if (read.isEmpty()) {
        // the whole read was inside the adaptor so skip it
        return;
    }
    RecalUtils.parsePlatformForRead(read, readsHeader, recalArgs);
    int[] isSNP = new int[read.getLength()];
    int[] isInsertion = new int[isSNP.length];
    int[] isDeletion = new int[isSNP.length];
    //Note: this function modifies the isSNP, isInsertion and isDeletion arguments so it can't be skipped, BAQ or no BAQ
    final int nErrors = calculateIsSNPOrIndel(read, refDS, isSNP, isInsertion, isDeletion);
    // note for efficiency reasons we don't compute the BAQ array unless we actually have
    // some error to marginalize over.  For ILMN data ~85% of reads have no error
    final byte[] baqArray = (nErrors == 0 || !recalArgs.enableBAQ) ? flatBAQArray(read) : calculateBAQArray(read, refDS);
    if (baqArray != null) {
        // some reads just can't be BAQ'ed
        final ReadCovariates covariates = RecalUtils.computeCovariates(read, readsHeader, this.covariates, true, keyCache);
        // skip known sites of variation as well as low quality and non-regular bases
        final boolean[] skip = calculateSkipArray(read, knownSites);
        final double[] snpErrors = calculateFractionalErrorArray(isSNP, baqArray);
        final double[] insertionErrors = calculateFractionalErrorArray(isInsertion, baqArray);
        final double[] deletionErrors = calculateFractionalErrorArray(isDeletion, baqArray);
        // aggregate all of the info into our info object, and update the data
        final ReadRecalibrationInfo info = new ReadRecalibrationInfo(read, covariates, skip, snpErrors, insertionErrors, deletionErrors);
        updateRecalTablesForRead(info);
    }
    numReadsProcessed++;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReadTransformer(org.broadinstitute.hellbender.transformers.ReadTransformer) ReadCovariates(org.broadinstitute.hellbender.utils.recalibration.covariates.ReadCovariates)

Example 2 with ReadTransformer

use of org.broadinstitute.hellbender.transformers.ReadTransformer in project gatk by broadinstitute.

the class ReadTransformerTest method testCompose.

@Test(dataProvider = "UnmodifiedReadDataProvider")
public void testCompose(final GATKRead read) {
    ReadTransformer leftThen20 = moveLeft.compose(moveTo20);
    leftThen20.apply(read);
    Assert.assertEquals(read.getStart(), 19);
    moveTo20.compose(moveLeft).apply(read);
    Assert.assertEquals(read.getStart(), 20);
}
Also used : ReadTransformer(org.broadinstitute.hellbender.transformers.ReadTransformer) Test(org.testng.annotations.Test)

Example 3 with ReadTransformer

use of org.broadinstitute.hellbender.transformers.ReadTransformer in project gatk by broadinstitute.

the class GATKTool method getTransformedReadStream.

/**
     * Returns a stream over the reads, which are:
     *
     * 1. Transformed with {@link #makePreReadFilterTransformer()}.
     * 2. Filtered with {@code filter}.
     * 3. Transformed with {@link #makePostReadFilterTransformer()}.
     *
     * Note: the filter is passed to keep the state of {@link CountingReadFilter}, obtained with {@link #makeReadFilter()}.
     */
protected Stream<GATKRead> getTransformedReadStream(final ReadFilter filter) {
    // if has reads, return an transformed/filtered/transformed stream
    if (hasReads()) {
        final ReadTransformer preTransformer = makePreReadFilterTransformer();
        final ReadTransformer postTransformer = makePostReadFilterTransformer();
        return Utils.stream(reads).map(preTransformer).filter(filter).map(postTransformer);
    }
    // returns an empty Stream if there are no reads
    return Stream.empty();
}
Also used : ReadTransformer(org.broadinstitute.hellbender.transformers.ReadTransformer)

Example 4 with ReadTransformer

use of org.broadinstitute.hellbender.transformers.ReadTransformer in project gatk by broadinstitute.

the class BaseRecalibrationEngine method makeReadTransform.

private ReadTransformer makeReadTransform() {
    ReadTransformer f0 = BaseRecalibrationEngine::consolidateCigar;
    ReadTransformer f = f0.andThen(this::setDefaultBaseQualities).andThen(this::resetOriginalBaseQualities).andThen(ReadClipper::hardClipAdaptorSequence).andThen(ReadClipper::hardClipSoftClippedBases);
    return f;
}
Also used : ReadClipper(org.broadinstitute.hellbender.utils.clipping.ReadClipper) ReadTransformer(org.broadinstitute.hellbender.transformers.ReadTransformer)

Example 5 with ReadTransformer

use of org.broadinstitute.hellbender.transformers.ReadTransformer in project gatk by broadinstitute.

the class ReadTransformerTest method testAndThen.

@Test(dataProvider = "UnmodifiedReadDataProvider")
public void testAndThen(final GATKRead read) {
    ReadTransformer leftThen20 = moveLeft.andThen(moveTo20);
    leftThen20.apply(read);
    Assert.assertEquals(read.getStart(), 20);
    moveTo20.andThen(moveLeft).apply(read);
    Assert.assertEquals(read.getStart(), 19);
}
Also used : ReadTransformer(org.broadinstitute.hellbender.transformers.ReadTransformer) Test(org.testng.annotations.Test)

Aggregations

ReadTransformer (org.broadinstitute.hellbender.transformers.ReadTransformer)5 Test (org.testng.annotations.Test)2 ReadClipper (org.broadinstitute.hellbender.utils.clipping.ReadClipper)1 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)1 ReadCovariates (org.broadinstitute.hellbender.utils.recalibration.covariates.ReadCovariates)1