Example #1
0
        public int[] DepthAtSites(IEnumerable <ICluster> clusters)
        {
            var depthAtSites = new int[0];
            var veadgroups   = clusters.SelectMany(x => x.GetVeadGroups());

            return(VeadGroup.DepthAtSites(veadgroups));
        }
Example #2
0
        public Agreement(VeadGroup vg1, VeadGroup vg2) : this()
        {
            var read1 = vg1.RepresentativeVead;
            var read2 = vg2.RepresentativeVead;

            for (var i = 0; i < read1.SiteResults.Length; i++)
            {
                var vs1 = read1.SiteResults[i];
                var vs2 = read2.SiteResults[i];

                if ((vs1.VcfAlternateAllele == "N") || (vs2.VcfAlternateAllele == "N"))
                {
                    continue;
                }

                if ((vs1.VcfAlternateAllele == vs2.VcfAlternateAllele) && (vs1.VcfReferenceAllele == vs2.VcfReferenceAllele))
                {
                    NumAgreement++;
                }

                else
                {
                    NumDisagreement++;
                }
            }
        }
Example #3
0
        public void CreateAndAddCluster(VeadGroup veadGroup)
        {
            var clusterName = "#" + (NumClusters + 1);
            var cluster     = new Cluster(clusterName, new List <VeadGroup> {
                veadGroup
            });

            AddCluster(cluster);
        }
Example #4
0
        public void Add(VeadGroup vg, bool updateConsensus = true)
        {
            _veadGroups.Add(vg);

            if (!Closed && updateConsensus)
            {
                UpdateConsensus(vg);
            }
        }
Example #5
0
        private void UpdateConsensus(VeadGroup rg)
        {
            if (_consensus == null)
            {
                return;
            }

            //TODO why would you ever have more known refs than alts or vice versa?
            VeadGroupMerger.MergeProfile1Into2(rg.SiteResults, _consensus.SiteResults);

            _numKnownRef = _consensus.SiteResults.Count(s => s.HasRefData());
            _numKnownAlt = _consensus.SiteResults.Count(s => s.HasAltData());
        }
Example #6
0
        public SortedDictionary <int, List <Cluster> > GetClusterFits(VeadGroup r1)
        {
            var bestFits = new SortedDictionary <int, List <Cluster> >();

            for (var clusterIndex = 0; clusterIndex < NumClusters; clusterIndex++)
            {
                var cluster = Clusters[clusterIndex];

                var bestAgreementWithThiscluster = cluster.GetBestAgreementWithVeadGroup(r1, _clusterParameters.MaxNumberDisagreements);

                //not allowed to connect this read!
                if (!AgreementIsSufficient(bestAgreementWithThiscluster, _clusterParameters.MaxNumberDisagreements, _clusterParameters.MinNumberAgreements))
                {
                    continue;
                }

                if (!bestFits.ContainsKey(bestAgreementWithThiscluster.Score))
                {
                    bestFits.Add(bestAgreementWithThiscluster.Score, new List <Cluster>());
                }

                bestFits[bestAgreementWithThiscluster.Score].Add(cluster);

                if ((bestFits.Count <= 1) && (bestFits[bestAgreementWithThiscluster.Score].Count <= 1))
                {
                    continue;
                }

                //TODO, when debug enabled.

                /*
                 * WriteToClusterLog("investigate!!");
                 * WriteToClusterLog("found a read that can join two clusters!");
                 * WriteToClusterLog("read group: " + r1.ToString());
                 * WriteToClusterLog("bestFits.Count: " + bestFits.Count);
                 * WriteToClusterLog("num best scoring : " + bestFits[bestAgreementWithThiscluster.Score].Count);
                 *
                 * foreach (var c in bestFits[bestAgreementWithThiscluster.Score])
                 * {
                 *  WriteToClusterLog("\t" + c.Name);
                 * }*/
            }

            return(bestFits);
        }
Example #7
0
        private Agreement GetAgreementWithCluster(VeadGroup v1)
        {
            var netAgreement = new Agreement();

            for (var i = 0; i < NumVeadGroups; i++)
            {
                var v2 = _veadGroups[i];

                if (v1 == v2)
                {
                    continue;
                }

                var a = new Agreement(v1, v2);
                netAgreement.AddAgreement(a);
            }

            return(netAgreement);
        }
Example #8
0
        public void ResetConsensus()
        {
            _consensus   = null;
            _numKnownAlt = 0;
            _numKnownRef = 0;

            if ((_veadGroups == null) || (_veadGroups.Count == 0))
            {
                return;
            }

            var vead = new Vead(Name, _veadGroups[0].SiteResults);

            _consensus = new VeadGroup(vead);

            foreach (var rg in _veadGroups.Where(rg => !Closed))
            {
                UpdateConsensus(rg);
            }
        }
Example #9
0
        public Agreement GetBestAgreementWithVeadGroup(VeadGroup newVeadGroup, int maxNumberDisagreements)
        {
            var bestAgreement = new Agreement();

            foreach (var agreement in _veadGroups.Where(vg => newVeadGroup.Name != vg.Name).
                     Select(vg => new Agreement(newVeadGroup, vg)))
            {
                //we disagree with something in the cluster already.
                if (agreement.NumDisagreement > maxNumberDisagreements)
                {
                    return(null);
                }

                if (agreement.CompareTo(bestAgreement) > 0)
                {
                    bestAgreement = agreement;
                }
            }

            return(bestAgreement);
        }
Example #10
0
        public VeadGroup GetWorstAgreement()
        {
            // There will always be a "worst" unless there are no vead groups...

            VeadGroup worstVeadGroup = null;
            var       worstAgreement = new Agreement {
                NumAgreement = int.MaxValue, NumDisagreement = 0
            };

            for (var i = 0; i < NumVeadGroups; i++)
            {
                var agreementWithCluster = GetAgreementWithCluster(_veadGroups[i]);

                if (agreementWithCluster.CompareTo(worstAgreement) >= 0)
                {
                    continue;
                }

                worstAgreement = agreementWithCluster;
                worstVeadGroup = _veadGroups[i];
            }

            return(worstVeadGroup);
        }
Example #11
0
        public void DepthAtSites(IEnumerable <ICluster> clusters, out int[] depths, out int[] nocalls)
        {
            var veadgroups = clusters.SelectMany(x => x.GetVeadGroups());

            VeadGroup.DepthAtSites(veadgroups, out depths, out nocalls);
        }
Example #12
0
 public void Remove(VeadGroup vg)
 {
     _veadGroups.Remove(vg);
     ResetConsensus();
 }
Example #13
0
        public int GetClusterReferenceSupport(IEnumerable <ICluster> clusters)
        {
            var clusterVead = new Vead("test", GetConsensusSites());
            var numRef      = 0;

            foreach (VariantSite vs in clusterVead.SiteResults)
            {
                // Nima: If cluster contains reference or X>X at this site, this site won't be included in the MNV.
                // So veads that support reference for this cluster can hold any variant at these sites (hence using N>N).
                // In the following example, cluster reference support for Cluster3 includes both Cluster1 and Cluster4
                //---------------------------------------
                //      Sites       S1      S2      S3
                //      Cluster1    R       R       R
                //      Cluster2    R       R       X
                //      Cluster3    R       X       X
                //      Cluster4    X       R       R
                //----------------------------------------
                //Cluster3's refVead N>N    R>R     R>R
                //
                // However, if the cluster is all ref we should avoid all N>N, and instead have the original R>R
                // In example above:
                //Cluster1's refVead R>R    R>R     R>R
                if (vs.IsReference || vs.VcfAlternateAllele == vs.VcfReferenceAllele)
                {
                    vs.VcfReferenceAllele = "N";
                    vs.VcfAlternateAllele = "N";
                    if (vs.IsReference)
                    {
                        numRef++;
                    }
                }
                else  // If cluster contains a variant at this site, ref veads need to contain ref>ref at this site.
                {
                    vs.VcfReferenceAllele = vs.VcfReferenceAllele[0].ToString();
                    vs.VcfAlternateAllele = vs.VcfReferenceAllele;
                }
            }
            var refVead = clusterVead;

            // Check if all variants were reference, assign original consensus to refVead
            if (numRef == clusterVead.SiteResults.Count())
            {
                refVead = new Vead("test", GetConsensusSites());
            }

            var clusterRefVeadGroup = new VeadGroup(refVead);


            var numVariants      = clusterRefVeadGroup.NumSitesPerVead;
            var cluterRefSupport = 0;

            foreach (var cls in clusters)
            {
                List <VeadGroup> vgs = cls.GetVeadGroups();
                foreach (var vg in vgs)
                {
                    var agreement = new Agreement(vg, clusterRefVeadGroup);
                    if (agreement.NumDisagreement == 0 &&
                        agreement.NumAgreement >= numVariants)
                    {
                        cluterRefSupport += vg.NumVeads;
                    }
                }
            }
            return(cluterRefSupport);
        }