public static SimplifiedDiploidGenotype GetSimplifiedGenotype(int alleleDepth, int totalDepth, double[] means, double[] priors) { // Get genotype category double[] posteriors = CalculatePosteriors(alleleDepth, totalDepth, means, priors); var maxPosterior = posteriors.Max(); int category = Array.IndexOf(posteriors, maxPosterior); return(MixtureModelResult.IntToGenotypeCategory(category)); }
public static MixtureModelResult CalculateQScoreAndGenotypePosteriors(int alleleDepth, int totalDepth, double[] means, double[] priors) { // Get genotype category int category = MixtureModelResult.GenotypeCategoryToInt(GetSimplifiedGenotype(alleleDepth, totalDepth, means, priors)); // Get Q score and genotype posterior (int qScore, float[] genotypePosteriors) = CalculateQScoreAndGenotypePosteriors(alleleDepth, totalDepth, category, means, priors, _defaultQScoreEffectiveN); return(new MixtureModelResult { GenotypeCategoryAsInt = category, QScore = qScore, GenotypePosteriors = genotypePosteriors }); }
public List <CalledAllele> SetGenotypes(IEnumerable <CalledAllele> alleles) { var singleGTForLoci = CalculateDiploidGenotypeFromBinomialModel(alleles, MinDepthToGenotype, _adaptiveGenotypingParameters, out var allelesToPrune); int phaseSetIndex = 1; //reserve -1 for unset, and 0 for reference, and 1 and 2 for alts foreach (var allele in alleles) { allele.Genotype = singleGTForLoci; if (allele.TotalCoverage == 0) { allele.GenotypeQscore = MinGQScore; allele.GenotypePosteriors = new float[] { _adaptiveGenotypingParameters.MaxGenotypePosteriors, _adaptiveGenotypingParameters.MaxGenotypePosteriors, _adaptiveGenotypingParameters.MaxGenotypePosteriors }; } else { var(model, prior) = _adaptiveGenotypingParameters.GetModelsAndPriors(allele); MixtureModelResult adaptiveGTResult = AdaptiveGenotyperCalculator.GetGenotypeAndQScore(allele, model, prior); allele.GenotypeQscore = Math.Max(Math.Min(adaptiveGTResult.QScore, MaxGQScore), MinGQScore); allele.GenotypePosteriors = adaptiveGTResult.GenotypePosteriors; } if (allele.IsRefType) { allele.PhaseSetIndex = 0; } else { allele.PhaseSetIndex = phaseSetIndex; phaseSetIndex++; } } // Calculate GP for multiallelic variant based on multinomial distribution if (alleles.First().Genotype == Genotype.HeterozygousAlt1Alt2) { CalledAllele allele1 = alleles.First(), allele2 = alleles.ElementAt(1); var(model1, _) = _adaptiveGenotypingParameters.GetModelsAndPriors(allele1); var(model2, _) = _adaptiveGenotypingParameters.GetModelsAndPriors(allele2); var mixtureModelResult = AdaptiveGenotyperCalculator.GetMultiAllelicQScores(allele1, allele2, new List <double[]> { model1, model2 }); foreach (CalledAllele allele in alleles) { allele.GenotypeQscore = Math.Max(Math.Min(mixtureModelResult.QScore, MaxGQScore), MinGQScore); allele.GenotypePosteriors = mixtureModelResult.GenotypePosteriors; } } return(allelesToPrune); }