Search in sources :

Example 1 with SamComparison

use of org.broadinstitute.hellbender.utils.read.SamComparison in project gatk by broadinstitute.

the class CompareSAMs method doWork.

@Override
protected Object doWork() {
    IOUtil.assertFileIsReadable(samFiles.get(0));
    IOUtil.assertFileIsReadable(samFiles.get(1));
    SamReaderFactory factory = SamReaderFactory.makeDefault().validationStringency(VALIDATION_STRINGENCY);
    SamReader sam1 = factory.referenceSequence(REFERENCE_SEQUENCE).open(samFiles.get(0));
    SamReader sam2 = factory.referenceSequence(REFERENCE_SEQUENCE).open(samFiles.get(1));
    SamComparison comparison = new SamComparison(sam1, sam2);
    comparison.printReport();
    if (comparison.areEqual()) {
        System.out.println("Files match.");
    } else {
        System.out.println("Files differ.");
    }
    CloserUtil.close(sam1);
    CloserUtil.close(sam2);
    return comparison.areEqual();
}
Also used : SamReader(htsjdk.samtools.SamReader) SamReaderFactory(htsjdk.samtools.SamReaderFactory) SamComparison(org.broadinstitute.hellbender.utils.read.SamComparison)

Example 2 with SamComparison

use of org.broadinstitute.hellbender.utils.read.SamComparison in project gatk by broadinstitute.

the class SamAssertionUtils method samsEqualLenient.

/**
     * Compares SAM/BAM files in a stringent way but not by byte identity (allow reorder of attributes).
     * Returns null if the files are considered equals and returns a String describing the reason for comparison failure.
     * The lenient comparison only checks headers and alignment info {@see SamComparison}. Compares headers, and if headers are compatible enough, compares SAMRecords,
     * looking only at basic alignment info.
     */
public static String samsEqualLenient(final File actualSam, final File expectedSam, final ValidationStringency validation, final File reference) throws IOException {
    assertCRAMContentsIfCRAM(actualSam);
    assertCRAMContentsIfCRAM(expectedSam);
    try (final SamReader reader1 = getReader(actualSam, validation, reference);
        final SamReader reader2 = getReader(expectedSam, validation, reference)) {
        final SamComparison comparison = new SamComparison(reader1, reader2);
        return comparison.areEqual() ? null : "SamComparison fails";
    }
}
Also used : SamComparison(org.broadinstitute.hellbender.utils.read.SamComparison)

Aggregations

SamComparison (org.broadinstitute.hellbender.utils.read.SamComparison)2 SamReader (htsjdk.samtools.SamReader)1 SamReaderFactory (htsjdk.samtools.SamReaderFactory)1