private static List <OverlappingSegmentsRegion> GetSegmentSets(int defaultAlleleCountThreshold, Dictionary <string, List <BedEntry> > commonRegions, Dictionary <string, IReadOnlyList <SampleGenomicBin> > genomicBinsByChromosome, Dictionary <string, List <BedInterval> > segmentIntervalsByChromosome, Dictionary <string, List <Balleles> > allelesByChromosomeCommonSegs, Segments segments) { var segmentsSetByChromosome = new ConcurrentDictionary <string, List <OverlappingSegmentsRegion> >(); Parallel.ForEach( segments.GetChromosomes(), chr => { var segmentsByChromosome = segments.GetSegmentsForChromosome(chr).ToList(); if (commonRegions.Keys.Any(chromosome => chromosome == chr)) { var commonCnvCanvasSegments = CanvasSegment.CreateSegmentsFromCommonCnvs(genomicBinsByChromosome[chr], segmentIntervalsByChromosome[chr], allelesByChromosomeCommonSegs[chr]); segmentsSetByChromosome[chr] = CanvasSegment.MergeCommonCnvSegments(segmentsByChromosome, commonCnvCanvasSegments, defaultAlleleCountThreshold); } else { segmentsSetByChromosome[chr] = segmentsByChromosome.Select( segment => new OverlappingSegmentsRegion(new List <CanvasSegment> { segment }, null)).ToList(); } }); return(segmentsSetByChromosome.OrderBy(i => i.Key).Select(x => x.Value).SelectMany(x => x).ToList()); }