Bug fixes with Mauricio to functions in ReadUtils used by reduced reads and the haplotype caller.
This commit is contained in:
parent
74b018a1f3
commit
4d35272916
|
|
@ -726,38 +726,6 @@ public class ReadUtils {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for a read coordinate that corresponds to the reference coordinate in the soft clipped region before
|
||||
* the alignment start of the read.
|
||||
*
|
||||
* @param read
|
||||
* @param refCoord
|
||||
* @return the corresponding read coordinate or -1 if it failed to find it (it has been hard clipped before)
|
||||
*/
|
||||
@Requires({"refCoord >= read.getUnclippedStart()", "refCoord < read.getAlignmentStart()"})
|
||||
private static int getReadCoordinateForReferenceCoordinateBeforeAlignmentStart(SAMRecord read, int refCoord) {
|
||||
if (getRefCoordSoftUnclippedStart(read) <= refCoord)
|
||||
return refCoord - getRefCoordSoftUnclippedStart(read) + 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Looks for a read coordinate that corresponds to the reference coordinate in the soft clipped region after
|
||||
* the alignment end of the read.
|
||||
*
|
||||
* @param read
|
||||
* @param refCoord
|
||||
* @return the corresponding read coordinate or -1 if it failed to find it (it has been hard clipped before)
|
||||
*/
|
||||
@Requires({"refCoord <= read.getUnclippedEnd()", "refCoord > read.getAlignmentEnd()"})
|
||||
private static int getReadCoordinateForReferenceCoordinateBeforeAlignmentEnd(SAMRecord read, int refCoord) {
|
||||
if (getRefCoordSoftUnclippedEnd(read) >= refCoord)
|
||||
return refCoord - getRefCoordSoftUnclippedStart(read) + 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public enum ClippingTail {
|
||||
LEFT_TAIL,
|
||||
RIGHT_TAIL
|
||||
|
|
@ -802,25 +770,14 @@ public class ReadUtils {
|
|||
* @param refCoord
|
||||
* @return the read coordinate corresponding to the requested reference coordinate. (see warning!)
|
||||
*/
|
||||
@Requires({"refCoord >= read.getUnclippedStart()", "refCoord <= read.getUnclippedEnd()"})
|
||||
@Requires({"refCoord >= getRefCoordSoftUnclippedStart(read)", "refCoord <= getRefCoordSoftUnclippedEnd(read)"})
|
||||
@Ensures({"result.getFirst() >= 0", "result.getFirst() < read.getReadLength()"})
|
||||
public static Pair<Integer, Boolean> getReadCoordinateForReferenceCoordinate(SAMRecord read, int refCoord) {
|
||||
int readBases = 0;
|
||||
int refBases = 0;
|
||||
boolean fallsInsideDeletion = false;
|
||||
|
||||
if (refCoord < read.getAlignmentStart()) {
|
||||
readBases = getReadCoordinateForReferenceCoordinateBeforeAlignmentStart(read, refCoord);
|
||||
if (readBases < 0)
|
||||
throw new ReviewedStingException("Requested a coordinate in a hard clipped area of the read. No equivalent read coordinate.");
|
||||
}
|
||||
else if (refCoord > read.getAlignmentEnd()) {
|
||||
readBases = getReadCoordinateForReferenceCoordinateBeforeAlignmentEnd(read, refCoord);
|
||||
if (readBases < 0)
|
||||
throw new ReviewedStingException("Requested a coordinate in a hard clipped area of the read. No equivalent read coordinate.");
|
||||
}
|
||||
else {
|
||||
int goal = refCoord - read.getAlignmentStart(); // The goal is to move this many reference bases
|
||||
int goal = refCoord - getRefCoordSoftUnclippedStart(read); // The goal is to move this many reference bases
|
||||
boolean goalReached = refBases == goal;
|
||||
|
||||
Iterator<CigarElement> cigarElementIterator = read.getCigar().getCigarElements().iterator();
|
||||
|
|
@ -828,7 +785,7 @@ public class ReadUtils {
|
|||
CigarElement cigarElement = cigarElementIterator.next();
|
||||
int shift = 0;
|
||||
|
||||
if (cigarElement.getOperator().consumesReferenceBases()) {
|
||||
if (cigarElement.getOperator().consumesReferenceBases() || cigarElement.getOperator() == CigarOperator.SOFT_CLIP) {
|
||||
if (refBases + cigarElement.getLength() < goal)
|
||||
shift = cigarElement.getLength();
|
||||
else
|
||||
|
|
@ -891,7 +848,7 @@ public class ReadUtils {
|
|||
|
||||
if (!goalReached)
|
||||
throw new ReviewedStingException("Somehow the requested coordinate is not covered by the read. Too many deletions?");
|
||||
}
|
||||
|
||||
|
||||
return new Pair<Integer, Boolean>(readBases, fallsInsideDeletion);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue