Пример #1
0
        public bool Add(CalledAllele nextVariant, string issueLogPath)
        {
            UpdateBuffer(nextVariant);

            //Check the buffer, and see if we passed an amplicon edge in our window.
            //If we did, then we are interested in this window. In particular, at the variant in the middle of it.

            if (DidWeDetectAnEdge(_testIndex, _trailingAlleleBuffer))
            {
                var AlleleOfInterest = _trailingAlleleBuffer[_testIndex];  //we keep this as a class, to do the math on

                var category = MutationCategoryUtil.GetMutationCategory(AlleleOfInterest.ReferenceAllele, AlleleOfInterest.AlternateAllele);
                NumPossibleVariants++;

                if (category != MutationCategory.Reference)
                {
                    CountsByCategory[category]++;

                    File.AppendAllText(issueLogPath, AlleleOfInterest + Environment.NewLine);


                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        public CountData()
        {
            var categories = MutationCategoryUtil.GetAllMutationCategories();

            foreach (var nucleotideTransitionCategory in categories)
            {
                CountsByCategory.Add(nucleotideTransitionCategory, 0);
            }
        }
Пример #3
0
        public bool Add(CalledAllele variant)
        {
            if (variant == null)
            {
                return(false);
            }

            var category = MutationCategoryUtil.GetMutationCategory(variant);

            NumPossibleVariants++;

            if (category != MutationCategory.Reference)
            {
                CountsByCategory[category]++;

                return(true);
            }


            return(false);
        }
        /// <summary>
        /// This is a pretty naive reader. The mutation categories must be listed first, and the rates must be listed last, or the parsing fails.
        /// There are some hard coded strings. Yes, maybe it should be in json.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static CountData ReadCountsFile(string file)
        {
            CountData variantCounts = new CountData();
            bool      inRateSection = false;

            using (StreamReader sr = new StreamReader(new FileStream(file, FileMode.Open)))
            {
                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 IOException("Unable to parse counts from noise file " + file);
                        }

                        string firstWord = splat[0];
                        switch (firstWord)
                        {
                        case "AllPossibleVariants":
                            variantCounts.NumPossibleVariants += result;
                            break;

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

                        default:

                            //if its a mutation category - do something. Else do nothing
                            if (MutationCategoryUtil.IsValidCategory(firstWord))
                            {
                                MutationCategory category = MutationCategoryUtil.GetMutationCategory(firstWord);

                                //this category should always exist. this is just defensive
                                if (!variantCounts.CountsByCategory.ContainsKey(category))
                                {
                                    variantCounts.CountsByCategory.Add(category, 0);
                                    Logger.WriteWarningToLog("This counts file found a mutation category listed that this version of VQR is not aware of, and cannot process. Please check " + firstWord);
                                }

                                variantCounts.CountsByCategory[category] += result;
                            }
                            break;
                        }
                    }
                    if (line.Contains("CountsByCategory"))
                    {
                        inRateSection = true;
                    }
                }
            }

            return(variantCounts);
        }