Beispiel #1
0
        private void ReadAmbiguousCode()
        {
            Helper.CheckCondition(Ambiguous1LetterNucCodeToChoices == null); //!!!raise error
            Ambiguous1LetterNucCodeToChoices = new Dictionary <char, string>();
            SortedNucCodeChoicesToAmbiguous1LetterNucCode = new Dictionary <string, char>();
            NucSetToAmbiguous1LetterNucCode = new Dictionary <HashableSet <char>, char>();

            string sLine = null;

            using (StreamReader streamreaderAmbigFile = OpenResource("AmbiguousCodes.txt"))
            {
                while (null != (sLine = streamreaderAmbigFile.ReadLine()))
                {
                    string[] rgFields = sLine.Split('\t');
                    Helper.CheckCondition(rgFields.Length == 2);    //!!!raise error
                    Helper.CheckCondition(rgFields[0].Length == 1); //!!!raise error
                    char cAmbiguousCode = rgFields[0][0];
                    Ambiguous1LetterNucCodeToChoices.Add(cAmbiguousCode, rgFields[1]);

                    string options = rgFields[1];
                    var    optionsAsHashableSet = new HashableSet <char>(options.ToCharArray());
                    if (!NucSetToAmbiguous1LetterNucCode.ContainsKey(optionsAsHashableSet))
                    {
                        NucSetToAmbiguous1LetterNucCode.Add(optionsAsHashableSet, cAmbiguousCode);

                        string sortedNucs = new string(options.ToCharArray().OrderBy(c => c).ToArray());
                        SortedNucCodeChoicesToAmbiguous1LetterNucCode.Add(sortedNucs, cAmbiguousCode);
                    }
                }
            }
            foreach (char nuc in Unambiguous1LetterNucSet)
            {
                SortedNucCodeChoicesToAmbiguous1LetterNucCode.Add(nuc.ToString(), nuc);
            }
        }
Beispiel #2
0
        public static char DnaSetAsChar(Set <char> dnas)
        {
            //if (dnas.Count == 1 && dnas.First() == '-')
            //{
            //    return '-';
            //}
            if (dnas.Count == 1)
            {
                return(dnas.First());
            }

            return(Biology.GetInstance().NucSetToAmbiguous1LetterNucCode[HashableSet <char> .GetInstance(dnas)]);
        }