public static void CheckSegment(SegmentWithBins segment, int expectedStart, int expectedEnd, double expectedMedCoverage, int expectedCount) { Assert.Equal((uint)expectedStart, segment.Start); Assert.Equal((uint)expectedEnd, segment.End); Assert.Equal(expectedMedCoverage, segment.MedianCoverage); Assert.Equal(expectedCount, segment.Bins.Count); }
public void AddBinTest() { var bin1 = new Bin(100, 2000, 10d); var bin2 = new Bin(2500, 3000, 5d); var bin3 = new Bin(5000, 8000, 45d); var segmentWithBins = new SegmentWithBins(1, bin1); SegmentTestHelpers.CheckSegment(segmentWithBins, 100, 2000, 10, 1); segmentWithBins.AddBin(bin2); SegmentTestHelpers.CheckSegment(segmentWithBins, 100, 3000, 7.5, 2); segmentWithBins.AddBin(bin3); SegmentTestHelpers.CheckSegment(segmentWithBins, 100, 8000, 10, 3); // Order they are added in should not affect final result segmentWithBins = new SegmentWithBins(1, bin1); segmentWithBins.AddBin(bin3); segmentWithBins.AddBin(bin2); SegmentTestHelpers.CheckSegment(segmentWithBins, 100, 8000, 10, 3); }
public Dictionary <string, List <SegmentWithBins> > PostProcessSegments( GenomeSegmentationResults segmentationResults, PloidyInfo referencePloidy, Dictionary <string, List <SampleGenomicBin> > excludedIntervals, CoverageInfo coverageInfo) { var starts = new Dictionary <string, bool>(); var stops = new Dictionary <string, bool>(); foreach (string chr in segmentationResults.SegmentByChr.Keys) { for (int segmentIndex = 0; segmentIndex < segmentationResults.SegmentByChr[chr].Length; segmentIndex++) { var segment = segmentationResults.SegmentByChr[chr][segmentIndex]; starts[chr + ":" + segment.start] = true; stops[chr + ":" + segment.end] = true; } } int segmentNum = -1; var segmentsByChromosome = new Dictionary <string, List <SegmentWithBins> >(); foreach (string chr in coverageInfo.StartByChr.Keys) { segmentsByChromosome.Add(chr, new List <SegmentWithBins>()); SegmentWithBins currentSegment = null; List <SampleGenomicBin> excludeIntervals = null; if (excludedIntervals.ContainsKey(chr)) { excludeIntervals = excludedIntervals[chr]; } var excludeIndex = 0; // Points to the first interval which *doesn't* end before our current position uint previousBinEnd = 0; for (int binIndex = 0; binIndex < coverageInfo.StartByChr[chr].Length; binIndex++) { uint start = coverageInfo.StartByChr[chr][binIndex]; uint end = coverageInfo.EndByChr[chr][binIndex]; bool newSegment = IsNewSegment(starts, chr, excludeIntervals, previousBinEnd, end, start, ref excludeIndex, referencePloidy); var bin = new Bin(start, end, coverageInfo.CoverageByChr[chr][binIndex]); if (newSegment) { segmentNum++; currentSegment = new SegmentWithBins(segmentNum, bin); segmentsByChromosome[chr].Add(currentSegment); } else { if (currentSegment == null) { currentSegment = new SegmentWithBins(segmentNum, bin); segmentsByChromosome[chr].Add(currentSegment); } else { currentSegment.AddBin(bin); } } previousBinEnd = end; } } return(segmentsByChromosome); }