return false;
}
}
private boolean compareCoordinateSortedAlignments() {
final SecondaryOrSupplementarySkippingIterator itLeft =
new SecondaryOrSupplementarySkippingIterator(samReaders[0].iterator());
final SecondaryOrSupplementarySkippingIterator itRight =
new SecondaryOrSupplementarySkippingIterator(samReaders[1].iterator());
// Save any reads which haven't been matched during in-order scan.
final Map<String, SAMRecord> leftUnmatched = new HashMap<String, SAMRecord>();
final Map<String, SAMRecord> rightUnmatched = new HashMap<String, SAMRecord>();
boolean ret = true;
while (itLeft.hasCurrent()) {
if (!itRight.hasCurrent()) {
// Exhausted right side. See if any of the remaining left reads match
// any of the saved right reads.
for( ; itLeft.hasCurrent(); itLeft.advance()) {
final SAMRecord left = itLeft.getCurrent();
final SAMRecord right = rightUnmatched.remove(left.getReadName());
if (right == null) {
++missingRight;
} else {
tallyAlignmentRecords(left, right);
}
}
break;
}
// Don't assume stability of order beyond the coordinate. Therefore grab all the
// reads from the left that has the same coordinate.
final SAMRecord left = itLeft.getCurrent();
final Map<String, SAMRecord> leftCurrentCoordinate = new HashMap<String, SAMRecord>();
leftCurrentCoordinate.put(left.getReadName(), left);
while (itLeft.advance()) {
final SAMRecord nextLeft = itLeft.getCurrent();
if (compareAlignmentCoordinates(left, nextLeft) == 0) {
leftCurrentCoordinate.put(nextLeft.getReadName(), nextLeft);
} else {
break;
}
}
// Advance the right iterator until it is >= the left reads that have just been grabbed
while (itRight.hasCurrent() && compareAlignmentCoordinates(left, itRight.getCurrent()) > 0) {
final SAMRecord right = itRight.getCurrent();
rightUnmatched.put(right.getReadName(), right);
itRight.advance();
}
// For each right read that has the same coordinate as the current left reads,
// see if there is a matching left read. If so, process and discard. If not,
// save the right read for later.
for (;itRight.hasCurrent() && compareAlignmentCoordinates(left, itRight.getCurrent()) == 0; itRight.advance()) {
final SAMRecord right = itRight.getCurrent();
final SAMRecord matchingLeft = leftCurrentCoordinate.remove(right.getReadName());
if (matchingLeft != null) {
ret = tallyAlignmentRecords(matchingLeft, right) && ret;
} else {
rightUnmatched.put(right.getReadName(), right);
}
}
// Anything left in leftCurrentCoordinate has not been matched
for (final SAMRecord samRecord : leftCurrentCoordinate.values()) {
leftUnmatched.put(samRecord.getReadName(), samRecord);
}
}
// The left iterator has been exhausted. See if any of the remaining right reads
// match any of the saved left reads.
for( ; itRight.hasCurrent(); itRight.advance()) {
final SAMRecord right = itRight.getCurrent();
final SAMRecord left = leftUnmatched.remove(right.getReadName());
if (left != null) {
tallyAlignmentRecords(left, right);
} else {
++missingLeft;