diff --git a/src/main/java/picard/analysis/CollectSNVQualityYieldMetrics.java b/src/main/java/picard/analysis/CollectQualityYieldMetricsSNVQ.java similarity index 88% rename from src/main/java/picard/analysis/CollectSNVQualityYieldMetrics.java rename to src/main/java/picard/analysis/CollectQualityYieldMetricsSNVQ.java index ea302ddab7..3eef7f1e3d 100644 --- a/src/main/java/picard/analysis/CollectSNVQualityYieldMetrics.java +++ b/src/main/java/picard/analysis/CollectQualityYieldMetricsSNVQ.java @@ -50,12 +50,12 @@ */ @CommandLineProgramProperties( - summary = CollectSNVQualityYieldMetrics.USAGE_SUMMARY + CollectSNVQualityYieldMetrics.USAGE_DETAILS, - oneLineSummary = CollectSNVQualityYieldMetrics.USAGE_SUMMARY, + summary = CollectQualityYieldMetricsSNVQ.USAGE_SUMMARY + CollectQualityYieldMetricsSNVQ.USAGE_DETAILS, + oneLineSummary = CollectQualityYieldMetricsSNVQ.USAGE_SUMMARY, programGroup = DiagnosticsAndQCProgramGroup.class ) @DocumentedFeature -public class CollectSNVQualityYieldMetrics extends SinglePassSamProgram { +public class CollectQualityYieldMetricsSNVQ extends SinglePassSamProgram { private QualityYieldMetricsCollector collector = null; public Histogram qualityHistogram = new Histogram<>("KEY", "BQ_COUNT"); private Vector readPositionQualityStats = new Vector<>(); @@ -189,7 +189,6 @@ public void acceptRecord(final SAMRecord rec, final ReferenceSequence ref) { // add up quals, and quals >= 20 int readPosition = 0; for (final int qual : quals) { - metrics.Q20_EQUIVALENT_YIELD += qual; if (qual >= 40) { metrics.Q20_BASES++; @@ -203,7 +202,6 @@ public void acceptRecord(final SAMRecord rec, final ReferenceSequence ref) { } if (isPfRead) { - metrics.PF_Q20_EQUIVALENT_YIELD += qual; if (qual >= 40) { metrics.PF_Q20_BASES++; metrics.PF_Q30_BASES++; @@ -229,7 +227,7 @@ public void acceptRecord(final SAMRecord rec, final ReferenceSequence ref) { if (q >= 40) { metrics.Q20_SNVQ++; metrics.Q30_SNVQ++; - metrics.Q40_SNVQS++; + metrics.Q40_SNVQ++; if ( isPfRead ) { metrics.PF_Q20_SNVQ++; metrics.PF_Q30_SNVQ++; @@ -274,8 +272,6 @@ public void acceptRecord(final SAMRecord rec, final ReferenceSequence ref) { } public void finish() { - metrics.Q20_EQUIVALENT_YIELD = metrics.Q20_EQUIVALENT_YIELD / 20; - metrics.PF_Q20_EQUIVALENT_YIELD = metrics.PF_Q20_EQUIVALENT_YIELD / 20; metrics.calculateDerivedFields(); } @@ -338,7 +334,7 @@ public QualityYieldMetrics(final boolean useOriginalQualities) { * The total number of bases in all reads */ @MergeByAdding - public long TOTAL_BASES; + public long TOTAL_BASES = 0; /** * The total number of bases in all PF reads @@ -386,7 +382,7 @@ public QualityYieldMetrics(final boolean useOriginalQualities) { * The total number of SNVQ values in all reads */ @MergeByAdding - public long TOTAL_SNVQ; + public long TOTAL_SNVQ = 0; /** * The total number of SNVQ values in all PF reads @@ -422,7 +418,7 @@ public QualityYieldMetrics(final boolean useOriginalQualities) { * The number of SNVQ values in all reads that achieve quality score 40 or higher */ @MergeByAdding - public long Q40_SNVQS = 0; + public long Q40_SNVQ = 0; /** * The number of SNVQ values in PF reads that achieve quality score 40 or higher @@ -431,16 +427,40 @@ public QualityYieldMetrics(final boolean useOriginalQualities) { public long PF_Q40_SNVQ = 0; /** - * The sum of quality scores of all bases divided by 20 + * The percentage of SNVQ values in all reads that achieve quality score 20 or higher */ - @MergeByAdding - public long Q20_EQUIVALENT_YIELD = 0; + @MergingIsManual + public double PCT_Q20_SNVQ = 0; /** - * The sum of quality scores of all bases in PF reads divided by 20 + * The percentage of SNVQ values in all reads that achieve quality score 30 or higher */ - @MergeByAdding - public long PF_Q20_EQUIVALENT_YIELD = 0; + @MergingIsManual + public double PCT_Q30_SNVQ = 0; + + /** + * The percentage of SNVQ values in all reads that achieve quality score 40 or higher + */ + @MergingIsManual + public double PCT_Q40_SNVQ = 0; + + /** + * The percentage of SNVQ values in all reads that achieve quality score 20 or higher and pass filter + */ + @MergingIsManual + public double PCT_PF_Q20_SNVQ = 0; + + /** + * The percentage of SNVQ values in all reads that achieve quality score 30 or higher and pass filter + */ + @MergingIsManual + public double PCT_PF_Q30_SNVQ = 0; + + /** + * The percentage of SNVQ values in all reads that achieve quality score 40 or higher and pass filter + */ + @MergingIsManual + public double PCT_PF_Q40_SNVQ = 0; @MergeByAssertEquals protected final boolean useOriginalQualities; @@ -449,6 +469,14 @@ public QualityYieldMetrics(final boolean useOriginalQualities) { public void calculateDerivedFields() { super.calculateDerivedFields(); this.READ_LENGTH = this.TOTAL_READS == 0 ? 0 : (int) (this.TOTAL_BASES / this.TOTAL_READS); + + this.PCT_Q20_SNVQ = this.TOTAL_SNVQ == 0 ? 0 : (double)this.Q20_SNVQ / this.TOTAL_SNVQ; + this.PCT_Q30_SNVQ = this.TOTAL_SNVQ == 0 ? 0 : (double)this.Q30_SNVQ / this.TOTAL_SNVQ; + this.PCT_Q40_SNVQ = this.TOTAL_SNVQ == 0 ? 0 : (double)this.Q40_SNVQ / this.TOTAL_SNVQ; + + this.PCT_PF_Q20_SNVQ = this.PF_SNVQ == 0 ? 0 : (double)this.PF_Q20_SNVQ / this.PF_SNVQ; + this.PCT_PF_Q30_SNVQ = this.PF_SNVQ == 0 ? 0 : (double)this.PF_Q30_SNVQ / this.PF_SNVQ; + this.PCT_PF_Q40_SNVQ = this.PF_SNVQ == 0 ? 0 : (double)this.PF_Q40_SNVQ / this.PF_SNVQ; } @Override diff --git a/src/test/java/picard/analysis/CollectSNVQualityYieldMetricsTest.java b/src/test/java/picard/analysis/CollectQualityYieldMetricsSNVQTest.java similarity index 56% rename from src/test/java/picard/analysis/CollectSNVQualityYieldMetricsTest.java rename to src/test/java/picard/analysis/CollectQualityYieldMetricsSNVQTest.java index ce1b997a39..eb2ad990dc 100644 --- a/src/test/java/picard/analysis/CollectSNVQualityYieldMetricsTest.java +++ b/src/test/java/picard/analysis/CollectQualityYieldMetricsSNVQTest.java @@ -34,13 +34,13 @@ import java.io.IOException; /** - * Created by kbergin on 11/23/15. + * Created by dror27 on 24/01/2024. */ -public class CollectSNVQualityYieldMetricsTest extends CommandLineProgramTest { +public class CollectQualityYieldMetricsSNVQTest extends CommandLineProgramTest { private static final File TEST_DATA_DIR = new File("testdata/picard/sam/"); public String getCommandLineProgramName() { - return CollectSNVQualityYieldMetrics.class.getSimpleName(); + return CollectQualityYieldMetricsSNVQ.class.getSimpleName(); } @Test @@ -55,26 +55,35 @@ public void test() throws IOException { Assert.assertEquals(runPicardCommandLine(args), 0); - final MetricsFile output = new MetricsFile<>(); + final MetricsFile output = new MetricsFile<>(); output.read(new FileReader(outfile)); Assert.assertEquals(output.getMetrics().size(),1); - final CollectSNVQualityYieldMetrics.QualityYieldMetrics metrics = output.getMetrics().get(0); - /* - Assert.assertEquals(metrics.TOTAL_READS, 52); - Assert.assertEquals(metrics.PF_READS, 52); - Assert.assertEquals(metrics.READ_LENGTH, 101); - Assert.assertEquals(metrics.TOTAL_BASES, 5252); - Assert.assertEquals(metrics.PF_BASES, 5252); - Assert.assertEquals(metrics.Q20_BASES, 3532); - Assert.assertEquals(metrics.PF_Q20_BASES, 3532); - Assert.assertEquals(metrics.Q30_BASES, 3145); - Assert.assertEquals(metrics.PF_Q30_BASES, 3145); - Assert.assertEquals(metrics.Q20_EQUIVALENT_YIELD, 6497); - Assert.assertEquals(metrics.PF_Q20_EQUIVALENT_YIELD, 6497); - */ - + final CollectQualityYieldMetricsSNVQ.QualityYieldMetrics metrics = output.getMetrics().get(0); + Assert.assertEquals(metrics.TOTAL_READS, 26577); + Assert.assertTrue(metrics.PF_READS > 0); + Assert.assertTrue(metrics.READ_LENGTH > 0); + Assert.assertTrue(metrics.TOTAL_BASES > 0); + Assert.assertTrue(metrics.PF_BASES > 0); + Assert.assertTrue(metrics.Q20_BASES > 0); + Assert.assertTrue(metrics.PF_Q20_BASES > 0); + Assert.assertTrue(metrics.PF_Q30_BASES > 0); + Assert.assertTrue(metrics.Q40_BASES > 0); + Assert.assertTrue(metrics.PF_Q40_BASES > 0); + Assert.assertTrue(metrics.TOTAL_SNVQ > 0); + Assert.assertTrue(metrics.PF_SNVQ > 0); + Assert.assertTrue(metrics.Q20_SNVQ > 0); + Assert.assertTrue(metrics.PF_Q20_SNVQ > 0); + Assert.assertTrue(metrics.Q30_SNVQ > 0); + Assert.assertTrue(metrics.PF_Q30_SNVQ > 00); + Assert.assertTrue(metrics.Q40_SNVQ > 0); + Assert.assertTrue(metrics.PF_Q40_SNVQ > 0); + Assert.assertTrue(metrics.PCT_Q20_SNVQ > 0); + Assert.assertTrue(metrics.PCT_Q30_SNVQ > 0); + Assert.assertTrue(metrics.PCT_Q40_SNVQ > 0); + Assert.assertTrue(metrics.PCT_PF_Q20_SNVQ > 00); + Assert.assertTrue(metrics.PCT_PF_Q30_SNVQ > 0); + Assert.assertTrue(metrics.PCT_PF_Q40_SNVQ > 0); } - }