Skip to content

Commit

Permalink
CollectQualityYieldMetricsFlow changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dror27 committed Jan 24, 2024
1 parent d87b9bd commit 6300de3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
43 changes: 12 additions & 31 deletions src/main/java/picard/analysis/CollectQualityYieldMetricsFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,17 @@ public void acceptRecord(final SAMRecord rec, final ReferenceSequence ref) {
if (!this.includeSecondaryAlignments && rec.isSecondaryAlignment()) return;
if (!this.includeSupplementalAlignments && rec.getSupplementaryAlignmentFlag()) return;
metrics.TOTAL_READS++;

final boolean isPfRead = !rec.getReadFailsVendorQualityCheckFlag();
if (!isPfRead) {
if ( !isPfRead ) {
return;
}

// NOTE: code below runs only isPfRead reads

// convert to a flow based read
FlowBasedReadUtils.ReadGroupInfo info = FlowBasedReadUtils.getReadGroupInfo(rec.getHeader(), rec);
FlowBasedRead fread = new FlowBasedRead(rec, info.flowOrder, info.maxClass, fbargs);


metrics.PF_READS++;
metrics.PF_FLOWS += fread.getKey().length;

Expand All @@ -175,21 +177,12 @@ public void acceptRecord(final SAMRecord rec, final ReferenceSequence ref) {
for (final int qual : quals) {
metrics.Q20_EQUIVALENT_YIELD += qual;

metrics.PF_Q20_EQUIVALENT_YIELD += qual;
if (qual >= 30) {
metrics.Q20_FLOWS++;
metrics.Q30_FLOWS++;
metrics.PF_Q20_FLOWS++;
metrics.PF_Q30_FLOWS++;
} else if (qual >= 20) {
metrics.Q20_FLOWS++;
}

if (isPfRead) {
metrics.PF_Q20_EQUIVALENT_YIELD += qual;
if (qual >= 30) {
metrics.PF_Q20_FLOWS++;
metrics.PF_Q30_FLOWS++;
} else if (qual >= 20) {
metrics.PF_Q20_FLOWS++;
}
metrics.PF_Q20_FLOWS++;
}

if ( INCLUDE_BQ_HISTOGRAM ) {
Expand Down Expand Up @@ -324,12 +317,6 @@ public QualityYieldMetricsFlow() {
@MergeByAdding
public long PF_FLOWS = 0;

/**
* The number of flows in all reads that achieve quality score 20 or higher
*/
@MergeByAdding
public long Q20_FLOWS = 0;

/**
* The number of flows in PF reads that achieve quality score 20 or higher
*/
Expand All @@ -342,12 +329,6 @@ public QualityYieldMetricsFlow() {
@MergingIsManual
public double PCT_PF_Q20_FLOWS = 0;

/**
* The number of flows in all reads that achieve quality score 30 or higher
*/
@MergeByAdding
public long Q30_FLOWS = 0;

/**
* The number of flows in PF reads that achieve quality score 30 or higher
*/
Expand All @@ -358,7 +339,7 @@ public QualityYieldMetricsFlow() {
* The percentage of flows in all reads that achieve quality score 30 or higher
*/
@MergingIsManual
public double PCT_Q30_FLOWS = 0;
public double PCT_PF_Q30_FLOWS = 0;

/**
* The sum of quality scores of all flows divided by 20
Expand All @@ -376,8 +357,8 @@ public QualityYieldMetricsFlow() {
public void calculateDerivedFields() {
super.calculateDerivedFields();
this.MEAN_READ_LENGTH_IN_FLOWS = this.PF_READS == 0 ? 0 : (int) (this.PF_FLOWS / this.PF_READS);
this.PCT_PF_Q20_FLOWS = (double)this.PF_Q20_FLOWS / this.PF_FLOWS;
this.PCT_Q30_FLOWS = (double)this.PF_Q30_FLOWS / this.PF_FLOWS;
this.PCT_PF_Q20_FLOWS = this.PF_FLOWS == 0 ? 0 : (double)this.PF_Q20_FLOWS / this.PF_FLOWS;
this.PCT_PF_Q30_FLOWS = this.PF_FLOWS == 0 ? 0 : (double)this.PF_Q30_FLOWS / this.PF_FLOWS;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,11 @@ public void test() throws IOException {
Assert.assertEquals(metrics.TOTAL_READS, 56);
Assert.assertEquals(metrics.PF_READS, 56);
Assert.assertEquals(metrics.MEAN_READ_LENGTH_IN_FLOWS, 375);
Assert.assertEquals(metrics.TOTAL_FLOWS, 21053);
Assert.assertEquals(metrics.PF_FLOWS, 21053);
Assert.assertEquals(metrics.Q20_FLOWS, 20667);
Assert.assertEquals(metrics.PF_Q20_FLOWS, 20667);
Assert.assertTrue(metrics.PCT_PF_Q20_FLOWS > 0);
Assert.assertEquals(metrics.Q30_FLOWS, 20256);
Assert.assertEquals(metrics.PF_Q30_FLOWS, 20256);
Assert.assertTrue(metrics.PCT_Q30_FLOWS > 0);
Assert.assertTrue(metrics.PCT_PF_Q30_FLOWS > 0);
Assert.assertEquals(metrics.Q20_EQUIVALENT_YIELD, 41177);
Assert.assertEquals(metrics.PF_Q20_EQUIVALENT_YIELD, 41177);
}
Expand Down

0 comments on commit 6300de3

Please sign in to comment.