use of htsjdk.samtools.SecondaryOrSupplementarySkippingIterator in project gatk by broadinstitute.
the class CompareBaseQualities method doWork.
@Override
protected Object doWork() {
if (roundDown && (staticQuantizationQuals == null || staticQuantizationQuals.isEmpty())) {
throw new CommandLineException.BadArgumentValue("round_down_quantized", "true", "This option can only be used if static_quantized_quals is also used");
}
staticQuantizedMapping = constructStaticQuantizedMapping(staticQuantizationQuals, roundDown);
IOUtil.assertFileIsReadable(samFiles.get(0));
IOUtil.assertFileIsReadable(samFiles.get(1));
final SamReaderFactory factory = SamReaderFactory.makeDefault().validationStringency(VALIDATION_STRINGENCY);
final SamReader reader1 = factory.referenceSequence(REFERENCE_SEQUENCE).open(samFiles.get(0));
final SamReader reader2 = factory.referenceSequence(REFERENCE_SEQUENCE).open(samFiles.get(1));
final SecondaryOrSupplementarySkippingIterator it1 = new SecondaryOrSupplementarySkippingIterator(reader1.iterator());
final SecondaryOrSupplementarySkippingIterator it2 = new SecondaryOrSupplementarySkippingIterator(reader2.iterator());
final CompareMatrix finalMatrix = new CompareMatrix(staticQuantizedMapping);
final ProgressMeter progressMeter = new ProgressMeter(1.0);
progressMeter.start();
while (it1.hasCurrent() && it2.hasCurrent()) {
final SAMRecord read1 = it1.getCurrent();
final SAMRecord read2 = it2.getCurrent();
progressMeter.update(read1);
if (!read1.getReadName().equals(read2.getReadName())) {
throw new UserException.BadInput("files do not have the same exact order of reads:" + read1.getReadName() + " vs " + read2.getReadName());
}
finalMatrix.add(read1.getBaseQualities(), read2.getBaseQualities());
it1.advance();
it2.advance();
}
progressMeter.stop();
if (it1.hasCurrent() || it2.hasCurrent()) {
throw new UserException.BadInput("files do not have the same exact number of reads");
}
CloserUtil.close(reader1);
CloserUtil.close(reader2);
finalMatrix.printOutResults(outputFilename);
if (throwOnDiff && finalMatrix.hasNonDiagonalElements()) {
throw new UserException("Quality scores from the two BAMs do not match");
}
return finalMatrix.hasNonDiagonalElements() ? 1 : 0;
}
Aggregations