private static QualityRecalibrationData GetRecalibrationTables(SignatureSorterResultFiles resultsFilePaths,
                                                                       VQROptions options)
        {
            CountData BasicCounts = null;
            CountData EdgeCounts  = null;

            QualityRecalibrationData recalibrationData = new QualityRecalibrationData();

            if (options.DoBasicChecks)
            {
                if (!File.Exists(resultsFilePaths.BasicCountsFilePath))
                {
                    Logger.WriteToLog("Cannot do basic recalibration. Cannot find {0} ", resultsFilePaths.BasicCountsFilePath);
                }
                else
                {
                    Logger.WriteToLog("Found counts file: {0} ", resultsFilePaths.BasicCountsFilePath);

                    BasicCounts = CountsFileReader.ReadCountsFile(resultsFilePaths.BasicCountsFilePath);
                    recalibrationData.BasicLookupTable = GetPhredScaledCalibratedRates(options.BamFilterParams.MinimumBaseCallQuality, options.ZFactor, BasicCounts);


                    //if no work to do here...
                    if ((recalibrationData.BasicLookupTable == null) || (recalibrationData.BasicLookupTable.Count == 0))
                    {
                        Logger.WriteToLog("No general recalibration needed.");
                    }
                    else
                    {
                        Logger.WriteToLog("General mutation bias detected. This sample may have sample-specific prep issues such as FFPE or oxidation damage.");
                    }
                }
            }

            if (options.DoAmpliconPositionChecks)
            {
                if (!File.Exists(resultsFilePaths.AmpliconEdgeCountsFilePath))
                {
                    Logger.WriteToLog("Cannot do amplicon-position based recalibration. Cannot find {0} ", resultsFilePaths.AmpliconEdgeCountsFilePath);
                }
                else
                {
                    Logger.WriteToLog("Found counts file: {0} ", resultsFilePaths.AmpliconEdgeCountsFilePath);


                    EdgeCounts = CountsFileReader.ReadCountsFile(resultsFilePaths.AmpliconEdgeCountsFilePath);
                    recalibrationData.AmpliconEdgeVariantsLookupTable = GetPhredScaledCalibratedRates(options.BamFilterParams.MinimumBaseCallQuality, options.ZFactor, EdgeCounts);
                    recalibrationData.AmpliconEdgeVariantsList        = VariantListReader.ReadVariantListFile(resultsFilePaths.AmpliconEdgeSuspectListFilePath);


                    if ((recalibrationData.AmpliconEdgeVariantsLookupTable == null) || (recalibrationData.AmpliconEdgeVariantsLookupTable.Count == 0))
                    {
                        Logger.WriteToLog("No position-in-amplicon recalibration needed.");
                    }
                }
            }

            //compare edge-issues with FFPE-like issues.
            //Did the bulk of variants appear to come from the edge of amplicons..?
            //Look at the diff in percents.
            //If a variant is X more likely to be called when its by an edge - thats an estimate of the error.
            if (options.DoBasicChecks && options.DoAmpliconPositionChecks)
            {
                recalibrationData.EdgeRiskLookupTable = GetPhredScaledCalibratedRatesForEdges(options.BamFilterParams.MinimumBaseCallQuality, options.AlignmentWarningThreshold, BasicCounts, EdgeCounts);
            }


            return(recalibrationData);
        }
        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);
        }