Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tedsharpe committed May 19, 2019
1 parent c85f866 commit 3e4efb7
Showing 1 changed file with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public final class AnalyzeSaturationMutagenesis extends GATKTool {

@VisibleForTesting static Reference reference;
@VisibleForTesting static CodonTracker codonTracker; // device for turning SNVs into CodonVariations
@VisibleForTesting static SAMFileGATKReadWriter bamWriter;
@VisibleForTesting static SAMFileGATKReadWriter rejectedReadsBAMWriter;

// a map of SNV sets onto number of observations of that set of variations
private static final HopscotchMap<SNVCollectionCount, Long, SNVCollectionCount> variationCounts =
Expand Down Expand Up @@ -173,7 +173,7 @@ public void onTraversalStart() {
reference = new Reference(ReferenceDataSource.of(referenceArguments.getReferencePath()));
codonTracker = new CodonTracker(orfCoords, reference.getRefSeq(), logger);
if ( writeRejectedReads ) {
bamWriter = createSAMWriter(new File(outputFilePrefix + ".rejected.bam"), false);
rejectedReadsBAMWriter = createSAMWriter(new File(outputFilePrefix + ".rejected.bam"), false);
}
}

Expand Down Expand Up @@ -235,7 +235,7 @@ public Object onTraversalSuccess() {
writeAAFractions();
writeReadCounts();
writeCoverageSizeHistogram();
if ( bamWriter != null ) bamWriter.close();
if ( rejectedReadsBAMWriter != null ) rejectedReadsBAMWriter.close();
return super.onTraversalSuccess();
}

Expand Down Expand Up @@ -509,20 +509,20 @@ private static void writeReadCounts() {
writer.write(">>Unpaired reads:\t" + nUnpairedReads + "\t" +
df.format(100. * nUnpairedReads / nEvaluableReads) + "%");
writer.newLine();
writeMoleculeCounts(unpairedCounts, df, writer);
writeReportTypeCounts(unpairedCounts, df, writer);
}

final long nDisjointReads = disjointPairCounts.totalCounts();
writer.write(">>Reads in disjoint pairs evaluated separately:\t" + nDisjointReads + "\t" +
df.format(100. * nDisjointReads / nEvaluableReads) + "%");
writer.newLine();
writeMoleculeCounts(disjointPairCounts, df, writer);
writeReportTypeCounts(disjointPairCounts, df, writer);

final long nOverlappingReads = 2 * overlappingPairCounts.totalCounts();
writer.write(">>Reads in overlapping pairs evaluated together:\t" + nOverlappingReads + "\t" +
df.format(100. * nOverlappingReads / nEvaluableReads) + "%");
writer.newLine();
writeMoleculeCounts(overlappingPairCounts, df, writer);
writeReportTypeCounts(overlappingPairCounts, df, writer);

final long totalBases = totalBaseCalls;
writer.write("Total base calls:\t" + totalBases + "\t100.000%");
Expand All @@ -540,9 +540,9 @@ private static void writeReadCounts() {
}
}

private static void writeMoleculeCounts( final ReportTypeCounts counts,
final DecimalFormat df,
final BufferedWriter writer ) throws IOException {
private static void writeReportTypeCounts( final ReportTypeCounts counts,
final DecimalFormat df,
final BufferedWriter writer ) throws IOException {
final long totalCounts = counts.totalCounts();
for ( final ReportType reportType : ReportType.values() ) {
final long count = counts.getCount(reportType);
Expand Down Expand Up @@ -1566,9 +1566,9 @@ private static List<SNV> combineVariations( final ReadReport report1, final Read

private static ReadReport rejectRead( final GATKRead read, final ReportType reportType ) {
readCounts.bumpCount(reportType);
if ( bamWriter != null ) {
if ( rejectedReadsBAMWriter != null ) {
read.setAttribute(ReportType.REPORT_TYPE_ATTRIBUTE_KEY, reportType.attributeValue);
bamWriter.addRead(read);
rejectedReadsBAMWriter.addRead(read);
}
return ReadReport.NULL_REPORT;
}
Expand All @@ -1577,6 +1577,7 @@ private static Interval calculateTrim( final GATKRead read ) {
return calculateShortFragmentTrim(read, calculateQualityTrim(read.getBaseQualitiesNoCopy()));
}

//* find first and last minLength consecutive bases with quality scores at least as big as minQ */
@VisibleForTesting static Interval calculateQualityTrim( final byte[] quals ) {
// find initial end-trim
int readStart = 0;
Expand Down Expand Up @@ -1610,6 +1611,7 @@ private static Interval calculateTrim( final GATKRead read ) {
return new Interval(readStart, readEnd);
}

/** if properly paired, and fragment length is less than read length, trim read ends to fragment length */
private static Interval calculateShortFragmentTrim( final GATKRead read, final Interval qualityTrim ) {
if ( qualityTrim.size() < minLength ) return qualityTrim;

Expand Down Expand Up @@ -1641,35 +1643,33 @@ private static Interval calculateShortFragmentTrim( final GATKRead read, final I
processReport(read2, report2, disjointPairCounts);
}
} else if ( report2.getRefCoverage().isEmpty() ) {
if ( !report1.getRefCoverage().isEmpty() ) {
processReport(read1, report1, disjointPairCounts);
}
processReport(read1, report1, disjointPairCounts);
} else {
final int overlapStart = Math.max(report1.getFirstRefIndex(), report2.getFirstRefIndex());
final int overlapEnd = Math.min(report1.getLastRefIndex(), report2.getLastRefIndex());
if ( overlapStart <= overlapEnd ) { // if mates overlap, or are adjacent
final ReadReport combinedReport = new ReadReport(report1, report2);
final ReportType reportType = combinedReport.updateCounts(codonTracker, variationCounts, reference);
overlappingPairCounts.bumpCount(reportType);
if ( reportType.attributeValue != null && bamWriter != null ) {
if ( reportType.attributeValue != null && rejectedReadsBAMWriter != null ) {
read1.setAttribute(ReportType.REPORT_TYPE_ATTRIBUTE_KEY, reportType.attributeValue);
bamWriter.addRead(read1);
rejectedReadsBAMWriter.addRead(read1);
read2.setAttribute(ReportType.REPORT_TYPE_ATTRIBUTE_KEY, reportType.attributeValue);
bamWriter.addRead(read2);
rejectedReadsBAMWriter.addRead(read2);
}
} else { // mates are disjoint
final ReportType ignoredMate = ReportType.IGNORED_MATE;
if ( read1.isFirstOfPair() ) {
processReport(read1, report1, disjointPairCounts);
if ( bamWriter != null ) {
if ( rejectedReadsBAMWriter != null ) {
read2.setAttribute(ReportType.REPORT_TYPE_ATTRIBUTE_KEY, ignoredMate.attributeValue);
bamWriter.addRead(read2);
rejectedReadsBAMWriter.addRead(read2);
}
} else {
processReport(read2, report2, disjointPairCounts);
if ( bamWriter != null ) {
if ( rejectedReadsBAMWriter != null ) {
read1.setAttribute(ReportType.REPORT_TYPE_ATTRIBUTE_KEY, ignoredMate.attributeValue);
bamWriter.addRead(read1);
rejectedReadsBAMWriter.addRead(read1);
}
}
disjointPairCounts.bumpCount(ignoredMate);
Expand All @@ -1682,9 +1682,9 @@ private static void processReport( final GATKRead read,
final ReportTypeCounts counts ) {
final ReportType reportType = readReport.updateCounts(codonTracker, variationCounts, reference);
counts.bumpCount(reportType);
if ( reportType.attributeValue != null && bamWriter != null ) {
if ( reportType.attributeValue != null && rejectedReadsBAMWriter != null ) {
read.setAttribute(ReportType.REPORT_TYPE_ATTRIBUTE_KEY, reportType.attributeValue);
bamWriter.addRead(read);
rejectedReadsBAMWriter.addRead(read);
}
}
}

0 comments on commit 3e4efb7

Please sign in to comment.