public void GetRelativeWeights() { var setOfClusters = CreateDefaultSetOfClusters(); var weights = setOfClusters.GetRelativeWeights(); Assert.Equal(0, weights.Count); var veadgroups = ClusterTestHelpers.GetSampleVeadGroups(); var cluster = new Cluster("test", veadgroups); setOfClusters.AddCluster(cluster); weights = setOfClusters.GetRelativeWeights(); Assert.Equal(1, weights.Count); Assert.Equal(1, weights["test"]); var veadgroups2 = ClusterTestHelpers.GetSampleVeadGroups(); var cluster2 = new Cluster("test2", veadgroups2); setOfClusters.AddCluster(cluster2); weights = setOfClusters.GetRelativeWeights(); Assert.Equal(2, weights.Count); Assert.Equal(.5, weights["test"]); Assert.Equal(.5, weights["test2"]); }
public void ReAssignWorstFit() { var setOfClusters = CreateDefaultSetOfClusters(); var veadgroups = ClusterTestHelpers.GetSampleVeadGroups(3, 1, prefix: _random.Next().ToString()); var cluster = new Cluster("test", veadgroups); setOfClusters.AddCluster(cluster); Assert.Equal(1, setOfClusters.NumClusters); Assert.Equal(3, setOfClusters.Clusters.First().NumVeads); // Only one cluster: shouldn't do anything. setOfClusters.ReAssignWorstFit(); Assert.Equal(1, setOfClusters.NumClusters); Assert.Equal(3, setOfClusters.Clusters.First().NumVeads); //TODO this does not yield expected results. See the TODO in SetOfClusters.ReassignWorstFit //// If reassigning worst leaves cluster empty, remove that cluster //var veadgroups2 = ClusterTestHelpers.GetSampleVeadGroups(1,1, prefix: _random.Next().ToString()); //var cluster2 = new Cluster("test2", veadgroups2); //setOfClusters.AddCluster(cluster2); //Assert.Equal(2, setOfClusters.NumClusters); //setOfClusters.ReAssignWorstFit(); //Assert.Equal(1, setOfClusters.NumClusters); //Assert.Equal(4, setOfClusters.Clusters.First().NumVeads); }
public void Cluster() { var veadgroups = ClusterTestHelpers.GetSampleVeadGroups(); var cluster = new Cluster("test", veadgroups); Assert.Equal("test", cluster.Name); }
public void GetVeadGroups() { var veadGroups = ClusterTestHelpers.GetSampleVeadGroups(); var cluster = new Cluster("test", veadGroups); Assert.Equal(1, cluster.GetVeadGroups().Count); }
public void AddFromList() { var initialVeadGroups = ClusterTestHelpers.GetSampleVeadGroups(); var cluster = new Cluster("test", initialVeadGroups); cluster.Add(ClusterTestHelpers.GetSampleVeadGroups(3, 2)); Assert.Equal(3, cluster.GetVeadGroups().Count); }
public void Remove() { var initialVeadGroups = ClusterTestHelpers.GetSampleVeadGroups(3, 3); var cluster = new Cluster("test", initialVeadGroups); Assert.Equal(3, cluster.GetVeadGroups().Count); cluster.Remove(initialVeadGroups.First()); Assert.Equal(2, cluster.GetVeadGroups().Count); }
public void CreateAndAddCluster() { var setOfClusters = CreateDefaultSetOfClusters(); var veadgroups = ClusterTestHelpers.GetSampleVeadGroups(); setOfClusters.CreateAndAddCluster(veadgroups.First()); Assert.Equal(1, setOfClusters.Clusters.Count()); Assert.Equal("#1", setOfClusters.Clusters.First().Name); }
public void AddCluster() { var setOfClusters = CreateDefaultSetOfClusters(); var veadgroups = ClusterTestHelpers.GetSampleVeadGroups(); var cluster = new Cluster("test", veadgroups); setOfClusters.AddCluster(cluster); Assert.Equal(1, setOfClusters.Clusters.Count()); }
public void SetCountsAtConsensusSites() { var initialVeadGroups = ClusterTestHelpers.GetSampleVeadGroups(); var cluster = new Cluster("test", initialVeadGroups); Assert.Equal(1, cluster.GetVeadGroups().Count); Assert.Equal(2, cluster.GetConsensusSites().Count()); // CountsAtSites should be same length as GetConsensusSites Assert.Equal(2, cluster.CountsAtSites.Length); Assert.Equal(new List <int>() { 4, 4 }, cluster.CountsAtSites); }
public void ResetConsensus() { var initialVeadGroups = ClusterTestHelpers.GetSampleVeadGroups(3, 3); var cluster = new Cluster("test", initialVeadGroups); Assert.Equal(3, cluster.NumVeadGroups); Assert.Equal(9, cluster.NumVeads); Assert.Equal(2, cluster.GetConsensusSites().Count()); foreach (var initialVeadGroup in initialVeadGroups.ToList()) { cluster.Remove(initialVeadGroup); } Assert.Equal(0, cluster.NumVeadGroups); Assert.Equal(0, cluster.NumVeads); Assert.Equal(0, cluster.GetConsensusSites().Count()); }
public void GetVeadCountsInCluster() { var initialVeadGroups = ClusterTestHelpers.GetSampleVeadGroups(3, 3); var cluster = new Cluster("test", initialVeadGroups); var variantSite = new VariantSite(0) { VcfReferenceAllele = "A", VcfAlternateAllele = "T" }; var variantSite2 = new VariantSite(0) { VcfReferenceAllele = "A", VcfAlternateAllele = "C" }; var sites = new List <VariantSite>() { variantSite, variantSite2 }; Assert.Equal(9, cluster.GetVeadCountsInCluster(sites)[variantSite]); Assert.Equal(0, cluster.GetVeadCountsInCluster(sites)[variantSite2]); }
public void FindBestClusterFits() { var setOfClusters = CreateDefaultSetOfClusters(); var veadgroups = ClusterTestHelpers.GetSampleVeadGroups(prefix: _random.Next().ToString()); var cluster = new Cluster("test", veadgroups); setOfClusters.AddCluster(cluster); var veadgroups2 = ClusterTestHelpers.GetSampleVeadGroups(prefix: _random.Next().ToString()); var cluster2 = new Cluster("test2", veadgroups2); setOfClusters.AddCluster(cluster2); var matchingVeadGroup = ClusterTestHelpers.GetSampleVeadGroups(useAlternateVariantSites: false, prefix: _random.Next().ToString()); var misMatchingVeadGroup = ClusterTestHelpers.GetSampleVeadGroups(useAlternateVariantSites: true, prefix: _random.Next().ToString()); var bestFits = setOfClusters.GetClusterFits(matchingVeadGroup.First()); Assert.Equal(1, bestFits.Count); Assert.Equal(2, bestFits.Keys.First()); Assert.Equal(2, bestFits[2].Count); //TODO var mismatchCluster = new Cluster("mismatch", misMatchingVeadGroup); setOfClusters.AddCluster(mismatchCluster); bestFits = setOfClusters.GetClusterFits(matchingVeadGroup.First()); foreach (var fit in bestFits) { Console.WriteLine("{0}: {1}", fit.Key, fit.Value.Count); } //Assert.Equal(2, bestFits.Count); }
public void GetBestAgreement() { var initialVeadGroups = ClusterTestHelpers.GetSampleVeadGroups(3, 1); var matchVeadGroups = ClusterTestHelpers.GetSampleVeadGroups(3, 1, false, _random.Next().ToString()); var nonMatchVeadGroups = ClusterTestHelpers.GetSampleVeadGroups(3, 1, true, _random.Next().ToString()); var cluster = new Cluster("test", initialVeadGroups); var bestAgreement = cluster.GetBestAgreementWithVeadGroup(matchVeadGroups.First(), 0); Assert.Equal(0, bestAgreement.NumDisagreement); Assert.Equal(2, bestAgreement.NumAgreement); // Since we're starting with default Agreement (0,0), will never get a bestAgreement worse than that... bestAgreement = cluster.GetBestAgreementWithVeadGroup(nonMatchVeadGroups.First(), 5); //Assert.Equal(2, bestAgreement.NumDisagreement); Assert.Equal(0, bestAgreement.NumDisagreement); Assert.Equal(0, bestAgreement.NumAgreement); // If we're over the max num disagreements, return null bestAgreement = cluster.GetBestAgreementWithVeadGroup(nonMatchVeadGroups.First(), 1); Assert.True(bestAgreement == null); }
public void RemoveCluster() { var setOfClusters = CreateDefaultSetOfClusters(); var veadgroups = ClusterTestHelpers.GetSampleVeadGroups(); var cluster = new Cluster("test", veadgroups); setOfClusters.AddCluster(cluster); var veadgroups2 = ClusterTestHelpers.GetSampleVeadGroups(); var cluster2 = new Cluster("test2", veadgroups2); setOfClusters.AddCluster(cluster2); Assert.Equal(2, setOfClusters.Clusters.Count()); setOfClusters.RemoveCluster("test"); var clustersRemaining = setOfClusters.Clusters; Assert.Equal(1, clustersRemaining.Count()); Assert.Equal("test2", clustersRemaining.First().Name); }
public void GetWorstAgreement() { var initialVeadGroups = ClusterTestHelpers.GetSampleVeadGroups(3, 1); var matchVeadGroups = ClusterTestHelpers.GetSampleVeadGroups(3, 1); var nonMatchVeadGroups = ClusterTestHelpers.GetSampleVeadGroups(3, 1, true); var cluster = new Cluster("test", initialVeadGroups); // If there's only one veadgroup, that will by default be the "worst" var worst = cluster.GetWorstAgreement(); Assert.Equal(initialVeadGroups.First(), worst); // This is a tie, they're both the same, first will go cluster.Add(matchVeadGroups); worst = cluster.GetWorstAgreement(); Assert.Equal(initialVeadGroups.First(), worst); // The non-matching group should be the worst agreement cluster.Add(nonMatchVeadGroups); worst = cluster.GetWorstAgreement(); Assert.Equal(nonMatchVeadGroups.First(), worst); }
public void RemoveWorstClusters() { //check it works with zero clusters. var setOfClusters = CreateDefaultSetOfClusters(); Assert.Equal(0, setOfClusters.NumClusters); int result = setOfClusters.RemoveWorstClusters(0); Assert.Equal(0, setOfClusters.NumClusters); Assert.Equal(0, result); result = setOfClusters.RemoveWorstClusters(2); Assert.Equal(0, setOfClusters.NumClusters); Assert.Equal(0, result); //check it works with one cluster var veadgroups = ClusterTestHelpers.GetSampleVeadGroups(); var cluster = new Cluster("test", veadgroups); setOfClusters.AddCluster(cluster); result = setOfClusters.RemoveWorstClusters(0); Assert.Equal(1, setOfClusters.NumClusters); Assert.Equal(1, result); result = setOfClusters.RemoveWorstClusters(1); Assert.Equal(0, setOfClusters.NumClusters); Assert.Equal(1, result); setOfClusters.AddCluster(cluster); Assert.Equal(1, setOfClusters.NumClusters); result = setOfClusters.RemoveWorstClusters(2); Assert.Equal(0, setOfClusters.NumClusters); Assert.Equal(1, result); //check it works with two clusters (equal clusters) setOfClusters.AddCluster(cluster); var clusterSame = new Cluster("same", veadgroups); setOfClusters.AddCluster(clusterSame); Assert.Equal(2, setOfClusters.NumClusters); result = setOfClusters.RemoveWorstClusters(0); Assert.Equal(2, setOfClusters.NumClusters); Assert.Equal(2, result); result = setOfClusters.RemoveWorstClusters(1); Assert.Equal(2, setOfClusters.NumClusters); Assert.Equal(2, result); result = setOfClusters.RemoveWorstClusters(2); Assert.Equal(0, setOfClusters.NumClusters); Assert.Equal(2, result); //check it works with two clusters (unequal clusters) //So there is one distinct worst cluster (ie, result==1). var smallnum_veadgroups = ClusterTestHelpers.GetSampleVeadGroups(numVeads: 2, numVeadGroups: 1); setOfClusters.AddCluster(cluster); var clusterSmall = new Cluster("small", smallnum_veadgroups); setOfClusters.AddCluster(clusterSmall); Assert.Equal(2, setOfClusters.NumClusters); result = setOfClusters.RemoveWorstClusters(0); Assert.Equal(2, setOfClusters.NumClusters); Assert.Equal(1, result); result = setOfClusters.RemoveWorstClusters(1); Assert.Equal(1, setOfClusters.NumClusters); Assert.Equal(1, result); setOfClusters.AddCluster(clusterSmall); Assert.Equal(2, setOfClusters.NumClusters); result = setOfClusters.RemoveWorstClusters(2); Assert.Equal(1, setOfClusters.NumClusters); Assert.Equal(1, result); //three clusters (one low, two high weighted): setOfClusters.AddCluster(clusterSmall); setOfClusters.AddCluster(clusterSame); Assert.Equal(3, setOfClusters.NumClusters); result = setOfClusters.RemoveWorstClusters(0); Assert.Equal(3, setOfClusters.NumClusters); Assert.Equal(1, result); result = setOfClusters.RemoveWorstClusters(1); Assert.Equal(2, setOfClusters.NumClusters); Assert.Equal(1, result); Assert.NotEqual("small", setOfClusters.Clusters[0].Name); Assert.NotEqual("small", setOfClusters.Clusters[1].Name); //four clusters (two low, two high weighted): setOfClusters.AddCluster(clusterSmall); var smallnum2_veadgroups = ClusterTestHelpers.GetSampleVeadGroups(numVeads: 1, numVeadGroups: 2); var clusterSmall2 = new Cluster("small2", smallnum_veadgroups); setOfClusters.AddCluster(clusterSmall2); Assert.Equal(4, setOfClusters.NumClusters); result = setOfClusters.RemoveWorstClusters(0); Assert.Equal(4, setOfClusters.NumClusters); Assert.Equal(2, result); result = setOfClusters.RemoveWorstClusters(1); Assert.Equal(4, setOfClusters.NumClusters); Assert.Equal(2, result); result = setOfClusters.RemoveWorstClusters(3); Assert.Equal(2, setOfClusters.NumClusters); Assert.Equal(2, result); result = setOfClusters.RemoveWorstClusters(1); Assert.Equal(2, setOfClusters.NumClusters); Assert.Equal(2, result); Assert.NotEqual("small", setOfClusters.Clusters[0].Name); Assert.NotEqual("small", setOfClusters.Clusters[1].Name); Assert.NotEqual("small2", setOfClusters.Clusters[0].Name); Assert.NotEqual("small2", setOfClusters.Clusters[1].Name); result = setOfClusters.RemoveWorstClusters(56); Assert.Equal(0, setOfClusters.NumClusters); Assert.Equal(2, result); }