Added Hard Clipping Tail Ends
Added functionality to hard clip the low quality tail ends of reads (lowQual <= 2)
This commit is contained in:
parent
0d976d6211
commit
993ecb85da
|
|
@ -15,6 +15,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class ReadClipper {
|
public class ReadClipper {
|
||||||
SAMRecord read;
|
SAMRecord read;
|
||||||
|
boolean wasClipped;
|
||||||
List<ClippingOp> ops = null;
|
List<ClippingOp> ops = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -24,6 +25,7 @@ public class ReadClipper {
|
||||||
*/
|
*/
|
||||||
public ReadClipper(final SAMRecord read) {
|
public ReadClipper(final SAMRecord read) {
|
||||||
this.read = read;
|
this.read = read;
|
||||||
|
this.wasClipped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,7 +43,7 @@ public class ReadClipper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean wasClipped() {
|
public boolean wasClipped() {
|
||||||
return ops != null;
|
return wasClipped;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SAMRecord getRead() {
|
public SAMRecord getRead() {
|
||||||
|
|
@ -52,7 +54,7 @@ public class ReadClipper {
|
||||||
int start = (refStart < 0) ? 0 : ReadUtils.getReadCoordinateForReferenceCoordinate(read, refStart);
|
int start = (refStart < 0) ? 0 : ReadUtils.getReadCoordinateForReferenceCoordinate(read, refStart);
|
||||||
int stop = (refStop < 0) ? read.getReadLength() - 1 : ReadUtils.getReadCoordinateForReferenceCoordinate(read, refStop);
|
int stop = (refStop < 0) ? read.getReadLength() - 1 : ReadUtils.getReadCoordinateForReferenceCoordinate(read, refStop);
|
||||||
|
|
||||||
System.out.println("DEBUG -- clipping start/stop: " + start + "/" + stop);
|
System.out.println("Clipping start/stop: " + start + "/" + stop);
|
||||||
this.addOp(new ClippingOp(start, stop));
|
this.addOp(new ClippingOp(start, stop));
|
||||||
return clipRead(ClippingRepresentation.HARDCLIP_BASES);
|
return clipRead(ClippingRepresentation.HARDCLIP_BASES);
|
||||||
}
|
}
|
||||||
|
|
@ -68,6 +70,28 @@ public class ReadClipper {
|
||||||
return hardClipByReferenceCoordinates(right, -1);
|
return hardClipByReferenceCoordinates(right, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SAMRecord hardClipLowQualEnds(byte lowQual) {
|
||||||
|
byte [] quals = read.getBaseQualities();
|
||||||
|
int leftClipIndex = 0;
|
||||||
|
int rightClipIndex = read.getReadLength() - 1;
|
||||||
|
|
||||||
|
// check how far we can clip both sides
|
||||||
|
while (quals[rightClipIndex] <= lowQual) rightClipIndex--;
|
||||||
|
while (quals[leftClipIndex] <= lowQual) leftClipIndex++;
|
||||||
|
|
||||||
|
// if the entire read should be clipped, then return an empty read. (--todo: maybe null is better? testing this for now)
|
||||||
|
if (leftClipIndex > rightClipIndex)
|
||||||
|
return (new SAMRecord(read.getHeader()));
|
||||||
|
|
||||||
|
if (rightClipIndex < read.getReadLength() - 1) {
|
||||||
|
this.addOp(new ClippingOp(rightClipIndex + 1, read.getReadLength() - 1));
|
||||||
|
}
|
||||||
|
if (leftClipIndex > 0 ) {
|
||||||
|
this.addOp(new ClippingOp(0, leftClipIndex - 1));
|
||||||
|
}
|
||||||
|
return this.clipRead(ClippingRepresentation.HARDCLIP_BASES);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a new read corresponding to this.read that's been clipped according to ops, if any are present.
|
* Return a new read corresponding to this.read that's been clipped according to ops, if any are present.
|
||||||
*
|
*
|
||||||
|
|
@ -83,6 +107,7 @@ public class ReadClipper {
|
||||||
for (ClippingOp op : getOps()) {
|
for (ClippingOp op : getOps()) {
|
||||||
clippedRead = op.apply(algorithm, clippedRead);
|
clippedRead = op.apply(algorithm, clippedRead);
|
||||||
}
|
}
|
||||||
|
wasClipped = true;
|
||||||
return clippedRead;
|
return clippedRead;
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
throw new RuntimeException(e); // this should never happen
|
throw new RuntimeException(e); // this should never happen
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue