Search in sources :

Example 16 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class ReadLikelihoods method appendReads.

// Append the new read reference into the structure per-sample.
private void appendReads(final List<GATKRead> newSampleReads, final int sampleIndex, final int sampleReadCount, final int newSampleReadCount) {
    final GATKRead[] sampleReads = readsBySampleIndex[sampleIndex] = Arrays.copyOf(readsBySampleIndex[sampleIndex], newSampleReadCount);
    int nextReadIndex = sampleReadCount;
    final Object2IntMap<GATKRead> sampleReadIndex = readIndexBySampleIndex[sampleIndex];
    for (final GATKRead newRead : newSampleReads) {
        //        throw new IllegalArgumentException("you cannot add reads that are already in read-likelihood collection");
        if (sampleReadIndex != null) {
            sampleReadIndex.put(newRead, nextReadIndex);
        }
        sampleReads[nextReadIndex++] = newRead;
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead)

Example 17 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class ClippingOp method applyREVERT_SOFTCLIPPED_BASES.

private GATKRead applyREVERT_SOFTCLIPPED_BASES(final GATKRead read) {
    GATKRead unclipped = read.copy();
    final Cigar unclippedCigar = new Cigar();
    int matchesCount = 0;
    for (final CigarElement element : read.getCigarElements()) {
        if (element.getOperator() == CigarOperator.SOFT_CLIP || element.getOperator() == CigarOperator.MATCH_OR_MISMATCH) {
            matchesCount += element.getLength();
        } else if (matchesCount > 0) {
            unclippedCigar.add(new CigarElement(matchesCount, CigarOperator.MATCH_OR_MISMATCH));
            matchesCount = 0;
            unclippedCigar.add(element);
        } else {
            unclippedCigar.add(element);
        }
    }
    if (matchesCount > 0) {
        unclippedCigar.add(new CigarElement(matchesCount, CigarOperator.MATCH_OR_MISMATCH));
    }
    unclipped.setCigar(unclippedCigar);
    final int newStart = read.getStart() + calculateAlignmentStartShift(read.getCigar(), unclippedCigar);
    if (newStart <= 0) {
        // if the start of the unclipped read occurs before the contig,
        // we must hard clip away the bases since we cannot represent reads with
        // negative or 0 alignment start values in the SAMRecord (e.g., 0 means unaligned)
        // We cannot set the read to temporarily have a negative start position, as our Read
        // interface will not allow it. Instead, since we know that the final start position will
        // be 1 after the hard clip operation, set it to 1 explicitly. We have to set it twice:
        // once before the hard clip (to reset the alignment stop / read length in read implementations
        // that cache these values, such as SAMRecord), and again after the hard clip.
        unclipped.setPosition(unclipped.getContig(), 1);
        unclipped = applyHARDCLIP_BASES(unclipped, 0, -newStart);
        unclipped.setPosition(unclipped.getContig(), 1);
        return unclipped;
    } else {
        unclipped.setPosition(unclipped.getContig(), newStart);
        return unclipped;
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Cigar(htsjdk.samtools.Cigar) CigarElement(htsjdk.samtools.CigarElement)

Example 18 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class ReadClipper method softClipBothEndsByReferenceCoordinates.

/**
     * Soft clips both tails of a read.
     *   Left tail goes from the beginning to the 'left' coordinate (inclusive)
     *   Right tail goes from the 'right' coordinate (inclusive) until the end of the read
     *
     * @param left the coordinate of the last base to be clipped in the left tail (inclusive)
     * @param right the coordinate of the first base to be clipped in the right tail (inclusive)
     * @return a new read, without the clipped bases
     */
private GATKRead softClipBothEndsByReferenceCoordinates(final int left, final int right) {
    if (read.isEmpty()) {
        return ReadUtils.emptyRead(read);
    }
    if (left == right) {
        logger.warn("Attempting to clip the entirety of a read by by reference coordinates: %s", read.toString());
        return ReadUtils.emptyRead(read);
    }
    final GATKRead leftTailRead = softClipByReferenceCoordinates(right, -1);
    // make the left cut index no longer part of the read. In that case, clip the read entirely.
    if (left > leftTailRead.getEnd()) {
        return ReadUtils.emptyRead(read);
    }
    final ReadClipper clipper = new ReadClipper(leftTailRead);
    return clipper.softClipByReferenceCoordinates(-1, left);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead)

Example 19 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class ReadClipper method clipRead.

private GATKRead clipRead(final ClippingRepresentation algorithm, boolean runAsserts) {
    Utils.nonNull(algorithm);
    if (ops == null) {
        return getRead();
    }
    GATKRead clippedRead = read;
    for (final ClippingOp op : getOps()) {
        final int readLength = clippedRead.getLength();
        //check if the clipped read can still be clipped in the range requested
        if (op.start < readLength) {
            ClippingOp fixedOperation = op;
            if (op.stop >= readLength) {
                fixedOperation = new ClippingOp(op.start, readLength - 1);
            }
            clippedRead = fixedOperation.apply(algorithm, clippedRead, runAsserts);
        }
    }
    wasClipped = true;
    ops.clear();
    if (clippedRead.isEmpty()) {
        return ReadUtils.emptyRead(clippedRead);
    }
    return clippedRead;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead)

Example 20 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class AmbiguousBaseReadFilterTest method testTest.

@Test(dataProvider = "sequenceStrings")
public void testTest(final String seq_in, final Boolean test_out) throws Exception {
    AmbiguousBaseReadFilter filter = new AmbiguousBaseReadFilter(0.05f);
    final byte[] qual = new byte[seq_in.length()];
    Arrays.fill(qual, (byte) 30);
    GATKRead read_in = ArtificialReadUtils.createArtificialRead(seq_in.getBytes(), qual, "*");
    final boolean test_i = filter.test(read_in);
    Assert.assertEquals(test_out.booleanValue(), test_i);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Test(org.testng.annotations.Test)

Aggregations

GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)457 Test (org.testng.annotations.Test)286 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)163 SAMFileHeader (htsjdk.samtools.SAMFileHeader)87 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)59 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)40 ArrayList (java.util.ArrayList)34 Collectors (java.util.stream.Collectors)34 List (java.util.List)30 Cigar (htsjdk.samtools.Cigar)29 File (java.io.File)28 java.util (java.util)28 DataProvider (org.testng.annotations.DataProvider)28 JavaRDD (org.apache.spark.api.java.JavaRDD)26 Haplotype (org.broadinstitute.hellbender.utils.haplotype.Haplotype)26 Assert (org.testng.Assert)25 ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)24 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)22 Argument (org.broadinstitute.barclay.argparser.Argument)18 UserException (org.broadinstitute.hellbender.exceptions.UserException)18