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);
        }
Esempio n. 2
0
        private static List <CalledAllele> WhatToDoToAlleles(VcfConsumerAppOptions options, T recalibrationData, UpdateSingleAlleleMethod whatToDoWithAllele,
                                                             UpdateCoLocatedAllelesMethod whatToDoWithCoLocatedAlleles, List <CalledAllele> variantListFromFile, ref bool updateNeeded)
        {
            //do any loci-wide actions
            var modifiedAsAGroup = new List <CalledAllele>()
            {
            };
            TypeOfUpdateNeeded updateneededForLoci = whatToDoWithCoLocatedAlleles(options, recalibrationData, variantListFromFile, out modifiedAsAGroup);

            updateNeeded = (updateneededForLoci != TypeOfUpdateNeeded.NoChangeNeeded);

            //do any per-individual allele actions on the new list
            var modifiedAsIndividualAlleles = new List <CalledAllele>()
            {
            };

            foreach (var calledAllele in modifiedAsAGroup)
            {
                var convertedVariants = new List <CalledAllele>()
                {
                };
                TypeOfUpdateNeeded updateneededForAllele = whatToDoWithAllele(options, recalibrationData, calledAllele, out convertedVariants);
                updateNeeded = updateNeeded || (updateneededForAllele != TypeOfUpdateNeeded.NoChangeNeeded);

                if (updateneededForAllele != TypeOfUpdateNeeded.DeleteCompletely)
                {
                    modifiedAsIndividualAlleles.AddRange(convertedVariants);
                }
            }

            return(modifiedAsIndividualAlleles);
        }
Esempio n. 3
0
 /// <summary>
 /// This method determines what to actually write out.
 /// </summary>
 public static TypeOfUpdateNeeded GetTypeOfUpdate(AdaptiveGtOptions options, List <CalledAllele> alleles,
                                                  TypeOfUpdateNeeded defaultUpdate, out List <CalledAllele> outGoingAlleles)
 {
     if (!options.VcfWritingParams.OutputGvcfFile &&
         alleles[0].Genotype == Genotype.HomozygousRef ||
         alleles[0].Genotype == Genotype.RefLikeNoCall)
     {
         outGoingAlleles = new List <CalledAllele>(); // Empty list because we don't want to output anything
         return(TypeOfUpdateNeeded.DeleteCompletely);
     }
     else
     {
         outGoingAlleles = alleles;
         return(defaultUpdate);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Take in a vcf, do stuff to it, write out a vcf. Streamed line by line, loci by loci, so as not to blow up your computer.
        /// </summary>
        /// <param name="vcfOut"> the output file name</param>
        /// <param name="options"> all the parameters associated with writing out a vcf</param>
        /// <param name="recalibrationData">the data you need for doing your "stuff" </param>
        /// <param name="whatToDoWithSingleAllele">how you want to change each allele</param>
        /// <param name="whatToDoWithCoLocatedAlleles">how you want to change each set of alleles, by loci</param>
        /// <param name="canSkipLinesWithoutProcessing">when you can skip lines (saves CPU time)</param>
        /// <param name="getVcfFileWriter">what your special vcf writer should be, includes special header lines, etc</param>
        /// <param name="shouldTrimComplexAlleles">if ACGT-> ACCT is ok, or if you want it trimmed to G -> C. this might affect position and ordering. Generally turn if OFF for processing vcfs, post scylla. </param>
        private static void UpdateVcf(string vcfOut, VcfConsumerAppOptions options, bool shouldTrimComplexAlleles, T recalibrationData,
                                      UpdateSingleAlleleMethod whatToDoWithSingleAllele, UpdateCoLocatedAllelesMethod whatToDoWithCoLocatedAlleles,
                                      CanSkipVcfLinesMethod canSkipLinesWithoutProcessing, GetVcfFileWriter getVcfFileWriter)
        {
            using (AlleleReader reader = new AlleleReader(options.VcfPath, shouldTrimComplexAlleles))
            {
                using (VcfFileWriter writer = getVcfFileWriter(options, vcfOut))
                {
                    writer.WriteHeader();
                    writer.FlushBuffer();

                    var variantListFromFile = new List <CalledAllele>()
                    {
                    };

                    string incomingHangingLine = null;
                    string outgoingHangingLine = null;

                    while (true)
                    {
                        //get the next group to process
                        incomingHangingLine = outgoingHangingLine;
                        var coLocatedVcfLinesToProcess = reader.CloseColocatedLines(incomingHangingLine,
                                                                                    out outgoingHangingLine);

                        //how we know we are done
                        if (coLocatedVcfLinesToProcess.Count == 0)
                        {
                            break;
                        }

                        bool updateNeededForLocus = false;
                        TypeOfUpdateNeeded updatedNeededForLine = canSkipLinesWithoutProcessing(coLocatedVcfLinesToProcess);

                        switch (updatedNeededForLine)
                        {
                        case TypeOfUpdateNeeded.NoChangeNeeded:
                            writer.Write(coLocatedVcfLinesToProcess);
                            break;

                        case TypeOfUpdateNeeded.Modify:
                            //then we need to change them into alleles and do stuff to them
                            variantListFromFile = AlleleReader.VcfLinesToAlleles(coLocatedVcfLinesToProcess);
                            List <CalledAllele> modifiedVariantListToWrite = WhatToDoToAlleles(options, recalibrationData,
                                                                                               whatToDoWithSingleAllele, whatToDoWithCoLocatedAlleles, variantListFromFile, ref updateNeededForLocus);

                            if (updateNeededForLocus)
                            {
                                writer.Write(modifiedVariantListToWrite);
                            }
                            else
                            {
                                writer.Write(coLocatedVcfLinesToProcess);
                            }
                            break;

                        case TypeOfUpdateNeeded.DeleteCompletely:
                        default:
                            break;
                        }
                    }
                }
            }
        }