예제 #1
0
        public void CreateIndex()
        {
            var          searchTag = $"\"{SectionToIndex}\":[";
            const string headerTag = "{\"header\":";
            var          index     = new JasixIndex();
            string       line;

            //skipping lines before the sectionToIndex arrives
            while ((line = _reader.ReadLine()) != null)
            {
                if (line.StartsWith(headerTag))
                {
                    index.HeaderLine = ExtractHeader(line);
                }
                if (line.EndsWith(searchTag))
                {
                    break;
                }
            }

            // we need the location before accessing the line
            var fileLoc = _reader.Position;

            string previousChr = "";
            int    previousPos = 0;

            while ((line = _reader.ReadLine()) != null)
            {
                if (line.StartsWith("]"))
                {
                    break;
                }
                line = line.TrimEnd(',');
                var chrPos = GetChromPosition(line);

                CheckFileSorted(chrPos.chr, chrPos.position, previousChr, previousPos);

                index.Add(chrPos.chr, chrPos.position, chrPos.end, fileLoc);
                fileLoc     = _reader.Position;
                previousChr = chrPos.chr;
                previousPos = chrPos.position;
            }

            index.Write(_writeStream);

            Console.WriteLine();

            var peakMemoryUsageBytes = MemoryUtilities.GetPeakMemoryUsage();
            var wallTimeSpan         = _benchmark.GetElapsedTime();

            Console.WriteLine();
            if (peakMemoryUsageBytes > 0)
            {
                Console.WriteLine("Peak memory usage: {0}", MemoryUtilities.ToHumanReadable(peakMemoryUsageBytes));
            }
            Console.WriteLine("Time: {0}", Benchmark.ToHumanReadable(wallTimeSpan));
        }
예제 #2
0
        private static ExitCodes ProgramExecution()
        {
            (string hostName, string remoteCacheDir, string remoteReferencesDir, string manifestGRCh37,
             string manifestGRCh38) = Configuration.Load();

            List <GenomeAssembly> genomeAssemblies = GenomeAssemblyHelper.GetGenomeAssemblies(_genomeAssembly);

            var client = new Client(hostName);

            Console.Write("- downloading manifest... ");

            Dictionary <GenomeAssembly, List <string> > remotePathsByGenomeAssembly =
                Manifest.GetRemotePaths(client, genomeAssemblies, manifestGRCh37, manifestGRCh38);

            (string cacheDir, string referencesDir, string saDir, List <string> outputDirectories) =
                OutputDirectory.Create(_outputDirectory, genomeAssemblies);

            var fileList = new List <RemoteFile>();

            fileList.AddCacheFiles(genomeAssemblies, remoteCacheDir, cacheDir)
            .AddReferenceFiles(genomeAssemblies, remoteReferencesDir, referencesDir)
            .AddSupplementaryAnnotationFiles(remotePathsByGenomeAssembly, saDir);

            Console.WriteLine($"{fileList.Count} files.\n");

            // get rid of extra files in the output directories
            OutputDirectory.Cleanup(fileList, outputDirectories);

            // get length, checksum, and checks existence
            Console.WriteLine("- downloading file metadata:");
            AnnotationRepository.DownloadMetadata(client, fileList);

            // remove obsolete files from the output directory
            OutputDirectory.RemoveOldFiles(fileList);

            // remove skipped files from our list
            List <RemoteFile> filesToDownload = OutputDirectory.RemoveSkippedFiles(fileList);

            // download the latest files
            if (filesToDownload.Count > 0)
            {
                long numBytesToDownload = OutputDirectory.GetNumDownloadBytes(filesToDownload);
                Console.WriteLine($"- downloading files ({MemoryUtilities.ToHumanReadable(numBytesToDownload)}):");

                AnnotationRepository.DownloadFiles(client, filesToDownload);
            }

            // sanity check
            OutputDirectory.CheckFiles(fileList);

            bool foundError = fileList.Any(x => !x.Pass);

            return(foundError ? ExitCodes.InvalidData : ExitCodes.Success);
        }
예제 #3
0
        public void CreateIndex()
        {
            var index = new JasixIndex();

            IndexHeader(index);

            string lastLine = IndexPositions(index);

            IndexGenes(lastLine, index);

            index.Write(_writeStream);

            Console.WriteLine();

            long peakMemoryUsageBytes = MemoryUtilities.GetPeakMemoryUsage();
            var  wallTimeSpan         = _benchmark.GetElapsedTime();

            Console.WriteLine();
            if (peakMemoryUsageBytes > 0)
            {
                Console.WriteLine("Peak memory usage: {0}", MemoryUtilities.ToHumanReadable(peakMemoryUsageBytes));
            }
            Console.WriteLine("Time: {0}", Benchmark.ToHumanReadable(wallTimeSpan));
        }
        /// <summary>
        /// executes the command-line workflow
        /// </summary>
        public void Execute(string[] args)
        {
            var bench = new Benchmark();

            try
            {
                List <string> unsupportedOps = null;

                if (args == null || args.Length == 0)
                {
                    SetExitCode(ExitCodes.MissingCommandLineOption);
                    _showHelpMenu = true;
                }
                else
                {
                    try
                    {
                        unsupportedOps = _commandLineOps.Parse(args);

                        if (unsupportedOps.Count > 0)
                        {
                            SetExitCode(ExitCodes.UnknownCommandLineOption);
                            _showHelpMenu = true;
                        }
                    }
                    catch (OptionException oe)
                    {
                        _errorBuilder.AppendFormat("{0}ERROR: {1}\n", _errorSpacer, oe.Message);
                        SetExitCode(ExitCodes.UnknownCommandLineOption);
                        _showHelpMenu = true;
                    }
                }

                if (_showVersion)
                {
                    Console.WriteLine("{0} {1}", _versionProvider.GetProgramVersion(), _versionProvider.GetDataVersion());
                    SetExitCode(ExitCodes.Success);
                }
                else
                {
                    if (!Console.IsOutputRedirected)
                    {
                        CommandLineUtilities.DisplayBanner(_programAuthors);
                    }

                    if (_showHelpMenu)
                    {
                        Help.Show(_commandLineOps, _commandLineExample, _programDescription);

                        CommandLineUtilities.ShowUnsupportedOptions(unsupportedOps);

                        Console.WriteLine();
                        Console.WriteLine(_versionProvider.GetDataVersion());
                        Console.WriteLine();

                        // print the errors if any were found
                        if (FoundParsingErrors())
                        {
                            return;
                        }
                    }
                    else
                    {
                        ValidateCommandLine();

                        // print the errors if any were found
                        if (FoundParsingErrors())
                        {
                            return;
                        }

                        ProgramExecution();
                    }
                }
            }
            catch (Exception e)
            {
                ExitCode = ExitCodeUtilities.ShowException(e);
            }

            _peakMemoryUsageBytes = MemoryUtilities.GetPeakMemoryUsage();
            _wallTimeSpan         = bench.GetElapsedTime();

            if (!_showVersion && !_showHelpMenu && !Console.IsOutputRedirected)
            {
                Console.WriteLine();
                if (_peakMemoryUsageBytes > 0)
                {
                    Console.WriteLine("Peak memory usage: {0}", MemoryUtilities.ToHumanReadable(_peakMemoryUsageBytes));
                }
                Console.WriteLine("Time: {0}", Benchmark.ToHumanReadable(_wallTimeSpan));
            }
        }
예제 #5
0
 public void ToHumanReadable(long numBytes, string expectedResult)
 {
     Assert.Equal(expectedResult, MemoryUtilities.ToHumanReadable(numBytes));
 }
예제 #6
0
        public void ToHumanReadable_Convert_Bytes()
        {
            var observedValue = MemoryUtilities.ToHumanReadable(123);

            Assert.Equal("123 B", observedValue);
        }