diff --git a/src/main/java/picard/fingerprint/FingerprintChecker.java b/src/main/java/picard/fingerprint/FingerprintChecker.java index 62a7ee247b..c384b8d91f 100644 --- a/src/main/java/picard/fingerprint/FingerprintChecker.java +++ b/src/main/java/picard/fingerprint/FingerprintChecker.java @@ -526,8 +526,8 @@ public Map fingerprintSamFile(final Path samF public Map fingerprintSamFile(final Path samFile, final Path indexPath, final boolean forceIndex, final Function blockToProbMapper) { + final SamReader in = getSamReader(samFile, indexPath, forceIndex); - checkDictionaryGoodForFingerprinting(in.getFileHeader().getSequenceDictionary()); if (!in.hasIndex()) { log.warn(String.format("Operating without an index! We could be here for a while. (%s)", samFile.toUri().toString())); @@ -535,6 +535,8 @@ public Map fingerprintSamFile(final Path samF log.info(String.format("Reading an indexed file (%s)", samFile.toUri().toString())); } + checkDictionaryGoodForFingerprinting(in.getFileHeader().getSequenceDictionary()); + // fingerprinting allows that headers differ, but SamLocusIterator doesn't allow the dictionary of the query // interval list to differ from that of the samfile, leading to an exception thrown. // At this point we already know that the dictionary of the haplotypes is a proper prefix of that of the sam file @@ -712,12 +714,16 @@ public Map fingerprintFiles(final Collection< } else if (indexPath != null) { log.info("Using explicit index provided for " + p); } - - // Perform fingerprinting on SAM or VCF file - if (CheckFingerprint.fileContainsReads(p)) { - oneFileFingerprints = fingerprintSamFile(p, indexPath, forceIndex, HaplotypeProbabilitiesFromSequence::new); - } else { - oneFileFingerprints = fingerprintVcf(p, indexPath, forceIndex); + try { + // Perform fingerprinting on SAM or VCF file + if (CheckFingerprint.fileContainsReads(p)) { + oneFileFingerprints = fingerprintSamFile(p, indexPath, forceIndex, HaplotypeProbabilitiesFromSequence::new); + } else { + oneFileFingerprints = fingerprintVcf(p, indexPath, forceIndex); + } + } catch (SequenceUtil.SequenceListsDifferException e){ + log.error("file %s caused an exception".formatted(p)); + throw e; } if (oneFileFingerprints.isEmpty()) {