Skip to content

Commit

Permalink
CollectQualityYieldMetricsSNVQTest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dror27 committed Jan 24, 2024
1 parent 6300de3 commit aa7418b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> qualityHistogram = new Histogram<>("KEY", "BQ_COUNT");
private Vector<SeriesStats> readPositionQualityStats = new Vector<>();
Expand Down Expand Up @@ -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++;
Expand All @@ -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++;
Expand All @@ -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++;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,26 +55,35 @@ public void test() throws IOException {

Assert.assertEquals(runPicardCommandLine(args), 0);

final MetricsFile<CollectSNVQualityYieldMetrics.QualityYieldMetrics, ?> output = new MetricsFile<>();
final MetricsFile<CollectQualityYieldMetricsSNVQ.QualityYieldMetrics, ?> 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);
}

}

0 comments on commit aa7418b

Please sign in to comment.