public List<SAMValidationError> validateMates(final PairEndInfo mate, final String readName) { final List<SAMValidationError> errors = new ArrayList<>(); validateMateFields(this, mate, readName, errors); validateMateFields(mate, this, readName, errors); // Validations that should not be repeated on both ends if (this.firstOfPairFlag == mate.firstOfPairFlag) { final String whichEnd = this.firstOfPairFlag ? "first" : "second"; errors.add(new SAMValidationError( Type.MATES_ARE_SAME_END, "Both mates are marked as " + whichEnd + " of pair", readName, this.recordNumber )); } return errors; }
public List<SAMValidationError> validateMates(final PairEndInfo mate, final String readName) { final List<SAMValidationError> errors = new ArrayList<>(); validateMateFields(this, mate, readName, errors); validateMateFields(mate, this, readName, errors); // Validations that should not be repeated on both ends if (this.firstOfPairFlag == mate.firstOfPairFlag) { final String whichEnd = this.firstOfPairFlag ? "first" : "second"; errors.add(new SAMValidationError( Type.MATES_ARE_SAME_END, "Both mates are marked as " + whichEnd + " of pair", readName, this.recordNumber )); } return errors; }
public List<SAMValidationError> validateMates(final PairEndInfo mate, final String readName) { final List<SAMValidationError> errors = new ArrayList<SAMValidationError>(); validateMateFields(this, mate, readName, errors); validateMateFields(mate, this, readName, errors); // Validations that should not be repeated on both ends if (this.firstOfPairFlag == mate.firstOfPairFlag) { final String whichEnd = this.firstOfPairFlag ? "first" : "second"; errors.add(new SAMValidationError( Type.MATES_ARE_SAME_END, "Both mates are marked as " + whichEnd + " of pair", readName, this.recordNumber )); } return errors; }
/** * Report error if a tag value is a Long. */ private void validateTags(final SAMRecord record, final long recordNumber) { for (final SAMRecord.SAMTagAndValue tagAndValue : record.getAttributes()) { if (tagAndValue.value instanceof Long) { addError(new SAMValidationError(Type.TAG_VALUE_TOO_LARGE, "Numeric value too large for tag " + tagAndValue.tag, record.getReadName(), recordNumber)); } } }
public void validateBamFileTermination(final File inputFile) { try { if (!IOUtil.isBlockCompressed(inputFile.toPath())) { return; } final BlockCompressedInputStream.FileTermination terminationState = BlockCompressedInputStream.checkTermination(inputFile); if (terminationState.equals(BlockCompressedInputStream.FileTermination.DEFECTIVE)) { addError(new SAMValidationError(Type.TRUNCATED_FILE, "BAM file has defective last gzip block", inputFile.getPath())); } else if (terminationState.equals(BlockCompressedInputStream.FileTermination.HAS_HEALTHY_LAST_BLOCK)) { addError(new SAMValidationError(Type.BAM_FILE_MISSING_TERMINATOR_BLOCK, "Older BAM file -- does not have terminator block", inputFile.getPath())); } } catch (IOException e) { throw new SAMException("IOException", e); } }
public void validateBamFileTermination(final File inputFile) { try { if (!IOUtil.isBlockCompressed(inputFile.toPath())) { return; } final BlockCompressedInputStream.FileTermination terminationState = BlockCompressedInputStream.checkTermination(inputFile); if (terminationState.equals(BlockCompressedInputStream.FileTermination.DEFECTIVE)) { addError(new SAMValidationError(Type.TRUNCATED_FILE, "BAM file has defective last gzip block", inputFile.getPath())); } else if (terminationState.equals(BlockCompressedInputStream.FileTermination.HAS_HEALTHY_LAST_BLOCK)) { addError(new SAMValidationError(Type.BAM_FILE_MISSING_TERMINATOR_BLOCK, "Older BAM file -- does not have terminator block", inputFile.getPath())); } } catch (IOException e) { throw new SAMException("IOException", e); } }
/** * Report error if a tag value is a Long, or if there's a duplicate dag, * or if there's a CG tag is obvered (CG tags are converted to cigars in * the bam code, and should not appear in other formats) */ private void validateTags(final SAMRecord record, final long recordNumber) { final List<SAMRecord.SAMTagAndValue> attributes = record.getAttributes(); final Set<String> tags = new HashSet<>(attributes.size()); for (final SAMRecord.SAMTagAndValue tagAndValue : attributes) { if (tagAndValue.value instanceof Long) { addError(new SAMValidationError(Type.TAG_VALUE_TOO_LARGE, "Numeric value too large for tag " + tagAndValue.tag, record.getReadName(), recordNumber)); } if (!tags.add(tagAndValue.tag)) { addError(new SAMValidationError(Type.DUPLICATE_SAM_TAG, "Duplicate SAM tag (" + tagAndValue.tag + ") found.", record.getReadName(), recordNumber)); } } if (tags.contains(SAMTag.CG.name())){ addError(new SAMValidationError(Type.CG_TAG_FOUND_IN_ATTRIBUTES, "The CG Tag should only be used in BAM format to hold a large cigar. " + "It was found containing the value: " + record.getAttribute(SAMTag.CG.getBinaryTag()), record.getReadName(), recordNumber)); } }
private void validateReadGroup(final SAMRecord record, final SAMFileHeader header) { final SAMReadGroupRecord rg = record.getReadGroup(); if (rg == null) { addError(new SAMValidationError(Type.RECORD_MISSING_READ_GROUP, "A record is missing a read group", record.getReadName())); } else if (header.getReadGroup(rg.getId()) == null) { addError(new SAMValidationError(Type.READ_GROUP_NOT_FOUND, "A record has a read group not found in the header: ", record.getReadName() + ", " + rg.getReadGroupId())); } }
private void validateReadGroup(final SAMRecord record, final SAMFileHeader header) { final SAMReadGroupRecord rg = record.getReadGroup(); if (rg == null) { addError(new SAMValidationError(Type.RECORD_MISSING_READ_GROUP, "A record is missing a read group", record.getReadName())); } else if (header.getReadGroup(rg.getId()) == null) { addError(new SAMValidationError(Type.READ_GROUP_NOT_FOUND, "A record has a read group not found in the header: ", record.getReadName() + ", " + rg.getReadGroupId())); } }
private void validateReadGroup(final SAMRecord record, final SAMFileHeader header) { final SAMReadGroupRecord rg = record.getReadGroup(); if (rg == null) { addError(new SAMValidationError(Type.RECORD_MISSING_READ_GROUP, "A record is missing a read group", record.getReadName())); } else if (header.getReadGroup(rg.getId()) == null) { addError(new SAMValidationError(Type.READ_GROUP_NOT_FOUND, "A record has a read group not found in the header: ", record.getReadName() + ", " + rg.getReadGroupId())); } }
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 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); } }
/** * Run all validations of CIGAR. These include validation that the CIGAR makes sense independent of * placement, plus validation that CIGAR + placement yields all bases with M operator within the range of the reference. * @param recordNumber For error reporting, the record number in the SAM/BAM file. -1 if not known. * @return List of errors, or null if no errors. */ public List<SAMValidationError> validateCigar(final long recordNumber) { List<SAMValidationError> ret = null; if (null != getHeader() && getValidationStringency() != ValidationStringency.SILENT && !this.getReadUnmappedFlag()) { try { //make sure that the cashed version is good //wrapped in a try to catch an un-parsable string return SAMUtils.validateCigar(this, getCigar(), getReferenceIndex(), getAlignmentBlocks(), recordNumber, "Read CIGAR"); } catch( final IllegalArgumentException e){ return Collections.singletonList(new SAMValidationError(SAMValidationError.Type.INVALID_CIGAR,e.getMessage(),getReadName(),recordNumber)); } } return ret; }
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); } }
/** * Run all validations of CIGAR. These include validation that the CIGAR makes sense independent of * placement, plus validation that CIGAR + placement yields all bases with M operator within the range of the reference. * @param recordNumber For error reporting, the record number in the SAM/BAM file. -1 if not known. * @return List of errors, or null if no errors. */ public List<SAMValidationError> validateCigar(final long recordNumber) { List<SAMValidationError> ret = null; if (null != getHeader() && getValidationStringency() != ValidationStringency.SILENT && !this.getReadUnmappedFlag()) { try { //make sure that the cashed version is good //wrapped in a try to catch an un-parsable string return SAMUtils.validateCigar(this, getCigar(), getReferenceIndex(), getAlignmentBlocks(), recordNumber, "Read CIGAR"); } catch( final IllegalArgumentException e){ return Collections.singletonList(new SAMValidationError(SAMValidationError.Type.INVALID_CIGAR,e.getMessage(),getReadName(),recordNumber)); } } return ret; }
private void validateSamFile(final SamReader samReader, final PrintWriter out) { try { validateHeader(samReader.getFileHeader()); orderChecker = new SAMSortOrderChecker(samReader.getFileHeader().getSortOrder()); validateSamRecordsAndQualityFormat(samReader, samReader.getFileHeader()); validateUnmatchedPairs(); if (indexValidationStringency != IndexValidationStringency.NONE) { try { if (indexValidationStringency == IndexValidationStringency.LESS_EXHAUSTIVE) { BamIndexValidator.lessExhaustivelyTestIndex(samReader); } else { BamIndexValidator.exhaustivelyTestIndex(samReader); } } catch (Exception e) { addError(new SAMValidationError(Type.INVALID_INDEX_FILE_POINTER, e.getMessage(), null)); } } if (errorsByType.isEmpty()) { out.println("No errors found"); } } finally { out.flush(); } }
private void validateSamFile(final SAMFileReader samReader, final PrintWriter out) { try { samReader.setValidationStringency(ValidationStringency.SILENT); validateHeader(samReader.getFileHeader()); orderChecker = new SAMSortOrderChecker(samReader.getFileHeader().getSortOrder()); validateSamRecordsAndQualityFormat(samReader, samReader.getFileHeader()); validateUnmatchedPairs(); if (validateIndex) { try { BamIndexValidator.exhaustivelyTestIndex(samReader); } catch (Exception e) { addError(new SAMValidationError(Type.INVALID_INDEX_FILE_POINTER, e.getMessage(), null)); } } if (errorsByType.isEmpty()) { out.println("No errors found"); } } finally { out.flush(); } }
private void validateSortOrder(final SAMRecord record, final long recordNumber) { final SAMRecord prev = orderChecker.getPreviousRecord(); if (!orderChecker.isSorted(record)) { addError(new SAMValidationError( Type.RECORD_OUT_OF_ORDER, String.format( "The record is out of [%s] order, prior read name [%s], prior coodinates [%d:%d]", record.getHeader().getSortOrder().name(), prev.getReadName(), prev.getReferenceIndex(), prev.getAlignmentStart()), record.getReadName(), recordNumber)); } }
private boolean validateSortOrder(final SAMRecord record, final long recordNumber) { final SAMRecord prev = orderChecker.getPreviousRecord(); boolean isValidSortOrder = orderChecker.isSorted(record); if (!isValidSortOrder) { addError(new SAMValidationError( Type.RECORD_OUT_OF_ORDER, String.format( "The record is out of [%s] order, prior read name [%s], prior coodinates [%d:%d]", record.getHeader().getSortOrder().name(), prev.getReadName(), prev.getReferenceIndex(), prev.getAlignmentStart()), record.getReadName(), recordNumber)); } return isValidSortOrder; }
private boolean validateSortOrder(final SAMRecord record, final long recordNumber) { final SAMRecord prev = orderChecker.getPreviousRecord(); boolean isValidSortOrder = orderChecker.isSorted(record); if (!isValidSortOrder) { addError(new SAMValidationError( Type.RECORD_OUT_OF_ORDER, String.format( "The record is out of [%s] order, prior read name [%s], prior coodinates [%d:%d]", record.getHeader().getSortOrder().name(), prev.getReadName(), prev.getReferenceIndex(), prev.getAlignmentStart()), record.getReadName(), recordNumber)); } return isValidSortOrder; }