private void validateMateFields(final PairEndInfo end1, final PairEndInfo end2, final String readName, final List<SAMValidationError> errors) { if (end1.mateAlignmentStart != end2.readAlignmentStart) { errors.add(new SAMValidationError( Type.MISMATCH_MATE_ALIGNMENT_START, "Mate alignment does not match alignment start of mate", errors.add(new SAMValidationError( Type.MISMATCH_FLAG_MATE_NEG_STRAND, "Mate negative strand flag does not match read negative strand flag of mate", errors.add(new SAMValidationError( Type.MISMATCH_MATE_REF_INDEX, "Mate reference index (MRNM) does not match reference index of mate", errors.add(new SAMValidationError( Type.MISMATCH_FLAG_MATE_UNMAPPED, "Mate unmapped flag does not match read unmapped flag of mate", errors.add(new SAMValidationError( Type.MISMATCH_MATE_CIGAR_STRING, "Mate CIGAR string does not match CIGAR string of mate",
private void addError(final SAMValidationError error) { // Just ignore an error if it's of a type we're not interested in if (this.errorsToIgnore.contains(error.getType())) return; if (this.ignoreWarnings && error.getType().severity == SAMValidationError.Severity.WARNING) return; this.errorsByType.increment(error.getType()); if (verbose) { out.println(error); out.flush(); if (this.errorsByType.getCount() >= maxVerboseOutput) { throw new MaxOutputExceededException(); } } }
/** * Handle a list of validation errors according to the validation stringency. * * @param validationErrors List of errors to report, or null if there are no errors. * @param samRecordIndex Record number of the SAMRecord corresponding to the validation errors, or -1 if * the record number is not known. * @param validationStringency If STRICT, throw a SAMFormatException. If LENIENT, print the validation * errors to stderr. If SILENT, do nothing. */ public static void processValidationErrors(final List<SAMValidationError> validationErrors, final long samRecordIndex, final ValidationStringency validationStringency) { if (validationErrors != null && !validationErrors.isEmpty()) { for (final SAMValidationError validationError : validationErrors) { validationError.setRecordNumber(samRecordIndex); } if (validationStringency == ValidationStringency.STRICT) { throw new SAMFormatException("SAM validation error: " + validationErrors.get(0)); } else if (validationStringency == ValidationStringency.LENIENT) { for (final SAMValidationError error : validationErrors) { System.err.println("Ignoring SAM validation error: " + error); } } } }
private void reportErrorParsingLine(String reason, final SAMValidationError.Type type, final Throwable nestedException) { reason = "Error parsing SAM header. " + reason + ". Line:\n" + mCurrentLine; if (validationStringency != ValidationStringency.STRICT) { final SAMValidationError error = new SAMValidationError(type, reason, null, mReader.getLineNumber()); error.setSource(mSource); mFileHeader.addValidationError(error); } else { String fileMessage = ""; if (mSource != null) { fileMessage = "File " + mSource; } throw new SAMFormatException(reason + "; " + fileMessage + "; Line number " + mReader.getLineNumber(), nestedException); } }
if (errors != null) { for (final SAMValidationError error : errors) { error.setRecordNumber(recordNumber); addError(error); validateTags(record, recordNumber); if (sequenceDictionaryEmptyAndNoWarningEmitted && !record.getReadUnmappedFlag()) { addError(new SAMValidationError(Type.MISSING_SEQUENCE_DICTIONARY, "Sequence dictionary is empty", null)); sequenceDictionaryEmptyAndNoWarningEmitted = false; addError(new SAMValidationError(Type.QUALITY_NOT_STORED, "QUAL field is set to * (unspecified quality scores), this is allowed by the SAM" + " specification but many tools expect reads to include qualities ", final FastqQualityFormat format = qualityDetector.generateBestGuess(QualityEncodingDetector.FileContext.SAM, FastqQualityFormat.Standard); if (format != FastqQualityFormat.Standard) { addError(new SAMValidationError(Type.INVALID_QUALITY_FORMAT, String.format("Detected %s quality score encoding, but expected %s.", format, FastqQualityFormat.Standard), null)); addError(new SAMValidationError(Type.INVALID_QUALITY_FORMAT, e.getMessage(), null)); throw new SAMException(msg, e); } catch (FileTruncatedException e) { addError(new SAMValidationError(Type.TRUNCATED_FILE, "File is truncated", null)); } finally { iter.close();
if (validationErrors != null) { for (final SAMValidationError errorMessage : validationErrors) { reportErrorParsingLine(errorMessage.getMessage());
/** * Basic sanity check for a SAMRecord. Print errors to screen. * @param read SAM record * @throws IllegalArgumentException if read is null * @throws SanityCheckFailedException if errors */ public static void assertReadValid(final SAMRecord read) throws SanityCheckFailedException { if (read == null) { throw new IllegalArgumentException("SAMRecord is null"); } final List<SAMValidationError> errors = read.isValid(false); if ( errors != null) { errors.forEach(v -> System.out.println(v.toString())); } assertTrue(errors.isEmpty()); }
if (errors != null) { for (final SAMValidationError error : errors) { error.setRecordNumber(recordNumber); addError(error); validateTags(record, recordNumber); if (sequenceDictionaryEmptyAndNoWarningEmitted && !record.getReadUnmappedFlag()) { addError(new SAMValidationError(Type.MISSING_SEQUENCE_DICTIONARY, "Sequence dictionary is empty", null)); sequenceDictionaryEmptyAndNoWarningEmitted = false; addError(new SAMValidationError(Type.QUALITY_NOT_STORED, "QUAL field is set to * (unspecified quality scores), this is allowed by the SAM" + " specification but many tools expect reads to include qualities ", final FastqQualityFormat format = qualityDetector.generateBestGuess(QualityEncodingDetector.FileContext.SAM, FastqQualityFormat.Standard); if (format != FastqQualityFormat.Standard) { addError(new SAMValidationError(Type.INVALID_QUALITY_FORMAT, String.format("Detected %s quality score encoding, but expected %s.", format, FastqQualityFormat.Standard), null)); addError(new SAMValidationError(Type.INVALID_QUALITY_FORMAT, e.getMessage(), null)); throw new SAMException(msg, e); } catch (FileTruncatedException e) { addError(new SAMValidationError(Type.TRUNCATED_FILE, "File is truncated", null)); } finally { iter.close();
private void reportErrorParsingLine(String reason, final SAMValidationError.Type type, final Throwable nestedException) { reason = "Error parsing SAM header. " + reason + ". Line:\n" + mCurrentLine; if (validationStringency != ValidationStringency.STRICT) { final SAMValidationError error = new SAMValidationError(type, reason, null, mReader.getLineNumber()); error.setSource(mSource); mFileHeader.addValidationError(error); } else { String fileMessage = ""; if (mSource != null) { fileMessage = "File " + mSource; } throw new SAMFormatException(reason + "; " + fileMessage + "; Line number " + mReader.getLineNumber(), nestedException); } }
if (validationErrors != null) { for (final SAMValidationError errorMessage : validationErrors) { reportErrorParsingLine(errorMessage.getMessage());
/** * Basic sanity check for a SAMRecord. Print errors to screen. * @param read SAM record * @throws IllegalArgumentException if read is null * @throws SanityCheckFailedException if errors */ public static void assertReadValid(final SAMRecord read) throws SanityCheckFailedException { if (read == null) { throw new IllegalArgumentException("SAMRecord is null"); } final List<SAMValidationError> errors = read.isValid(false); if ( errors != null) { errors.forEach(v -> System.out.println(v.toString())); } assertTrue(errors.isEmpty()); }
private void validateMateFields(final PairEndInfo end1, final PairEndInfo end2, final String readName, final List<SAMValidationError> errors) { if (end1.mateAlignmentStart != end2.readAlignmentStart) { errors.add(new SAMValidationError( Type.MISMATCH_MATE_ALIGNMENT_START, "Mate alignment does not match alignment start of mate", errors.add(new SAMValidationError( Type.MISMATCH_FLAG_MATE_NEG_STRAND, "Mate negative strand flag does not match read negative strand flag of mate", errors.add(new SAMValidationError( Type.MISMATCH_MATE_REF_INDEX, "Mate reference index (MRNM) does not match reference index of mate", errors.add(new SAMValidationError( Type.MISMATCH_FLAG_MATE_UNMAPPED, "Mate unmapped flag does not match read unmapped flag of mate", errors.add(new SAMValidationError( Type.MISMATCH_MATE_CIGAR_STRING, "Mate CIGAR string does not match CIGAR string of mate",
if (errors != null) { for (final SAMValidationError error : errors) { error.setRecordNumber(recordNumber); addError(error); validateTags(record, recordNumber); if (sequenceDictionaryEmptyAndNoWarningEmitted && !record.getReadUnmappedFlag()) { addError(new SAMValidationError(Type.MISSING_SEQUENCE_DICTIONARY, "Sequence dictionary is empty", null)); sequenceDictionaryEmptyAndNoWarningEmitted = false; final FastqQualityFormat format = qualityDetector.generateBestGuess(QualityEncodingDetector.FileContext.SAM, FastqQualityFormat.Standard); if (format != FastqQualityFormat.Standard) { addError(new SAMValidationError(Type.INVALID_QUALITY_FORMAT, String.format("Detected %s quality score encoding, but expected %s.", format, FastqQualityFormat.Standard), null)); addError(new SAMValidationError(Type.INVALID_QUALITY_FORMAT, e.getMessage(), null)); throw new SAMException(msg, e); } catch (FileTruncatedException e) { addError(new SAMValidationError(Type.TRUNCATED_FILE, "File is truncated", null)); } finally { iter.close();
private void reportErrorParsingLine(String reason, final SAMValidationError.Type type, final Throwable nestedException) { reason = "Error parsing SAM header. " + reason + ". Line:\n" + mCurrentLine; if (validationStringency != ValidationStringency.STRICT) { final SAMValidationError error = new SAMValidationError(type, reason, null, mReader.getLineNumber()); error.setSource(mSource); mFileHeader.addValidationError(error); } else { String fileMessage = ""; if (mSource != null) { fileMessage = "File " + mSource; } throw new SAMFormatException(reason + "; " + fileMessage + "; Line number " + mReader.getLineNumber(), nestedException); } }
private void addError(final SAMValidationError error) { // Just ignore an error if it's of a type we're not interested in if (this.errorsToIgnore.contains(error.getType())) return; switch (error.getType().severity) { case WARNING: if (this.ignoreWarnings) { return; } this.numWarnings++; break; case ERROR: this.numErrors++; break; default: throw new SAMException("Unknown SAM validation error severity: " + error.getType().severity); } this.errorsByType.increment(error.getType()); if (verbose) { out.println(error); out.flush(); if (this.errorsByType.getCount() >= maxVerboseOutput) { throw new MaxOutputExceededException(); } } }
/** * Handle a list of validation errors according to the validation stringency. * * @param validationErrors List of errors to report, or null if there are no errors. * @param samRecordIndex Record number of the SAMRecord corresponding to the validation errors, or -1 if * the record number is not known. * @param validationStringency If STRICT, throw a SAMFormatException. If LENIENT, print the validation * errors to stderr. If SILENT, do nothing. */ public static void processValidationErrors(final List<SAMValidationError> validationErrors, final long samRecordIndex, final ValidationStringency validationStringency) { if (validationErrors != null && !validationErrors.isEmpty()) { for (final SAMValidationError validationError : validationErrors) { validationError.setRecordNumber(samRecordIndex); } if (validationStringency == ValidationStringency.STRICT) { throw new SAMFormatException("SAM validation error: " + validationErrors.get(0)); } else if (validationStringency == ValidationStringency.LENIENT) { for (final SAMValidationError error : validationErrors) { System.err.println("Ignoring SAM validation error: " + error); } } } }
if (validationErrors != null) { for (final SAMValidationError errorMessage : validationErrors) { reportErrorParsingLine(errorMessage.getMessage());
private void validateMateFields(final PairEndInfo end1, final PairEndInfo end2, final String readName, final List<SAMValidationError> errors) { if (end1.mateAlignmentStart != end2.readAlignmentStart) { errors.add(new SAMValidationError( Type.MISMATCH_MATE_ALIGNMENT_START, "Mate alignment does not match alignment start of mate", errors.add(new SAMValidationError( Type.MISMATCH_FLAG_MATE_NEG_STRAND, "Mate negative strand flag does not match read negative strand flag of mate", errors.add(new SAMValidationError( Type.MISMATCH_MATE_REF_INDEX, "Mate reference index (MRNM) does not match reference index of mate", errors.add(new SAMValidationError( Type.MISMATCH_FLAG_MATE_UNMAPPED, "Mate unmapped flag does not match read unmapped flag of mate", errors.add(new SAMValidationError( Type.MISMATCH_MATE_CIGAR_STRING, "Mate CIGAR string does not match CIGAR string of mate",
private void addError(final SAMValidationError error) { // Just ignore an error if it's of a type we're not interested in if (this.errorsToIgnore.contains(error.getType())) return; switch (error.getType().severity) { case WARNING: if (this.ignoreWarnings) { return; } this.numWarnings++; break; case ERROR: this.numErrors++; break; default: throw new SAMException("Unknown SAM validation error severity: " + error.getType().severity); } this.errorsByType.increment(error.getType()); if (verbose) { out.println(error); out.flush(); if (this.errorsByType.getCount() >= maxVerboseOutput) { throw new MaxOutputExceededException(); } } }
/** * Handle a list of validation errors according to the validation stringency. * * @param validationErrors List of errors to report, or null if there are no errors. * @param samRecordIndex Record number of the SAMRecord corresponding to the validation errors, or -1 if * the record number is not known. * @param validationStringency If STRICT, throw a SAMFormatException. If LENIENT, print the validation * errors to stderr. If SILENT, do nothing. */ public static void processValidationErrors(final List<SAMValidationError> validationErrors, final long samRecordIndex, final ValidationStringency validationStringency) { if (validationErrors != null && !validationErrors.isEmpty()) { for (final SAMValidationError validationError : validationErrors) { validationError.setRecordNumber(samRecordIndex); } if (validationStringency == ValidationStringency.STRICT) { throw new SAMFormatException("SAM validation error: " + validationErrors.get(0)); } else if (validationStringency == ValidationStringency.LENIENT) { for (final SAMValidationError error : validationErrors) { System.err.println("Ignoring SAM validation error: " + error); } } } }