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;
}
}
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;
}
}
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);
}
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;
}
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);
}
Aggregations