/** * Outputs validation error details to out. * * @param samReader records to validate * @param reference if null, NM tag validation is skipped * processing will stop after this threshold has been reached * @return boolean true if there are no validation errors, otherwise false */ public boolean validateSamFileVerbose(final SamReader samReader, final ReferenceSequenceFile reference) { init(reference, samReader.getFileHeader()); try { validateSamFile(samReader, out); } catch (MaxOutputExceededException e) { out.println("Maximum output of [" + maxVerboseOutput + "] errors reached."); } final boolean result = errorsByType.isEmpty(); cleanup(); return result; }
/** * Outputs validation error details to out. * * @param samReader records to validate * @param reference if null, NM tag validation is skipped * processing will stop after this threshold has been reached * @return boolean true if there are no validation errors, otherwise false */ public boolean validateSamFileVerbose(final SAMFileReader samReader, final ReferenceSequenceFile reference) { init(reference, samReader.getFileHeader()); try { validateSamFile(samReader, out); } catch (MaxOutputExceededException e) { out.println("Maximum output of [" + maxVerboseOutput + "] errors reached."); } boolean result = errorsByType.isEmpty(); cleanup(); return result; }
/** * Outputs validation error details to out. * * @param samReader records to validate * @param reference if null, NM tag validation is skipped * processing will stop after this threshold has been reached * @return boolean true if there are no validation errors, otherwise false */ public boolean validateSamFileVerbose(final SamReader samReader, final ReferenceSequenceFile reference) { init(reference, samReader.getFileHeader()); try { validateSamFile(samReader, out); } catch (MaxOutputExceededException e) { out.println("Maximum output of [" + maxVerboseOutput + "] errors reached."); } final boolean result = errorsByType.isEmpty(); cleanup(); return result; }
@Override protected void finish() { collector.finish(); final MetricsFile<RnaSeqMetrics, Integer> file = getMetricsFile(); collector.addAllLevelsToFile(file); file.write(OUTPUT); boolean atLeastOneHistogram = false; for (final Histogram<Integer> histo : file.getAllHistograms()) { atLeastOneHistogram = atLeastOneHistogram || !histo.isEmpty(); } // Generate the coverage by position plot if (CHART_OUTPUT != null && atLeastOneHistogram) { final int rResult = RExecutor.executeFromClasspath("picard/analysis/rnaSeqCoverage.R", OUTPUT.getAbsolutePath(), CHART_OUTPUT.getAbsolutePath(), INPUT.getName(), this.plotSubtitle); if (rResult != 0) { throw new PicardException("Problem invoking R to generate plot."); } } }
@Override protected void finish() { collector.finish(); final MetricsFile<RnaSeqMetrics, Integer> file = getMetricsFile(); collector.addAllLevelsToFile(file); file.write(OUTPUT); boolean atLeastOneHistogram = false; for (final Histogram<Integer> histo : file.getAllHistograms()) { atLeastOneHistogram = atLeastOneHistogram || !histo.isEmpty(); } // Generate the coverage by position plot if (CHART_OUTPUT != null && atLeastOneHistogram) { final int rResult = RExecutor.executeFromClasspath("picard/analysis/rnaSeqCoverage.R", OUTPUT.getAbsolutePath(), CHART_OUTPUT.getAbsolutePath(), INPUT.getName(), this.plotSubtitle); if (rResult != 0) { throw new PicardException("Problem invoking R to generate plot."); } } }
if (isEmpty()) { return;
@Test public void testValidSamFile() throws Exception { final SamReader samReader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT).open(new File(TEST_DATA_DIR, "valid.sam")); final Histogram<String> results = executeValidation(samReader, null, IndexValidationStringency.EXHAUSTIVE); Assert.assertTrue(results.isEmpty()); }
@Test public void testValidCRAMFileWithoutSeqDict() throws Exception { final File reference = new File(TEST_DATA_DIR, "nm_tag_validation.fa"); final SamReader samReader = SamReaderFactory .makeDefault() .validationStringency(ValidationStringency.SILENT) .referenceSequence(reference) .open(new File(TEST_DATA_DIR, "nm_tag_validation.cram")); final Histogram<String> results = executeValidation(samReader, new FastaSequenceFile(reference, true), IndexValidationStringency.EXHAUSTIVE); Assert.assertTrue(!results.isEmpty()); }
@Test public void duplicateReadsOutOfOrder() throws Exception { final SamReader samReader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT).open(new File(TEST_DATA_DIR, "duplicated_reads_out_of_order.sam")); final Histogram<String> results = executeValidation(samReader, null, IndexValidationStringency.EXHAUSTIVE); Assert.assertFalse(results.isEmpty()); Assert.assertEquals(results.get(SAMValidationError.Type.MATES_ARE_SAME_END.getHistogramString()).getValue(), 2.0); }
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(); } }
@Test(enabled = false) public void duplicateReads() throws Exception { final SamReader samReader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT).open(new File(TEST_DATA_DIR, "duplicated_reads.sam")); final Histogram<String> results = executeValidation(samReader, null, IndexValidationStringency.EXHAUSTIVE); Assert.assertFalse(results.isEmpty()); Assert.assertEquals(results.get(SAMValidationError.Type.MATES_ARE_SAME_END.getHistogramString()).getValue(), 2.0); }
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 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(); } }
@Test public void testAddHistogram() { final int[] is1 = {4,4,5,5,5}; final Histogram<Integer> histo1 = new Histogram<>(); Assert.assertTrue(histo1.isEmpty()); for (final int i : is1) histo1.increment(i); Assert.assertFalse(histo1.isEmpty()); final int[] is2 = {5,5, 6,6,6,6}; final Histogram<Integer> histo2 = new Histogram<>(); for (final int i : is2) histo2.increment(i); Assert.assertEquals(histo1.get(4).getValue(), 2.0); Assert.assertEquals(histo1.get(5).getValue(), 3.0); Assert.assertEquals(histo1.get(6), null); histo1.addHistogram(histo2); Assert.assertEquals(histo1.get(4).getValue(), 2.0); Assert.assertEquals(histo1.get(5).getValue(), 5.0); Assert.assertEquals(histo1.get(6).getValue(), 4.0); }
/** * Outputs validation summary report to out. * * @param samReader records to validate * @param reference if null, NM tag validation is skipped * @return boolean true if there are no validation errors, otherwise false */ public boolean validateSamFileSummary(final SamReader samReader, final ReferenceSequenceFile reference) { init(reference, samReader.getFileHeader()); validateSamFile(samReader, out); boolean result = errorsByType.isEmpty(); if (errorsByType.getCount() > 0) { // Convert to a histogram with String IDs so that WARNING: or ERROR: can be prepended to the error type. final Histogram<String> errorsAndWarningsByType = new Histogram<>("Error Type", "Count"); for (final Histogram.Bin<Type> bin : errorsByType.values()) { errorsAndWarningsByType.increment(bin.getId().getHistogramString(), bin.getValue()); } final MetricsFile<ValidationMetrics, String> metricsFile = new MetricsFile<>(); errorsByType.setBinLabel("Error Type"); errorsByType.setValueLabel("Count"); metricsFile.setHistogram(errorsAndWarningsByType); metricsFile.write(out); } cleanup(); return result; }
/** * Outputs validation summary report to out. * * @param samReader records to validate * @param reference if null, NM tag validation is skipped * @return boolean true if there are no validation errors, otherwise false */ public boolean validateSamFileSummary(final SamReader samReader, final ReferenceSequenceFile reference) { init(reference, samReader.getFileHeader()); validateSamFile(samReader, out); boolean result = errorsByType.isEmpty(); if (errorsByType.getCount() > 0) { // Convert to a histogram with String IDs so that WARNING: or ERROR: can be prepended to the error type. final Histogram<String> errorsAndWarningsByType = new Histogram<>("Error Type", "Count"); for (final Histogram.Bin<Type> bin : errorsByType.values()) { errorsAndWarningsByType.increment(bin.getId().getHistogramString(), bin.getValue()); } final MetricsFile<ValidationMetrics, String> metricsFile = new MetricsFile<>(); errorsByType.setBinLabel("Error Type"); errorsByType.setValueLabel("Count"); metricsFile.setHistogram(errorsAndWarningsByType); metricsFile.write(out); } cleanup(); return result; }
/** * Outputs validation summary report to out. * * @param samReader records to validate * @param reference if null, NM tag validation is skipped * @return boolean true if there are no validation errors, otherwise false */ public boolean validateSamFileSummary(final SAMFileReader samReader, final ReferenceSequenceFile reference) { init(reference, samReader.getFileHeader()); validateSamFile(samReader, out); boolean result = errorsByType.isEmpty(); if (errorsByType.getCount() > 0) { // Convert to a histogram with String IDs so that WARNING: or ERROR: can be prepended to the error type. final Histogram<String> errorsAndWarningsByType = new Histogram<String>("Error Type", "Count"); for (final Histogram<SAMValidationError.Type>.Bin bin : errorsByType.values()) { errorsAndWarningsByType.increment(bin.getId().getHistogramString(), bin.getValue()); } final MetricsFile<ValidationMetrics, String> metricsFile = new MetricsFile<ValidationMetrics, String>(); errorsByType.setBinLabel("Error Type"); errorsByType.setValueLabel("Count"); metricsFile.setHistogram(errorsAndWarningsByType); metricsFile.write(out); } cleanup(); return result; }