Java Code Examples for htsjdk.samtools.metrics.MetricsFile#getMetrics()
The following examples show how to use
htsjdk.samtools.metrics.MetricsFile#getMetrics() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CollectGcBiasMetrics.java From picard with MIT License | 6 votes |
private void writeResultsToFiles() { final MetricsFile<GcBiasMetrics, Integer> file = getMetricsFile(); final MetricsFile<GcBiasDetailMetrics, ?> detailMetricsFile = getMetricsFile(); final MetricsFile<GcBiasSummaryMetrics, ?> summaryMetricsFile = getMetricsFile(); multiCollector.addAllLevelsToFile(file); final List<GcBiasMetrics> gcBiasMetricsList = file.getMetrics(); for (final GcBiasMetrics gcbm : gcBiasMetricsList) { final List<GcBiasDetailMetrics> gcDetailList = gcbm.DETAILS.getMetrics(); for (final GcBiasDetailMetrics d : gcDetailList) { detailMetricsFile.addMetric(d); } summaryMetricsFile.addMetric(gcbm.SUMMARY); } detailMetricsFile.write(OUTPUT); summaryMetricsFile.write(SUMMARY_OUTPUT); final NumberFormat fmt = NumberFormat.getIntegerInstance(); fmt.setGroupingUsed(true); RExecutor.executeFromClasspath(R_SCRIPT, OUTPUT.getAbsolutePath(), SUMMARY_OUTPUT.getAbsolutePath(), CHART_OUTPUT.getAbsolutePath(), String.valueOf(SCAN_WINDOW_SIZE)); }
Example 2
Source File: CollectTargetedMetricsTest.java From picard with MIT License | 6 votes |
@Test(dataProvider = "targetedIntervalDataProvider") public void runCollectTargetedMetricsTest(final File input, final File outfile, final File perTargetOutfile, final String referenceFile, final String targetIntervals, final int sampleSize) throws IOException { final String[] args = new String[] { "TARGET_INTERVALS=" + targetIntervals, "INPUT=" + input.getAbsolutePath(), "OUTPUT=" + outfile.getAbsolutePath(), "REFERENCE_SEQUENCE=" + referenceFile, "PER_TARGET_COVERAGE=" + perTargetOutfile.getAbsolutePath(), "LEVEL=ALL_READS", "AMPLICON_INTERVALS=" + targetIntervals, "SAMPLE_SIZE=" + sampleSize }; Assert.assertEquals(runPicardCommandLine(args), 0); final MetricsFile<TargetedPcrMetrics, Comparable<?>> output = new MetricsFile<>(); output.read(new FileReader(outfile)); for (final TargetedPcrMetrics metrics : output.getMetrics()) { Assert.assertEquals(metrics.TOTAL_READS, numReads * 2); Assert.assertEquals(metrics.HET_SNP_SENSITIVITY, .997972, .02); } }
Example 3
Source File: CollectAlignmentSummaryMetricsTest.java From picard with MIT License | 6 votes |
@Test public void testZeroLengthReads() throws IOException { final File input = new File(TEST_DATA_DIR, "summary_alignment_stats_test2.sam"); final File outfile = File.createTempFile("alignmentMetrics", ".txt"); outfile.deleteOnExit(); final String[] args = new String[]{ "INPUT=" + input.getAbsolutePath(), "OUTPUT=" + outfile.getAbsolutePath(), "COLLECT_ALIGNMENT_INFORMATION=false" }; Assert.assertEquals(runPicardCommandLine(args), 0); final MetricsFile<AlignmentSummaryMetrics, Comparable<?>> output = new MetricsFile<>(); try (FileReader reader = new FileReader(outfile)) { output.read(reader); } for (final AlignmentSummaryMetrics metrics : output.getMetrics()) { // test that it doesn't blow up } }
Example 4
Source File: CollectWgsMetricsTest.java From picard with MIT License | 5 votes |
@Test(dataProvider = "wgsAlgorithm") public void testLargeIntervals(final String useFastAlgorithm) throws IOException { final File input = new File(TEST_DIR, "forMetrics.sam"); final File outfile = File.createTempFile("test", ".wgs_metrics"); outfile.deleteOnExit(); final File ref = new File(TEST_DIR, "merger.fasta"); final File intervals = new File(TEST_DIR, "largeIntervals.interval_list"); final int sampleSize = 1000; final String[] args = new String[]{ "INPUT=" + input.getAbsolutePath(), "OUTPUT=" + outfile.getAbsolutePath(), "REFERENCE_SEQUENCE=" + ref.getAbsolutePath(), "INTERVALS=" + intervals.getAbsolutePath(), "SAMPLE_SIZE=" + sampleSize, "USE_FAST_ALGORITHM=" + useFastAlgorithm }; Assert.assertEquals(runPicardCommandLine(args), 0); final MetricsFile<WgsMetrics, Comparable<?>> output = new MetricsFile<>(); try (FileReader reader = new FileReader(outfile)) { output.read(reader); } for (final WgsMetrics metrics : output.getMetrics()) { Assert.assertEquals(metrics.GENOME_TERRITORY, 404); Assert.assertEquals(metrics.PCT_EXC_ADAPTER, 0D); Assert.assertEquals(metrics.PCT_EXC_MAPQ, 0.271403); Assert.assertEquals(metrics.PCT_EXC_DUPE, 0.182149); Assert.assertEquals(metrics.PCT_EXC_UNPAIRED, 0.091075); } }
Example 5
Source File: CollectMultipleMetricsTest.java From picard with MIT License | 5 votes |
public void runGcTest(final File input) throws IOException { final File outfile = File.createTempFile("test", ""); outfile.deleteOnExit(); final String[] args = new String[]{ "INPUT=" + input.getAbsolutePath(), "OUTPUT=" + outfile.getAbsolutePath(), "REFERENCE_SEQUENCE=" + CHR_M_REFERENCE.getAbsolutePath(), "METRIC_ACCUMULATION_LEVEL=" + MetricAccumulationLevel.ALL_READS.name(), "PROGRAM=null", "PROGRAM=" + CollectMultipleMetrics.Program.CollectAlignmentSummaryMetrics.name(), "PROGRAM=" + CollectMultipleMetrics.Program.CollectInsertSizeMetrics.name(), "PROGRAM=" + CollectMultipleMetrics.Program.CollectGcBiasMetrics.name() }; Assert.assertEquals(runPicardCommandLine(args), 0); final MetricsFile<GcBiasSummaryMetrics, Comparable<?>> output = new MetricsFile<GcBiasSummaryMetrics, Comparable<?>>(); output.read(new FileReader(outfile + ".gc_bias.summary_metrics")); for (final GcBiasSummaryMetrics metrics : output.getMetrics()) { if (metrics.ACCUMULATION_LEVEL.equals(ACCUMULATION_LEVEL_ALL_READS)) { //ALL_READS level Assert.assertEquals(metrics.TOTAL_CLUSTERS, 300); Assert.assertEquals(metrics.ALIGNED_READS, 600); Assert.assertEquals(metrics.AT_DROPOUT, 7.234062); Assert.assertEquals(metrics.GC_DROPOUT, 4.086217); Assert.assertEquals(metrics.GC_NC_0_19, 0.0); Assert.assertEquals(metrics.GC_NC_20_39, 1.06826); Assert.assertEquals(metrics.GC_NC_40_59, 0.987036); Assert.assertEquals(metrics.GC_NC_60_79, 0.0); Assert.assertEquals(metrics.GC_NC_80_100, 0.0); } else { Assert.fail("Unexpected metric: " + metrics); } } }
Example 6
Source File: GenotypeConcordanceTest.java From picard with MIT License | 5 votes |
@Test public void testNormalizeAllelesForWritingVCF() throws FileNotFoundException { final File truthVcfPath = new File(TEST_DATA_PATH.getAbsolutePath(), NORMALIZE_NO_CALLS_TRUTH); final File callVcfPath = new File(TEST_DATA_PATH.getAbsolutePath(), NORMALIZE_NO_CALLS_CALL); final File outputBaseFileName = new File(OUTPUT_DATA_PATH, "MultipleRefAlleles"); final File outputContingencyMetrics = new File(outputBaseFileName.getAbsolutePath() + GenotypeConcordance.CONTINGENCY_METRICS_FILE_EXTENSION); outputContingencyMetrics.deleteOnExit(); final GenotypeConcordance genotypeConcordance = new GenotypeConcordance(); genotypeConcordance.TRUTH_VCF = truthVcfPath; genotypeConcordance.TRUTH_SAMPLE = "truth"; genotypeConcordance.CALL_VCF = callVcfPath; genotypeConcordance.CALL_SAMPLE = "truth"; genotypeConcordance.OUTPUT = new File(OUTPUT_DATA_PATH, "MultipleRefAlleles"); genotypeConcordance.OUTPUT_VCF = true; Assert.assertEquals(genotypeConcordance.instanceMain(new String[0]), 0); final MetricsFile<GenotypeConcordanceContingencyMetrics, Comparable<?>> output = new MetricsFile<GenotypeConcordanceContingencyMetrics, Comparable<?>>(); output.read(new FileReader(outputContingencyMetrics)); for (final GenotypeConcordanceContingencyMetrics metrics : output.getMetrics()) { if(metrics.VARIANT_TYPE == VariantContext.Type.INDEL){ Assert.assertEquals(metrics.TP_COUNT, 3); Assert.assertEquals(metrics.TN_COUNT, 3); Assert.assertEquals(metrics.FP_COUNT, 0); Assert.assertEquals(metrics.FN_COUNT, 0); Assert.assertEquals(metrics.EMPTY_COUNT, 2); } } }
Example 7
Source File: GenotypeConcordanceTest.java From picard with MIT License | 5 votes |
/** * Tests that we ignore a spanning deletion (*) instead of throwing an exception. */ @Test public void testSpanningDeletion() throws FileNotFoundException { final File truthVcfPath = new File(TEST_DATA_PATH.getAbsolutePath(), "spanningDeletionTruth.vcf"); final File callVcfPath = new File(TEST_DATA_PATH.getAbsolutePath(), "spanningDeletionCallset.vcf"); final File outputBaseFileName = new File(OUTPUT_DATA_PATH, "spanningDeletion"); final File outputContingencyMetrics = new File(outputBaseFileName.getAbsolutePath() + GenotypeConcordance.CONTINGENCY_METRICS_FILE_EXTENSION); outputContingencyMetrics.deleteOnExit(); final GenotypeConcordance genotypeConcordance = new GenotypeConcordance(); genotypeConcordance.TRUTH_VCF = truthVcfPath; genotypeConcordance.TRUTH_SAMPLE = "/dev/stdin"; genotypeConcordance.CALL_VCF = callVcfPath; genotypeConcordance.CALL_SAMPLE = "CHMI_CHMI3_WGS2"; genotypeConcordance.OUTPUT = new File(OUTPUT_DATA_PATH, "spanningDeletion"); genotypeConcordance.OUTPUT_VCF = true; Assert.assertEquals(genotypeConcordance.instanceMain(new String[0]), 0); final MetricsFile<GenotypeConcordanceContingencyMetrics, Comparable<?>> output = new MetricsFile<GenotypeConcordanceContingencyMetrics, Comparable<?>>(); output.read(new FileReader(outputContingencyMetrics)); for (final GenotypeConcordanceContingencyMetrics metrics : output.getMetrics()) { if (metrics.VARIANT_TYPE == VariantContext.Type.SNP) { Assert.assertEquals(metrics.TP_COUNT, 1); Assert.assertEquals(metrics.TN_COUNT,0); Assert.assertEquals(metrics.FP_COUNT, 0); Assert.assertEquals(metrics.FN_COUNT, 0); Assert.assertEquals(metrics.EMPTY_COUNT, 0); } } }
Example 8
Source File: CollectGcBiasMetricsTest.java From picard with MIT License | 5 votes |
/** * Compares metric's results by summary files without duplicates. * @throws IOException */ @Test public void runNonDupsComparisonTest() throws IOException { final File inputFileWithDuplicates = new File("testdata/picard/metrics/chrMReads.sam"); final File detailsOutfile = File.createTempFile("test", ".gc_bias_detail_metrics"); final File summaryOutfile = File.createTempFile("test", ".gc_bias_summary_metrics"); detailsOutfile.deleteOnExit(); summaryOutfile.deleteOnExit(); runGcBias(inputFileWithDuplicates, CHR_M_REFERENCE.getAbsolutePath(), summaryOutfile, detailsOutfile, true); final MetricsFile<GcBiasSummaryMetrics, Comparable<?>> outputSummary = new MetricsFile<>(); outputSummary.read(new FileReader(summaryOutfile)); for (final GcBiasSummaryMetrics summary : outputSummary.getMetrics()) { if (summary.ACCUMULATION_LEVEL.equals(ACCUMULATION_LEVEL_ALL_READS) && summary.READS_USED.equals(READS_USED_UNIQUE)) { //ALL_READS level for case without duplicates Assert.assertEquals(summary.TOTAL_CLUSTERS, 3); Assert.assertEquals(summary.ALIGNED_READS, 3); Assert.assertEquals(summary.AT_DROPOUT, 79.180328); Assert.assertEquals(summary.GC_DROPOUT, 12.28901); Assert.assertEquals(summary.GC_NC_0_19, 0.0); Assert.assertEquals(summary.GC_NC_20_39, 0.0); Assert.assertEquals(summary.GC_NC_40_59, 1.246783); Assert.assertEquals(summary.GC_NC_60_79, 0.0); Assert.assertEquals(summary.GC_NC_80_100, 0.0); } if (summary.ACCUMULATION_LEVEL.equals(ACCUMULATION_LEVEL_ALL_READS) && summary.READS_USED.equals(READS_USED_ALL)) { //ALL_READS level Assert.assertEquals(summary.TOTAL_CLUSTERS, 5); Assert.assertEquals(summary.ALIGNED_READS, 5); Assert.assertEquals(summary.AT_DROPOUT, 79.180328); Assert.assertEquals(summary.GC_DROPOUT, 10.37037); Assert.assertEquals(summary.GC_NC_0_19, 0.0); Assert.assertEquals(summary.GC_NC_20_39, 0.0); Assert.assertEquals(summary.GC_NC_40_59, 1.246783); Assert.assertEquals(summary.GC_NC_60_79, 0.0); Assert.assertEquals(summary.GC_NC_80_100, 0.0); } } }
Example 9
Source File: CollectAlignmentSummaryMetricsTest.java From picard with MIT License | 5 votes |
@Test public void testChimeras() throws IOException { final File input = new File(TEST_DATA_DIR, "summary_alignment_stats_test_chimeras.sam"); final File reference = new File(TEST_DATA_DIR, "summary_alignment_stats_test.fasta"); final File outfile = File.createTempFile("alignmentMetrics", ".txt"); outfile.deleteOnExit(); final String[] args = new String[]{ "INPUT=" + input.getAbsolutePath(), "OUTPUT=" + outfile.getAbsolutePath(), "MAX_INSERT_SIZE=20", "REFERENCE_SEQUENCE=" + reference.getAbsolutePath(), }; Assert.assertEquals(runPicardCommandLine(args), 0); final MetricsFile<AlignmentSummaryMetrics, Comparable<?>> output = new MetricsFile<>(); try (FileReader reader = new FileReader(outfile)) { output.read(reader); } for (final AlignmentSummaryMetrics metrics : output.getMetrics()) { if (metrics.CATEGORY == AlignmentSummaryMetrics.Category.FIRST_OF_PAIR) { TestNGUtil.compareDoubleWithAccuracy(metrics.PCT_CHIMERAS, 5D / 6, 0.0001); } if (metrics.CATEGORY == AlignmentSummaryMetrics.Category.SECOND_OF_PAIR) { TestNGUtil.compareDoubleWithAccuracy(metrics.PCT_CHIMERAS, 3D / 6, 0.0001); } } }
Example 10
Source File: CollectAlignmentSummaryMetricsTest.java From picard with MIT License | 5 votes |
@Test public void testAdapterReads() throws IOException { final File input = new File(TEST_DATA_DIR, "summary_alignment_stats_test_adapter_reads.sam"); final File outfile = File.createTempFile("alignmentMetrics", ".txt"); outfile.deleteOnExit(); final String[] args = new String[]{ "INPUT=" + input.getAbsolutePath(), "OUTPUT=" + outfile.getAbsolutePath(), "MAX_INSERT_SIZE=200", "REFERENCE_SEQUENCE=" + CHR_M_REFERENCE.getAbsolutePath(), }; Assert.assertEquals(runPicardCommandLine(args), 0); final MetricsFile<AlignmentSummaryMetrics, Comparable<?>> output = new MetricsFile<>(); try (FileReader reader = new FileReader(outfile)) { output.read(reader); } for (final AlignmentSummaryMetrics metrics : output.getMetrics()) { if (metrics.CATEGORY == AlignmentSummaryMetrics.Category.FIRST_OF_PAIR) { TestNGUtil.compareDoubleWithAccuracy(metrics.PCT_ADAPTER, 0D, 0.0001); TestNGUtil.compareDoubleWithAccuracy(metrics.PCT_PF_READS_ALIGNED, 1D, 0.0001); } if (metrics.CATEGORY == AlignmentSummaryMetrics.Category.SECOND_OF_PAIR) { TestNGUtil.compareDoubleWithAccuracy(metrics.PCT_ADAPTER, 1D, 0.0001); TestNGUtil.compareDoubleWithAccuracy(metrics.PCT_PF_READS_ALIGNED, 0D, 0.0001); } } }
Example 11
Source File: CollectAlignmentSummaryMetricsTest.java From picard with MIT License | 4 votes |
@Test public void test() throws IOException { final File input = new File(TEST_DATA_DIR, "summary_alignment_stats_test.sam"); final File reference = new File(TEST_DATA_DIR, "summary_alignment_stats_test.fasta"); final File outfile = File.createTempFile("alignmentMetrics", ".txt"); outfile.deleteOnExit(); final String[] args = new String[]{ "INPUT=" + input.getAbsolutePath(), "OUTPUT=" + outfile.getAbsolutePath(), "REFERENCE_SEQUENCE=" + reference.getAbsolutePath(), }; Assert.assertEquals(runPicardCommandLine(args), 0); final MetricsFile<AlignmentSummaryMetrics, Comparable<?>> output = new MetricsFile<>(); try (FileReader reader = new FileReader(outfile)) { output.read(reader); } Assert.assertEquals(output.getMetrics().size(), 3); for (final AlignmentSummaryMetrics metrics : output.getMetrics()) { Assert.assertEquals(metrics.MEAN_READ_LENGTH, 101.0); switch (metrics.CATEGORY) { case FIRST_OF_PAIR: Assert.assertEquals(metrics.TOTAL_READS, 9); Assert.assertEquals(metrics.PF_READS, 7); Assert.assertEquals(metrics.PF_NOISE_READS, 1); Assert.assertEquals(metrics.PF_HQ_ALIGNED_READS, 3); Assert.assertEquals(metrics.PF_HQ_ALIGNED_Q20_BASES, 59); Assert.assertEquals(metrics.PF_HQ_MEDIAN_MISMATCHES, 19.0); Assert.assertEquals(metrics.PF_READS_ALIGNED, 3); Assert.assertEquals(metrics.PF_READS_IMPROPER_PAIRS, 1); Assert.assertEquals(metrics.PCT_PF_READS_IMPROPER_PAIRS, 0.333333 /* 1/3 */); Assert.assertEquals(metrics.PF_ALIGNED_BASES, 303); Assert.assertEquals(metrics.PF_MISMATCH_RATE, /*58D/303D*/0.191419); Assert.assertEquals(metrics.BAD_CYCLES, 19); break; case SECOND_OF_PAIR: Assert.assertEquals(metrics.TOTAL_READS, 9); Assert.assertEquals(metrics.PF_READS, 9); Assert.assertEquals(metrics.PF_NOISE_READS, 1); Assert.assertEquals(metrics.PF_HQ_ALIGNED_READS, 7); Assert.assertEquals(metrics.PF_HQ_ALIGNED_Q20_BASES, 239); Assert.assertEquals(metrics.PF_HQ_MEDIAN_MISMATCHES, 3.0); Assert.assertEquals(metrics.PF_READS_ALIGNED, 7); Assert.assertEquals(metrics.PF_READS_IMPROPER_PAIRS, 5); Assert.assertEquals(metrics.PCT_PF_READS_IMPROPER_PAIRS, 0.714286 /* 5/7 */); Assert.assertEquals(metrics.PF_ALIGNED_BASES, 707); Assert.assertEquals(metrics.PCT_READS_ALIGNED_IN_PAIRS, 0.285714 /* 2D/7 */); Assert.assertEquals(metrics.PF_MISMATCH_RATE, /*19D/707D*/0.026874); Assert.assertEquals(metrics.BAD_CYCLES, 3); break; case PAIR: Assert.assertEquals(metrics.TOTAL_READS, 18); Assert.assertEquals(metrics.PF_READS, 16); Assert.assertEquals(metrics.PF_NOISE_READS, 2); Assert.assertEquals(metrics.PF_HQ_ALIGNED_READS, 10); Assert.assertEquals(metrics.PF_HQ_ALIGNED_Q20_BASES, 298); Assert.assertEquals(metrics.PF_HQ_MEDIAN_MISMATCHES, 3.0); Assert.assertEquals(metrics.PF_READS_ALIGNED, 10); Assert.assertEquals(metrics.PF_READS_IMPROPER_PAIRS, 6); Assert.assertEquals(metrics.PCT_PF_READS_IMPROPER_PAIRS, 0.6 /* 6/10 */); Assert.assertEquals(metrics.PF_ALIGNED_BASES, 1010); Assert.assertEquals(metrics.PF_MISMATCH_RATE, /*77D/1010D*/0.076238); Assert.assertEquals(metrics.BAD_CYCLES, 22); break; case UNPAIRED: default: Assert.fail("Data does not contain this category: " + metrics.CATEGORY); } } }
Example 12
Source File: CollectAlignmentSummaryMetricsTest.java From picard with MIT License | 4 votes |
@Test public void testBisulfite() throws IOException { final File input = new File(TEST_DATA_DIR, "summary_alignment_bisulfite_test.sam"); final File reference = new File(TEST_DATA_DIR, "summary_alignment_stats_test.fasta"); final File outfile = File.createTempFile("alignmentMetrics", ".txt"); outfile.deleteOnExit(); final String[] args = new String[]{ "INPUT=" + input.getAbsolutePath(), "OUTPUT=" + outfile.getAbsolutePath(), "REFERENCE_SEQUENCE=" + reference.getAbsolutePath(), "IS_BISULFITE_SEQUENCED=true" }; Assert.assertEquals(runPicardCommandLine(args), 0); final NumberFormat format = NumberFormat.getInstance(); format.setMaximumFractionDigits(4); final MetricsFile<AlignmentSummaryMetrics, Comparable<?>> output = new MetricsFile<>(); try (FileReader reader = new FileReader(outfile)) { output.read(reader); } for (final AlignmentSummaryMetrics metrics : output.getMetrics()) { Assert.assertEquals(metrics.MEAN_READ_LENGTH, 101.0); switch (metrics.CATEGORY) { case FIRST_OF_PAIR: // 19 no-calls, one potentially methylated base, one mismatch at a potentially methylated base Assert.assertEquals(metrics.TOTAL_READS, 1); Assert.assertEquals(metrics.PF_READS, 1); Assert.assertEquals(metrics.PF_HQ_ALIGNED_BASES, 101); Assert.assertEquals(metrics.PF_HQ_MEDIAN_MISMATCHES, 21.0); Assert.assertEquals(metrics.PF_ALIGNED_BASES, 101); Assert.assertEquals(metrics.PF_MISMATCH_RATE, 0.212121 /*21D/99D*/); Assert.assertEquals(metrics.BAD_CYCLES, 21); Assert.assertEquals(format.format(metrics.PF_HQ_ERROR_RATE), format.format(21 / (double) 99)); break; case SECOND_OF_PAIR: // Three no-calls, two potentially methylated bases Assert.assertEquals(metrics.TOTAL_READS, 1); Assert.assertEquals(metrics.PF_READS, 1); Assert.assertEquals(metrics.PF_HQ_ALIGNED_BASES, 101); Assert.assertEquals(metrics.PF_HQ_MEDIAN_MISMATCHES, 4.0); Assert.assertEquals(metrics.PF_ALIGNED_BASES, 101); Assert.assertEquals(metrics.PF_MISMATCH_RATE, /*4D/99D*/0.040404); Assert.assertEquals(metrics.BAD_CYCLES, 4); Assert.assertEquals(format.format(metrics.PF_HQ_ERROR_RATE), format.format(4 / (double) 99)); break; case PAIR: Assert.assertEquals(metrics.TOTAL_READS, 2); Assert.assertEquals(metrics.PF_READS, 2); Assert.assertEquals(metrics.PF_HQ_ALIGNED_BASES, 202); Assert.assertEquals(metrics.PF_HQ_MEDIAN_MISMATCHES, 12.5D); Assert.assertEquals(metrics.PF_ALIGNED_BASES, 202); Assert.assertEquals(metrics.PF_MISMATCH_RATE, 0.126263);// 25D/198D Assert.assertEquals(metrics.BAD_CYCLES, 25); Assert.assertEquals(format.format(metrics.PF_HQ_ERROR_RATE), format.format(25 / (double) 198)); break; case UNPAIRED: default: Assert.fail("Data does not contain this category: " + metrics.CATEGORY); } } }
Example 13
Source File: CollectWgsMetricsTest.java From picard with MIT License | 4 votes |
@Test(dataProvider = "wgsDataProvider") public void testMetricsFromWGS(final File input, final File outfile, final String referenceFile, final String useFastAlgorithm) throws IOException { outfile.deleteOnExit(); final int sampleSize = 1000; final String[] args = new String[]{ "INPUT=" + input.getAbsolutePath(), "OUTPUT=" + outfile.getAbsolutePath(), "REFERENCE_SEQUENCE=" + referenceFile, "SAMPLE_SIZE=" + sampleSize, "USE_FAST_ALGORITHM=" + useFastAlgorithm }; Assert.assertEquals(runPicardCommandLine(args), 0); final MetricsFile<WgsMetrics, Comparable<?>> output = new MetricsFile<>(); try (FileReader reader = new FileReader(outfile)) { output.read(reader); } for (final WgsMetrics metrics : output.getMetrics()) { Assert.assertEquals(metrics.MEAN_COVERAGE, 13.985155, .02); Assert.assertEquals(metrics.PCT_EXC_OVERLAP, 0.0); // 52 of 606 bases Assert.assertEquals(metrics.PCT_EXC_BASEQ, 0.399906, .02); // 114 of 606 bases Assert.assertEquals(metrics.PCT_EXC_DUPE, 0.0); // 202 of 606 bases Assert.assertEquals(metrics.SD_COVERAGE, 57.364434, .02); Assert.assertEquals(metrics.MEDIAN_COVERAGE, 0.0); Assert.assertEquals(metrics.PCT_EXC_ADAPTER, 0.0); Assert.assertEquals(metrics.PCT_EXC_MAPQ, 0.0); Assert.assertEquals(metrics.PCT_EXC_UNPAIRED, 0.0); Assert.assertEquals(metrics.PCT_EXC_CAPPED, 0.519542, .001); Assert.assertEquals(metrics.PCT_EXC_TOTAL, 0.919537, .001); Assert.assertEquals(metrics.PCT_1X, 0.056364, .0001); Assert.assertEquals(metrics.PCT_5X, 0.056364, .0001); Assert.assertEquals(metrics.PCT_10X, 0.056364, .0001); Assert.assertEquals(metrics.PCT_15X, 0.056364, .0001); Assert.assertEquals(metrics.PCT_20X, 0.056364, .0001); Assert.assertEquals(metrics.PCT_25X, 0.056303, .0001); Assert.assertEquals(metrics.PCT_30X, 0.056303, .0001); Assert.assertEquals(metrics.PCT_40X, 0.056243, .0001); Assert.assertEquals(metrics.PCT_50X, 0.056243, .0001); Assert.assertEquals(metrics.PCT_60X, 0.056182, .0001); Assert.assertEquals(metrics.PCT_70X, 0.056182, .0001); Assert.assertEquals(metrics.PCT_80X, 0.056122, .0001); Assert.assertEquals(metrics.PCT_90X, 0.056062, .0001); Assert.assertEquals(metrics.PCT_100X, 0.056062, .0001); Assert.assertEquals(metrics.HET_SNP_SENSITIVITY, 0.056362, .02); Assert.assertEquals(metrics.HET_SNP_Q, 0.0); } }
Example 14
Source File: CollectWgsMetricsWithNonZeroCoverageTest.java From picard with MIT License | 4 votes |
@Test public void testWithIntervals() throws IOException { final File input = new File(TEST_DIR, "forMetrics.sam"); final File outfile = File.createTempFile("test", ".wgs_metrics"); final File pdffile = File.createTempFile("test", ".wgs_metrics.pdf"); final File ref = new File(TEST_DIR, "merger.fasta"); final File intervals = new File(TEST_DIR, "largeIntervals.interval_list"); final int sampleSize = 1000; outfile.deleteOnExit(); pdffile.deleteOnExit(); final String[] args = new String[] { "INPUT=" + input.getAbsolutePath(), "OUTPUT=" + outfile.getAbsolutePath(), "REFERENCE_SEQUENCE=" + ref.getAbsolutePath(), "INTERVALS=" + intervals.getAbsolutePath(), "SAMPLE_SIZE=" + sampleSize, "CHART=" + pdffile.getAbsolutePath() }; Assert.assertEquals(runPicardCommandLine(args), 0); final MetricsFile<WgsMetricsWithNonZeroCoverage , Integer> output = new MetricsFile<>(); output.read(new FileReader(outfile)); for (final WgsMetricsWithNonZeroCoverage metrics : output.getMetrics()) { if (metrics.CATEGORY == WgsMetricsWithNonZeroCoverage.Category.WHOLE_GENOME) { Assert.assertEquals(metrics.GENOME_TERRITORY, 404); Assert.assertEquals(metrics.PCT_EXC_MAPQ, 0.271403); Assert.assertEquals(metrics.PCT_EXC_DUPE, 0.182149); Assert.assertEquals(metrics.PCT_EXC_UNPAIRED, 0.091075); Assert.assertEquals(metrics.PCT_1X, 0.321782); } else { Assert.assertEquals(metrics.GENOME_TERRITORY, 130); Assert.assertEquals(metrics.PCT_EXC_MAPQ, 0.271403); Assert.assertEquals(metrics.PCT_EXC_DUPE, 0.182149); Assert.assertEquals(metrics.PCT_EXC_UNPAIRED, 0.091075); Assert.assertEquals(metrics.PCT_1X, 1.0); } } for (final Histogram<Integer> histogram : output.getAllHistograms()) { if (histogram.getValueLabel().equals("count_WHOLE_GENOME")) { Assert.assertEquals(histogram.get(0).getValue(), 274d); } else { Assert.assertEquals(histogram.get(0).getValue(), 0d); } Assert.assertEquals(histogram.get(1).getValue(), 9d); Assert.assertEquals(histogram.get(2).getValue(), 35d); Assert.assertEquals(histogram.get(3).getValue(), 86d); Assert.assertEquals(histogram.get(4).getValue(), 0d); } }
Example 15
Source File: CollectGcBiasMetricsTest.java From picard with MIT License | 4 votes |
@Test public void runGcBiasMultiLevelTest() throws IOException { final File outfile = File.createTempFile("test", ".gc_bias.summary_metrics"); final File detailsOutfile = File.createTempFile("test", ".gc_bias.detail_metrics"); outfile.deleteOnExit(); detailsOutfile.deleteOnExit(); runGcBias(tempSamFileChrM_O, REFERENCE_FILE_1, outfile, detailsOutfile, false); final MetricsFile<GcBiasSummaryMetrics, Comparable<?>> output = new MetricsFile<>(); output.read(new FileReader(outfile)); for (final GcBiasSummaryMetrics metrics : output.getMetrics()) { if (metrics.ACCUMULATION_LEVEL.equals(ACCUMULATION_LEVEL_ALL_READS)) { //ALL_READS level Assert.assertEquals(metrics.TOTAL_CLUSTERS, 300); Assert.assertEquals(metrics.ALIGNED_READS, 600); Assert.assertEquals(metrics.AT_DROPOUT, 21.624498); Assert.assertEquals(metrics.GC_DROPOUT, 3.525922); Assert.assertEquals(metrics.GC_NC_0_19, 0.0); Assert.assertEquals(metrics.GC_NC_20_39, 0.831374); Assert.assertEquals(metrics.GC_NC_40_59, 1.049672); Assert.assertEquals(metrics.GC_NC_60_79, 0.0); Assert.assertEquals(metrics.GC_NC_80_100, 0.0); } else if (metrics.READ_GROUP != null && metrics.READ_GROUP.equals("TestReadGroup1")) { //Library 1 Assert.assertEquals(metrics.TOTAL_CLUSTERS, 100); Assert.assertEquals(metrics.ALIGNED_READS, 200); Assert.assertEquals(metrics.AT_DROPOUT, 23.627784); Assert.assertEquals(metrics.GC_DROPOUT, 2.582877); Assert.assertEquals(metrics.GC_NC_0_19, 0.0); Assert.assertEquals(metrics.GC_NC_20_39, 0.793584); Assert.assertEquals(metrics.GC_NC_40_59, 1.060382); Assert.assertEquals(metrics.GC_NC_60_79, 0.0); Assert.assertEquals(metrics.GC_NC_80_100, 0.0); } else if (metrics.READ_GROUP != null && metrics.READ_GROUP.equals("TestReadGroup2")) {//Library 2 Assert.assertEquals(metrics.TOTAL_CLUSTERS, 100); Assert.assertEquals(metrics.ALIGNED_READS, 200); Assert.assertEquals(metrics.AT_DROPOUT, 23.784958); Assert.assertEquals(metrics.GC_DROPOUT, 4.025922); Assert.assertEquals(metrics.GC_NC_0_19, 0.0); Assert.assertEquals(metrics.GC_NC_20_39, 0.816258); Assert.assertEquals(metrics.GC_NC_40_59, 1.053956); Assert.assertEquals(metrics.GC_NC_60_79, 0.0); Assert.assertEquals(metrics.GC_NC_80_100, 0.0); } else if (metrics.READ_GROUP != null && metrics.READ_GROUP.equals("TestReadGroup3")) {//Library 3 Assert.assertEquals(metrics.TOTAL_CLUSTERS, 100); Assert.assertEquals(metrics.ALIGNED_READS, 200); Assert.assertEquals(metrics.AT_DROPOUT, 21.962578); Assert.assertEquals(metrics.GC_DROPOUT, 4.559328); Assert.assertEquals(metrics.GC_NC_0_19, 0.0); Assert.assertEquals(metrics.GC_NC_20_39, 0.88428); Assert.assertEquals(metrics.GC_NC_40_59, 1.034676); Assert.assertEquals(metrics.GC_NC_60_79, 0.0); Assert.assertEquals(metrics.GC_NC_80_100, 0.0); } else if (metrics.SAMPLE != null && metrics.SAMPLE.equals("TestSample1")) {//Library 1 and 2 Assert.assertEquals(metrics.TOTAL_CLUSTERS, 200); Assert.assertEquals(metrics.ALIGNED_READS, 400); Assert.assertEquals(metrics.AT_DROPOUT, 23.194597); Assert.assertEquals(metrics.GC_DROPOUT, 3.275922); Assert.assertEquals(metrics.GC_NC_0_19, 0.0); Assert.assertEquals(metrics.GC_NC_20_39, 0.804921); Assert.assertEquals(metrics.GC_NC_40_59, 1.057169); Assert.assertEquals(metrics.GC_NC_60_79, 0.0); Assert.assertEquals(metrics.GC_NC_80_100, 0.0); } else if (metrics.SAMPLE != null && metrics.SAMPLE.equals("TestSample2")) {//Library 3 Assert.assertEquals(metrics.TOTAL_CLUSTERS, 100); Assert.assertEquals(metrics.ALIGNED_READS, 200); Assert.assertEquals(metrics.AT_DROPOUT, 21.962578); Assert.assertEquals(metrics.GC_DROPOUT, 4.559328); Assert.assertEquals(metrics.GC_NC_0_19, 0.0); Assert.assertEquals(metrics.GC_NC_20_39, 0.88428); Assert.assertEquals(metrics.GC_NC_40_59, 1.034676); Assert.assertEquals(metrics.GC_NC_60_79, 0.0); Assert.assertEquals(metrics.GC_NC_80_100, 0.0); } else { Assert.fail("Unexpected metric: " + metrics); } } }
Example 16
Source File: CollectAlignmentSummaryMetricsTest.java From picard with MIT License | 4 votes |
@Test public void testBisulfiteButNot() throws IOException { final File input = new File(TEST_DATA_DIR, "summary_alignment_bisulfite_test.sam"); final File reference = new File(TEST_DATA_DIR, "summary_alignment_stats_test.fasta"); final File outfile = File.createTempFile("alignmentMetrics", ".txt"); outfile.deleteOnExit(); final String[] args = new String[]{ "INPUT=" + input.getAbsolutePath(), "OUTPUT=" + outfile.getAbsolutePath(), "REFERENCE_SEQUENCE=" + reference.getAbsolutePath(), "IS_BISULFITE_SEQUENCED=false" }; Assert.assertEquals(runPicardCommandLine(args), 0); final NumberFormat format = NumberFormat.getInstance(); format.setMaximumFractionDigits(4); final MetricsFile<AlignmentSummaryMetrics, Comparable<?>> output = new MetricsFile<>(); try (FileReader reader = new FileReader(outfile)) { output.read(reader); } for (final AlignmentSummaryMetrics metrics : output.getMetrics()) { Assert.assertEquals(metrics.MEAN_READ_LENGTH, 101.0); switch (metrics.CATEGORY) { case FIRST_OF_PAIR: // 19 no-calls, one potentially methylated base, one mismatch at a potentially methylated base Assert.assertEquals(metrics.TOTAL_READS, 1); Assert.assertEquals(metrics.PF_READS, 1); Assert.assertEquals(metrics.PF_HQ_ALIGNED_BASES, 101); Assert.assertEquals(metrics.PF_HQ_MEDIAN_MISMATCHES, 23.0); Assert.assertEquals(metrics.PF_ALIGNED_BASES, 101); Assert.assertEquals(metrics.PF_MISMATCH_RATE, 0.227723 /*23D/101D*/); Assert.assertEquals(metrics.BAD_CYCLES, 23); Assert.assertEquals(format.format(metrics.PF_HQ_ERROR_RATE), format.format(23 / (double) 101)); break; case SECOND_OF_PAIR: // Three no-calls, two potentially methylated bases Assert.assertEquals(metrics.TOTAL_READS, 1); Assert.assertEquals(metrics.PF_READS, 1); Assert.assertEquals(metrics.PF_HQ_ALIGNED_BASES, 101); Assert.assertEquals(metrics.PF_HQ_MEDIAN_MISMATCHES, 6.0); Assert.assertEquals(metrics.PF_ALIGNED_BASES, 101); Assert.assertEquals(metrics.PF_MISMATCH_RATE, /*6D/101D*/0.059406); Assert.assertEquals(metrics.BAD_CYCLES, 6); Assert.assertEquals(format.format(metrics.PF_HQ_ERROR_RATE), format.format(6 / (double) 101)); break; case PAIR: Assert.assertEquals(metrics.TOTAL_READS, 2); Assert.assertEquals(metrics.PF_READS, 2); Assert.assertEquals(metrics.PF_HQ_ALIGNED_BASES, 202); Assert.assertEquals(metrics.PF_HQ_MEDIAN_MISMATCHES, 14.5D); Assert.assertEquals(metrics.PF_ALIGNED_BASES, 202); Assert.assertEquals(metrics.PF_MISMATCH_RATE, 0.143564);// 29D/202D Assert.assertEquals(metrics.BAD_CYCLES, 29); Assert.assertEquals(format.format(metrics.PF_HQ_ERROR_RATE), format.format(29 / (double) 202)); break; case UNPAIRED: default: Assert.fail("Data does not contain this category: " + metrics.CATEGORY); } } }
Example 17
Source File: CollectVariantCallingMetricsTest.java From picard with MIT License | 4 votes |
@Test public void testMetricsTiny() throws IOException { final File dbSnpFile = new File(TEST_DATA_DIR, "mini.dbsnp.vcf"); final File vcfFile = new File(TEST_DATA_DIR, "mini.vcf"); final File outFile = new File(TEST_DATA_DIR, "vcmetrics_tiny"); final File summaryFile = new File(TEST_DATA_DIR, "vcmetrics_tiny.variant_calling_summary_metrics"); final File detailFile = new File(TEST_DATA_DIR, "vcmetrics_tiny.variant_calling_detail_metrics"); summaryFile.deleteOnExit(); detailFile.deleteOnExit(); final CollectVariantCallingMetrics program = new CollectVariantCallingMetrics(); program.INPUT = vcfFile; program.DBSNP = dbSnpFile; program.OUTPUT = outFile; Assert.assertEquals(program.doWork(), 0); final MetricsFile<CollectVariantCallingMetrics.VariantCallingSummaryMetrics, Comparable<?>> summary = new MetricsFile<>(); summary.read(new FileReader(summaryFile)); boolean parsedSummary = false; for (final CollectVariantCallingMetrics.VariantCallingSummaryMetrics metrics : summary.getMetrics()) { Assert.assertEquals(metrics.TOTAL_SNPS, 597); Assert.assertEquals(metrics.NOVEL_SNPS, 265); Assert.assertEquals(metrics.NUM_IN_DB_SNP, 332); Assert.assertEquals(metrics.PCT_DBSNP, 0.5561140179634094, 0.01); Assert.assertEquals(metrics.DBSNP_TITV, 3.955224, 0.01); Assert.assertEquals(metrics.NOVEL_TITV, 3.206349, 0.01); Assert.assertEquals(metrics.TOTAL_INDELS, 29); Assert.assertEquals(metrics.NOVEL_INDELS, 11); Assert.assertEquals(metrics.NUM_IN_DB_SNP_INDELS, 18); Assert.assertEquals(metrics.PCT_DBSNP_INDELS, 0.62069, 0.01); Assert.assertEquals(metrics.DBSNP_INS_DEL_RATIO, 0.125, 0.01); Assert.assertEquals(metrics.NOVEL_INS_DEL_RATIO, 0.375, 0.01); Assert.assertEquals(metrics.NUM_SINGLETONS, 245); parsedSummary = true; } Assert.assertTrue(parsedSummary, "Did not parse summary metrics."); final MetricsFile<CollectVariantCallingMetrics.VariantCallingDetailMetrics, Comparable<?>> detail = new MetricsFile<>(); detail.read(new FileReader(detailFile)); final List<CollectVariantCallingMetrics.VariantCallingDetailMetrics> detailMetrics = detail.getMetrics(); detail.getMetrics().stream().filter(metrics -> metrics.SAMPLE_ALIAS.equals("HG00160")).forEach(metrics -> { Assert.assertEquals(metrics.HET_HOMVAR_RATIO, 0.72549, 0.0001); Assert.assertEquals(metrics.TOTAL_GQ0_VARIANTS, 2); Assert.assertEquals(metrics.PCT_GQ0_VARIANTS, 0.022727); Assert.assertEquals(metrics.TOTAL_SNPS, 81); Assert.assertEquals(metrics.NUM_IN_DB_SNP, 44); Assert.assertEquals(metrics.NOVEL_SNPS, 37); Assert.assertEquals(metrics.PCT_DBSNP, 0.543210, 0.01); Assert.assertEquals(metrics.DBSNP_TITV, 6.333333, 0.01); Assert.assertEquals(metrics.NOVEL_TITV, 2.7, 0.01); Assert.assertEquals(metrics.TOTAL_INDELS, 6); Assert.assertEquals(metrics.NOVEL_INDELS, 3); Assert.assertEquals(metrics.NUM_IN_DB_SNP_INDELS, 3); Assert.assertEquals(metrics.PCT_DBSNP_INDELS, 0.5, 0.01); Assert.assertEquals(metrics.DBSNP_INS_DEL_RATIO, 0.0, 0.01); Assert.assertEquals(metrics.NOVEL_INS_DEL_RATIO, 0.0, 0.01); Assert.assertEquals(metrics.TOTAL_MULTIALLELIC_SNPS, 0.0, 0.01); Assert.assertEquals(metrics.NUM_IN_DB_SNP_MULTIALLELIC, 0, 0.01); Assert.assertEquals(metrics.TOTAL_COMPLEX_INDELS, 1.0, 0.01); Assert.assertEquals(metrics.NUM_IN_DB_SNP_COMPLEX_INDELS, 0, 0.01); Assert.assertEquals(metrics.SNP_REFERENCE_BIAS, 0.510204, 0.01); Assert.assertEquals(metrics.NUM_SINGLETONS, 3); }); Assert.assertEquals(detailMetrics.size(), 50, "Did not parse the desired number of detail metrics."); }
Example 18
Source File: ExtractIlluminaBarcodesTest.java From picard with MIT License | 4 votes |
/** * 4 cases tested: * * exact match to ACAGTG * * inexact match within threshold to TGACCA * * inexact match not within threshold to TGACCA * * inexact match where the next match is too close to ACAGTG * * @throws Exception */ @Test public void testBarcodeMatching() throws Exception { final int lane = 1; final int barcodePosition = 26; final MetricsFile<ExtractIlluminaBarcodes.BarcodeMetric, Integer> metricsFile = runIt(lane, "25T8B25T"); ExtractIlluminaBarcodes.BarcodeMetric metricOne = null; ExtractIlluminaBarcodes.BarcodeMetric metricTwo = null; ExtractIlluminaBarcodes.BarcodeMetric metricNoMatch = null; for (final ExtractIlluminaBarcodes.BarcodeMetric metric : metricsFile.getMetrics()) { if (metric.BARCODE.equals(BARCODES[0])) { metricOne = metric; } else if (metric.BARCODE.equals(BARCODES[2])) { metricTwo = metric; } else if (metric.BARCODE.equals("NNNNNNNN")) { metricNoMatch = metric; } } Assert.assertEquals(metricOne.PERFECT_MATCHES, 5); Assert.assertEquals(metricOne.ONE_MISMATCH_MATCHES, 0); Assert.assertEquals(metricOne.PF_READS, 3); Assert.assertEquals(metricOne.READS, 5); // one inexact match Assert.assertEquals(metricTwo.READS, 4); Assert.assertEquals(metricTwo.ONE_MISMATCH_MATCHES, 0); Assert.assertEquals(metricNoMatch.READS, 140); Assert.assertEquals(metricNoMatch.PF_READS, 112); // Check the barcode files themselves final File[] barcodeFiles = IOUtil.getFilesMatchingRegexp(basecallsDir, "s_" + lane + "_\\d{4}_barcode.txt"); Arrays.sort(barcodeFiles); final BasicInputParser barcodeParser = new BasicInputParser(true, barcodeFiles); // Exact match String[] illuminaFields = barcodeParser.next(); Assert.assertEquals(illuminaFields[1], "Y"); Assert.assertEquals(illuminaFields[2], "CAACTCTC"); // Inexact match illuminaFields = barcodeParser.next(); Assert.assertEquals(illuminaFields[1], "Y"); Assert.assertEquals(illuminaFields[2], "ACAGGTAT"); // Too many mismatches illuminaFields = barcodeParser.next(); Assert.assertEquals(illuminaFields[1], "N"); barcodeParser.close(); // Tack on test of barcode-informed Illumina Basecall parsing final ReadStructure rs = new ReadStructure("25T8B25T"); final IlluminaDataProviderFactory factory = new IlluminaDataProviderFactory(basecallsDir, lane, rs, new BclQualityEvaluationStrategy(BclQualityEvaluationStrategy.ILLUMINA_ALLEGED_MINIMUM_QUALITY), IlluminaDataType.BaseCalls, IlluminaDataType.QualityScores, IlluminaDataType.Barcodes); testParsing(factory, rs, metricOne, barcodePosition); }
Example 19
Source File: CollectRrbsMetrics.java From picard with MIT License | 4 votes |
@Override protected int doWork() { if (!METRICS_FILE_PREFIX.endsWith(".")) { METRICS_FILE_PREFIX = METRICS_FILE_PREFIX + "."; } final File SUMMARY_OUT = new File(METRICS_FILE_PREFIX + SUMMARY_FILE_EXTENSION); final File DETAILS_OUT = new File(METRICS_FILE_PREFIX + DETAIL_FILE_EXTENSION); final File PLOTS_OUT = new File(METRICS_FILE_PREFIX + PDF_FILE_EXTENSION); assertIoFiles(SUMMARY_OUT, DETAILS_OUT, PLOTS_OUT); final SamReader samReader = SamReaderFactory.makeDefault().open(INPUT); if (!ASSUME_SORTED && samReader.getFileHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate) { throw new PicardException("The input file " + INPUT.getAbsolutePath() + " does not appear to be coordinate sorted"); } final ReferenceSequenceFileWalker refWalker = new ReferenceSequenceFileWalker(REFERENCE_SEQUENCE); final ProgressLogger progressLogger = new ProgressLogger(log); final RrbsMetricsCollector metricsCollector = new RrbsMetricsCollector(METRIC_ACCUMULATION_LEVEL, samReader.getFileHeader().getReadGroups(), C_QUALITY_THRESHOLD, NEXT_BASE_QUALITY_THRESHOLD, MINIMUM_READ_LENGTH, MAX_MISMATCH_RATE); for (final SAMRecord samRecord : samReader) { progressLogger.record(samRecord); if (!samRecord.getReadUnmappedFlag() && !isSequenceFiltered(samRecord.getReferenceName())) { final ReferenceSequence referenceSequence = refWalker.get(samRecord.getReferenceIndex()); metricsCollector.acceptRecord(samRecord, referenceSequence); } } metricsCollector.finish(); final MetricsFile<RrbsMetrics, Comparable<?>> rrbsMetrics = getMetricsFile(); metricsCollector.addAllLevelsToFile(rrbsMetrics); // Using RrbsMetrics as a way to get both of the metrics objects through the MultiLevelCollector. Once // we get it out split it apart to the two separate MetricsFiles and write them to file final MetricsFile<RrbsSummaryMetrics, ?> summaryFile = getMetricsFile(); final MetricsFile<RrbsCpgDetailMetrics, ?> detailsFile = getMetricsFile(); for (final RrbsMetrics rrbsMetric : rrbsMetrics.getMetrics()) { summaryFile.addMetric(rrbsMetric.getSummaryMetrics()); for (final RrbsCpgDetailMetrics detailMetric : rrbsMetric.getDetailMetrics()) { detailsFile.addMetric(detailMetric); } } summaryFile.write(SUMMARY_OUT); detailsFile.write(DETAILS_OUT); RExecutor.executeFromClasspath(R_SCRIPT, DETAILS_OUT.getAbsolutePath(), SUMMARY_OUT.getAbsolutePath(), PLOTS_OUT.getAbsolutePath()); CloserUtil.close(samReader); return 0; }
Example 20
Source File: CollectSequencingArtifactMetrics.java From picard with MIT License | 4 votes |
@Override protected void finish() { final MetricsFile<PreAdapterSummaryMetrics, Integer> preAdapterSummaryMetricsFile = getMetricsFile(); final MetricsFile<PreAdapterDetailMetrics, Integer> preAdapterDetailMetricsFile = getMetricsFile(); final MetricsFile<BaitBiasSummaryMetrics, Integer> baitBiasSummaryMetricsFile = getMetricsFile(); final MetricsFile<BaitBiasDetailMetrics, Integer> baitBiasDetailMetricsFile = getMetricsFile(); final MetricsFile<ErrorSummaryMetrics,?> errorSummaryMetricsFile = getMetricsFile(); for (final ArtifactCounter counter : artifactCounters.values()) { // build metrics counter.finish(); // write metrics preAdapterSummaryMetricsFile.addAllMetrics(counter.getPreAdapterSummaryMetrics()); baitBiasSummaryMetricsFile.addAllMetrics(counter.getBaitBiasSummaryMetrics()); for (final PreAdapterDetailMetrics preAdapterDetailMetrics : counter.getPreAdapterDetailMetrics()) { if (CONTEXTS_TO_PRINT.isEmpty() || CONTEXTS_TO_PRINT.contains(preAdapterDetailMetrics.CONTEXT)) { preAdapterDetailMetricsFile.addMetric(preAdapterDetailMetrics); } } for (final BaitBiasDetailMetrics baitBiasDetailMetrics : counter.getBaitBiasDetailMetrics()) { if (CONTEXTS_TO_PRINT.isEmpty() || CONTEXTS_TO_PRINT.contains(baitBiasDetailMetrics.CONTEXT)) { baitBiasDetailMetricsFile.addMetric(baitBiasDetailMetrics); } } } preAdapterDetailMetricsFile.write(preAdapterDetailsOut); preAdapterSummaryMetricsFile.write(preAdapterSummaryOut); baitBiasDetailMetricsFile.write(baitBiasDetailsOut); baitBiasSummaryMetricsFile.write(baitBiasSummaryOut); // Calculate the summary error rates - it's CRITICAL that the other files are written out // first as this code modifies the pre-adapter detail metrics! if (!preAdapterDetailMetricsFile.getMetrics().isEmpty()) { final List<PreAdapterDetailMetrics> in = preAdapterDetailMetricsFile.getMetrics(); in.forEach(m -> { if (m.REF_BASE == 'G' || m.REF_BASE == 'T') { m.REF_BASE = (char) SequenceUtil.complement((byte) m.REF_BASE); m.ALT_BASE = (char) SequenceUtil.complement((byte) m.ALT_BASE); } }); // Group the metrics by error type final Map<String,List<PreAdapterDetailMetrics>> byError = in.stream().collect(Collectors.groupingBy(m -> m.REF_BASE + ">" + m.ALT_BASE)); for (final String error : new TreeSet<>(byError.keySet())) { final List<PreAdapterDetailMetrics> ms = byError.get(error); final ErrorSummaryMetrics summary = new ErrorSummaryMetrics(); summary.REF_BASE = ms.get(0).REF_BASE; summary.ALT_BASE = ms.get(0).ALT_BASE; summary.SUBSTITUTION = error; summary.REF_COUNT = ms.stream().mapToLong(m -> m.PRO_REF_BASES + m.CON_REF_BASES).sum(); summary.ALT_COUNT = ms.stream().mapToLong(m -> m.PRO_ALT_BASES + m.CON_ALT_BASES).sum(); summary.calculateDerivedFields(); errorSummaryMetricsFile.addMetric(summary); } } errorSummaryMetricsFile.write(errorSummaryFile); }