示例#1
0
文件: RegionGen.cs 项目: olgatei/Di4
        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");
        }
示例#2
0
        private bool Load(string fileName)
        {
            if (!ValidateFileName(fileName, out fileName))
            {
                return(false);
            }

            _parserSTW.Restart();
            BEDParser <Peak, PeakData> bedParser = new BEDParser <Peak, PeakData>(
                source: fileName,
                species: Genomes.HomoSapiens,
                assembly: Assemblies.hg19,
                readOnlyValidChrs: true,
                startOffset: 0,
                chrColumn: UserConfig.ParserParameters.chrColumn,
                leftEndColumn: UserConfig.ParserParameters.leftEndColumn,
                rightEndColumn: UserConfig.ParserParameters.rightEndColumn,
                summitColumn: -1,
                nameColumn: UserConfig.ParserParameters.nameColumn,
                valueColumn: UserConfig.ParserParameters.valueColumn,
                strandColumn: -1,
                defaultValue: 0.01,
                pValueFormat: pValueFormat.minus10_Log10_pValue,
                dropPeakIfInvalidValue: false,
                hashFunction: HashFunction.FNV);

            try { Repository.parsedSample = bedParser.Parse(); }
            catch (Exception e)
            {
                if (Path.GetDirectoryName(fileName) + Path.DirectorySeparatorChar == _workingDirectory &&
                    Path.GetExtension(fileName) == _logFile)
                {
                    Herald.Announce(Herald.MessageType.Error, string.Format("The requested extension should not have same extension as the log file."));
                }
                else
                {
                    Herald.Announce(Herald.MessageType.Error, string.Format("{0}", e.Message));
                }
                return(false);
            }
            _parserSTW.Stop();

            _accumulatedLoadET += _parserSTW.Elapsed.TotalSeconds;
            Herald.AnnounceExeReport("Loaded", new ExecutionReport(Repository.parsedSample.intervalsCount, _parserSTW.Elapsed));

            return(true);
        }
示例#3
0
        internal static ParsedChIPseqPeaks <int, Peak, Metadata> LoadSample(string arg)
        {
            BEDParser <Peak, Metadata> bedParser =
                new BEDParser <Peak, Metadata>(
                    source: arg,
                    species: Genomes.HomoSapiens,
                    assembly: Assemblies.hg19,
                    readOnlyValidChrs: false,
                    startOffset: 0,
                    chrColumn: 0,
                    leftEndColumn: 1,
                    rightEndColumn: 2,
                    nameColumn: 3,
                    summitColumn: -1,
                    valueColumn: 4,
                    strandColumn: -1,
                    defaultValue: 0.1,
                    pValueFormat: pValueFormat.minus1_Log10_pValue,
                    dropPeakIfInvalidValue: true);

            return(bedParser.Parse());
        }