Esempio n. 1
0
        public void GenerateMimToGeneSymbolFile(GeneSymbolUpdater geneSymbolUpdater)
        {
            using StreamWriter writer = new StreamWriter(_mimToSymbolStream);
            using var response        = _httpClient.GetAsync(Mim2GeneUrl).Result;
            using var reader          = new StreamReader(response.Content.ReadAsStreamAsync().Result);
            writer.WriteLine("#MIM number\tGene symbol");
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                if (line.OptimizedStartsWith('#'))
                {
                    continue;
                }

                var fields     = line.OptimizedSplit('\t');
                var geneSymbol = fields[3];
                if (string.IsNullOrEmpty(geneSymbol))
                {
                    continue;
                }

                var mimNumber         = fields[0];
                var entrezGeneId      = fields[2];
                var ensemblGeneId     = fields[4];
                var updatedGeneSymbol = geneSymbolUpdater.UpdateGeneSymbol(geneSymbol, ensemblGeneId, entrezGeneId);
                if (string.IsNullOrEmpty(updatedGeneSymbol))
                {
                    continue;
                }

                writer.WriteLine($"{mimNumber}\t{updatedGeneSymbol}");
            }
        }
Esempio n. 2
0
 public OmimParser(GeneSymbolUpdater geneSymbolUpdater, SaJsonSchema jsonSchema, string apiKey, string dumpFilePath)
 {
     _geneSymbolUpdater = geneSymbolUpdater;
     _jsonSchema        = jsonSchema;
     if (dumpFilePath != null)
     {
         _zipFileStream = new FileStream(dumpFilePath, FileMode.Create);
         _zipArchive    = new ZipArchive(_zipFileStream, ZipArchiveMode.Create);
     }
     _httpClient = new HttpClient();
     _httpClient.DefaultRequestHeaders.Add("ApiKey", apiKey);
 }
Esempio n. 3
0
        private static ExitCodes ProgramExecution()
        {
            _apiKey = GetEnvironmentVariable(OmimApiKeyEnvironmentVariableName);
            if (_apiKey == null)
            {
                throw new InvalidDataException("Please set the OMIM API key as the environment variable \"OmimApiKey\".");
            }

            var(entrezGeneIdToSymbol, ensemblGeneIdToSymbol) = GeneUtilities.ParseUniversalGeneArchive(_inputReferencePath, _universalGeneArchivePath);
            var geneSymbolUpdater = new GeneSymbolUpdater(entrezGeneIdToSymbol, ensemblGeneIdToSymbol);

            using (var omimQuery = new OmimQuery(_apiKey, _outputDirectory))
            {
                omimQuery.GenerateMimToGeneSymbolFile(geneSymbolUpdater);
                omimQuery.GenerateJsonResponse();
            }
            OmimVersion.WriteToFile(OmimQuery.JsonResponseFile, _outputDirectory);

            geneSymbolUpdater.DisplayStatistics();
            return(ExitCodes.Success);
        }
Esempio n. 4
0
        public IDictionary <string, string> GenerateMimToGeneSymbol(GeneSymbolUpdater geneSymbolUpdater)
        {
            var mimNumberToGeneSymbol = new Dictionary <string, string>();

            using (StreamWriter writer = new StreamWriter(_minToSymbolStream))
                using (var response = _httpClient.GetAsync(Mim2GeneUrl).Result)
                    using (var reader = new StreamReader(response.Content.ReadAsStreamAsync().Result))
                    {
                        writer.WriteLine("#MIM number\tGene symbol");
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            if (line.OptimizedStartsWith('#'))
                            {
                                continue;
                            }

                            var    fields     = line.OptimizedSplit('\t');
                            string geneSymbol = fields[3];
                            if (string.IsNullOrEmpty(geneSymbol))
                            {
                                continue;
                            }

                            string mimNumber         = fields[0];
                            string entrezGeneId      = fields[2];
                            string ensemblGeneId     = fields[4];
                            string updatedGeneSymbol = geneSymbolUpdater.UpdateGeneSymbol(geneSymbol, ensemblGeneId, entrezGeneId);
                            if (string.IsNullOrEmpty(updatedGeneSymbol))
                            {
                                continue;
                            }

                            writer.WriteLine($"{mimNumber}\t{updatedGeneSymbol}");
                            mimNumberToGeneSymbol[mimNumber] = updatedGeneSymbol;
                        }
                    }

            return(mimNumberToGeneSymbol);
        }
Esempio n. 5
0
        private static ExitCodes ProgramExecution()
        {
            _apiKey = GetEnvironmentVariable(OmimApiKeyEnvironmentVariableName);
            if (_apiKey == null)
            {
                throw new InvalidDataException("Please set the OMIM API key as the environment variable \"OmimApiKey\".");
            }

            var    version      = OmimVersion.GetVersion();
            string outFileName  = $"{version.Name}_{version.Version}";
            string dumpFilePath = Path.Combine(_outputDirectory, OmimDumpFileBaseName + version.Version + OmimDumpFileSuffix);

            var(entrezGeneIdToSymbol, ensemblGeneIdToSymbol) = OmimUtilities.ParseUniversalGeneArchive(_inputReferencePath, _universalGeneArchivePath);
            var geneSymbolUpdater = new GeneSymbolUpdater(entrezGeneIdToSymbol, ensemblGeneIdToSymbol);

            var omimSchema = OmimSchema.Get();

            using (var omimParser = new OmimParser(geneSymbolUpdater, omimSchema, _apiKey, dumpFilePath))
                using (var nsaStream = FileUtilities.GetCreateStream(Path.Combine(_outputDirectory, outFileName + SaCommon.NgaFileSuffix)))
                    using (var ngaWriter = new NgaWriter(nsaStream, version, SaCommon.OmimTag, SaCommon.SchemaVersion, true))
                        using (var saJsonSchemaStream = FileUtilities.GetCreateStream(Path.Combine(_outputDirectory, outFileName + SaCommon.NgaFileSuffix + SaCommon.JsonSchemaSuffix)))
                            using (var schemaWriter = new StreamWriter(saJsonSchemaStream))
                            {
                                var omimItems   = omimParser.GetItems();
                                var geneToItems = OmimUtilities.GetGeneToOmimEntriesAndSchema(omimItems);
                                ngaWriter.Write(geneToItems);
                                schemaWriter.Write(omimSchema);
                            }

            geneSymbolUpdater.DisplayStatistics();
            using (var writer = new StreamWriter(FileUtilities.GetCreateStream("UpdatedGeneSymbols.txt")))
            {
                geneSymbolUpdater.WriteUpdatedGeneSymbols(writer);
            }

            return(ExitCodes.Success);
        }