Exemple #1
0
        protected override void ProgramExecution()
        {
            Logger.WriteToLog("Generating counts file");
            string countsFile = Counts.WriteCountsFile(_options.InputVcf, _options.OutputDirectory, _options.LociCount);

            Logger.WriteToLog("Starting Recalibration");

            try
            {
                QualityRecalibration.Recalibrate(_options.InputVcf, countsFile, _options.OutputDirectory, _options.BaseQNoise,
                                                 _options.ZFactor, _options.MaxQScore, _options.FilterQScore, _options.QuotedCommandLineArgumentsString);
            }
            catch (Exception e)
            {
                Logger.WriteToLog("*** Error encountered: {0}", e);
                throw e;
            }

            Logger.WriteToLog("Work complete.");
        }
Exemple #2
0
        static int Main(string[] arguments)
        {
            if (arguments.Length == 0)
            {
                ApplicationOptions.PrintUsageInfo();
                return(1);
            }

            var options = ApplicationOptions.ParseCommandLine(arguments);

            Init(options);

            if (options == null)
            {
                ApplicationOptions.PrintUsageInfo();
                return(1);
            }
            try
            {
                if (!(options.InputVcf).ToLower().EndsWith(".genome.vcf"))
                {
                    Logger.WriteToLog(">>> **Warning**: VCF supplied to Recalibration algorithms should be genome VCF. Was this the intent?");
                    Logger.WriteToLog(">>> continuing...");
                }

                Logger.WriteToLog(">>> generating counts file");
                string countsFile = Counts.WriteCountsFile(options.InputVcf, options.OutputDirectory);

                Logger.WriteToLog(">>> starting Recalibration");
                QualityRecalibration.Recalibrate(options.InputVcf, countsFile, options.BaseQNoise,
                                                 options.ZFactor, options.MaxQScore, options.FilterQScore);
            }
            catch (Exception e)
            {
                Logger.WriteToLog("*** Error encountered: {0}", e);
            }
            Logger.WriteToLog(">>> Work complete.");
            Logger.TryCloseLog();
            return(0);
        }
        Dictionary <MutationCategory, int> GetPhredScaledCalibratedRates(int baselineQNoise, double zFactor, string noiseFile)
        {
            double baseNoiseRate = MathOperations.QtoP(baselineQNoise);
            var    counts        = new Counts();

            counts.LoadCountsFile(noiseFile);
            var countsByCategory           = counts.CountsByCategory;
            var PhredScaledRatesByCategory = new Dictionary <MutationCategory, int>();

            countsByCategory.Remove(MutationCategory.Deletion);
            countsByCategory.Remove(MutationCategory.Insertion);
            countsByCategory.Remove(MutationCategory.Other);
            countsByCategory.Remove(MutationCategory.Reference);

            double[] sortedFinalCounts = countsByCategory.Values.OrderBy(d => d).ToArray();

            if (countsByCategory.Keys.Count != 12)
            {
                return(null);
            }

            //take the average value, throwing out the top two and bottom two outlyiers.
            double numDataPoints = 8; //12 - 4;
            double avg           = 0;

            for (int i = 2; i < 10; i++)
            {
                avg += (sortedFinalCounts[i] / numDataPoints);
            }

            //get the variance
            double variance = 0;

            for (int i = 2; i < 10; i++)
            {
                variance += ((avg - sortedFinalCounts[i]) * (avg - sortedFinalCounts[i]) / numDataPoints);
            }

            //threshold = avg + z * sigma
            double threshold = avg + zFactor * Math.Sqrt(variance);

            foreach (var cat in countsByCategory.Keys)
            {
                double mutationCount = countsByCategory[cat];

                if (mutationCount > threshold)
                {
                    //baseline noise level is 'b' .
                    //the observed transition-rate is how frequently we observe a vf >b.

                    //so our expected freq due to noise =
                    // (prob of observation f_i <= b) + (prob of observation f_i > b)

                    double observedNoiseRate = 0;
                    if (counts.NumPossibleVariants > 0)
                    {
                        observedNoiseRate = mutationCount / counts.NumPossibleVariants;
                    }

                    //deliberately taking floor instead of rounding.
                    PhredScaledRatesByCategory.Add(cat, (int)(MathOperations.PtoQ(observedNoiseRate + baseNoiseRate)));
                }
            }

            return(PhredScaledRatesByCategory);
        }