From 08ac80c0804dceee76502de7de630095031f39b2 Mon Sep 17 00:00:00 2001 From: Eric Banks Date: Sun, 7 Oct 2012 10:52:01 -0400 Subject: [PATCH] RR bug: when the last base in the window around the polyploid consensus is filtered (low quality), the filtered consensus is not flushed and subsequent filtered bases (but importantly not contiguous to this one) are just added to this position. In other words, bases were being added to the wrong genomic positions. Fixed. --- .../reducereads/SlidingWindow.java | 19 ++++++++++++++----- .../reducereads/SyntheticRead.java | 14 +++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindow.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindow.java index e938ccba0..e39edf956 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindow.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindow.java @@ -291,7 +291,7 @@ public class SlidingWindow { reads.addAll(finalizeAndAdd(ConsensusType.CONSENSUS)); int endOfFilteredData = findNextNonFilteredDataElement(header, start, end); - addToFilteredData(header, start, endOfFilteredData, isNegativeStrand); + reads.addAll(addToFilteredData(header, start, endOfFilteredData, isNegativeStrand)); if (endOfFilteredData <= start) throw new ReviewedStingException(String.format("next start is <= current start: (%d <= %d)", endOfFilteredData, start)); @@ -418,7 +418,9 @@ public class SlidingWindow { * @param start the first header index to add to consensus * @param end the first header index NOT TO add to consensus */ - private void addToFilteredData(LinkedList header, int start, int end, boolean isNegativeStrand) { + private List addToFilteredData(LinkedList header, int start, int end, boolean isNegativeStrand) { + List result = new ArrayList(0); + if (filteredDataConsensus == null) filteredDataConsensus = new SyntheticRead(samHeader, readGroupAttribute, contig, contigIndex, filteredDataReadName + filteredDataConsensusCounter++, header.get(start).getLocation(), GATKSAMRecord.REDUCED_READ_CONSENSUS_TAG, hasIndelQualities, isNegativeStrand); @@ -434,8 +436,15 @@ public class SlidingWindow { if (!headerElement.hasFilteredData()) throw new ReviewedStingException("No filtered data in " + index); + if ( filteredDataConsensus.getRefStart() + filteredDataConsensus.size() != headerElement.getLocation() ) { + result.add(finalizeFilteredDataConsensus()); + filteredDataConsensus = new SyntheticRead(samHeader, readGroupAttribute, contig, contigIndex, filteredDataReadName + filteredDataConsensusCounter++, headerElement.getLocation(), GATKSAMRecord.REDUCED_READ_CONSENSUS_TAG, hasIndelQualities, isNegativeStrand); + } + genericAddBaseToConsensus(filteredDataConsensus, headerElement.getFilteredBaseCounts(), headerElement.getRMS()); } + + return result; } /** @@ -512,9 +521,6 @@ public class SlidingWindow { } } - int refStart = windowHeader.get(start).getLocation(); - int refStop = windowHeader.get(stop).getLocation(); - // Try to compress the variant region // the "foundEvent" protects us from trying to compress variant regions that are created by insertions if (canCompress && foundEvent) { @@ -524,6 +530,9 @@ public class SlidingWindow { // Return all reads that overlap the variant region and remove them from the window header entirely // also remove all reads preceding the variant region (since they will be output as consensus right after compression else { + final int refStart = windowHeader.get(start).getLocation(); + final int refStop = windowHeader.get(stop).getLocation(); + LinkedList toRemove = new LinkedList(); for (GATKSAMRecord read : readsInWindow) { if (read.getSoftStart() <= refStop) { diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SyntheticRead.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SyntheticRead.java index ab65020c3..ccf81dd67 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SyntheticRead.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SyntheticRead.java @@ -44,7 +44,7 @@ public class SyntheticRead { private String contig; private int contigIndex; private String readName; - private Integer refStart; + private int refStart; private boolean hasIndelQualities = false; private boolean isNegativeStrand = false; @@ -60,7 +60,7 @@ public class SyntheticRead { * @param refStart the alignment start (reference based) * @param readTag the reduce reads tag for the synthetic read */ - public SyntheticRead(SAMFileHeader header, GATKSAMReadGroupRecord readGroupRecord, String contig, int contigIndex, String readName, Integer refStart, String readTag, boolean hasIndelQualities, boolean isNegativeRead) { + public SyntheticRead(SAMFileHeader header, GATKSAMReadGroupRecord readGroupRecord, String contig, int contigIndex, String readName, int refStart, String readTag, boolean hasIndelQualities, boolean isNegativeRead) { final int initialCapacity = 10000; bases = new ArrayList(initialCapacity); counts = new ArrayList(initialCapacity); @@ -80,7 +80,7 @@ public class SyntheticRead { this.isNegativeStrand = isNegativeRead; } - public SyntheticRead(List bases, List counts, List quals, List insertionQuals, List deletionQuals, double mappingQuality, String readTag, SAMFileHeader header, GATKSAMReadGroupRecord readGroupRecord, String contig, int contigIndex, String readName, Integer refStart, boolean hasIndelQualities, boolean isNegativeRead) { + public SyntheticRead(List bases, List counts, List quals, List insertionQuals, List deletionQuals, double mappingQuality, String readTag, SAMFileHeader header, GATKSAMReadGroupRecord readGroupRecord, String contig, int contigIndex, String readName, int refStart, boolean hasIndelQualities, boolean isNegativeRead) { this.bases = bases; this.counts = counts; this.quals = quals; @@ -115,11 +115,15 @@ public class SyntheticRead { this.mappingQuality += mappingQuality; } - public BaseIndex getBase(int readCoordinate) { + public BaseIndex getBase(final int readCoordinate) { return bases.get(readCoordinate); } - /** + public int getRefStart() { + return refStart; + } + + /** * Creates a GATKSAMRecord of the synthetic read. Will return null if the read is invalid. * * Invalid reads are :