public void TestMergeSegments() { // Construct several segments, and invoke CanvasSegment.MergeSegments, and ensure that the expected // merges (and no others) occurred. List <CanvasSegment> allSegments = new List <CanvasSegment>(); List <SampleGenomicBin> counts = new List <SampleGenomicBin>(); // Chr1 gets five segments and we should merge to three: CanvasSegment seg = new CanvasSegment("chr1", 1000000, 2000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); seg = new CanvasSegment("chr1", 2000000, 2000100, counts); seg.CopyNumber = 3; allSegments.Add(seg); seg = new CanvasSegment("chr1", 2000100, 3000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); seg = new CanvasSegment("chr1", 3000000, 3100000, counts); seg.CopyNumber = 3; allSegments.Add(seg); seg = new CanvasSegment("chr1", 3100000, 4000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); // Chr2 gets segments with a large gap between, so can't merge: seg = new CanvasSegment("chr2", 1000000, 2000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); seg = new CanvasSegment("chr2", 3000000, 3000100, counts); seg.CopyNumber = 3; allSegments.Add(seg); seg = new CanvasSegment("chr2", 4000000, 5000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); // Chr3 has three segments that all merge to 1 big one: seg = new CanvasSegment("chr3", 1000000, 2000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); seg = new CanvasSegment("chr3", 2000000, 3000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); seg = new CanvasSegment("chr3", 3000000, 4000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); var mergedSegments = CanvasSegment.MergeSegments(allSegments, 50000, 10000); var segmentsByChromosome = CanvasSegment.GetSegmentsByChromosome(mergedSegments); Assert.Equal(3, segmentsByChromosome["chr1"].Count); Assert.Equal(3, segmentsByChromosome["chr2"].Count); Assert.Single(segmentsByChromosome["chr3"]); }
public void TestMergeSegments() { // Construct several segments, and invoke CanvasSegment.MergeSegments, and ensure that the expected // merges (and no others) occurred. List <CanvasSegment> allSegments = new List <CanvasSegment>(); List <float> counts = new List <float>(); // Chr1 gets five segments and we should merge to three: CanvasSegment seg = new CanvasSegment("chr1", 1000000, 2000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); seg = new CanvasSegment("chr1", 2000000, 2000100, counts); seg.CopyNumber = 3; allSegments.Add(seg); seg = new CanvasSegment("chr1", 2000100, 3000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); seg = new CanvasSegment("chr1", 3000000, 3100000, counts); seg.CopyNumber = 3; allSegments.Add(seg); seg = new CanvasSegment("chr1", 3100000, 4000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); // Chr2 gets segments with a large gap between, so can't merge: seg = new CanvasSegment("chr2", 1000000, 2000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); seg = new CanvasSegment("chr2", 3000000, 3000100, counts); seg.CopyNumber = 3; allSegments.Add(seg); seg = new CanvasSegment("chr2", 4000000, 5000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); // Chr3 has three segments that all merge to 1 big one: seg = new CanvasSegment("chr3", 1000000, 2000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); seg = new CanvasSegment("chr3", 2000000, 3000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); seg = new CanvasSegment("chr3", 3000000, 4000000, counts); seg.CopyNumber = 2; allSegments.Add(seg); CanvasSegment.MergeSegments(ref allSegments, 50000, 10000); Dictionary <string, List <CanvasSegment> > segmentsByChromosome = CanvasSegment.GetSegmentsByChromosome(allSegments); Assert.AreEqual(segmentsByChromosome["chr1"].Count, 3); Assert.AreEqual(segmentsByChromosome["chr2"].Count, 3); Assert.AreEqual(segmentsByChromosome["chr3"].Count, 1); }