long totalMapq = 0;
CloseableIterator<SAMRecord> iter = reader.queryOverlapping(region.getSeqname(), (int) region.getStart(), (int) region.getEnd());
while (iter.hasNext()) {
SAMRecord read = iter.next();
if (read.getMappingQuality() >= 10) {
String qualStr = read.getBaseQualityString();
boolean readLt5 = false;
boolean readLt10 = false;
boolean readLt20 = false;
boolean readLt30 = false;
boolean internalReadLt20 = false;
numReads++;
numBases += qualStr.length();
int readBasesLt5 = 0;
for (int i=0; i<qualStr.length(); i++) {
// Assuming phred33
int qual = qualStr.charAt(i) - '!';
totalQuality += qual;
if (qual < 5) {
numBasesLt5++;
readBasesLt5++;
readLt5 = true;
}
if (qual < 10) {
numBasesLt10++;
readLt10 = true;
}
if (qual < 20) {
numBasesLt20++;
readLt20 = true;
if ((i>=10) && (i<90)) {
internalReadLt20 = true;
}
}
if (qual < 30) {
readLt30 = true;
}
}
if (readLt5) {
numReadsLt5++;
}
if (readLt10) {
numReadsLt10++;
}
if (readLt20) {
numReadsLt20++;
}
if (readLt30) {
numReadsLt30++;
}
if (readBasesLt5 >= 10) {
numReads5X10++;
}
if (internalReadLt20 == true) {
numInternalReadsLt20++;
}
if (read.getReadString().contains("N")) {
numReadsWithAmbiguousBases++;
}
if (readLt20 || read.getReadString().contains("N")) {
numReadsIntersectLt20Ambiguous++;
}
if (read.getMappingQuality() < minMapq) {
minMapq = read.getMappingQuality();
}
totalMapq += read.getMappingQuality();
}
}
iter.close();