Search in sources :

Example 1 with SecondaryOrSupplementarySkippingIterator

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;
}
Also used : SamReader(htsjdk.samtools.SamReader) SamReaderFactory(htsjdk.samtools.SamReaderFactory) ProgressMeter(org.broadinstitute.hellbender.engine.ProgressMeter) SAMRecord(htsjdk.samtools.SAMRecord) SecondaryOrSupplementarySkippingIterator(htsjdk.samtools.SecondaryOrSupplementarySkippingIterator) UserException(org.broadinstitute.hellbender.exceptions.UserException)

Aggregations

SAMRecord (htsjdk.samtools.SAMRecord)1 SamReader (htsjdk.samtools.SamReader)1 SamReaderFactory (htsjdk.samtools.SamReaderFactory)1 SecondaryOrSupplementarySkippingIterator (htsjdk.samtools.SecondaryOrSupplementarySkippingIterator)1 ProgressMeter (org.broadinstitute.hellbender.engine.ProgressMeter)1 UserException (org.broadinstitute.hellbender.exceptions.UserException)1