コード例 #1
0
        private List <CalledAllele> GetNextSetOfAllelesToProcess(List <CalledAllele> leftoverAlleles,
                                                                 string thisChr, IVcfFileWriter <CalledAllele> writer)
        {
            var originalAlleles = new List <CalledAllele>();

            //if alleles are left over from the last nbhd, do them first.
            if (leftoverAlleles.Count > 0)
            {
                if (leftoverAlleles[0].Chromosome != thisChr)
                {
                    //we have already gone into the wrong chr. This cant possibly be in our nbhd.
                    //write straight to vcf.
                    writer.Write(leftoverAlleles);

                    return(GetNextSetOfAllelesToProcess(new List <CalledAllele>(), thisChr, writer));
                }
                else //they might be in our nbhd, so send them through the process
                {
                    originalAlleles.AddRange(leftoverAlleles);
                }
                leftoverAlleles = new List <CalledAllele>();
                return(originalAlleles);
            }
            else
            {
                originalAlleles = GetNextBlockOfOriginalAllelesFromVcfVar().ToList();
                return(originalAlleles);
            }
        }
コード例 #2
0
        public List <Tuple <CalledAllele, string> > WriteVariantsUptoChr(
            IVcfFileWriter <CalledAllele> writer, List <Tuple <CalledAllele, string> > alleleTuplesLeftoverList, string stopChr)
        {
            WriteDistinctVcfLines(writer, alleleTuplesLeftoverList);

            while (true)
            {
                var alleleTuplesInProcessList = GetNextBlockOfOriginalAlleleTuplesFromVcfVar();

                if (alleleTuplesInProcessList.Count == 0)
                {
                    return(new List <Tuple <CalledAllele, string> >());
                }

                if (alleleTuplesInProcessList[0].Item1.Chromosome != stopChr)
                {
                    //still not in the right nbhd
                    WriteDistinctVcfLines(writer, alleleTuplesInProcessList);
                }
                else
                {
                    return(alleleTuplesInProcessList);
                }
            }
        }
コード例 #3
0
        private List <Tuple <CalledAllele, string> > GetNextSetOfAlleleTuplesToProcess(
            IVcfFileWriter <CalledAllele> writer, List <Tuple <CalledAllele, string> > alleleTuplesLeftoverList, string thisChr)
        {
            var alleleTuplesOriginalList = new List <Tuple <CalledAllele, string> >();

            //if alleles are left over from the last nbhd, do them first.
            if (alleleTuplesLeftoverList.Count > 0)
            {
                if (alleleTuplesLeftoverList[0].Item1.Chromosome != thisChr)
                {
                    //we have already gone into the wrong chr. This cant possibly be in our nbhd.
                    //write straight to vcf.
                    WriteDistinctVcfLines(writer, alleleTuplesLeftoverList);

                    return(GetNextSetOfAlleleTuplesToProcess(writer, new List <Tuple <CalledAllele, string> >(), thisChr));
                }
                else //they might be in our nbhd, so send them through the process
                {
                    alleleTuplesOriginalList.AddRange(alleleTuplesLeftoverList);
                }
                return(alleleTuplesOriginalList);
            }
            else
            {
                alleleTuplesOriginalList = GetNextBlockOfOriginalAlleleTuplesFromVcfVar();
                return(alleleTuplesOriginalList);
            }
        }
コード例 #4
0
        public void WriteRemainingVariants(IVcfFileWriter <CalledAllele> writer, List <CalledAllele> allelesPastNbhd)
        {
            writer.Write(allelesPastNbhd);

            while (true)
            {
                var alleles = GetNextBlockOfOriginalAllelesFromVcfVar();

                if (alleles.Count() == 0)
                {
                    return;
                }

                writer.Write(alleles);
            }
        }
コード例 #5
0
        public void WriteRemainingVariants(IVcfFileWriter <CalledAllele> writer, List <Tuple <CalledAllele, string> > alleleTuplesPastNbhd)
        {
            WriteDistinctVcfLines(writer, alleleTuplesPastNbhd);

            while (true)
            {
                var alleleTuplesOriginalFromVcfVarList = GetNextBlockOfOriginalAlleleTuplesFromVcfVar();

                if (!alleleTuplesOriginalFromVcfVarList.Any())
                {
                    return;
                }

                WriteDistinctVcfLines(writer, alleleTuplesOriginalFromVcfVarList);
            }
        }
コード例 #6
0
        private void WriteDistinctVcfLines(IVcfFileWriter <CalledAllele> writer, List <Tuple <CalledAllele, string> > alleleTuples)
        {
            var distinctVcfLines = new HashSet <string>();

            foreach (var alleleTuple in alleleTuples)
            {
                if (alleleTuple.Item2 == "")
                {
                    writer.Write(new List <CalledAllele> {
                        alleleTuple.Item1
                    });
                }
                else
                {
                    if (!distinctVcfLines.Contains(alleleTuple.Item2))
                    {
                        distinctVcfLines.Add(alleleTuple.Item2);
                        writer.Write(alleleTuple.Item2);
                    }
                }
            }
        }
コード例 #7
0
        public List <CalledAllele> WriteVariantsUptoChr(IVcfFileWriter <CalledAllele> writer, List <CalledAllele> leftoverAlleles, string stopChr)
        {
            writer.Write(leftoverAlleles);

            while (true)
            {
                var allelesInProcess = GetNextBlockOfOriginalAllelesFromVcfVar().ToList();

                if (allelesInProcess == null || allelesInProcess.Count == 0)
                {
                    return(new List <CalledAllele>());
                }

                if (allelesInProcess[0].Chromosome != stopChr)
                {
                    //still not in the right nbhd
                    writer.Write(allelesInProcess);
                }
                else
                {
                    return(allelesInProcess);
                }
            }
        }
コード例 #8
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);
        }
コード例 #9
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);
        }