Removing dependencies in the annotations on extended events. Some refactoring involved in this.
This commit is contained in:
parent
c2e27729c7
commit
44ac49aa34
|
|
@ -41,7 +41,7 @@ public class DepthOfCoverage extends InfoFieldAnnotation implements StandardAnno
|
||||||
|
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
for ( Map.Entry<String, AlignmentContext> sample : stratifiedContexts.entrySet() )
|
for ( Map.Entry<String, AlignmentContext> sample : stratifiedContexts.entrySet() )
|
||||||
depth += sample.getValue().hasBasePileup() ? sample.getValue().getBasePileup().depthOfCoverage() : sample.getValue().getExtendedEventPileup().depthOfCoverage();
|
depth += sample.getValue().hasBasePileup() ? sample.getValue().getBasePileup().depthOfCoverage() : 0;
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put(getKeyNames().get(0), String.format("%d", depth));
|
map.put(getKeyNames().get(0), String.format("%d", depth));
|
||||||
return map;
|
return map;
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,7 @@ import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.StandardAnnota
|
||||||
import org.broadinstitute.sting.utils.codecs.vcf.VCFFormatHeaderLine;
|
import org.broadinstitute.sting.utils.codecs.vcf.VCFFormatHeaderLine;
|
||||||
import org.broadinstitute.sting.utils.codecs.vcf.VCFHeaderLineCount;
|
import org.broadinstitute.sting.utils.codecs.vcf.VCFHeaderLineCount;
|
||||||
import org.broadinstitute.sting.utils.codecs.vcf.VCFHeaderLineType;
|
import org.broadinstitute.sting.utils.codecs.vcf.VCFHeaderLineType;
|
||||||
import org.broadinstitute.sting.utils.pileup.ExtendedEventPileupElement;
|
|
||||||
import org.broadinstitute.sting.utils.pileup.PileupElement;
|
import org.broadinstitute.sting.utils.pileup.PileupElement;
|
||||||
import org.broadinstitute.sting.utils.pileup.ReadBackedExtendedEventPileup;
|
|
||||||
import org.broadinstitute.sting.utils.pileup.ReadBackedPileup;
|
import org.broadinstitute.sting.utils.pileup.ReadBackedPileup;
|
||||||
import org.broadinstitute.sting.utils.variantcontext.Allele;
|
import org.broadinstitute.sting.utils.variantcontext.Allele;
|
||||||
import org.broadinstitute.sting.utils.variantcontext.Genotype;
|
import org.broadinstitute.sting.utils.variantcontext.Genotype;
|
||||||
|
|
@ -44,9 +42,9 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class DepthPerAlleleBySample extends GenotypeAnnotation implements StandardAnnotation {
|
public class DepthPerAlleleBySample extends GenotypeAnnotation implements StandardAnnotation {
|
||||||
|
|
||||||
private static String REF_ALLELE = "REF";
|
private static final String REF_ALLELE = "REF";
|
||||||
|
|
||||||
private static String DEL = "DEL"; // constant, for speed: no need to create a key string for deletion allele every time
|
private static final String DEL = "DEL"; // constant, for speed: no need to create a key string for deletion allele every time
|
||||||
|
|
||||||
public Map<String, Object> annotate(RefMetaDataTracker tracker, AnnotatorCompatibleWalker walker, ReferenceContext ref, AlignmentContext stratifiedContext, VariantContext vc, Genotype g) {
|
public Map<String, Object> annotate(RefMetaDataTracker tracker, AnnotatorCompatibleWalker walker, ReferenceContext ref, AlignmentContext stratifiedContext, VariantContext vc, Genotype g) {
|
||||||
if ( g == null || !g.isCalled() )
|
if ( g == null || !g.isCalled() )
|
||||||
|
|
@ -62,7 +60,8 @@ public class DepthPerAlleleBySample extends GenotypeAnnotation implements Standa
|
||||||
|
|
||||||
private Map<String,Object> annotateSNP(AlignmentContext stratifiedContext, VariantContext vc) {
|
private Map<String,Object> annotateSNP(AlignmentContext stratifiedContext, VariantContext vc) {
|
||||||
|
|
||||||
if ( ! stratifiedContext.hasBasePileup() ) return null;
|
if ( ! stratifiedContext.hasBasePileup() )
|
||||||
|
return null;
|
||||||
|
|
||||||
HashMap<Byte, Integer> alleleCounts = new HashMap<Byte, Integer>();
|
HashMap<Byte, Integer> alleleCounts = new HashMap<Byte, Integer>();
|
||||||
for ( Allele allele : vc.getAlleles() )
|
for ( Allele allele : vc.getAlleles() )
|
||||||
|
|
@ -87,17 +86,16 @@ public class DepthPerAlleleBySample extends GenotypeAnnotation implements Standa
|
||||||
|
|
||||||
private Map<String,Object> annotateIndel(AlignmentContext stratifiedContext, VariantContext vc) {
|
private Map<String,Object> annotateIndel(AlignmentContext stratifiedContext, VariantContext vc) {
|
||||||
|
|
||||||
if ( ! stratifiedContext.hasExtendedEventPileup() ) {
|
if ( ! stratifiedContext.hasBasePileup() )
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
ReadBackedExtendedEventPileup pileup = stratifiedContext.getExtendedEventPileup();
|
ReadBackedPileup pileup = stratifiedContext.getBasePileup();
|
||||||
if ( pileup == null )
|
if ( pileup == null )
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
HashMap<String, Integer> alleleCounts = new HashMap<String, Integer>();
|
final HashMap<String, Integer> alleleCounts = new HashMap<String, Integer>();
|
||||||
alleleCounts.put(REF_ALLELE,0);
|
alleleCounts.put(REF_ALLELE, 0);
|
||||||
Allele refAllele = vc.getReference();
|
final Allele refAllele = vc.getReference();
|
||||||
|
|
||||||
for ( Allele allele : vc.getAlternateAlleles() ) {
|
for ( Allele allele : vc.getAlternateAlleles() ) {
|
||||||
|
|
||||||
|
|
@ -108,33 +106,24 @@ public class DepthPerAlleleBySample extends GenotypeAnnotation implements Standa
|
||||||
alleleCounts.put(getAlleleRepresentation(allele), 0);
|
alleleCounts.put(getAlleleRepresentation(allele), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ExtendedEventPileupElement e : pileup.toExtendedIterable() ) {
|
for ( PileupElement p : pileup ) {
|
||||||
if ( e.isInsertion() ) {
|
if ( p.isBeforeInsertion() ) {
|
||||||
|
|
||||||
final String b = e.getEventBases();
|
final String b = p.getEventBases();
|
||||||
if ( alleleCounts.containsKey(b) ) {
|
if ( alleleCounts.containsKey(b) ) {
|
||||||
alleleCounts.put(b, alleleCounts.get(b)+1);
|
alleleCounts.put(b, alleleCounts.get(b)+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else if ( p.isBeforeDeletionStart() ) {
|
||||||
if ( e.isDeletion() ) {
|
if ( p.getEventLength() == refAllele.length() ) {
|
||||||
if ( e.getEventLength() == refAllele.length() ) {
|
|
||||||
// this is indeed the deletion allele recorded in VC
|
// this is indeed the deletion allele recorded in VC
|
||||||
final String b = DEL;
|
final String b = DEL;
|
||||||
if ( alleleCounts.containsKey(b) ) {
|
if ( alleleCounts.containsKey(b) ) {
|
||||||
alleleCounts.put(b, alleleCounts.get(b)+1);
|
alleleCounts.put(b, alleleCounts.get(b)+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else {
|
} else if ( p.getRead().getAlignmentEnd() > vc.getStart() ) {
|
||||||
// System.out.print(" deletion of WRONG length found");
|
alleleCounts.put(REF_ALLELE, alleleCounts.get(REF_ALLELE)+1);
|
||||||
// }
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ( e.getRead().getAlignmentEnd() <= vc.getStart() ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
alleleCounts.put(REF_ALLELE,alleleCounts.get(REF_ALLELE)+1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,9 @@ public class HaplotypeScore extends InfoFieldAnnotation implements StandardAnnot
|
||||||
if (stratifiedContexts.size() == 0) // size 0 means that call was made by someone else and we have no data here
|
if (stratifiedContexts.size() == 0) // size 0 means that call was made by someone else and we have no data here
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
if (!vc.isSNP() && !vc.isIndel() && !vc.isMixed())
|
||||||
|
return null;
|
||||||
|
|
||||||
final AlignmentContext context = AlignmentContextUtils.joinContexts(stratifiedContexts.values());
|
final AlignmentContext context = AlignmentContextUtils.joinContexts(stratifiedContexts.values());
|
||||||
|
|
||||||
final int contextWingSize = Math.min((ref.getWindow().size() - 1) / 2, MIN_CONTEXT_WING_SIZE);
|
final int contextWingSize = Math.min((ref.getWindow().size() - 1) / 2, MIN_CONTEXT_WING_SIZE);
|
||||||
|
|
@ -71,41 +74,27 @@ public class HaplotypeScore extends InfoFieldAnnotation implements StandardAnnot
|
||||||
|
|
||||||
final int locus = ref.getLocus().getStart() + (ref.getLocus().getStop() - ref.getLocus().getStart()) / 2;
|
final int locus = ref.getLocus().getStart() + (ref.getLocus().getStop() - ref.getLocus().getStart()) / 2;
|
||||||
|
|
||||||
// Compute all haplotypes consistent with the current read pileup
|
if ( !context.hasBasePileup() )
|
||||||
ReadBackedPileup pileup = null;
|
|
||||||
if (context.hasExtendedEventPileup())
|
|
||||||
pileup = context.getExtendedEventPileup();
|
|
||||||
else if (context.hasBasePileup())
|
|
||||||
pileup = context.getBasePileup();
|
|
||||||
|
|
||||||
if (pileup == null)
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
final ReadBackedPileup pileup = context.getBasePileup();
|
||||||
|
|
||||||
|
// Compute all haplotypes consistent with the current read pileup
|
||||||
final List<Haplotype> haplotypes = computeHaplotypes(pileup, contextSize, locus, vc);
|
final List<Haplotype> haplotypes = computeHaplotypes(pileup, contextSize, locus, vc);
|
||||||
|
|
||||||
final MathUtils.RunningAverage scoreRA = new MathUtils.RunningAverage();
|
final MathUtils.RunningAverage scoreRA = new MathUtils.RunningAverage();
|
||||||
if (haplotypes != null) {
|
if (haplotypes != null) {
|
||||||
for (final Genotype genotype : vc.getGenotypes()) {
|
for (final Genotype genotype : vc.getGenotypes()) {
|
||||||
final AlignmentContext thisContext = stratifiedContexts.get(genotype.getSampleName());
|
final AlignmentContext thisContext = stratifiedContexts.get(genotype.getSampleName());
|
||||||
if (thisContext != null) {
|
if (thisContext != null && thisContext.hasBasePileup()) {
|
||||||
final ReadBackedPileup thisPileup;
|
final ReadBackedPileup thisPileup = thisContext.getBasePileup();
|
||||||
if (thisContext.hasExtendedEventPileup())
|
if (vc.isSNP())
|
||||||
thisPileup = thisContext.getExtendedEventPileup();
|
scoreRA.add(scoreReadsAgainstHaplotypes(haplotypes, thisPileup, contextSize, locus)); // Taking the simple average of all sample's score since the score can be negative and the RMS doesn't make sense
|
||||||
else if (thisContext.hasBasePileup())
|
else if (vc.isIndel() || vc.isMixed()) {
|
||||||
thisPileup = thisContext.getBasePileup();
|
Double d = scoreIndelsAgainstHaplotypes(thisPileup);
|
||||||
else
|
if (d == null)
|
||||||
thisPileup = null;
|
|
||||||
|
|
||||||
if (thisPileup != null) {
|
|
||||||
if (vc.isSNP())
|
|
||||||
scoreRA.add(scoreReadsAgainstHaplotypes(haplotypes, thisPileup, contextSize, locus)); // Taking the simple average of all sample's score since the score can be negative and the RMS doesn't make sense
|
|
||||||
else if (vc.isIndel() || vc.isMixed()) {
|
|
||||||
Double d = scoreIndelsAgainstHaplotypes(thisPileup);
|
|
||||||
if (d == null)
|
|
||||||
return null;
|
|
||||||
scoreRA.add(d); // Taking the simple average of all sample's score since the score can be negative and the RMS doesn't make sense
|
|
||||||
} else
|
|
||||||
return null;
|
return null;
|
||||||
|
scoreRA.add(d); // Taking the simple average of all sample's score since the score can be negative and the RMS doesn't make sense
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,12 +62,10 @@ public abstract class RankSumTest extends InfoFieldAnnotation implements Standar
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadBackedPileup pileup = null;
|
if (!context.hasBasePileup())
|
||||||
if (context.hasExtendedEventPileup())
|
continue;
|
||||||
pileup = context.getExtendedEventPileup();
|
|
||||||
else if (context.hasBasePileup())
|
|
||||||
pileup = context.getBasePileup();
|
|
||||||
|
|
||||||
|
final ReadBackedPileup pileup = context.getBasePileup();
|
||||||
if (pileup == null)
|
if (pileup == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ import org.broadinstitute.sting.utils.SampleUtils;
|
||||||
import org.broadinstitute.sting.utils.classloader.PluginManager;
|
import org.broadinstitute.sting.utils.classloader.PluginManager;
|
||||||
import org.broadinstitute.sting.utils.codecs.vcf.*;
|
import org.broadinstitute.sting.utils.codecs.vcf.*;
|
||||||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||||
import org.broadinstitute.sting.utils.variantcontext.VariantContextUtils;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
@ -168,20 +167,14 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> implements Ann
|
||||||
protected Boolean ALWAYS_APPEND_DBSNP_ID = false;
|
protected Boolean ALWAYS_APPEND_DBSNP_ID = false;
|
||||||
public boolean alwaysAppendDbsnpId() { return ALWAYS_APPEND_DBSNP_ID; }
|
public boolean alwaysAppendDbsnpId() { return ALWAYS_APPEND_DBSNP_ID; }
|
||||||
|
|
||||||
@Hidden
|
|
||||||
@Argument(fullName="vcfContainsOnlyIndels", shortName="dels",doc="Use if you are annotating an indel vcf, currently VERY experimental", required = false)
|
|
||||||
protected boolean indelsOnly = false;
|
|
||||||
|
|
||||||
@Argument(fullName="MendelViolationGenotypeQualityThreshold",shortName="mvq",required=false,doc="The genotype quality treshold in order to annotate mendelian violation ratio")
|
@Argument(fullName="MendelViolationGenotypeQualityThreshold",shortName="mvq",required=false,doc="The genotype quality treshold in order to annotate mendelian violation ratio")
|
||||||
public double minGenotypeQualityP = 0.0;
|
public double minGenotypeQualityP = 0.0;
|
||||||
|
|
||||||
@Argument(fullName="requireStrictAlleleMatch", shortName="strict", doc="If provided only comp tracks that exactly match both reference and alternate alleles will be counted as concordant", required=false)
|
@Argument(fullName="requireStrictAlleleMatch", shortName="strict", doc="If provided only comp tracks that exactly match both reference and alternate alleles will be counted as concordant", required=false)
|
||||||
private boolean requireStrictAlleleMatch = false;
|
protected boolean requireStrictAlleleMatch = false;
|
||||||
|
|
||||||
private VariantAnnotatorEngine engine;
|
private VariantAnnotatorEngine engine;
|
||||||
|
|
||||||
private Collection<VariantContext> indelBufferContext;
|
|
||||||
|
|
||||||
|
|
||||||
private void listAnnotationsAndExit() {
|
private void listAnnotationsAndExit() {
|
||||||
System.out.println("\nStandard annotations in the list below are marked with a '*'.");
|
System.out.println("\nStandard annotations in the list below are marked with a '*'.");
|
||||||
|
|
@ -261,10 +254,6 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> implements Ann
|
||||||
|
|
||||||
VCFHeader vcfHeader = new VCFHeader(hInfo, samples);
|
VCFHeader vcfHeader = new VCFHeader(hInfo, samples);
|
||||||
vcfWriter.writeHeader(vcfHeader);
|
vcfWriter.writeHeader(vcfHeader);
|
||||||
|
|
||||||
if ( indelsOnly ) {
|
|
||||||
indelBufferContext = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUniqueHeaderLine(VCFHeaderLine line, Set<VCFHeaderLine> currentSet) {
|
public static boolean isUniqueHeaderLine(VCFHeaderLine line, Set<VCFHeaderLine> currentSet) {
|
||||||
|
|
@ -294,13 +283,6 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> implements Ann
|
||||||
*/
|
*/
|
||||||
public boolean includeReadsWithDeletionAtLoci() { return true; }
|
public boolean includeReadsWithDeletionAtLoci() { return true; }
|
||||||
|
|
||||||
/**
|
|
||||||
* We want to see extended events if annotating indels
|
|
||||||
*
|
|
||||||
* @return true
|
|
||||||
*/
|
|
||||||
public boolean generateExtendedEvents() { return indelsOnly; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For each site of interest, annotate based on the requested annotation types
|
* For each site of interest, annotate based on the requested annotation types
|
||||||
*
|
*
|
||||||
|
|
@ -334,19 +316,8 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> implements Ann
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! indelsOnly ) {
|
for ( VariantContext annotatedVC : annotatedVCs )
|
||||||
for ( VariantContext annotatedVC : annotatedVCs )
|
vcfWriter.add(annotatedVC);
|
||||||
vcfWriter.add(annotatedVC);
|
|
||||||
} else {
|
|
||||||
// check to see if the buffered context is different (in location) this context
|
|
||||||
if ( indelBufferContext != null && ! VariantContextUtils.getLocation(getToolkit().getGenomeLocParser(),indelBufferContext.iterator().next()).equals(VariantContextUtils.getLocation(getToolkit().getGenomeLocParser(),annotatedVCs.iterator().next())) ) {
|
|
||||||
for ( VariantContext annotatedVC : indelBufferContext )
|
|
||||||
vcfWriter.add(annotatedVC);
|
|
||||||
indelBufferContext = annotatedVCs;
|
|
||||||
} else {
|
|
||||||
indelBufferContext = annotatedVCs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue