Exemplo n.º 1
0
        public static string[] Read_string_array_and_remove_non_letters_from_beginning_and_end_of_each_line(string filename)
        {
            string        directory      = Global_directory_and_file_class.Custom_data_directory;
            string        full_file_name = directory + filename;
            StreamReader  reader         = new StreamReader(full_file_name);
            List <string> string_list    = new List <string>();
            string        inputLine;

            while ((inputLine = reader.ReadLine()) != null)
            {
                string_list.Add(Text_class.Remove_space_comma_semicolon_colon_from_end_and_beginning_of_text(inputLine));
            }
            return(string_list.ToArray());
        }
        private Obo_networkTable_line_class[] Read_obo_file()
        {
            Obo_networkTable_private_readOptions_class readOptions = new Obo_networkTable_private_readOptions_class();
            StreamReader reader = new StreamReader(readOptions.Complete_file_name);
            string       input_line;
            bool         new_term    = false;
            string       id          = "error";
            string       name        = "error";
            string       parent_id   = "error";
            string       parent_name = "error";

            string[] splitString;
            string[] parent_id_parent_name;
            Obo_interaction_type_enum interaction_type;
            StringBuilder             sb;
            int  splitString_length;
            bool continue_reading        = true;
            bool new_parent              = false;
            bool at_least_one_line_added = false;
            bool end_of_term             = false;
            bool is_obsolete             = false;

            List <Obo_networkTable_line_class> networkTable_list = new List <Obo_networkTable_line_class>();
            Obo_networkTable_line_class        new_networkTable_line;
            Dictionary <string, bool>          added_scps_dict = new Dictionary <string, bool>();

            while (((input_line = reader.ReadLine()) != null) && (continue_reading))
            {
                #region Get split stings
                splitString        = input_line.Split(':');
                splitString_length = splitString.Length;
                if ((splitString_length > 2) && (!splitString[0].Equals("synonym")) && (!splitString[0].Equals("xref")) && (!splitString[0].Equals("def")))
                {
                    sb = new StringBuilder();
                    for (int indexS = 1; indexS < splitString_length; indexS++)
                    {
                        splitString[indexS] = splitString[indexS].Replace("{", "").Replace("}", "");
                        if (indexS > 1)
                        {
                            sb.AppendFormat(":");
                        }
                        sb.AppendFormat(splitString[indexS]);
                    }
                    splitString = new string[] { splitString[0], sb.ToString() };
                }
                #endregion

                #region Set every turn default values
                parent_id        = Global_class.Empty_entry;
                parent_name      = Global_class.Empty_entry;
                interaction_type = Obo_interaction_type_enum.E_m_p_t_y;
                new_parent       = false;
                #endregion

                if (String.IsNullOrEmpty(splitString[0]))
                {
                    end_of_term = true;
                }
                else
                {
                    switch (splitString[0])
                    {
                    case Obo_networkTable_private_readOptions_class.New_term_marker:
                        new_term    = true;
                        is_obsolete = false;
                        break;

                    case Obo_networkTable_private_readOptions_class.Id_marker:
                        id = Text_class.Remove_space_comma_semicolon_colon_from_end_and_beginning_of_text(splitString[1]);
                        break;

                    case Obo_networkTable_private_readOptions_class.Namespace_marker:
                        break;

                    case Obo_networkTable_private_readOptions_class.Name_marker:
                        name = Text_class.Remove_space_comma_semicolon_colon_from_end_and_beginning_of_text(splitString[1]);
                        break;

                    case Obo_networkTable_private_readOptions_class.Is_a_marker:
                        parent_id_parent_name = splitString[1].Split(Obo_networkTable_private_readOptions_class.Parent_id_parent_name_separator);
                        parent_id             = Text_class.Remove_space_comma_semicolon_colon_from_end_and_beginning_of_text(parent_id_parent_name[0]);
                        if (parent_id_parent_name.Length == 2)
                        {
                            parent_name = Text_class.Remove_space_comma_semicolon_colon_from_end_and_beginning_of_text(parent_id_parent_name[1]);
                        }
                        interaction_type = Obo_interaction_type_enum.Is_a;
                        new_parent       = true;
                        break;

                    case Obo_networkTable_private_readOptions_class.Part_of_marker:
                        parent_id_parent_name = splitString[1].Split(Obo_networkTable_private_readOptions_class.Parent_id_parent_name_separator);
                        parent_id             = Text_class.Remove_space_comma_semicolon_colon_from_end_and_beginning_of_text(parent_id_parent_name[0]);
                        parent_name           = Text_class.Remove_space_comma_semicolon_colon_from_end_and_beginning_of_text(parent_id_parent_name[1]);
                        interaction_type      = Obo_interaction_type_enum.Part_of;
                        new_parent            = true;
                        break;

                    case Obo_networkTable_private_readOptions_class.End_reading_marker:
                        continue_reading = false;
                        break;

                    case Obo_networkTable_private_readOptions_class.Is_obsolete_marker:
                        is_obsolete = true;
                        break;

                    default:
                        break;
                    }
                }
                if (new_term)
                {
                    new_term = false;
                    id       = (string)Global_class.Empty_entry.Clone();
                    name     = (string)Global_class.Empty_entry.Clone();
                    at_least_one_line_added = false;
                    end_of_term             = false;
                }
                else if ((new_parent) && (!is_obsolete))
                {
                    new_networkTable_line                  = new Obo_networkTable_line_class(id, name);
                    new_networkTable_line.Parent_id        = (string)parent_id.Clone();
                    new_networkTable_line.Parent_name      = (string)parent_name.Clone();
                    new_networkTable_line.Interaction_type = interaction_type;
                    networkTable_list.Add(new_networkTable_line);
                    at_least_one_line_added = true;
                }
                else if ((end_of_term) && (!at_least_one_line_added) && (!is_obsolete))
                {
                    if (!added_scps_dict.ContainsKey(name))
                    {
                        new_networkTable_line = new Obo_networkTable_line_class(id, name);
                        networkTable_list.Add(new_networkTable_line);
                        at_least_one_line_added = true;
                    }
                    else
                    {
                        throw new Exception("Process name already exists");
                    }
                }
            }
            return(networkTable_list.ToArray());
        }