Beispiel #1
0
        private void PopulateCVEnumData()
        {
            var invalidSymbols        = @" @/[():^?*+<=!~`#$%&{}|;'.,>\";              // WARNING: '-' must be at beginning or end, in middle it must be escaped, or it is interpreted as a range
            var invalidSymbolsEscaped = System.Text.RegularExpressions.Regex.Escape(invalidSymbols);
            var invalidSymbolsRegex   = @"[\]\s" + invalidSymbolsEscaped + "\\-\\\"]"; // add all whitespace matching, manually escape the ']', since above call doesn't

            // Add "CVID_Unknown" to the list first
            var unknown = new OBO_File.OBO_Term
            {
                Id         = "??:0000000",
                Name       = "CVID_Unknown",
                EnumName   = "CVID_Unknown",
                Def        = "CVID_Unknown [Unknown]",
                IsObsolete = false
            };

            _cvEnumData.Add("CVID_Unknown", unknown);
            _cvMapData.Add("??", new Dictionary <string, OBO_File.OBO_Term>()
            {
                { "CVID_Unknown", unknown }
            });

            const string obsol = "_OBSOLETE";

            foreach (var obo in _allObo)
            {
                if (obo.IsGeneratedId && obo.Terms.Count > 0)
                {
                    var tempId = obo.Terms.Values.ToList()[0].Id;
                    tempId = tempId.Split(':')[0];
                    obo.Id = tempId;
                }
                var id     = obo.Id;
                var parent = new Dictionary <string, OBO_File.OBO_Term>();
                _cvMapData.Add(id, parent);

                foreach (var term in obo.Terms.Values)
                {
                    var name = id + "_";
                    //name += term.Name.Replace(' ', '_');
                    name += System.Text.RegularExpressions.Regex.Replace(term.Name, invalidSymbolsRegex, "_");
                    //name += System.Text.RegularExpressions.Regex.Replace(term.Name.Replace(' ', '_'), invalidSymbolsRegex, "_");
                    if (term.IsObsolete)
                    {
                        name += obsol;
                    }
                    var tName   = name;
                    var counter = 0;
                    while (_cvEnumData.ContainsKey(name))
                    {
                        counter++;
                        name = tName + counter;
                    }
                    _cvEnumData.Add(name, term);
                    parent.Add(name, term);
                    term.EnumName = name;
                }
            }
        }
Beispiel #2
0
        public void Read(string url)
        {
            var fileData = (new WebClient()).DownloadString(url);

            FileData = new OBO_File(url);
            using (var reader = new StringReader(fileData))
            {
                var line = reader.ReadLine();
                while (string.IsNullOrWhiteSpace(line) && line != null)
                {
                    line = reader.ReadLine();
                }

                var type = "header";
                var data = new List <KeyValuePair <string, string> >();
                while (reader.Peek() != -1 && !string.IsNullOrWhiteSpace(line))
                {
                    if (line.StartsWith("["))
                    {
                        type = line;

                        line = reader.ReadLine();
                        while (string.IsNullOrWhiteSpace(line) && line != null)
                        {
                            line = reader.ReadLine();
                        }
                    }
                    data.Clear();
                    while (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("["))
                    {
                        var keyStop    = line.IndexOf(':');
                        var valueStart = line[keyStop + 1] == ' ' ? keyStop + 2 : keyStop + 1;
                        data.Add(new KeyValuePair <string, string>(line.Substring(0, keyStop), line.Substring(valueStart)));

                        line = reader.ReadLine();
                        while (string.IsNullOrWhiteSpace(line) && line != null)
                        {
                            line = reader.ReadLine();
                        }
                    }

                    switch (type.ToLower())
                    {
                    case "header":
                        FileData.Header = new OBO_File.OBO_Header(data);
                        break;

                    case "[term]":
                        var term = new OBO_File.OBO_Term(data);
                        if (FileData.Terms.ContainsKey(term.Id))
                        {
                            Console.WriteLine("Warning: Duplicate term id found");
                            Console.WriteLine("\tFirst term: \t\"" + FileData.Terms[term.Id].Id + "\": \"" +
                                              FileData.Terms[term.Id].Def + "\".");
                            Console.WriteLine("\tConflict term: \t\"" + term.Id + "\": \"" + term.Def + "\".");
                            Console.WriteLine("\tChanging conflict id to \"" + term.Id + "_\"");
                            term.Id = term.Id + "_";
                        }
                        FileData.Terms.Add(term.Id, term);
                        break;

                    case "[typedef]":
                        var typeDef = new OBO_File.OBO_Typedef(data);
                        FileData.Typedefs.Add(typeDef.Id, typeDef);
                        break;

                    case "[instance]":
                        var instance = new OBO_File.OBO_Instance(data);
                        FileData.Instances.Add(instance.Id, instance);
                        break;
                    }
                }
            }

            foreach (var import in FileData.Header.Import)
            {
                var reader = new OBO_Reader();
                reader.Read(import);
                ImportedFileData.Add(reader.FileData);
                ImportedFileData.AddRange(reader.ImportedFileData);
            }
        }