/** Tests to ensure that a locus is bi-allelic within the given set of samples. */ private boolean isVariant(final Genotype... gts) { for (final Genotype gt : gts) { if (gt.isCalled() && !gt.isHomRef()) return true; } return false; }
/** Tests to ensure that a locus is bi-allelic within the given set of samples. */ private boolean isVariant(final Genotype... gts) { for (final Genotype gt : gts) { if (gt.isCalled() && !gt.isHomRef()) return true; } return false; }
private void updatePairMetricsCounters(Genotype parent, Genotype child, int mvCount, HashMap<Byte,Integer> counters){ //Increment metrics counters if(parent.isCalled() && child.isCalled()){ counters.put(NUM_PAIR_GENOTYPES_CALLED,counters.get(NUM_PAIR_GENOTYPES_CALLED)+1); if(parent.isPhased()) counters.put(NUM_PAIR_GENOTYPES_PHASED,counters.get(NUM_PAIR_GENOTYPES_PHASED)+1); else{ counters.put(NUM_PAIR_VIOLATIONS,counters.get(NUM_PAIR_VIOLATIONS)+mvCount); if(parent.isHet() && child.isHet()) counters.put(NUM_PAIR_HET_HET,counters.get(NUM_PAIR_HET_HET)+1); } }else{ counters.put(NUM_PAIR_GENOTYPES_NOCALL,counters.get(NUM_PAIR_GENOTYPES_NOCALL)+1); } }
private EnumMap<GenotypeType,Double> getLikelihoodsAsMapSafeNull(Genotype genotype){ if(genotype == null || !genotype.isCalled() || genotype.getLikelihoods() == null){ EnumMap<GenotypeType,Double> likelihoods = new EnumMap<GenotypeType, Double>(GenotypeType.class); likelihoods.put(GenotypeType.HOM_REF,1.0/3.0); likelihoods.put(GenotypeType.HET,1.0/3.0); likelihoods.put(GenotypeType.HOM_VAR,1.0/3.0); return likelihoods; } return genotype.getLikelihoods().getAsMap(true); }
private void updateTrioMetricsCounters(Genotype mother, Genotype father, Genotype child, int mvCount, HashMap<Byte,Integer> counters){ //Increment metrics counters if(mother.isCalled() && father.isCalled() && child.isCalled()){ counters.put(NUM_TRIO_GENOTYPES_CALLED,counters.get(NUM_TRIO_GENOTYPES_CALLED)+1); if(mother.isPhased()) counters.put(NUM_TRIO_GENOTYPES_PHASED,counters.get(NUM_TRIO_GENOTYPES_PHASED)+1); else{ if(mvCount > 0){ if(mvCount >1) counters.put(NUM_TRIO_DOUBLE_VIOLATIONS,counters.get(NUM_TRIO_DOUBLE_VIOLATIONS)+1); else counters.put(NUM_TRIO_VIOLATIONS,counters.get(NUM_TRIO_VIOLATIONS)+1); } else if(mother.isHet() && father.isHet() && child.isHet()) counters.put(NUM_TRIO_HET_HET_HET,counters.get(NUM_TRIO_HET_HET_HET)+1); } }else{ counters.put(NUM_TRIO_GENOTYPES_NOCALL,counters.get(NUM_TRIO_GENOTYPES_NOCALL)+1); } }
private boolean containsCalls(final HaplotypeCallerGenotypingEngine.CalledHaplotypes calledHaplotypes) { final List<VariantContext> calls = calledHaplotypes.getCalls(); if (calls.isEmpty()) return false; for (final VariantContext call : calls) for (final Genotype genotype : call.getGenotypes()) if (genotype.isCalled()) return true; return false; }
public void annotate(final RefMetaDataTracker tracker, final AnnotatorCompatible walker, final ReferenceContext ref, final AlignmentContext stratifiedContext, final VariantContext vc, final Genotype g, final GenotypeBuilder gb, final PerReadAlleleLikelihoodMap alleleLikelihoodMap) { // Can only call from MuTect2 if ( !(walker instanceof MuTect2) ) { synchronized (this) { if (!walkerIdentityCheckWarningLogged) { if (walker != null) logger.warn("Annotation will not be calculated, can only be called from MuTect2, not " + walker.getClass().getSimpleName()); else logger.warn("Annotation will not be calculated, can only be called from MuTect2"); walkerIdentityCheckWarningLogged = true; } } return; } if ( g == null || !g.isCalled() || ( stratifiedContext == null && alleleLikelihoodMap == null) ) return; if (alleleLikelihoodMap != null) { annotateWithLikelihoods(alleleLikelihoodMap, vc, gb); } }
public static boolean isUnfilteredCalledDiploidGenotype(Genotype gt) { return (! gt.isFiltered() && gt.isCalled() && gt.getPloidy() == 2); }
/** * Increment the number of called alternate and reference plus alternate alleles for a genotype * * @param calledAltAlleles number of called alternate alleles for all genotypes * @param calledAlleles number of called alleles for all genotypes * @param genotype genotype * @return incremented called alleles * @throws IllegalArgumentException if calledAltAlleles or genotype are null */ public static int incrementChromosomeCountsInfo(final Map<Allele, Integer> calledAltAlleles, final int calledAlleles, final Genotype genotype) { if ( calledAltAlleles == null ) throw new IllegalArgumentException("Called alternate alleles can not be null"); if ( genotype == null ) throw new IllegalArgumentException("Genotype can not be null"); int incrementedCalledAlleles = calledAlleles; if (genotype.isCalled()) { for (final Allele allele : genotype.getAlleles()) { incrementedCalledAlleles++; if (allele.isNonReference()) { calledAltAlleles.put(allele, calledAltAlleles.get(allele) + 1); } } } return incrementedCalledAlleles; }
private boolean haveSameGenotypes(final Genotype g1, final Genotype g2) { if ( g1 == null || g2 == null ) return false; if ((g1.isCalled() && g2.isFiltered()) || (g2.isCalled() && g1.isFiltered()) || (g1.isFiltered() && g2.isFiltered() && XLfiltered)) return false; List<Allele> a1s = g1.getAlleles(); List<Allele> a2s = g2.getAlleles(); return (a1s.containsAll(a2s) && a2s.containsAll(a1s)); } @Override
private boolean doAllelesMatch(final Genotype eval, final Genotype truth, final Allele truthRef, final Set<Allele> truthSiteAlleles) { // When determining if alleles match, there are a number of cases to consider. In order: // 1) If either genotype is uncalled or unavailable, the alleles MATCH // 2) If the truth genotype is hom ref, then: // a) If the truth variant is mononallelic (no alternate alleles), the alleles MATCH // b) Otherwise, the alleles match IFF the alleles in the eval genotype are a subset // of the alleles in the truth VARIANT // 3) Otherwise, the alleles match IFF the alleles in the eval genotype are a subset // of the alleles in (the truth GENOTYPE + the truth REF allele) boolean matching = true; if (eval.isCalled() && truth.isCalled()) { // Case 1 if (truth.isHomRef()) { // Case 2 matching = truthSiteAlleles.size() == 1 || truthSiteAlleles.containsAll(eval.getAlleles()); } else { // Case 3 final Set<Allele> truthAlleles = new HashSet<>(truth.getAlleles()); truthAlleles.add(truthRef); matching = truthAlleles.containsAll(eval.getAlleles()); } } return matching; }
private boolean sampleHasVariant(final Genotype g) { return (g !=null && !g.isHomRef() && (g.isCalled() || (g.isFiltered() && !XLfiltered))); }
private String formatJsScriptWithGenotype(String js, Genotype gt) { // Comments are copied from htsjdk if(js.contains("{HOM}")){ js= js.replace("{HOM}", Boolean.toString(gt.isHom())); } if(js.contains("{HET}")){ js= js.replace("{HET}", Boolean.toString(gt.isHet())); } if(js.contains("{HOM_REF}")){ js= js.replace("{HOM_REF}", Boolean.toString(gt.isHomRef())); } if(js.contains("{HOM_VAR}")){ js= js.replace("{HOM_VAR}", Boolean.toString(gt.isHomVar())); // true if all observed alleles are alt; if any alleles are no-calls, return false. } if(js.contains("{HET_NON_REF}")){ js= js.replace("{HET_NON_REF}", Boolean.toString(gt.isHetNonRef())); // true if we're het (observed alleles differ) and neither allele is reference; if the ploidy is less than 2 or if any alleles are no-calls, this method will return false. } if(js.contains("{CALLED}")){ js= js.replace("{CALLED}", Boolean.toString(gt.isCalled())); // true if this genotype is comprised of any alleles that are not no-calls (even if some are). } if(js.contains("{NO_CALL}")){ js= js.replace("{NO_CALL}", Boolean.toString(gt.isNoCall())); // true if this genotype is not actually a genotype but a "no call" (e.g. './.' in VCF); if any alleles are not no-calls (even if some are), this method will return false. } if(js.contains("{MIXED}")){ js= js.replace("{MIXED}", Boolean.toString(gt.isMixed())); // true if this genotype is comprised of both calls and no-calls. } return js; }
public Map<String, Object> annotate(final RefMetaDataTracker tracker, final AnnotatorCompatible walker, final ReferenceContext ref, final Map<String, AlignmentContext> stratifiedContexts, final VariantContext vc, final Map<String, PerReadAlleleLikelihoodMap> stratifiedPerReadAlleleLikelihoodMap) { if ( vc.isMonomorphicInSamples() || !vc.hasGenotypes() ) return null; final StringBuilder samples = new StringBuilder(); for ( Genotype genotype : vc.getGenotypesOrderedByName() ) { if ( genotype.isCalled() && !genotype.isHomRef() ){ if ( samples.length() > 0 ) samples.append(","); samples.append(genotype.getSampleName()); } } if ( samples.length() == 0 ) return null; Map<String, Object> map = new HashMap<String, Object>(); map.put(getKeyNames().get(0), samples.toString()); return map; }
public void annotate(final RefMetaDataTracker tracker, final AnnotatorCompatible walker, final ReferenceContext ref, final AlignmentContext stratifiedContext, final VariantContext vc, final Genotype g, final GenotypeBuilder gb, final PerReadAlleleLikelihoodMap alleleLikelihoodMap) { // Can only call from MuTect2 if ( !(walker instanceof MuTect2) ) { synchronized (this) { if (!walkerIdentityCheckWarningLogged) { if (walker != null) logger.warn("Annotation will not be calculated, can only be called from MuTect2, not " + walker.getClass().getSimpleName()); else logger.warn("Annotation will not be calculated, can only be called from MuTect2"); walkerIdentityCheckWarningLogged = true; } } return; } if (g == null || !g.isCalled() || (stratifiedContext == null && alleleLikelihoodMap == null)) return; refAllele = vc.getReference(); altAllele = vc.getAlternateAllele(0); if (alleleLikelihoodMap != null) { annotateWithLikelihoods(alleleLikelihoodMap, vc, gb); } }
public void validateAlternateAlleles() { if ( !hasGenotypes() ) return; List<Allele> reportedAlleles = getAlleles(); Set<Allele> observedAlleles = new HashSet<Allele>(); observedAlleles.add(getReference()); for ( final Genotype g : getGenotypes() ) { if ( g.isCalled() ) observedAlleles.addAll(g.getAlleles()); } if ( observedAlleles.contains(Allele.NO_CALL) ) observedAlleles.remove(Allele.NO_CALL); if ( reportedAlleles.size() != observedAlleles.size() ) throw new TribbleException.InternalCodecException(String.format("one or more of the ALT allele(s) for the record at position %s:%d are not observed at all in the sample genotypes", getChr(), getStart())); int originalSize = reportedAlleles.size(); // take the intersection and see if things change observedAlleles.retainAll(reportedAlleles); if ( observedAlleles.size() != originalSize ) throw new TribbleException.InternalCodecException(String.format("one or more of the ALT allele(s) for the record at position %s:%d are not observed at all in the sample genotypes", getChr(), getStart())); }
public void annotate(final RefMetaDataTracker tracker, final AnnotatorCompatible walker, final ReferenceContext ref, final AlignmentContext stratifiedContext, final VariantContext vc, final Genotype g, final GenotypeBuilder gb, final PerReadAlleleLikelihoodMap alleleLikelihoodMap){ if ( g == null || !g.isCalled() || stratifiedContext == null ) return; int mq0 = 0; final ReadBackedPileup pileup = stratifiedContext.getBasePileup(); for (PileupElement p : pileup ) { if ( p.getMappingQual() == 0 ) mq0++; } gb.attribute(getKeyNames().get(0), mq0); }
/** * Evaluate the genotypes of mom, dad, and child to detect Mendelian violations * * @param gMom * @param gDad * @param gChild * @return true if the three genotypes represent a Mendelian violation; false otherwise */ public static boolean isViolation(final Genotype gMom, final Genotype gDad, final Genotype gChild) { //1 parent is no "call if(!gMom.isCalled()){ return (gDad.isHomRef() && gChild.isHomVar()) || (gDad.isHomVar() && gChild.isHomRef()); } else if(!gDad.isCalled()){ return (gMom.isHomRef() && gChild.isHomVar()) || (gMom.isHomVar() && gChild.isHomRef()); } //Both parents have genotype information return !(gMom.getAlleles().contains(gChild.getAlleles().get(0)) && gDad.getAlleles().contains(gChild.getAlleles().get(1)) || gMom.getAlleles().contains(gChild.getAlleles().get(1)) && gDad.getAlleles().contains(gChild.getAlleles().get(0))); }
public void annotate(final RefMetaDataTracker tracker, final AnnotatorCompatible walker, final ReferenceContext ref, final AlignmentContext stratifiedContext, final VariantContext vc, final Genotype g, final GenotypeBuilder gb, final PerReadAlleleLikelihoodMap alleleLikelihoodMap) { if ( g == null || !g.isCalled() || ( stratifiedContext == null && alleleLikelihoodMap == null) ) return; if (alleleLikelihoodMap != null && !alleleLikelihoodMap.isEmpty()) { annotateWithLikelihoods(alleleLikelihoodMap, vc, gb); } else if ( stratifiedContext != null && (vc.isSNP())) { annotateWithPileup(stratifiedContext, vc, gb); } else { gb.AD(new int[vc.getNAlleles()]); } }
public void annotate(final RefMetaDataTracker tracker, final AnnotatorCompatible walker, final ReferenceContext ref, final AlignmentContext stratifiedContext, final VariantContext vc, final Genotype g, final GenotypeBuilder gb, final PerReadAlleleLikelihoodMap alleleLikelihoodMap){ // We need a heterozygous genotype and either a context or non-empty alleleLikelihoodMap if ( g == null || !g.isCalled() || !g.isHet() || ( stratifiedContext == null && (alleleLikelihoodMap == null || alleleLikelihoodMap.isEmpty())) ) return; // If we have a <NON_REF> allele the SNP is biallelic if there are 3 alleles and both the reference and first alt allele are length 1. final boolean biallelicSNP = vc.hasAllele(GATKVCFConstants.NON_REF_SYMBOLIC_ALLELE) ? vc.getAlleles().size() == 3 && vc.getReference().length() == 1 && vc.getAlternateAllele(0).length() == 1 : vc.isSNP() && vc.isBiallelic(); if ( !biallelicSNP ) return; final Double ratio = (alleleLikelihoodMap != null && !alleleLikelihoodMap.isEmpty()) ? annotateWithLikelihoods(alleleLikelihoodMap, vc) : annotateWithPileup(stratifiedContext, vc); if (ratio == null) return; gb.attribute(getKeyNames().get(0), Double.valueOf(String.format("%.2f", ratio))); }