コード例 #1
0
        public List <CalledAllele> WriteVariantsUptoIncludingNbhd(
            IVcfNeighborhood nbhdWithMNVs,
            IVcfFileWriter <CalledAllele> writer, List <CalledAllele> leftoverAlleles)
        {
            var calledMNVs                = nbhdWithMNVs.CalledVariants;
            var allelesReadyToWrite       = new List <CalledAllele>();
            var allelesInCurrentVcfNbhd   = new List <CalledAllele>();
            var allelesToGoupWithNextNbhd = new List <CalledAllele>();

            var allelesInProcess = new List <CalledAllele>();

            int  orderWithRespectToNbhd = -1;
            bool quittingNbhd           = false;
            bool takenCareOfLeftOvers   = (leftoverAlleles.Count() == 0);

            while (true)
            {
                if (quittingNbhd)
                {
                    break;
                }

                if (takenCareOfLeftOvers)
                {
                    allelesInProcess = GetNextBlockOfOriginalAllelesFromVcfVar().ToList();
                }
                else
                {
                    allelesInProcess     = GetNextSetOfAllelesToProcess(leftoverAlleles, nbhdWithMNVs.ReferenceName, writer);
                    takenCareOfLeftOvers = true;
                }


                if (allelesInProcess.Count() == 0)
                {
                    break;
                }

                foreach (var originalAllele in allelesInProcess)
                {
                    if (quittingNbhd)
                    {
                        allelesReadyToWrite.Add(originalAllele);
                        continue;
                    }

                    orderWithRespectToNbhd = OrderWithNeighborhood(nbhdWithMNVs, originalAllele);
                    switch (orderWithRespectToNbhd)
                    {
                    case (-1):    //if we are before the nbhd, write straight to vcf
                        allelesReadyToWrite.Add(originalAllele);
                        break;

                    case (0):     //in the nbhd
                        allelesInCurrentVcfNbhd.Add(originalAllele);
                        break;

                    default:
                        //if we are either ahead of our nbhd, or gone into the wrong chr)
                        //Close out the nbhd and finish up.
                        var mergedVariants = GetMergedListOfVariants(nbhdWithMNVs, allelesInCurrentVcfNbhd);
                        allelesReadyToWrite.AddRange(mergedVariants);
                        allelesToGoupWithNextNbhd.Add(originalAllele);
                        quittingNbhd = true;
                        break;
                    }
                }
            }

            //close out any remaining nbhd
            if (orderWithRespectToNbhd == 0)
            {
                var mergedVariants = GetMergedListOfVariants(nbhdWithMNVs, allelesInCurrentVcfNbhd);
                allelesReadyToWrite.AddRange(mergedVariants);
            }

            var alleleAfterAdjustment = VcfMergerUtils.AdjustForcedAllele(allelesReadyToWrite);

            writer.Write(alleleAfterAdjustment);
            return(allelesToGoupWithNextNbhd);
        }
コード例 #2
0
        public List <Tuple <CalledAllele, string> > WriteVariantsUptoIncludingNbhd(
            IVcfFileWriter <CalledAllele> writer, List <Tuple <CalledAllele, string> > alleleTuplesLeftoverList, ICallableNeighborhood nbhdWithMNVs)
        {
            var alleleTuplesInProcessList           = new List <Tuple <CalledAllele, string> >();
            var alleleTuplesReadyToWriteList        = new List <Tuple <CalledAllele, string> >();
            var alleleTuplesInCurrentVcfNbhdList    = new List <Tuple <CalledAllele, string> >();
            var alleleTuplesToGroupWithNextNbhdList = new List <Tuple <CalledAllele, string> >();

            int  orderWithRespectToNbhd = -1;
            bool quittingNbhd           = false;
            bool takenCareOfLeftOvers   = !alleleTuplesLeftoverList.Any();

            while (true)
            {
                if (quittingNbhd)
                {
                    break;
                }

                if (takenCareOfLeftOvers)
                {
                    alleleTuplesInProcessList = GetNextBlockOfOriginalAlleleTuplesFromVcfVar();
                }
                else
                {
                    alleleTuplesInProcessList = GetNextSetOfAlleleTuplesToProcess(
                        writer, alleleTuplesLeftoverList, nbhdWithMNVs.ReferenceName);
                    takenCareOfLeftOvers = true;
                }

                if (!alleleTuplesInProcessList.Any())
                {
                    break;
                }

                foreach (var originalAlleleTuple in alleleTuplesInProcessList)
                {
                    if (quittingNbhd)
                    {
                        alleleTuplesToGroupWithNextNbhdList.Add(originalAlleleTuple);
                        continue;
                    }

                    orderWithRespectToNbhd = OrderWithNeighborhood(nbhdWithMNVs, originalAlleleTuple.Item1);
                    switch (orderWithRespectToNbhd)
                    {
                    case (-1):    //if we are before the nbhd, write straight to vcf
                        alleleTuplesReadyToWriteList.Add(originalAlleleTuple);
                        break;

                    case (0):     //in the nbhd
                        alleleTuplesInCurrentVcfNbhdList.Add(originalAlleleTuple);
                        break;

                    default:
                        //if we are either ahead of our nbhd, or gone into the wrong chr)
                        //Close out the nbhd and finish up.
                        var mergedVariants = GetMergedListOfVariants(nbhdWithMNVs, alleleTuplesInCurrentVcfNbhdList);
                        alleleTuplesReadyToWriteList.AddRange(mergedVariants);
                        alleleTuplesToGroupWithNextNbhdList.Add(originalAlleleTuple);
                        quittingNbhd = true;
                        break;
                    }
                }
            }

            //close out any remaining nbhd
            if (orderWithRespectToNbhd == 0)
            {
                var mergedVariants = GetMergedListOfVariants(nbhdWithMNVs, alleleTuplesInCurrentVcfNbhdList);
                alleleTuplesReadyToWriteList.AddRange(mergedVariants);
            }

            var alleleTuplesAfterAdjustmentList = VcfMergerUtils.AdjustForcedAllele(alleleTuplesReadyToWriteList);

            WriteDistinctVcfLines(writer, alleleTuplesAfterAdjustmentList);

            return(alleleTuplesToGroupWithNextNbhdList);
        }