private void processLocus(ReadsAtLocus normalReads, ReadsAtLocus tumorReads) {
String chromosome = normalReads.getChromosome();
int position = normalReads.getPosition();
CigarElement tumorIndel = null;
int tumorCount = 0;
int tumorRefCount = 0;
int mismatch0Count = 0;
int mismatch1Count = 0;
int totalMismatchCount = 0;
boolean hasSufficientDistanceFromReadEnd = false;
int maxContigMapq = 0;
int minReadIndex = Integer.MAX_VALUE;
int maxReadIndex = Integer.MIN_VALUE;
int normalCount = 0;
int normalRefCount = 0;
Map<String, Integer> insertBasesMap = new HashMap<String, Integer>();
for (SAMRecord read : tumorReads.getReads()) {
if (!read.getDuplicateReadFlag()) {
IndelInfo readElement = checkForIndelAtLocus(read, position);
if (readElement != null) {
Integer ymInt = (Integer) read.getAttribute(ReadAdjuster.MISMATCHES_TO_CONTIG_TAG);
if (ymInt != null) {
int ym = ymInt;
if (ym == 0) {
mismatch0Count++;
}
if (ym <= 1) {
mismatch1Count++;
}
totalMismatchCount += ym;
}
} else if (matchesReference(read, position)) {
tumorRefCount += 1;
}
if (tumorIndel == null && readElement != null) {
tumorIndel = readElement.getCigarElement();
tumorCount = 1;
maxContigMapq = Math.max(maxContigMapq, read.getIntegerAttribute(ReadAdjuster.CONTIG_QUALITY_TAG));
if (readElement.getInsertBases() != null) {
updateInsertBases(insertBasesMap, readElement.getInsertBases());
}
minReadIndex = readElement.getReadIndex() < minReadIndex ? readElement.getReadIndex() : minReadIndex;
maxReadIndex = readElement.getReadIndex() > maxReadIndex ? readElement.getReadIndex() : maxReadIndex;
} else if (tumorIndel != null && readElement != null) {
if (tumorIndel.equals(readElement.getCigarElement())) {
// Increment tumor indel support count
tumorCount += 1;
maxContigMapq = Math.max(maxContigMapq, read.getIntegerAttribute(ReadAdjuster.CONTIG_QUALITY_TAG));
if (readElement.getInsertBases() != null) {
updateInsertBases(insertBasesMap, readElement.getInsertBases());
}
minReadIndex = readElement.getReadIndex() < minReadIndex ? readElement.getReadIndex() : minReadIndex;
maxReadIndex = readElement.getReadIndex() > maxReadIndex ? readElement.getReadIndex() : maxReadIndex;
} else {
// We will not deal with multiple indels at a single locus for now.
tumorIndel = null;
tumorCount = 0;
break;
}
}
if (!hasSufficientDistanceFromReadEnd && tumorIndel != null && readElement != null && readElement.getCigarElement().equals(tumorIndel)) {
hasSufficientDistanceFromReadEnd = sufficientDistanceFromReadEnd(read, readElement.getReadIndex());
}
}
}
float tumorFraction = (float) tumorCount / (float) tumorReads.getReads().size();
if (tumorCount >= MIN_SUPPORTING_READS && hasSufficientDistanceFromReadEnd && tumorFraction >= MIN_TUMOR_FRACTION) {
for (SAMRecord read : normalReads.getReads()) {
if (!read.getDuplicateReadFlag()) {
IndelInfo normalInfo = checkForIndelAtLocus(read.getAlignmentStart(), read.getCigar(), position);
if (normalInfo != null && sufficientDistanceFromReadEnd(read, normalInfo.getReadIndex())) {
normalCount += 1;
} else if (normalInfo == null && matchesReference(read, position)) {
normalRefCount += 1;
}
}
}
}
if (tumorIndel != null && !isNormalCountOK(normalCount, normalReads.getReads().size(), tumorCount, tumorReads.getReads().size())) {
tumorIndel = null;
tumorCount = 0;
}
if (tumorCount >= MIN_SUPPORTING_READS && hasSufficientDistanceFromReadEnd && tumorFraction >= MIN_TUMOR_FRACTION) {
String insertBases = null;
if (tumorIndel.getOperator() == CigarOperator.I) {
insertBases = getInsertBaseConsensus(insertBasesMap, tumorIndel.getLength());
}
int repeatPeriod = getRepeatPeriod(chromosome, position, tumorIndel, insertBases);
double qual = calcPhredScaledQuality(normalRefCount, normalCount, tumorRefCount, tumorCount);