private static TypeOfUpdateNeeded UpdateAllele(VcfConsumerAppOptions appOptions, QualityRecalibrationData recalibrationData, CalledAllele inAllele, out List <CalledAllele> outAlleles)
        {
            outAlleles = new List <CalledAllele> {
                inAllele
            };
            VQROptions         options        = (VQROptions)appOptions;
            var                cat            = MutationCounter.GetMutationCategory(inAllele);
            TypeOfUpdateNeeded updateHappened = TypeOfUpdateNeeded.NoChangeNeeded;

            if (options.DoBasicChecks && recalibrationData.BasicLookupTable.ContainsKey(cat))
            {
                UpdateVariantQScoreAndRefilter(options.MaxQScore, options.VariantCallingParams.MinimumVariantQScoreFilter, recalibrationData.BasicLookupTable, inAllele, cat, false);
                updateHappened = TypeOfUpdateNeeded.Modify;
            }

            if (options.DoAmpliconPositionChecks &&
                recalibrationData.AmpliconEdgeVariantsLookupTable.ContainsKey(cat) &&
                recalibrationData.AmpliconEdgeVariantsList.ContainsKey(inAllele.Chromosome) &&
                recalibrationData.AmpliconEdgeVariantsList[inAllele.Chromosome].Contains(inAllele.ReferencePosition))
            {
                UpdateVariantQScoreAndRefilter(options.MaxQScore, options.VariantCallingParams.MinimumVariantQScoreFilter, recalibrationData.EdgeRiskLookupTable, inAllele, cat, true);
                updateHappened = TypeOfUpdateNeeded.Modify;
            }

            return(updateHappened);
        }
Пример #2
0
        public static void Recalibrate(string vcfIn, string vcfOut, string sampleCountsFileName,
                                       int baselineQNoise, double zFactor, int maxQscore, int filterQScore)
        {
            if (!File.Exists(sampleCountsFileName))
            {
                Logger.WriteToLog("Cannot recalibrate. Cannot find {0} ", sampleCountsFileName);
                return;
            }
            else
            {
                Logger.WriteToLog("Found counts file: {0} ", sampleCountsFileName);
            }

            var LookupTable = GetPhredScaledCalibratedRates(baselineQNoise, zFactor, sampleCountsFileName);

            //if no work to do here...
            if ((LookupTable == null) || (LookupTable.Count == 0))
            {
                return;
            }

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

            using (VcfReader reader = new VcfReader(vcfIn))
                using (StreamWriter writer = new StreamWriter(vcfOut))
                {
                    writer.NewLine = "\n";
                    List <string> headerLines = reader.HeaderLines;
                    foreach (string headerLine in headerLines)
                    {
                        writer.WriteLine(headerLine);
                    }

                    var originalVar = new VcfVariant();
                    while (reader.GetNextVariant(originalVar))
                    {
                        var cat = MutationCounter.GetMutationCategory(originalVar);

                        if (LookupTable.ContainsKey(cat))
                        {
                            UpdateVariant(maxQscore, filterQScore, LookupTable, originalVar, cat);
                        }
                        writer.WriteLine(originalVar);
                    }
                }
        }
Пример #3
0
        private static void DoRecalibrationWork(string vcfIn, string vcfOut, string sampleCountsFileName,
                                                int baselineQNoise, double zFactor, int maxQscore, int filterQScore, string quotedCommandLineString)
        {
            if (!File.Exists(sampleCountsFileName))
            {
                Logger.WriteToLog("Cannot recalibrate. Cannot find {0} ", sampleCountsFileName);
                return;
            }
            else
            {
                Logger.WriteToLog("Found counts file: {0} ", sampleCountsFileName);
            }

            var LookupTable = GetPhredScaledCalibratedRates(baselineQNoise, zFactor, sampleCountsFileName);

            //if no work to do here...
            if ((LookupTable == null) || (LookupTable.Count == 0))
            {
                Logger.WriteToLog("No recalibration needed.");
                return;
            }

            using (VcfReader reader = new VcfReader(vcfIn))
                using (StreamWriter writer = new StreamWriter(new FileStream(vcfOut, FileMode.CreateNew)))
                {
                    writer.NewLine = "\n";
                    List <string> headerLines = reader.HeaderLines;
                    WriteHeaders(writer, headerLines, quotedCommandLineString);


                    var originalVar = new VcfVariant();
                    while (reader.GetNextVariant(originalVar))
                    {
                        var cat = MutationCounter.GetMutationCategory(originalVar);

                        if (LookupTable.ContainsKey(cat))
                        {
                            UpdateVariant(maxQscore, filterQScore, LookupTable, originalVar, cat);
                        }
                        writer.WriteLine(originalVar);
                    }
                }
        }
Пример #4
0
        public void LoadCountsFile(string file)
        {
            bool inRateSection = false;

            using (StreamReader sr = new StreamReader(file))
            {
                string line;

                while (true)
                {
                    line = sr.ReadLine();

                    if (line == "")
                    {
                        continue;
                    }

                    if (line == null)
                    {
                        break;
                    }

                    if (inRateSection)
                    {
                        string[] Splat = line.Split();

                        if (Splat.Length < 2)
                        {
                            continue;
                        }


                        double result = -1;
                        if (!(double.TryParse(Splat[1], out result)))
                        {
                            throw new ApplicationException("Unable to parse counts from noise file " + file);
                        }

                        switch (Splat[0])
                        {
                        case "AllPossibleVariants":
                            NumPossibleVariants += result;
                            break;

                        case "FalsePosVariantsFound":
                        case "ErrorRate(%)":
                        case "VariantsCountedTowardEstimate":
                        case "ErrorRateEstimate(%)":
                        case "MismatchEstimate(%)":
                            continue;

                        default:
                            MutationCategory category = MutationCounter.GetMutationCategory(Splat[0]);
                            CountsByCategory[category] += result;
                            break;
                        }
                    }
                    if (line.Contains("CountsByCategory"))
                    {
                        inRateSection = true;
                    }
                }
            }
        }