From 7928b287fcb76d80bcc1e6889f0474f782d2fe08 Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Wed, 19 Oct 2011 13:15:27 -0400 Subject: [PATCH] GATKSamRecord now produced by SAMFileReaders by default -- Removed all of the unnecessary caching operations in GATKSAMRecord -- GATKSAMRecord renamed to GATKSamRecord for consistency --- .../gatk/datasources/reads/SAMDataSource.java | 4 +- .../iterators/ReadFormattingIterator.java | 26 +- ...elGenotypeLikelihoodsCalculationModel.java | 6 +- .../recalibration/CountCovariatesWalker.java | 6 +- .../recalibration/RecalDataManager.java | 8 +- .../TableRecalibrationWalker.java | 4 +- .../sting/utils/sam/GATKSAMRecord.java | 368 +----------------- .../sting/utils/sam/GATKSamRecordFactory.java | 26 +- .../sting/utils/sam/ReadUtils.java | 18 +- 9 files changed, 81 insertions(+), 385 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/SAMDataSource.java b/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/SAMDataSource.java index 96d8d7e1a..8452aadfd 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/SAMDataSource.java +++ b/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/SAMDataSource.java @@ -647,7 +647,9 @@ public class SAMDataSource { BAQ.QualityMode qmode, IndexedFastaSequenceFile refReader, byte defaultBaseQualities) { - wrappedIterator = new ReadFormattingIterator(wrappedIterator, useOriginalBaseQualities, defaultBaseQualities); + if ( useOriginalBaseQualities || defaultBaseQualities >= 0 ) + // only wrap if we are replacing the original qualitiies or using a default base quality + wrappedIterator = new ReadFormattingIterator(wrappedIterator, useOriginalBaseQualities, defaultBaseQualities); // NOTE: this (and other filtering) should be done before on-the-fly sorting // as there is no reason to sort something that we will end of throwing away diff --git a/public/java/src/org/broadinstitute/sting/gatk/iterators/ReadFormattingIterator.java b/public/java/src/org/broadinstitute/sting/gatk/iterators/ReadFormattingIterator.java index 2f30d12a8..9a89d2086 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/iterators/ReadFormattingIterator.java +++ b/public/java/src/org/broadinstitute/sting/gatk/iterators/ReadFormattingIterator.java @@ -2,7 +2,6 @@ package org.broadinstitute.sting.gatk.iterators; import net.sf.samtools.SAMRecord; import org.apache.log4j.Logger; -import org.broadinstitute.sting.utils.sam.GATKSAMRecord; /** * An iterator which does post-processing of a read, including potentially wrapping @@ -78,7 +77,30 @@ public class ReadFormattingIterator implements StingSAMIterator { * no next exists. */ public SAMRecord next() { - return new GATKSAMRecord(wrappedIterator.next(), useOriginalBaseQualities, defaultBaseQualities); + SAMRecord rec = wrappedIterator.next(); + + // if we are using default quals, check if we need them, and add if necessary. + // 1. we need if reads are lacking or have incomplete quality scores + // 2. we add if defaultBaseQualities has a positive value + if (defaultBaseQualities >= 0) { + byte reads [] = rec.getReadBases(); + byte quals [] = rec.getBaseQualities(); + if (quals == null || quals.length < reads.length) { + byte new_quals [] = new byte [reads.length]; + for (int i=0; i attributes = record.getAttributes(); - for ( SAMTagAndValue attribute : attributes ) - setAttribute(attribute.tag, attribute.value); - - // if we are using default quals, check if we need them, and add if necessary. - // 1. we need if reads are lacking or have incomplete quality scores - // 2. we add if defaultBaseQualities has a positive value - if (defaultBaseQualities >= 0) { - byte reads [] = record.getReadBases(); - byte quals [] = record.getBaseQualities(); - if (quals == null || quals.length < reads.length) { - byte new_quals [] = new byte [reads.length]; - for (int i=0; i getAttributes() { return mRecord.getAttributes(); } - - public SAMFileHeader getHeader() { return mRecord.getHeader(); } - - public void setHeader(SAMFileHeader samFileHeader) { mRecord.setHeader(samFileHeader); } - - public byte[] getVariableBinaryRepresentation() { return mRecord.getVariableBinaryRepresentation(); } - - public int getAttributesBinarySize() { return mRecord.getAttributesBinarySize(); } - - public String format() { return mRecord.format(); } - - public List getAlignmentBlocks() { return mRecord.getAlignmentBlocks(); } - - public List validateCigar(long l) { return mRecord.validateCigar(l); } - @Override public boolean equals(Object o) { if (this == o) return true; // note -- this forbids a GATKSAMRecord being equal to its underlying SAMRecord - if (!(o instanceof GATKSAMRecord)) return false; + if (!(o instanceof GATKSamRecord)) return false; // note that we do not consider the GATKSAMRecord internal state at all - return mRecord.equals(((GATKSAMRecord)o).mRecord); - } - - public int hashCode() { return mRecord.hashCode(); } - - public List isValid() { return mRecord.isValid(); } - - public Object clone() throws CloneNotSupportedException { return mRecord.clone(); } - - public String toString() { return mRecord.toString(); } - - public SAMFileSource getFileSource() { return mRecord.getFileSource(); } - - /** - * Sets a marker providing the source reader for this file and the position in the file from which the read originated. - * @param fileSource source of the given file. - */ - @Override - protected void setFileSource(final SAMFileSource fileSource) { - try { - Method method = SAMRecord.class.getDeclaredMethod("setFileSource",SAMFileSource.class); - method.setAccessible(true); - method.invoke(mRecord,fileSource); - } - catch(Exception ex) { - throw new ReviewedStingException("Unable to invoke setFileSource method",ex); - } + return super.equals(o); } } diff --git a/public/java/src/org/broadinstitute/sting/utils/sam/GATKSamRecordFactory.java b/public/java/src/org/broadinstitute/sting/utils/sam/GATKSamRecordFactory.java index 7c98a68e6..9076f06ae 100644 --- a/public/java/src/org/broadinstitute/sting/utils/sam/GATKSamRecordFactory.java +++ b/public/java/src/org/broadinstitute/sting/utils/sam/GATKSamRecordFactory.java @@ -57,18 +57,18 @@ public class GATKSamRecordFactory implements SAMRecordFactory { final int mateAlignmentStart, final int insertSize, final byte[] variableLengthBlock) { - return new BAMRecord(header, - referenceSequenceIndex, - alignmentStart, - readNameLength, - mappingQuality, - indexingBin, - cigarLen, - flags, - readLen, - mateReferenceSequenceIndex, - mateAlignmentStart, - insertSize, - variableLengthBlock); + return new GATKSamRecord(header, + referenceSequenceIndex, + alignmentStart, + readNameLength, + mappingQuality, + indexingBin, + cigarLen, + flags, + readLen, + mateReferenceSequenceIndex, + mateAlignmentStart, + insertSize, + variableLengthBlock); } } diff --git a/public/java/src/org/broadinstitute/sting/utils/sam/ReadUtils.java b/public/java/src/org/broadinstitute/sting/utils/sam/ReadUtils.java index d1e9a236f..f91d77244 100755 --- a/public/java/src/org/broadinstitute/sting/utils/sam/ReadUtils.java +++ b/public/java/src/org/broadinstitute/sting/utils/sam/ReadUtils.java @@ -274,10 +274,10 @@ public class ReadUtils { * @param adaptorLength length of adaptor sequence * @return a new read with adaptor sequence hard-clipped out or null if read is fully clipped */ - public static GATKSAMRecord hardClipAdaptorSequence(final SAMRecord rec, int adaptorLength) { + public static GATKSamRecord hardClipAdaptorSequence(final SAMRecord rec, int adaptorLength) { Pair adaptorBoundaries = getAdaptorBoundaries(rec, adaptorLength); - GATKSAMRecord result = (GATKSAMRecord)rec; + GATKSamRecord result = (GATKSamRecord)rec; if ( adaptorBoundaries != null ) { if ( rec.getReadNegativeStrandFlag() && adaptorBoundaries.second >= rec.getAlignmentStart() && adaptorBoundaries.first < rec.getAlignmentEnd() ) @@ -290,7 +290,7 @@ public class ReadUtils { } // return true if the read needs to be completely clipped - private static GATKSAMRecord hardClipStartOfRead(SAMRecord oldRec, int stopPosition) { + private static GATKSamRecord hardClipStartOfRead(SAMRecord oldRec, int stopPosition) { if ( stopPosition >= oldRec.getAlignmentEnd() ) { // BAM representation issue -- we can't clip away all bases in a read, just leave it alone and let the filter deal with it @@ -298,9 +298,9 @@ public class ReadUtils { return null; } - GATKSAMRecord rec; + GATKSamRecord rec; try { - rec = (GATKSAMRecord)oldRec.clone(); + rec = (GATKSamRecord)oldRec.clone(); } catch (Exception e) { return null; } @@ -370,7 +370,7 @@ public class ReadUtils { return rec; } - private static GATKSAMRecord hardClipEndOfRead(SAMRecord oldRec, int startPosition) { + private static GATKSamRecord hardClipEndOfRead(SAMRecord oldRec, int startPosition) { if ( startPosition <= oldRec.getAlignmentStart() ) { // BAM representation issue -- we can't clip away all bases in a read, just leave it alone and let the filter deal with it @@ -378,9 +378,9 @@ public class ReadUtils { return null; } - GATKSAMRecord rec; + GATKSamRecord rec; try { - rec = (GATKSAMRecord)oldRec.clone(); + rec = (GATKSamRecord)oldRec.clone(); } catch (Exception e) { return null; } @@ -598,7 +598,7 @@ public class ReadUtils { * @param rec original SAM record * @return a new read with adaptor sequence hard-clipped out or null if read is fully clipped */ - public static GATKSAMRecord hardClipAdaptorSequence(final SAMRecord rec) { + public static GATKSamRecord hardClipAdaptorSequence(final SAMRecord rec) { return hardClipAdaptorSequence(rec, DEFAULT_ADAPTOR_SIZE); }