This commit is for Kiran

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2898 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
chartl 2010-02-26 18:18:38 +00:00
parent 87f8fb7282
commit cfff486338
2 changed files with 44 additions and 4 deletions

View File

@ -39,6 +39,7 @@ import java.util.Map;
/**
* Useful class for storing different AlignmentContexts
* User: ebanks
* Modified: chartl (split by read group)
*/
public class StratifiedAlignmentContext {
@ -140,6 +141,40 @@ public class StratifiedAlignmentContext {
myContext.add(read, p.getOffset());
}
return contexts;
}
/**
* Splits the given AlignmentContext into a StratifiedAlignmentContext per read group.
*
* @param pileup the original pileup
* @return a Map of sample name to StratifiedAlignmentContext
* @todo - support for collapsing or assuming read groups if they are missing
*
**/
public static Map<String,StratifiedAlignmentContext> splitContextByReadGroup(ReadBackedPileup pileup) {
HashMap<String,StratifiedAlignmentContext> contexts = new HashMap<String,StratifiedAlignmentContext>();
for ( PileupElement p : pileup ) {
SAMRecord read = p.getRead();
SAMReadGroupRecord readGroup = read.getReadGroup();
if ( readGroup == null ) {
throw new StingException("Missing read group for read " + read.getReadName());
}
String group = readGroup.getReadGroupId();
StratifiedAlignmentContext myContext = contexts.get(group);
if ( myContext == null ) {
myContext = new StratifiedAlignmentContext(pileup.getLocation());
contexts.put(group,myContext);
}
myContext.add(read,p.getOffset());
}
return contexts;
}
}

View File

@ -141,12 +141,17 @@ public class CoverageStatistics extends LocusWalker<Map<String,Integer>, DepthOf
}
public Map<String,Integer> map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
Map<String, StratifiedAlignmentContext> contextsBySample =
StratifiedAlignmentContext.splitContextBySample(context.getBasePileup());
Map<String,StratifiedAlignmentContext> contexts;
if ( useReadGroup ) {
contexts = StratifiedAlignmentContext.splitContextByReadGroup(context.getBasePileup());
} else {
contexts = StratifiedAlignmentContext.splitContextBySample(context.getBasePileup());
}
HashMap<String,Integer> depthBySample = new HashMap<String,Integer>();
for ( String sample : contextsBySample.keySet() ) {
AlignmentContext sampleContext = contextsBySample.get(sample).getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE);
for ( String sample : contexts.keySet() ) {
AlignmentContext sampleContext = contexts.get(sample).getContext(StratifiedAlignmentContext.StratifiedContextType.COMPLETE);
int properDepth = 0;
for ( PileupElement e : sampleContext.getBasePileup() ) {
if ( e.getQual() >= minBaseQuality && e.getMappingQual() >= minMappingQuality ) {