Skip to content

Commit

Permalink
Quals taken from BQ
Browse files Browse the repository at this point in the history
  • Loading branch information
dror27 committed Jan 17, 2024
1 parent 7d50edb commit f19f680
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/main/java/picard/analysis/CollectSNVQualityYieldMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMRecord;
import htsjdk.samtools.SAMUtils;
import htsjdk.samtools.SAMTag;
import htsjdk.samtools.metrics.MetricsFile;
import htsjdk.samtools.reference.ReferenceSequence;
import htsjdk.samtools.util.Histogram;
Expand All @@ -41,8 +41,6 @@
import picard.util.help.HelpConstants;

import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Vector;

/**
Expand All @@ -59,7 +57,7 @@
@DocumentedFeature
public class CollectSNVQualityYieldMetrics extends SinglePassSamProgram {
private QualityYieldMetricsCollector collector = null;
public Histogram<Integer> qualityHistogram = new Histogram<>("KEY", "QUAL_COUNT");
public Histogram<Integer> qualityHistogram = new Histogram<>("KEY", "BQ_COUNT");
private Vector<SeriesStats> readPositionQualityStats = new Vector<>();
public Histogram<Integer> snvqHistogram = new Histogram<>("KEY", "SNVQ_COUNT");
private Vector<SeriesStats> readPositionSnvqStats = new Vector<>();
Expand All @@ -83,10 +81,10 @@ public class CollectSNVQualityYieldMetrics extends SinglePassSamProgram {
"the QualityYieldMetrics documentation</a> for details and explanations of the output metrics." +
"<hr />";

@Argument(shortName = StandardOptionDefinitions.USE_ORIGINAL_QUALITIES_SHORT_NAME,
doc = "If available in the OQ tag, use the original quality scores " +
"as inputs instead of the quality scores in the QUAL field.")
public boolean USE_ORIGINAL_QUALITIES = true;
@Argument(shortName = StandardOptionDefinitions.USE_ACTUAL_BASE_QUALITIES_SHORT_NAME,
doc = "Use the actual base quality (QUAL) scores " +
"as inputs instead of the quality scores in the BQ field.")
public boolean USE_ACTUAL_ORIGINAL_QUALITIES = false;

@Argument(doc = "If true, include bases from secondary alignments in metrics. Setting to true may cause double-counting " +
"of bases if there are secondary alignments in the input file.")
Expand All @@ -110,7 +108,7 @@ protected boolean usesNoRefReads() {
@Override
protected void setup(final SAMFileHeader header, final File samFile) {
IOUtil.assertFileIsWritable(OUTPUT);
this.collector = new QualityYieldMetricsCollector(USE_ORIGINAL_QUALITIES, INCLUDE_SECONDARY_ALIGNMENTS, INCLUDE_SUPPLEMENTAL_ALIGNMENTS);
this.collector = new QualityYieldMetricsCollector(USE_ACTUAL_ORIGINAL_QUALITIES, INCLUDE_SECONDARY_ALIGNMENTS, INCLUDE_SUPPLEMENTAL_ALIGNMENTS);
}

@Override
Expand All @@ -134,7 +132,7 @@ protected void finish() {
public class QualityYieldMetricsCollector {
// If true, include bases from secondary alignments in metrics. Setting to true may cause double-counting
// of bases if there are secondary alignments in the input file.
private final boolean useOriginalQualities;
private final boolean useActualBaseQualities;

// If true, include bases from secondary alignments in metrics. Setting to true may cause double-counting
// of bases if there are secondary alignments in the input file.
Expand All @@ -147,13 +145,13 @@ public class QualityYieldMetricsCollector {
// The metrics to be accumulated
private final QualityYieldMetrics metrics;

public QualityYieldMetricsCollector(final boolean useOriginalQualities,
public QualityYieldMetricsCollector(final boolean useActualBaseQualities,
final boolean includeSecondaryAlignments,
final boolean includeSupplementalAlignments) {
this.useOriginalQualities = useOriginalQualities;
this.useActualBaseQualities = useActualBaseQualities;
this.includeSecondaryAlignments = includeSecondaryAlignments;
this.includeSupplementalAlignments = includeSupplementalAlignments;
this.metrics = new QualityYieldMetrics(useOriginalQualities);
this.metrics = new QualityYieldMetrics(useActualBaseQualities);
}

public void acceptRecord(final SAMRecord rec, final ReferenceSequence ref) {
Expand All @@ -172,8 +170,8 @@ public void acceptRecord(final SAMRecord rec, final ReferenceSequence ref) {

// access regular quality
final byte[] quals;
if (this.useOriginalQualities) {
byte[] tmp = rec.getOriginalBaseQualities();
if (!this.useActualBaseQualities) {
byte[] tmp = rec.getStringAttribute(SAMTag.BQ).getBytes();
if (tmp == null) tmp = rec.getBaseQualities();
quals = tmp;
} else {
Expand Down Expand Up @@ -287,14 +285,14 @@ public void addMetricsToFile(final MetricsFile<QualityYieldMetrics, Integer> met

public void addHistograms(MetricsFile<QualityYieldMetrics, Integer> metricsFile) {

final Histogram<Integer> h1 = new Histogram<>("KEY", "READ_INDEX_MEAN_QUAL");
final Histogram<Integer> h1 = new Histogram<>("KEY", "READ_INDEX_MEAN_BQ");
for ( int i = 0; i < readPositionQualityStats.size() ; i++ ) {
SeriesStats ss = readPositionQualityStats.get(i);
h1.increment(i, ss.getMean());
}
metricsFile.addHistogram(h1);

final Histogram<Integer> h2 = new Histogram<>("KEY", "READ_INDEX_MEAN_SNVQL");
final Histogram<Integer> h2 = new Histogram<>("KEY", "READ_INDEX_MEAN_SNVQ");
for ( int i = 0; i < readPositionSnvqStats.size() ; i++ ) {
SeriesStats ss = readPositionSnvqStats.get(i);
h2.increment(i, ss.getMean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ public class StandardOptionDefinitions {
public static final String MINIMUM_LOD_SHORT_NAME = "LOD";
public static final String SORT_ORDER_SHORT_NAME = "SO";
public static final String USE_ORIGINAL_QUALITIES_SHORT_NAME = "OQ";
public static final String USE_ACTUAL_BASE_QUALITIES_SHORT_NAME = "ABQ";
}

0 comments on commit f19f680

Please sign in to comment.