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;
|
||||
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.put(getKeyNames().get(0), String.format("%d", depth));
|
||||
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.VCFHeaderLineCount;
|
||||
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.ReadBackedExtendedEventPileup;
|
||||
import org.broadinstitute.sting.utils.pileup.ReadBackedPileup;
|
||||
import org.broadinstitute.sting.utils.variantcontext.Allele;
|
||||
import org.broadinstitute.sting.utils.variantcontext.Genotype;
|
||||
|
|
@ -44,9 +42,9 @@ import java.util.Map;
|
|||
*/
|
||||
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) {
|
||||
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) {
|
||||
|
||||
if ( ! stratifiedContext.hasBasePileup() ) return null;
|
||||
if ( ! stratifiedContext.hasBasePileup() )
|
||||
return null;
|
||||
|
||||
HashMap<Byte, Integer> alleleCounts = new HashMap<Byte, Integer>();
|
||||
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) {
|
||||
|
||||
if ( ! stratifiedContext.hasExtendedEventPileup() ) {
|
||||
if ( ! stratifiedContext.hasBasePileup() )
|
||||
return null;
|
||||
}
|
||||
|
||||
ReadBackedExtendedEventPileup pileup = stratifiedContext.getExtendedEventPileup();
|
||||
ReadBackedPileup pileup = stratifiedContext.getBasePileup();
|
||||
if ( pileup == null )
|
||||
return null;
|
||||
|
||||
HashMap<String, Integer> alleleCounts = new HashMap<String, Integer>();
|
||||
alleleCounts.put(REF_ALLELE,0);
|
||||
Allele refAllele = vc.getReference();
|
||||
final HashMap<String, Integer> alleleCounts = new HashMap<String, Integer>();
|
||||
alleleCounts.put(REF_ALLELE, 0);
|
||||
final Allele refAllele = vc.getReference();
|
||||
|
||||
for ( Allele allele : vc.getAlternateAlleles() ) {
|
||||
|
||||
|
|
@ -108,33 +106,24 @@ public class DepthPerAlleleBySample extends GenotypeAnnotation implements Standa
|
|||
alleleCounts.put(getAlleleRepresentation(allele), 0);
|
||||
}
|
||||
|
||||
for ( ExtendedEventPileupElement e : pileup.toExtendedIterable() ) {
|
||||
if ( e.isInsertion() ) {
|
||||
for ( PileupElement p : pileup ) {
|
||||
if ( p.isBeforeInsertion() ) {
|
||||
|
||||
final String b = e.getEventBases();
|
||||
final String b = p.getEventBases();
|
||||
if ( alleleCounts.containsKey(b) ) {
|
||||
alleleCounts.put(b, alleleCounts.get(b)+1);
|
||||
}
|
||||
|
||||
} else {
|
||||
if ( e.isDeletion() ) {
|
||||
if ( e.getEventLength() == refAllele.length() ) {
|
||||
} else if ( p.isBeforeDeletionStart() ) {
|
||||
if ( p.getEventLength() == refAllele.length() ) {
|
||||
// this is indeed the deletion allele recorded in VC
|
||||
final String b = DEL;
|
||||
if ( alleleCounts.containsKey(b) ) {
|
||||
alleleCounts.put(b, alleleCounts.get(b)+1);
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// System.out.print(" deletion of WRONG length found");
|
||||
// }
|
||||
}
|
||||
else {
|
||||
if ( e.getRead().getAlignmentEnd() <= vc.getStart() ) {
|
||||
continue;
|
||||
}
|
||||
alleleCounts.put(REF_ALLELE,alleleCounts.get(REF_ALLELE)+1);
|
||||
}
|
||||
} else if ( p.getRead().getAlignmentEnd() > vc.getStart() ) {
|
||||
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
|
||||
return null;
|
||||
|
||||
if (!vc.isSNP() && !vc.isIndel() && !vc.isMixed())
|
||||
return null;
|
||||
|
||||
final AlignmentContext context = AlignmentContextUtils.joinContexts(stratifiedContexts.values());
|
||||
|
||||
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;
|
||||
|
||||
// Compute all haplotypes consistent with the current read pileup
|
||||
ReadBackedPileup pileup = null;
|
||||
if (context.hasExtendedEventPileup())
|
||||
pileup = context.getExtendedEventPileup();
|
||||
else if (context.hasBasePileup())
|
||||
pileup = context.getBasePileup();
|
||||
|
||||
if (pileup == null)
|
||||
if ( !context.hasBasePileup() )
|
||||
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 MathUtils.RunningAverage scoreRA = new MathUtils.RunningAverage();
|
||||
if (haplotypes != null) {
|
||||
for (final Genotype genotype : vc.getGenotypes()) {
|
||||
final AlignmentContext thisContext = stratifiedContexts.get(genotype.getSampleName());
|
||||
if (thisContext != null) {
|
||||
final ReadBackedPileup thisPileup;
|
||||
if (thisContext.hasExtendedEventPileup())
|
||||
thisPileup = thisContext.getExtendedEventPileup();
|
||||
else if (thisContext.hasBasePileup())
|
||||
thisPileup = thisContext.getBasePileup();
|
||||
else
|
||||
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
|
||||
if (thisContext != null && thisContext.hasBasePileup()) {
|
||||
final ReadBackedPileup thisPileup = thisContext.getBasePileup();
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,12 +62,10 @@ public abstract class RankSumTest extends InfoFieldAnnotation implements Standar
|
|||
continue;
|
||||
}
|
||||
|
||||
ReadBackedPileup pileup = null;
|
||||
if (context.hasExtendedEventPileup())
|
||||
pileup = context.getExtendedEventPileup();
|
||||
else if (context.hasBasePileup())
|
||||
pileup = context.getBasePileup();
|
||||
if (!context.hasBasePileup())
|
||||
continue;
|
||||
|
||||
final ReadBackedPileup pileup = context.getBasePileup();
|
||||
if (pileup == null)
|
||||
continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import org.broadinstitute.sting.utils.SampleUtils;
|
|||
import org.broadinstitute.sting.utils.classloader.PluginManager;
|
||||
import org.broadinstitute.sting.utils.codecs.vcf.*;
|
||||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||
import org.broadinstitute.sting.utils.variantcontext.VariantContextUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -168,20 +167,14 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> implements Ann
|
|||
protected Boolean ALWAYS_APPEND_DBSNP_ID = false;
|
||||
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")
|
||||
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)
|
||||
private boolean requireStrictAlleleMatch = false;
|
||||
protected boolean requireStrictAlleleMatch = false;
|
||||
|
||||
private VariantAnnotatorEngine engine;
|
||||
|
||||
private Collection<VariantContext> indelBufferContext;
|
||||
|
||||
|
||||
private void listAnnotationsAndExit() {
|
||||
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);
|
||||
vcfWriter.writeHeader(vcfHeader);
|
||||
|
||||
if ( indelsOnly ) {
|
||||
indelBufferContext = null;
|
||||
}
|
||||
}
|
||||
|
||||
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; }
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
|
@ -334,19 +316,8 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> implements Ann
|
|||
}
|
||||
}
|
||||
|
||||
if ( ! indelsOnly ) {
|
||||
for ( VariantContext annotatedVC : annotatedVCs )
|
||||
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;
|
||||
}
|
||||
}
|
||||
for ( VariantContext annotatedVC : annotatedVCs )
|
||||
vcfWriter.add(annotatedVC);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue