Hack to fix mysterious disappearing read attributes. Ultimately caused

by the fact that the GATKSAMRecord, by design, needs to both inherit from 
SAMRecord and wrap a 'member' SAMRecord, and method calls that aren't
implemented as explicit passthroughs can compromise the content of the
SAMRecord in subtle ways.

Will be automatically fixed when Picard moves to a lightweight SAMRecord
interface rather than the current heavyweight implementation.  But in 
the short-term, there's no obvious fix.


git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4489 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2010-10-13 19:06:54 +00:00
parent da29fcdb68
commit 83b8676b69
2 changed files with 80 additions and 3 deletions

View File

@ -1,8 +1,10 @@
package org.broadinstitute.sting.utils.sam;
import java.lang.reflect.Method;
import java.util.*;
import net.sf.samtools.*;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
import org.broadinstitute.sting.utils.exceptions.UserException;
/**
@ -16,6 +18,11 @@ import org.broadinstitute.sting.utils.exceptions.UserException;
* if they are ever modified externally then one must also invoke the
* setReadGroup() method here to ensure that the cache is kept up-to-date.
*
* 13 Oct 2010 - mhanna - this class is fundamentally flawed: it uses a decorator
* pattern to wrap a heavyweight object, which can lead
* to heinous side effects if the wrapping is not carefully
* done. Hopefully SAMRecord will become an interface and
* this will eventually be fixed.
*/
public class GATKSAMRecord extends SAMRecord {
@ -327,6 +334,76 @@ public class GATKSAMRecord extends SAMRecord {
public void setValidationStringency(net.sf.samtools.SAMFileReader.ValidationStringency validationStringency) { mRecord.setValidationStringency(validationStringency); }
public Object getAttribute(final String tag) { return mRecord.getAttribute(tag); }
public Integer getIntegerAttribute(final String tag) { return mRecord.getIntegerAttribute(tag); }
public Short getShortAttribute(final String tag) { return mRecord.getShortAttribute(tag); }
public Byte getByteAttribute(final String tag) { return mRecord.getByteAttribute(tag); }
public String getStringAttribute(final String tag) { return mRecord.getStringAttribute(tag); }
public Character getCharacterAttribute(final String tag) { return mRecord.getCharacterAttribute(tag); }
public Float getFloatAttribute(final String tag) { return mRecord.getFloatAttribute(tag); }
public byte[] getByteArrayAttribute(final String tag) { return mRecord.getByteArrayAttribute(tag); }
protected Object getAttribute(final short tag) {
Object attribute;
try {
Method method = mRecord.getClass().getDeclaredMethod("getAttribute",Short.TYPE);
method.setAccessible(true);
attribute = method.invoke(mRecord,tag);
}
catch(Exception ex) {
throw new ReviewedStingException("Unable to invoke getAttribute method",ex);
}
return attribute;
}
public void setAttribute(final String tag, final Object value) { mRecord.setAttribute(tag,value); }
protected void setAttribute(final short tag, final Object value) {
try {
Method method = mRecord.getClass().getDeclaredMethod("setAttribute",Short.TYPE,Object.class);
method.setAccessible(true);
method.invoke(mRecord,tag,value);
}
catch(Exception ex) {
throw new ReviewedStingException("Unable to invoke setAttribute method",ex);
}
}
public void clearAttributes() { mRecord.clearAttributes(); }
protected void setAttributes(final SAMBinaryTagAndValue attributes) {
try {
Method method = mRecord.getClass().getDeclaredMethod("setAttributes",SAMBinaryTagAndValue.class);
method.setAccessible(true);
method.invoke(mRecord,attributes);
}
catch(Exception ex) {
throw new ReviewedStingException("Unable to invoke setAttributes method",ex);
}
}
protected SAMBinaryTagAndValue getBinaryAttributes() {
SAMBinaryTagAndValue binaryAttributes;
try {
Method method = mRecord.getClass().getDeclaredMethod("getBinaryAttributes");
method.setAccessible(true);
binaryAttributes = (SAMBinaryTagAndValue)method.invoke(mRecord);
}
catch(Exception ex) {
throw new ReviewedStingException("Unable to invoke getBinaryAttributes method",ex);
}
return binaryAttributes;
}
public List<SAMTagAndValue> getAttributes() { return mRecord.getAttributes(); }
public SAMFileHeader getHeader() { return mRecord.getHeader(); }
public void setHeader(SAMFileHeader samFileHeader) { mRecord.setHeader(samFileHeader); }

View File

@ -9,7 +9,7 @@ public class IndelRealignerIntegrationTest extends WalkerTest {
@Test
public void testRealignerLod5() {
String[] md5s = {"2265e03ed1a2290e60208559925c30ef", "c4ef635f2597b12b93a73199f07e509b"};
String[] md5s = {"a377de4e2eb4df8ef79590e4131afe35", "c4ef635f2597b12b93a73199f07e509b"};
WalkerTestSpec spec = new WalkerTestSpec(
"-T IndelRealigner -noPG -LOD 5 -maxConsensuses 100 -greedy 100 -R " + b36KGReference + " -I " + validationDataLocation + "NA12878.chrom1.SLX.SRP000032.2009_06.bam -L 1:10023000-10030000 -compress 1 -targetIntervals " + validationDataLocation + "cleaner.test.intervals -o %s -stats %s --sortInCoordinateOrderEvenThoughItIsHighlyUnsafe",
2,
@ -19,7 +19,7 @@ public class IndelRealignerIntegrationTest extends WalkerTest {
@Test
public void testRealignerLod50() {
String[] md5s = {"2265e03ed1a2290e60208559925c30ef", "3735a510513b6fa4161d92155e026283"};
String[] md5s = {"a377de4e2eb4df8ef79590e4131afe35", "3735a510513b6fa4161d92155e026283"};
WalkerTestSpec spec = new WalkerTestSpec(
"-T IndelRealigner -noPG -LOD 50 -maxConsensuses 100 -greedy 100 -R " + b36KGReference + " -I " + validationDataLocation + "NA12878.chrom1.SLX.SRP000032.2009_06.bam -L 1:10023000-10030000 -compress 1 -targetIntervals " + validationDataLocation + "cleaner.test.intervals -o %s -stats %s --sortInCoordinateOrderEvenThoughItIsHighlyUnsafe",
2,
@ -29,7 +29,7 @@ public class IndelRealignerIntegrationTest extends WalkerTest {
@Test
public void testRealignerKnownsOnly() {
String[] md5s = {"dc2fe2856840b12a34bb57de2ca71cd0", "74652bd8240291293ec921f8ecfa1622"};
String[] md5s = {"654cb0c845c3f25af6a3f8911ac06a73", "74652bd8240291293ec921f8ecfa1622"};
WalkerTestSpec spec = new WalkerTestSpec(
"-T IndelRealigner -noPG -LOD 1.0 -R " + b36KGReference + " -I " + validationDataLocation + "NA12878.chrom1.SLX.SRP000032.2009_06.bam -L 1:10023000-10076000 -compress 1 -targetIntervals " + validationDataLocation + "NA12878.indels.intervals -B:knownIndels,VCF " + validationDataLocation + "NA12878.indels.vcf4 -o %s -stats %s --sortInCoordinateOrderEvenThoughItIsHighlyUnsafe -knownsOnly",
2,