Exemplo n.º 1
0
        public override void Write(IEnumerable <CalledAllele> calledAlleles, IRegionMapper mapper = null)
        {
            //this is a cheap hack, to be removed as soon as I merge another change.
            var comparer       = new AlleleComparer();
            var sortedVariants = calledAlleles.OrderBy(a => a, comparer).ThenBy(a => a.Reference).ThenBy(a => a.Alternate);

            base.Write(sortedVariants);
        }
Exemplo n.º 2
0
        public static List <CalledAllele> GetMergedListOfVariants(IVcfNeighborhood completedNbhd, List <CalledAllele> originalVariantsInsideRange)
        {
            var mergedVariantList = new List <CalledAllele>();
            Dictionary <int, List <CalledAllele> > foundMNVS = completedNbhd.CalledVariants;

            //track which variants got used for MNV phasing.
            var indexesOfVariantsRecalledByMnvCaller = completedNbhd.GetOriginalVcfVariants();

            //decide which of the original variants we keep, and which get replaced.
            for (int i = 0; i < originalVariantsInsideRange.Count; i++)
            {
                var  originalCall          = originalVariantsInsideRange[i];
                var  currentPosition       = originalCall.Coordinate;
                bool variantWasAlreadyUsed = CheckIfUsed(indexesOfVariantsRecalledByMnvCaller, originalCall);

                if (foundMNVS.ContainsKey(currentPosition))
                {
                    //add all the MNVs
                    mergedVariantList.AddRange(foundMNVS[currentPosition]);
                    foundMNVS[currentPosition] = new List <CalledAllele>();//empty out the list, but leave the fact that there were MNVs here.

                    //add back any original variants,
                    //so long as they were not used by the caller, and not reference
                    if (!(variantWasAlreadyUsed) &&
                        (originalCall.Type != Pisces.Domain.Types.AlleleCategory.Reference))
                    {
                        mergedVariantList.Add(originalCall);
                    }

                    continue;
                }

                //Else, we did not find any MNVs here.
                //Then this position should be either the original call from the vcf,
                //or a new reference call converted from a variant that got used by the MNV caller.
                if (variantWasAlreadyUsed)
                {
                    var newRef = completedNbhd.CalledRefs[originalCall.Coordinate];

                    //sometimes several variants were used, all at the same position. we dont need to add new references for all of them.
                    if ((mergedVariantList.Count == 0) || (mergedVariantList.Last().Coordinate != currentPosition))
                    {
                        mergedVariantList.Add(newRef);
                    }
                }
                else //wasnt used for MNV calling
                {
                    mergedVariantList.Add(originalVariantsInsideRange[i]);
                }
            }

            //incase we called any MNVs past the edge of the input VCF.
            foreach (var mnvsLeft in foundMNVS)
            {
                mergedVariantList.AddRange(mnvsLeft.Value);
            }

            var comparer = new AlleleComparer();

            mergedVariantList.Sort(comparer);


            return(mergedVariantList);
        }