readIds = new HashSet<String>();
List<SAMRecord> reads = new ArrayList<SAMRecord>();
readsList.add(reads);
for (Feature region : regions) {
SAMFileReader reader = new SAMFileReader(new File(input));
reader.setValidationStringency(ValidationStringency.SILENT);
Iterator<SAMRecord> iter;
if (region != null) {
iter = reader.queryOverlapping(region.getSeqname(), (int) region.getStart(), (int) region.getEnd());
} else {
iter = reader.iterator();
}
int candidateReadCount = 0;
while (iter.hasNext() && !isMaxReadsForRegionExceeded) {
SAMRecord read = iter.next();
readCount++;
// Don't allow same read to be counted twice.
if ( (!realigner.isFiltered(read)) &&
(!read.getDuplicateReadFlag()) &&
(!read.getReadFailsVendorQualityCheckFlag()) &&
(read.getMappingQuality() >= realigner.getMinMappingQuality() || read.getReadUnmappedFlag()) &&
//(Sam2Fastq.isPrimary(read)) &&
// (!isHardClipped(read)) &&
((!checkForDupes) || (!readIds.contains(getIdentifier(read))))) {
if (read.getReadString().length() > readLength) {
reader.close();
throw new IllegalArgumentException("Maximum read length of: " + readLength +
" exceeded for: " + read.getSAMString());
}
Integer numBestHits = (Integer) read.getIntegerAttribute("X0");
boolean hasAmbiguousInitialAlignment = numBestHits != null && numBestHits > 1;
if (!hasAmbiguousInitialAlignment) {
if (!checkForDupes) {
readIds.add(getIdentifier(read));
}
if (!isAssemblyCandidate && isAssemblyTriggerCandidate(read, c2r)) {
candidateReadCount++;
}
reads.add(read);
if (shouldSearchForSv && isSvCandidate(read, region)) {
svCandidates.add(new Position(read.getMateReferenceName(), read.getMateAlignmentStart(), input));
}
if (reads.size() > maxReadsPerSample) {
isMaxReadsForRegionExceeded = true;
break;
}
}
}
}
reader.close();
if (candidateReadCount > minCandidateCount(reads.size(), region)) {
isAssemblyCandidate = true;
}
}