-Pushed base quals back down into SAMRecord; if -OQ is used, the SAMRecord quals get updated automatically

-Better integration test


git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3020 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
ebanks 2010-03-17 16:00:10 +00:00
parent 76d14d17dc
commit 4340601c26
2 changed files with 21 additions and 51 deletions

View File

@ -3,7 +3,6 @@ package org.broadinstitute.sting.utils.sam;
import java.util.*;
import net.sf.samtools.*;
import org.broadinstitute.sting.utils.QualityUtils;
import org.broadinstitute.sting.utils.StingException;
import org.broadinstitute.sting.gatk.GenomeAnalysisEngine;
@ -26,8 +25,6 @@ public class GATKSAMRecord extends SAMRecord {
// the SAMRecord data we're caching
private String mReadString = null;
private String mQualString = null;
private byte[] mQualities = null;
private SAMReadGroupRecord mReadGroup = null;
private boolean mNegativeStrandFlag;
private boolean mUnmappedFlag;
@ -42,8 +39,6 @@ public class GATKSAMRecord extends SAMRecord {
// These attributes exist in memory only, and are never written to disk.
private Map<Object, Object> temporaryAttributes;
private final static String ORIGINAL_QUAL_ATTRIBUTE_TAG = "OQ"; // The tag that holds the original quality scores
public GATKSAMRecord(SAMRecord record) {
super(null); // it doesn't matter - this isn't used
if ( record == null )
@ -58,6 +53,17 @@ public class GATKSAMRecord extends SAMRecord {
List<SAMTagAndValue> attributes = record.getAttributes();
for ( SAMTagAndValue attribute : attributes )
setAttribute(attribute.tag, attribute.value);
// if we are using original quals, set them now if t hey are present in the record
if ( GenomeAnalysisEngine.instance.getArguments().useOriginalBaseQualities ) {
byte[] originalQuals = mRecord.getOriginalBaseQualities();
if ( originalQuals != null )
mRecord.setBaseQualities(originalQuals);
}
// sanity check that the lengths of the base and quality strings are equal
if ( getBaseQualities().length != getReadLength() )
throw new StingException(String.format("Error: the number of base qualities does not match the number of bases in %s (and the GATK does not currently support '*' for the quals)", mRecord.getReadName()));
}
///////////////////////////////////////////////////////////////////////////////
@ -120,50 +126,6 @@ public class GATKSAMRecord extends SAMRecord {
mSecondOfPairFlag = b;
}
public byte[] getBaseQualities() {
if ( mQualities == null ) {
if ( GenomeAnalysisEngine.instance.getArguments().useOriginalBaseQualities ) {
final Object attr = mRecord.getAttribute(ORIGINAL_QUAL_ATTRIBUTE_TAG);
if ( attr != null ) {
if ( attr instanceof String ) {
mQualities = QualityUtils.fastqToPhred((String)attr);
} else {
throw new StingException(String.format("Value encoded by %s in %s isn't a string!", ORIGINAL_QUAL_ATTRIBUTE_TAG, mRecord.getReadName()));
}
}
}
// if we don't want original quals or couldn't find them, use the main quals
if ( mQualities == null )
mQualities = mRecord.getBaseQualities();
// sanity check that the lengths of the base and quality strings are equal
if ( mQualities.length != getReadLength() )
throw new StingException(String.format("Error: the number of base qualities does not match the number of bases in %s (and the GATK does not currently support '*' for the quals)", mRecord.getReadName()));
}
return mQualities;
}
public String getBaseQualityString() {
if ( mQualString == null ) {
final byte[] quals = getBaseQualities();
if ( Arrays.equals(NULL_QUALS, quals) )
mQualString = NULL_QUALS_STRING;
else
mQualString = SAMUtils.phredToFastq(quals);
}
return mQualString;
}
public void setBaseQualities(byte[] bytes) {
mQualities = bytes;
mRecord.setBaseQualities(bytes);
}
public void setBaseQualityString(String s) {
mQualString = s;
mRecord.setBaseQualityString(s);
}
/**
* Checks whether an attribute has been set for the given key.
*
@ -250,6 +212,14 @@ public class GATKSAMRecord extends SAMRecord {
public int getReadLength() { return mRecord.getReadLength(); }
public byte[] getBaseQualities() { return mRecord.getBaseQualities(); }
public void setBaseQualities(byte[] bytes) { mRecord.setBaseQualities(bytes); }
public String getBaseQualityString() { return mRecord.getBaseQualityString(); }
public void setBaseQualityString(String s) { mRecord.setBaseQualityString(s); }
public byte[] getOriginalBaseQualities() { return mRecord.getOriginalBaseQualities(); }
public void setOriginalBaseQualities(byte[] bytes) { mRecord.setOriginalBaseQualities(bytes); }

View File

@ -47,10 +47,10 @@ public class ClipReadsWalkersIntegrationTest extends WalkerTest {
" -T ClipReads" +
" -I " + validationDataLocation + "originalQuals.chr1.1-1K.bam" +
" -L chr1:1-1,000" +
" -OQ -QT 4" +
" -OQ -QT 4 -CR WRITE_Q0S" +
" -o %s -ob %s",
2,
Arrays.asList("55c01ccc2e84481b22d3632cdb06c8ba", "ff7c6edba61307738b34786e14edbef9"));
Arrays.asList("55c01ccc2e84481b22d3632cdb06c8ba", "12eeaaa8df3d742f68cdd8838b203825"));
executeTest("clipOriginalQuals", spec);
}
}