All walkers now use read.getReadGroup()

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1839 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
ebanks 2009-10-14 19:27:40 +00:00
parent 0a09fa4d5c
commit 52d2e0ca07
8 changed files with 15 additions and 37 deletions

View File

@ -25,11 +25,8 @@ public class PlatformUnitFilter implements SamRecordFilter {
Object pu_attr = samRecord.getAttribute("PU"); Object pu_attr = samRecord.getAttribute("PU");
if ( pu_attr == null ) { if ( pu_attr == null ) {
// no platform unit in the record, go get the header if we have at least read group // no platform unit in the record, go get from read group
final String rgId = (String)samRecord.getAttribute("RG"); SAMReadGroupRecord rgr = samRecord.getReadGroup();
if (rgId == null) return false; // we do not have read group either, can not filter
SAMReadGroupRecord rgr = samRecord.getHeader().getReadGroup(rgId);
pu_attr = rgr.getAttribute("PU") ; pu_attr = rgr.getAttribute("PU") ;
} }

View File

@ -97,14 +97,13 @@ public class SplitSamFileWalker extends ReadWalker<SAMRecord, Map<String, SAMFil
* Write out the read * Write out the read
*/ */
public Map<String, SAMFileWriter> reduce(SAMRecord read, Map<String, SAMFileWriter> outputs) { public Map<String, SAMFileWriter> reduce(SAMRecord read, Map<String, SAMFileWriter> outputs) {
final String readGroup = read.getAttribute("RG").toString(); final String sample = read.getReadGroup().getSample();
final String sample = read.getHeader().getReadGroup(readGroup).getSample();
SAMFileWriter output = outputs.get(sample); SAMFileWriter output = outputs.get(sample);
if ( output != null ) { if ( output != null ) {
output.addAlignment(read); output.addAlignment(read);
} else { } 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; return outputs;

View File

@ -203,8 +203,7 @@ public abstract class EMGenotypeCalculationModel extends GenotypeCalculationMode
if ( POOLED_INPUT ) { if ( POOLED_INPUT ) {
sample = "POOL"; sample = "POOL";
} else { } else {
String readGroup = read.getAttribute("RG").toString(); // can't be null because those are filtered out sample = read.getReadGroup().getSample();
sample = read.getHeader().getReadGroup(readGroup).getSample();
} }
// create a new context object if this is the first time we're seeing a read for this sample // create a new context object if this is the first time we're seeing a read for this sample

View File

@ -819,16 +819,7 @@ public class IndelGenotyperWalker extends ReadWalker<Integer,Integer> {
indels.set(pos, indelsAtSite); indels.set(pos, indelsAtSite);
} }
String sample = null; String sample = r.getReadGroup().getSample();
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();
}
}
boolean found = false; boolean found = false;
for ( IndelVariant v : indelsAtSite ) { for ( IndelVariant v : indelsAtSite ) {

View File

@ -119,17 +119,16 @@ public class CovariateCounterWalker extends LocusWalker<Integer, PrintStream> {
throw new RuntimeException("Expectedly long read, please increase maxium read len with maxReadLen parameter: " + read.format()); 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.getReadGroup();
SAMReadGroupRecord readGroup = read.getHeader().getReadGroup(readGroupString);
if ( readGroupString == null ) { if ( readGroup == null ) {
throw new RuntimeException("No read group annotation found for read " + read.format()); throw new RuntimeException("No read group annotation found for read " + read.format());
} }
if ((read.getMappingQuality() >= MIN_MAPPING_QUALITY && isSupportedReadGroup(readGroup) )) { if ((read.getMappingQuality() >= MIN_MAPPING_QUALITY && isSupportedReadGroup(readGroup) )) {
int offset = offsets.get(i); 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 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);
} }
} }
} }

View File

@ -95,8 +95,7 @@ public class CoverageBySample extends LocusWalker<String, String>
for (int i = 0; i < context.getReads().size(); i++) for (int i = 0; i < context.getReads().size(); i++)
{ {
SAMRecord read = context.getReads().get(i); SAMRecord read = context.getReads().get(i);
String RG = (String)(read.getAttribute("RG")); String sample = read.getReadGroup().getSample();
String sample = header.getReadGroup(RG).getSample();
counts.put(sample, counts.get(sample)+1); counts.put(sample, counts.get(sample)+1);
} }
return counts; return counts;
@ -124,12 +123,11 @@ public class CoverageBySample extends LocusWalker<String, String>
{ {
SAMRecord read = context.getReads().get(i); SAMRecord read = context.getReads().get(i);
Integer offset = context.getOffsets().get(i); Integer offset = context.getOffsets().get(i);
String RG = (String)(read.getAttribute("RG"));
assert(header != null); 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"); } //if (SAMPLE_NAME_REGEX != null) { sample = sample.replaceAll(SAMPLE_NAME_REGEX, "$1"); }
reads[index.get(sample)].add(read); reads[index.get(sample)].add(read);
offsets[index.get(sample)].add(offset); offsets[index.get(sample)].add(offset);

View File

@ -35,9 +35,7 @@ public class ListSampleIds extends LocusWalker<Boolean, Boolean>
for ( int i = 0; i < reads.size(); i++ ) for ( int i = 0; i < reads.size(); i++ )
{ {
SAMRecord read = reads.get(i); SAMRecord read = reads.get(i);
String rg = (String) read.getAttribute("RG"); SAMReadGroupRecord readGroup = read.getReadGroup();
SAMFileHeader header = read.getHeader();
SAMReadGroupRecord readGroup = header.getReadGroup(rg);
if (readGroup == null) { System.out.printf("."); return false; } if (readGroup == null) { System.out.printf("."); return false; }
String sample = readGroup.getSample(); String sample = readGroup.getSample();
System.out.printf("FROM_MAP %s\n", sample); System.out.printf("FROM_MAP %s\n", sample);

View File

@ -203,14 +203,11 @@ public class Utils {
} }
public static boolean is454Read(SAMRecord read) { public static boolean is454Read(SAMRecord read) {
Object readGroupAttr = read.getAttribute("RG"); SAMReadGroupRecord readGroup = read.getReadGroup();
if ( readGroupAttr != null ) { if ( readGroup != null ) {
SAMReadGroupRecord readGroup = read.getHeader().getReadGroup(readGroupAttr.toString());
if ( readGroup != null ) {
Object readPlatformAttr = readGroup.getAttribute("PL"); Object readPlatformAttr = readGroup.getAttribute("PL");
if ( readPlatformAttr != null ) if ( readPlatformAttr != null )
return readPlatformAttr.toString().toUpperCase().contains("454"); return readPlatformAttr.toString().toUpperCase().contains("454");
}
} }
return false; return false;
} }