public static void Recalibrate(SignatureSorterResultFiles countsFilePaths, VQROptions options)
        {
            string vcfFileName = Path.GetFileName(options.VcfPath);
            string vcfOut      = Path.Combine(options.OutputDirectory, vcfFileName + ".recal");

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

            try
            {
                //Read in the results files that have the data for the error modes detected.
                //Decide which types of variants we want to re-Qscore
                var recalibrationData = GetRecalibrationTables(countsFilePaths, options);

                //Update Vcf, variant by variant, based on the table data.
                VcfUpdater <QualityRecalibrationData> .UpdateVcfAlleleByAllele(vcfOut, options, false, recalibrationData, UpdateAllele, CanSkipVcfLines,
                                                                               VQRVcfWriter.GetVQRVcfFileWriter);

                //let the user know it worked
                if (File.Exists(vcfOut))
                {
                    Logger.WriteToLog("The following vcf was recalibrated: " + options.VcfPath);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteToLog("Recalibrate failed for " + options.VcfPath);
                Logger.WriteToLog("Exception: " + ex);
            }
        }
Пример #2
0
        protected override void ProgramExecution()
        {
            AdjustOptions(ref _options);

            Logger.WriteToLog("Generating counts files");
            SignatureSorterResultFiles results = SignatureSorter.StrainVcf(_options);

            Logger.WriteToLog("Starting Recalibration");

            try
            {
                QualityRecalibration.Recalibrate(results, _options);
            }
            catch (Exception e)
            {
                Logger.WriteToLog("*** Error encountered: {0}", e);
                throw e;
            }

            Logger.WriteToLog("Work complete.");
        }
        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);
        }