diff --git a/java/src/org/broadinstitute/sting/gatk/filters/PlatformUnitFilter.java b/java/src/org/broadinstitute/sting/gatk/filters/PlatformUnitFilter.java index eaeefdcb6..9acb1116c 100644 --- a/java/src/org/broadinstitute/sting/gatk/filters/PlatformUnitFilter.java +++ b/java/src/org/broadinstitute/sting/gatk/filters/PlatformUnitFilter.java @@ -25,11 +25,8 @@ public class PlatformUnitFilter implements SamRecordFilter { Object pu_attr = samRecord.getAttribute("PU"); if ( pu_attr == null ) { - // no platform unit in the record, go get the header if we have at least read group - final String rgId = (String)samRecord.getAttribute("RG"); - if (rgId == null) return false; // we do not have read group either, can not filter - - SAMReadGroupRecord rgr = samRecord.getHeader().getReadGroup(rgId); + // no platform unit in the record, go get from read group + SAMReadGroupRecord rgr = samRecord.getReadGroup(); pu_attr = rgr.getAttribute("PU") ; } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/SplitSamFileWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/SplitSamFileWalker.java index 91607e630..4055ef90e 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/SplitSamFileWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/SplitSamFileWalker.java @@ -97,14 +97,13 @@ public class SplitSamFileWalker extends ReadWalker reduce(SAMRecord read, Map outputs) { - final String readGroup = read.getAttribute("RG").toString(); - final String sample = read.getHeader().getReadGroup(readGroup).getSample(); + final String sample = read.getReadGroup().getSample(); SAMFileWriter output = outputs.get(sample); if ( output != null ) { output.addAlignment(read); } else { - throw new RuntimeException(String.format("Read group %s not present in header but found in read %s", readGroup, read.getReadName())); + throw new RuntimeException(String.format("Read group %s not present in header but found in read %s", read.getReadGroup().getReadGroupId(), read.getReadName())); } return outputs; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/EMGenotypeCalculationModel.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/EMGenotypeCalculationModel.java index c528b27b9..03b844024 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/EMGenotypeCalculationModel.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/EMGenotypeCalculationModel.java @@ -203,8 +203,7 @@ public abstract class EMGenotypeCalculationModel extends GenotypeCalculationMode if ( POOLED_INPUT ) { sample = "POOL"; } else { - String readGroup = read.getAttribute("RG").toString(); // can't be null because those are filtered out - sample = read.getHeader().getReadGroup(readGroup).getSample(); + sample = read.getReadGroup().getSample(); } // create a new context object if this is the first time we're seeing a read for this sample diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelGenotyperWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelGenotyperWalker.java index 8de931e75..39ea0118d 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelGenotyperWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelGenotyperWalker.java @@ -819,16 +819,7 @@ public class IndelGenotyperWalker extends ReadWalker { indels.set(pos, indelsAtSite); } - String sample = null; - Object readGroupAttr = r.getAttribute("RG"); - if ( readGroupAttr != null ) { - SAMReadGroupRecord readGroup = r.getHeader().getReadGroup(readGroupAttr.toString()); - if ( readGroup != null ) { - Object readSampleAttr = readGroup.getAttribute("SM"); - if ( readSampleAttr != null ) - sample = readSampleAttr.toString(); - } - } + String sample = r.getReadGroup().getSample(); boolean found = false; for ( IndelVariant v : indelsAtSite ) { diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterWalker.java index 25bb01748..31cd4fd4e 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterWalker.java @@ -119,17 +119,16 @@ public class CovariateCounterWalker extends LocusWalker { throw new RuntimeException("Expectedly long read, please increase maxium read len with maxReadLen parameter: " + read.format()); } - final String readGroupString = ((String)read.getAttribute("RG")); - SAMReadGroupRecord readGroup = read.getHeader().getReadGroup(readGroupString); + SAMReadGroupRecord readGroup = read.getReadGroup(); - if ( readGroupString == null ) { + if ( readGroup == null ) { throw new RuntimeException("No read group annotation found for read " + read.format()); } if ((read.getMappingQuality() >= MIN_MAPPING_QUALITY && isSupportedReadGroup(readGroup) )) { int offset = offsets.get(i); if ( offset > 0 && offset < (read.getReadLength() - 1) ) { // skip first and last bases because they suck and they don't have a dinuc count - counted_bases += covariateCounter.updateDataFromRead(readGroupString, read, offset, ref.getBase(), useOriginalQuals); + counted_bases += covariateCounter.updateDataFromRead(readGroup.getReadGroupId(), read, offset, ref.getBase(), useOriginalQuals); } } } diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/CoverageBySample.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/CoverageBySample.java index 0b2ba68d5..33dd8d6ed 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/CoverageBySample.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/CoverageBySample.java @@ -95,8 +95,7 @@ public class CoverageBySample extends LocusWalker for (int i = 0; i < context.getReads().size(); i++) { SAMRecord read = context.getReads().get(i); - String RG = (String)(read.getAttribute("RG")); - String sample = header.getReadGroup(RG).getSample(); + String sample = read.getReadGroup().getSample(); counts.put(sample, counts.get(sample)+1); } return counts; @@ -124,12 +123,11 @@ public class CoverageBySample extends LocusWalker { SAMRecord read = context.getReads().get(i); Integer offset = context.getOffsets().get(i); - String RG = (String)(read.getAttribute("RG")); assert(header != null); - assert(header.getReadGroup(RG) != null); + assert(read.getReadGroup() != null); - String sample = header.getReadGroup(RG).getSample(); + String sample = read.getReadGroup().getSample(); //if (SAMPLE_NAME_REGEX != null) { sample = sample.replaceAll(SAMPLE_NAME_REGEX, "$1"); } reads[index.get(sample)].add(read); offsets[index.get(sample)].add(offset); diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/ListSampleIds.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/ListSampleIds.java index c04f8470c..290175193 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/ListSampleIds.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/ListSampleIds.java @@ -35,9 +35,7 @@ public class ListSampleIds extends LocusWalker for ( int i = 0; i < reads.size(); i++ ) { SAMRecord read = reads.get(i); - String rg = (String) read.getAttribute("RG"); - SAMFileHeader header = read.getHeader(); - SAMReadGroupRecord readGroup = header.getReadGroup(rg); + SAMReadGroupRecord readGroup = read.getReadGroup(); if (readGroup == null) { System.out.printf("."); return false; } String sample = readGroup.getSample(); System.out.printf("FROM_MAP %s\n", sample); diff --git a/java/src/org/broadinstitute/sting/utils/Utils.java b/java/src/org/broadinstitute/sting/utils/Utils.java index 4b76c171f..707a48d46 100755 --- a/java/src/org/broadinstitute/sting/utils/Utils.java +++ b/java/src/org/broadinstitute/sting/utils/Utils.java @@ -203,14 +203,11 @@ public class Utils { } public static boolean is454Read(SAMRecord read) { - Object readGroupAttr = read.getAttribute("RG"); - if ( readGroupAttr != null ) { - SAMReadGroupRecord readGroup = read.getHeader().getReadGroup(readGroupAttr.toString()); - if ( readGroup != null ) { + SAMReadGroupRecord readGroup = read.getReadGroup(); + if ( readGroup != null ) { Object readPlatformAttr = readGroup.getAttribute("PL"); if ( readPlatformAttr != null ) return readPlatformAttr.toString().toUpperCase().contains("454"); - } } return false; }