static boolean allGenotypesAreUnfilteredAndCalled(VariantContext vc) { for (final Genotype gt : vc.getGenotypes()) { if (gt.isNoCall() || gt.isFiltered()) return false; } return true; }
private Map<String, Object> calculateIC(final VariantContext vc) { final GenotypesContext genotypes = (founderIds == null || founderIds.isEmpty()) ? vc.getGenotypes() : vc.getGenotypes(founderIds); if (genotypes == null || genotypes.size() < MIN_SAMPLES) return null; int idxAA = 0, idxAB = 1, idxBB = 2; if (!vc.isBiallelic()) { // for non-bliallelic case, do test with most common alt allele. // Get then corresponding indeces in GL vectors to retrieve GL of AA,AB and BB. int[] idxVector = vc.getGLIndecesOfAlternateAllele(vc.getAltAlleleWithHighestAlleleCount()); idxAA = idxVector[0]; idxAB = idxVector[1]; idxBB = idxVector[2]; } double refCount = 0.0; double hetCount = 0.0; double homCount = 0.0; int N = 0; // number of samples that have likelihoods for (final Genotype g : genotypes) { if (g.isNoCall() || !g.hasLikelihoods()) continue; if (g.getPloidy() != 2) // only work for diploid samples continue; N++; final double[] normalizedLikelihoods = MathUtils.normalizeFromLog10(g.getLikelihoods().getAsVector()); refCount += normalizedLikelihoods[idxAA]; hetCount += normalizedLikelihoods[idxAB]; homCount += normalizedLikelihoods[idxBB]; } if (N < MIN_SAMPLES) { return null; } final double p = (2.0 * refCount + hetCount) / (2.0 * (refCount + hetCount + homCount)); // expected reference allele frequency final double q = 1.0 - p; // expected alternative allele frequency final double F = 1.0 - (hetCount / (2.0 * p * q * (double) N)); // inbreeding coefficient Map<String, Object> map = new HashMap<String, Object>(); map.put(getKeyNames().get(0), String.format("%.4f", F)); return map; }
public void update2( VariantContext eval, VariantContext comp, RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { if (eval == null || (getWalker().ignoreAC0Sites() && eval.isMonomorphicInSamples())) return; final Type type = getType(eval); if (type == null) return; TypeSampleMap titvTable = null; // update DP, if possible if (eval.hasAttribute(VCFConstants.DEPTH_KEY)) depthPerSample.inc(type, ALL); // update counts allVariantCounts.inc(type, ALL); // type specific calculations if (type == Type.SNP && eval.isBiallelic()) { titvTable = VariantContextUtils.isTransition(eval) ? transitionsPerSample : transversionsPerSample; titvTable.inc(type, ALL); } // novelty calculation if (comp != null || (type == Type.CNV && overlapsKnownCNV(eval))) knownVariantCounts.inc(type, ALL); // per sample metrics for (final Genotype g : eval.getGenotypes()) { if (!g.isNoCall() && !g.isHomRef()) { countsPerSample.inc(type, g.getSampleName()); // update transition / transversion ratio if (titvTable != null) titvTable.inc(type, g.getSampleName()); if (g.hasDP()) depthPerSample.inc(type, g.getSampleName()); } } }