Exemplo n.º 1
0
        private bool AccumulationHistogram(string[] args)
        {
            if (args.Length != 2 && args.Length != 3)
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                return(false);
            }

            if (args.Length == 3 && !ParseMux(args[2]))
            {
                return(false);
            }

            string resultFile = "";

            if (!ExtractResultsFile(args[1], out resultFile))
            {
                return(false);                                              // invalid file URI.
            }
            ConcurrentDictionary <string, ConcurrentDictionary <char, List <AccEntry <int> > > > results;

            Herald.AnnounceExeReport("AccHistogram", di4B.AccumulationHistogram(out results, _maxDegreeOfParallelism));
            Herald.AnnounceExeReport("Export", Exporter.Export(resultFile, results, "chr\tleft\tright\taccumulation\tstrand", mux: _mux));
            return(true);
        }
Exemplo n.º 2
0
        private bool tmpLoadVCF(string fileName)
        {
            if (!ValidateFileName(fileName, out fileName))
            {
                return(false);
            }

            _parserSTW.Restart();

            VCFParser <Variant, VariantData> vcfParser = new VCFParser <Variant, VariantData>(source: fileName, species: Genomes.HomoSapiens, assembly: Assemblies.hg19);

            try { Repository.parsedVariants = vcfParser.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.parsedVariants.intervalsCount, _parserSTW.Elapsed));

            return(true);
        }
Exemplo n.º 3
0
        private bool Statistics(string[] args)
        {
            if (args.Length != 2)
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                return(false);
            }

            string resultFile = "";

            if (!ExtractResultsFile(args[1], out resultFile))
            {
                return(false);                                              // invalid file URI.
            }
            SortedDictionary <int, int> result = new SortedDictionary <int, int>();

            Herald.AnnounceExeReport("Statistics", di4B.LambdaSizeStats(out result));

            using (StreamWriter writer = new StreamWriter(resultFile))
            {
                writer.WriteLine("Lambda Size\tCount");
                foreach (var item in result)
                {
                    writer.WriteLine("{0}\t{1}", item.Key, item.Value);
                }
            }



            return(true);
        }
Exemplo n.º 4
0
        public bool Cover(string[] args)
        {
            if (args.Length < 6)
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Missing parameter."));
                return(false);
            }

            char   strand;
            int    minAcc, maxAcc;
            string coverOrSummit = args[0].ToLower();

            string resultFile = "";

            if (!ExtractResultsFile(args[1], out resultFile))
            {
                return(false);                                              // invalid file URI.
            }
            if (!char.TryParse(args[2], out strand))
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid strand parameter."));
                return(false);
            }
            if (!int.TryParse(args[3], out minAcc))
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid minimum accumulation parameter."));
                return(false);
            }
            if (!int.TryParse(args[4], out maxAcc))
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid maximum accumulation parameter."));
                return(false);
            }

            Aggregate agg = Aggregate.Count;

            if (!String2Aggregate(args[5], out agg))
            {
                return(false);
            }

            FunctionOutput <Output <int, Peak, PeakData> > result = null;

            switch (coverOrSummit)
            {
            case "cover":
                Herald.AnnounceExeReport("Cover", di4B.Cover(CoverVariation.Cover, strand, minAcc, maxAcc, agg, out result, _maxDegreeOfParallelism), Herald.SpeedUnit.bookmarkPerSecond);
                break;

            case "summit":
                Herald.AnnounceExeReport("Summit", di4B.Cover(CoverVariation.Summit, strand, minAcc, maxAcc, agg, out result, _maxDegreeOfParallelism), Herald.SpeedUnit.bookmarkPerSecond);
                break;
            }

            Herald.AnnounceExeReport("Export", Exporter.Export(resultFile, result, "chr\tleft\tright\tcount\tstrand"));

            return(true);
        }
Exemplo n.º 5
0
        public bool Index2ndResolution(string[] args)
        {
            if (args.Length < 2)
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                return(false);
            }

            int           binCount      = 0;
            CuttingMethod cuttingMethod = CuttingMethod.ZeroThresholding;

            switch (args[1].ToLower())
            {
            case "zt":
            case "zerothresholding":
                cuttingMethod = CuttingMethod.ZeroThresholding;
                break;

            case "uq":
            case "uniformscalarquantization":
                cuttingMethod = CuttingMethod.UniformScalarQuantization;
                if (args.Length != 3)
                {
                    Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                    return(false);
                }
                if (!int.TryParse(args[2], out binCount))
                {
                    Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                    return(false);
                }
                break;

            case "nuq":
            case "nonuniformscalarquantization":
                cuttingMethod = CuttingMethod.NonUniformScalarQuantization;
                if (args.Length != 3)
                {
                    Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                    return(false);
                }
                if (!int.TryParse(args[2], out binCount))
                {
                    Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                    return(false);
                }
                break;

            default:
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                return(false);
            }

            Herald.AnnounceExeReport("2RIndex", di4B.SecondResolutionIndex(cuttingMethod, binCount, _maxDegreeOfParallelism), speedUnit: Herald.SpeedUnit.blockPerSecond);
            return(true);
        }
Exemplo n.º 6
0
        private void BenchmarkAccHis()
        {
            int tries = 20;
            ConcurrentDictionary <string, ConcurrentDictionary <char, List <AccEntry <int> > > > results;

            for (int i = 0; i < tries; i++)
            {
                Herald.AnnounceExeReport("Run_" + i, di4B.AccumulationHistogram(out results, _maxDegreeOfParallelism));
            }
        }
Exemplo n.º 7
0
        private bool Index(string[] args)
        {
            if (args.Length != 2)
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Missing arguments."));
                return(false);
            }

            if (Path.GetExtension(args[1]) == ".vcf")
            {
                if (!tmpLoadVCF(args[1]))
                {
                    return(false);
                }

                var tmp = new Dictionary <string, Dictionary <char, List <Peak> > >();
                foreach (var chr in Repository.parsedVariants.intervals)
                {
                    tmp.Add(chr.Key, new Dictionary <char, List <Peak> >());
                    foreach (var strand in chr.Value)
                    {
                        tmp[chr.Key].Add(strand.Key, new List <Peak>());
                        foreach (var peak in strand.Value)
                        {
                            tmp[chr.Key][strand.Key].Add(new Peak()
                            {
                                left = peak.left, right = peak.right, hashKey = peak.hashKey
                            });
                        }
                    }
                }


                var report = di4B.Add(Repository.parsedVariants.fileHashKey, tmp, _indexingMode, _maxDegreeOfParallelism);
                Herald.AnnounceExeReport("Indexed", report);
                _tN2i += report.count;
            }
            else
            {
                if (!Load(args[1]))
                {
                    return(false);
                }
                var report = di4B.Add(Repository.parsedSample.fileHashKey, Repository.parsedSample.intervals, _indexingMode, _maxDegreeOfParallelism);
                Herald.AnnounceExeReport("Indexed", report);
                _tN2i += report.count;
            }

            return(true);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        private bool Dichotomies(string[] args)
        {
            if (args.Length != 2)
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                return(false);
            }
            string resultFile = "";

            if (!ExtractResultsFile(args[1], out resultFile))
            {
                return(false);                                              // invalid file URI.
            }
            ConcurrentDictionary <string, ConcurrentDictionary <char, ICollection <BlockKey <int> > > > results = null;

            Herald.AnnounceExeReport("Dichotomies", di4B.Dichotomies(out results, _maxDegreeOfParallelism));
            Herald.AnnounceExeReport("Export", Exporter.Export(resultFile, results));
            return(true);
        }
Exemplo n.º 10
0
        private bool ReportStats(string[] args)
        {
            if (args.Length != 2)
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                return(false);
            }
            string resultFile = "";

            if (!ExtractResultsFile(args[1], out resultFile))
            {
                return(false);                                              // invalid file URI.
            }
            SortedDictionary <string, SortedDictionary <char, Stats> > results = null;

            Herald.AnnounceExeReport("Statistics", di4B.Statistics(out results));
            Herald.AnnounceExeReport("Export", Exporter.Export(resultFile, results));
            return(true);
        }
Exemplo n.º 11
0
        private bool BlockInfoDis(string[] args)
        {
            if (args.Length != 2)
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                return(false);
            }
            string resultFile = "";

            if (!ExtractResultsFile(args[1], out resultFile))
            {
                return(false);                                              // invalid file URI.
            }
            BlockInfoDis results = null;

            Herald.AnnounceExeReport("BlockInfo", di4B.BlocksInfoDistribution(out results, _maxDegreeOfParallelism));
            Herald.AnnounceExeReport("Export", Exporter.Export(resultFile, results));

            return(true);
        }
Exemplo n.º 12
0
        private bool Map(string[] args)
        {
            if (args.Length != 5)
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                return(false);
            }

            string resultFile = "";

            if (!ExtractResultsFile(args[2], out resultFile))
            {
                return(false);                                              // invalid file URI.
            }
            char strand = '*';

            if (!char.TryParse(args[3], out strand))
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid strand argument [{0}].", args[3]));
                return(false);
            }

            Aggregate agg = Aggregate.Count;

            if (!String2Aggregate(args[4], out agg))
            {
                return(false);
            }

            if (!Load(args[1]))
            {
                return(false);
            }

            FunctionOutput <Output <int, Peak, PeakData> > result;

            Herald.AnnounceExeReport("Map", di4B.Map(strand, Repository.parsedSample.intervals, agg, out result, _maxDegreeOfParallelism));
            Herald.AnnounceExeReport("Export", Exporter.Export(resultFile, result, "chr\tleft\tright\tcount\tstrand"));

            return(true);
        }
Exemplo n.º 13
0
        private bool AccumulationDistribution(string[] args)
        {
            if (args.Length != 2)
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                return(false);
            }

            string resultFile = "";

            if (!ExtractResultsFile(args[1], out resultFile))
            {
                return(false);                                              // invalid file URI.
            }
            ConcurrentDictionary <string, ConcurrentDictionary <char, SortedDictionary <int, int> > > results;
            SortedDictionary <int, int> mergedResults;

            Herald.AnnounceExeReport("AccDistribution", di4B.AccumulationDistribution(out results, out mergedResults, _maxDegreeOfParallelism));
            Herald.AnnounceExeReport("Export", Exporter.Export(resultFile, results, mergedResults, "chr\tstrand\taccumulation\tcount"));
            return(true);
        }
Exemplo n.º 14
0
        private void BenchmarkCover()
        {
            int tries = 10;
            var agg   = Aggregate.Count;
            FunctionOutput <Output <int, Peak, PeakData> > result = null;
            var combinations = new List <int[]>
            {
                new int[] { 1, 2 },
                new int[] { 5, 10 },
                new int[] { 10, 20 },
                new int[] { 50, 60 },
                new int[] { 80, 90 },
                new int[] { 100, 200 },
                new int[] { 200, 220 },
                new int[] { 300, 320 },
                new int[] { 400, 500 },
                new int[] { 550, 1000 },
                new int[] { 1, 1 },
                new int[] { 10, 10 },
                new int[] { 25, 25 },
                new int[] { 50, 50 },
                new int[] { 60, 60 },
                new int[] { 80, 80 },
                new int[] { 100, 100 },
                new int[] { 150, 150 },
                new int[] { 200, 200 },
                new int[] { 500, 500 },
            };

            foreach (var c in combinations)
            {
                for (int i = 0; i < tries; i++)
                {
                    Herald.AnnounceExeReport(c[0] + "," + c[1], di4B.Cover(CoverVariation.Cover, '*', c[0], c[1], agg, out result, _maxDegreeOfParallelism), Herald.SpeedUnit.bookmarkPerSecond);
                }
            }
        }
Exemplo n.º 15
0
        private bool VariantAnalysis(string[] args)
        {
            if (args.Length != 3)
            {
                Herald.Announce(Herald.MessageType.Error, string.Format("Invalid arguments."));
                return(false);
            }

            string resultFile = "";

            if (!ExtractResultsFile(args[2], out resultFile))
            {
                return(false);                                              // invalid file URI.
            }
            if (!tmpLoadVCF(args[1]))
            {
                return(false);
            }

            var tmp = new Dictionary <string, Dictionary <char, List <Peak> > >();

            foreach (var chr in Repository.parsedVariants.intervals)
            {
                tmp.Add(chr.Key, new Dictionary <char, List <Peak> >());
                foreach (var s in chr.Value)
                {
                    tmp[chr.Key].Add(s.Key, new List <Peak>());
                    foreach (var peak in s.Value)
                    {
                        tmp[chr.Key][s.Key].Add(new Peak()
                        {
                            left = peak.left, right = peak.right, hashKey = peak.hashKey
                        });
                    }
                }
            }

            FunctionOutput <Output <int, Peak, PeakData> > result;
            Dictionary <uint, int> newRes = new Dictionary <uint, int>();

            Herald.AnnounceExeReport("Variant Analysis", di4B.VariantAnalysis('*', tmp, Aggregate.Count, out result, _maxDegreeOfParallelism, out newRes));
            Herald.AnnounceExeReport("Export", Exporter.Export(resultFile, result, "chr\tleft\tright\tcount\tstrand"));

            var sortedRes = newRes.ToList();

            sortedRes.Sort(
                delegate(KeyValuePair <uint, int> i, KeyValuePair <uint, int> j)
            {
                return(j.Value.CompareTo(i.Value));
            });


            using (StreamWriter writer = new StreamWriter(resultFile))
            {
                writer.WriteLine("Sampled_ID\tVariations_in_common_with_reference");
                foreach (var item in sortedRes)
                {
                    writer.WriteLine("{0}\t{1}", item.Key, item.Value);
                }
            }


            return(true);
        }
Exemplo n.º 16
0
 private bool Index2ndPass()
 {
     Herald.AnnounceExeReport("2ndPass", di4B.Add2ndPass(_maxDegreeOfParallelism), speedUnit: Herald.SpeedUnit.bookmarkPerSecond);
     return(true);
 }