示例#1
0
        public static TypeOfUpdateNeeded ProcessLocus(VcfConsumerAppOptions options, RecalibrationResults results,
                                                      List <CalledAllele> incomingAlleles, out List <CalledAllele> outGoingAlleles)
        {
            // Use somatic call for chrM
            if (GenotypeCreator.GetPloidyForThisChr(
                    options.VariantCallingParams.PloidyModel,
                    options.VariantCallingParams.IsMale,
                    incomingAlleles.First().Chromosome) != PloidyModel.DiploidByAdaptiveGT)
            {
                return(GetTypeOfUpdate((AdaptiveGtOptions)options, incomingAlleles, TypeOfUpdateNeeded.NoChangeNeeded,
                                       out outGoingAlleles));
            }

            var orderedAlleles = GetTopTwoAlleles(incomingAlleles);

            if (orderedAlleles.Count == 1)
            {
                var alleles = ProcessSingleVariantLocus(incomingAlleles[0], results);
                return(GetTypeOfUpdate((AdaptiveGtOptions)options, alleles, TypeOfUpdateNeeded.Modify, out outGoingAlleles));
            }
            else
            {
                var alleles = ProcessMultiAllelicLocus(orderedAlleles, results);
                return(GetTypeOfUpdate((AdaptiveGtOptions)options, alleles, TypeOfUpdateNeeded.Modify, out outGoingAlleles));
            }
        }
示例#2
0
        private static List <CalledAllele> ProcessMultiAllelicLocus(List <CalledAllele> orderedVariants,
                                                                    RecalibrationResults results)
        {
            RecalibrationResult resultForVariant   = GetModelFromType(orderedVariants[0], results);
            MixtureModelResult  mixtureModelResult = GetModelResult(orderedVariants[0], resultForVariant);

            switch (mixtureModelResult.GenotypeCategory)
            {
            case SimplifiedDiploidGenotype.HomozygousRef:
            case SimplifiedDiploidGenotype.HomozygousAlt:
                var allele = UpdateGenotypeAndQScore(orderedVariants[0], mixtureModelResult);
                return(new List <CalledAllele> {
                    allele
                });

            case SimplifiedDiploidGenotype.HeterozygousAltRef:
                orderedVariants[0].Genotype = Genotype.HeterozygousAlt1Alt2;
                orderedVariants[1].Genotype = Genotype.HeterozygousAlt1Alt2;
                orderedVariants             = UpdateMultiAllelicQScores(orderedVariants, results);
                return(orderedVariants);

            default:
                throw new ArgumentException("Invalid model results");
            }
        }
示例#3
0
        private static List <CalledAllele> ProcessSingleVariantLocus(CalledAllele allele,
                                                                     RecalibrationResults results)
        {
            RecalibrationResult resultForVariant = GetModelFromType(allele, results);

            return(new List <CalledAllele> {
                UpdateVariant(allele, resultForVariant)
            });
        }
示例#4
0
        private static RecalibrationResult GetModelFromType(CalledAllele allele, RecalibrationResults results)
        {
            var variantType = VariantReader.GetVariantType(allele);

            RecalibrationResult resultForVariant;

            if (variantType == VariantType.NoVariant || variantType == VariantType.Snv)
            {
                resultForVariant = results.SnvResults;
            }
            else if (variantType == VariantType.Indel)
            {
                resultForVariant = results.IndelResults;
            }
            else
            {
                throw new ArgumentException("Variant type unrecognized.");
            }

            return(resultForVariant);
        }
        public void Recalibrate()
        {
            // Read in VCF
            Logger.WriteToLog("Reading in vcf for variant frequencies.");
            List <RecalibratedVariantsCollection> variants = VariantReader.GetVariantFrequencies(_options.VcfPath);

            // Fit new models or load models from file
            List <MixtureModel> models;

            if (_options.ModelFile == null)
            {
                models = GetNewModels(_options.VcfPath, _options.OutputDirectory, variants);
            }
            else
            {
                models = ApplyModels(_options.VcfPath, _options.ModelFile, variants);
            }

            RecalibrationResults recalibrationResults = SummarizeModels(models, variants);

            AdaptiveGtWriter.RewriteVcf(_options.VcfPath, _options.OutputDirectory, _options, recalibrationResults);
        }
示例#6
0
        private static List <CalledAllele> UpdateMultiAllelicQScores(List <CalledAllele> variantList, RecalibrationResults results)
        {
            // Determine model types
            RecalibrationResult model1 = GetModelFromType(variantList[0], results);
            RecalibrationResult model2 = GetModelFromType(variantList[1], results);

            // Calculate posteriors based on multinomial distribution
            int dp = variantList[0].TotalCoverage;

            int[] ad = new int[3];
            ad[2] = variantList[0].AlleleSupport; //temp[1];
            ad[1] = variantList[1].AlleleSupport; //temp[0];
            ad[0] = dp - ad[1] - ad[2];
            if (ad[0] < 0)
            {
                ad[0] = 0;
                dp    = ad[1] + ad[2];
            }

            var mixtureModelResult = MixtureModel.GetMultinomialQScores(ad, dp,
                                                                        new List <double[]> {
                model1.Means, model2.Means
            });

            // Update variant genotypes fields
            variantList[0].GenotypePosteriors = mixtureModelResult.GenotypePosteriors;
            variantList[1].GenotypePosteriors = mixtureModelResult.GenotypePosteriors;

            variantList[0].GenotypeQscore = mixtureModelResult.QScore;
            variantList[1].GenotypeQscore = mixtureModelResult.QScore;

            return(variantList);
        }
示例#7
0
        public static void RewriteVcf(string vcfIn, string outDir, AdaptiveGtOptions options, RecalibrationResults results)
        {
            Logger.WriteToLog("Rewriting VCF.");

            string vcfFileName = Path.GetFileName(vcfIn);

            if (vcfFileName.Contains("genome."))
            {
                vcfFileName = vcfFileName.Replace("genome", "recal");
            }
            else
            {
                vcfFileName = vcfFileName.Replace(".vcf", ".recal.vcf");
            }

            string vcfOut = Path.Combine(outDir, vcfFileName);

            if (File.Exists(vcfOut))
            {
                File.Delete(vcfOut);
            }

            VcfUpdater <RecalibrationResults> .UpdateVcfLociByLoci(vcfOut, options, false, results, LocusProcessor.ProcessLocus,
                                                                   (List <string> vcfLine) => TypeOfUpdateNeeded.Modify, GetAdaptiveGtWriter);

            Logger.WriteToLog("filtering complete.");
        }