private void CreateShuffleRegions(string folderPath) { if (!Directory.Exists(folderPath + "sorted" + dirSep)) { Directory.CreateDirectory(folderPath + "sorted" + dirSep); } using (FileStream fs = new FileStream(folderPath + "sorted" + dirSep + "TESTONLY" + "." + filesExtension, FileMode.Append, FileAccess.Write)) using (StreamWriter sw = new StreamWriter(fs)) foreach (var coordinate in generatedCoordinatesFORTESTONLY) { sw.WriteLine(coordinate.Key.ToString() + "\t" + coordinate.Value.ToString()); } Console.WriteLine("Writing shuffled files."); string randomChr = null; char randomStrand = 'V'; int randomRegion = 0; Peak peak = null; var dirInfo = new DirectoryInfo(folderPath + dirSep + "sorted"); FileInfo[] determinedFiles = dirInfo.GetFiles("*." + filesExtension); foreach (FileInfo fileInfo in determinedFiles) { Console.WriteLine(string.Format("Now writing: {0}", Path.GetFileNameWithoutExtension(fileInfo.FullName))); BEDParser <Peak, PeakData> bedParser = new BEDParser <Peak, PeakData>(fileInfo.FullName, Genomes.HomoSapiens, Assemblies.hg19, true); var parsedSample = bedParser.Parse(); var intervals = parsedSample.intervals; if (!Directory.Exists(folderPath + "shuffled" + dirSep)) { Directory.CreateDirectory(folderPath + "shuffled" + dirSep); } using (FileStream fs = new FileStream(folderPath + "shuffled" + dirSep + Path.GetFileNameWithoutExtension(fileInfo.FullName) + "." + filesExtension, FileMode.Append, FileAccess.Write)) using (StreamWriter sw = new StreamWriter(fs)) while (intervals.Count > 0) { randomChr = intervals.ElementAt(rnd.Next(0, intervals.Count)).Key; randomStrand = intervals[randomChr].ElementAt(rnd.Next(0, intervals[randomChr].Count)).Key; randomRegion = rnd.Next(0, intervals[randomChr][randomStrand].Count); peak = intervals[randomChr][randomStrand][randomRegion]; sw.WriteLine(randomChr + "\t" + peak.ToString("\t") + "\t" + randomStrand); intervals[randomChr][randomStrand].RemoveAt(randomRegion); if (intervals[randomChr][randomStrand].Count == 0) { intervals[randomChr].Remove(randomStrand); } if (intervals[randomChr].Count == 0) { intervals.Remove(randomChr); } } } Console.WriteLine("Done"); }