Skip to content

Better error messages for missing contigs in reference #6469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ void initializeReads() {
factory = factory.referenceSequence(referenceArguments.getReferencePath());
}
else if (hasCramInput()) {
throw new UserException.MissingReference("A reference file is required when using CRAM files.");
throw UserException.MISSING_REFERENCE_FOR_CRAM;
}

if(bamIndexCachingShouldBeEnabled()) {
Expand Down Expand Up @@ -823,7 +823,7 @@ public final SAMFileGATKReadWriter createSAMWriter(final File outputFile, final
public final SAMFileGATKReadWriter createSAMWriter(final Path outputPath, final boolean preSorted) {
final boolean isCramFile = IOUtils.isCramFile(outputPath);
if (!hasReference() && isCramFile) {
throw new UserException.MissingReference("A reference file is required for writing CRAM files");
throw UserException.MISSING_REFERENCE_FOR_CRAM;
}

return new SAMFileGATKReadWriter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,4 @@ protected final void onShutdown() {
super.onShutdown();
}

/**
* The emit empty loci parameter comes with several pitfalls when used incorrectly. Here we check and either give
* warnings or errors.
*/
protected void validateEmitEmptyLociParameters() {
if (emitEmptyLoci()) {
if (getBestAvailableSequenceDictionary() == null) {
throw new UserException.MissingReference("Could not create a sequence dictionary nor find a reference. Therefore, emitting empty loci is impossible and this tool cannot be run. The easiest fix here is to specify a reference dictionary.");
}
if (!hasReference() && !hasUserSuppliedIntervals()) {
logger.warn("****************************************");
logger.warn("* Running this tool without a reference nor intervals can yield unexpected results, since it will emit results for loci with no reads. A sequence dictionary has been found. The easiest way avoid this message is to specify a reference.");
logger.warn("****************************************");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ protected JavaRDD<GATKRead> getGatkReadJavaRDD(TraversalParameters traversalPara

} else {
if (hasCramInput() && !hasReference()){
throw new UserException.MissingReference("A reference file is required when using CRAM files.");
throw UserException.MISSING_REFERENCE_FOR_CRAM;
}
final String refPath = hasReference() ? referenceArguments.getReferenceFileName() : null;
output = source.getParallelReads(input, refPath, traversalParameters, bamPartitionSplitSize, useNio);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,14 @@ public static class MissingReference extends UserException {
private static final long serialVersionUID = 0L;

public MissingReference(String message) { super(message); }

public MissingReference(final String message, final boolean commandLine) {
super(message + (commandLine ? String.format(" A reference is specified with the -%s command line argument.", StandardArgumentDefinitions.REFERENCE_SHORT_NAME) : ""));
}
}

public static final MissingReference MISSING_REFERENCE_FOR_CRAM = new MissingReference("A reference file is required when using CRAM files.", true);

public static class MissingIndex extends UserException {
private static final long serialVersionUID = 0L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void closeTool() {
if (outputWriter != null ) { outputWriter.close(); }
try {if (referenceReader != null) { referenceReader.close(); } }
catch (IOException ex) {
throw new UserException.MissingReference("Could not find reference file");
throw new UserException.MissingReference("Could not find reference file.", true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private Collection<ValidationType> calculateValidationTypesToApply(final List<Va
final Set<ValidationType> result = new LinkedHashSet<>(ValidationType.CONCRETE_TYPES);
result.removeAll(excludeTypeSet);
if (result.contains(ValidationType.REF) && !hasReference()) {
throw new UserException.MissingReference("Validation type " + ValidationType.REF.name() + " was selected but no reference was provided.");
throw new UserException.MissingReference("Validation type " + ValidationType.REF.name() + " was selected but no reference was provided.", true);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ public static void validateDictionaries( final String name1,
return;
case COMMON_SUBSET:
if ( requireSuperset ) {
throw new UserException.IncompatibleSequenceDictionaries(String.format("Dictionary %s is missing contigs found in dictionary %s", name1, name2), name1, dict1, name2, dict2);
final Set<String> contigs1 = dict1.getSequences().stream().map(SAMSequenceRecord::getSequenceName).collect(Collectors.toSet());
final List<String> missingContigs = dict2.getSequences().stream()
.map(SAMSequenceRecord::getSequenceName)
.filter(contig -> !contigs1.contains(contig))
.collect(Collectors.toList());
throw new UserException.IncompatibleSequenceDictionaries(String.format("Dictionary %s is missing contigs found in dictionary %s. Missing contigs: \n %s \n", name1, name2, String.join(", ", missingContigs)), name1, dict1, name2, dict2);
}
return;
case SUPERSET:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ public static SAMFileWriter createCommonSAMWriterFromFactory(
Utils.nonNull(header);

if (null == referenceFile && outputPath.toString().endsWith(FileExtensions.CRAM)) {
throw new UserException("A reference file is required for writing CRAM files");
throw new UserException.MissingReference("A reference file is required for writing CRAM files");
}

return factory.makeWriter(header.clone(), preSorted, outputPath, referenceFile);
Expand Down