Пример #1
0
        protected override MBT.Escience.Set <char> GetResidueSetFromCharAndCheckThatValid(char ch)
        {
            char       chUpper = char.ToUpper(ch);
            Biology    biology = Biology.GetInstance();
            Set <char> result;

            if (biology.Unambiguous1LetterNucCodes.Contains(chUpper))
            {
                result = new Set <char>(chUpper);
            }
            else if (biology.Ambiguous1LetterNucCodeToChoices.ContainsKey(chUpper))
            {
                string basesAsString = biology.Ambiguous1LetterNucCodeToChoices[chUpper];
                result = new Set <char>();
                foreach (char c in basesAsString)
                {
                    result.AddNew(c);
                }
            }
            else
            {
                throw new ArgumentException("Do not know dna base " + chUpper);
            }

            return(result);
        }
Пример #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)]);
        }
Пример #3
0
        /// <summary>
        /// Returns the reverse complement. Throws an exception if IsDna() is false.
        /// </summary>
        /// <exception cref="Exception">If IsDna() is false.</exception>
        /// <returns>The reverse complement</returns>
        public NamedSequence ReverseCompelement()
        {
            Helper.CheckCondition(IsDna(), "Cannot take the reverse complement of a sequence that is not DNA.");
            Biology       Biology = Biology.GetInstance();
            StringBuilder revComp = new StringBuilder(Sequence.Length);

            for (int i = Sequence.Length - 1; i >= 0; i--)
            {
                Helper.CheckCondition(Biology.DnaComplementarityCode.ContainsKey(Sequence[i]), "Cannot compute complement for " + Sequence[i]);
                char comp = Biology.DnaComplementarityCode[Sequence[i]];
                revComp.Append(comp);
            }
            return(new NamedSequence(Name, Protein, revComp.ToString()));
        }
Пример #4
0
        protected virtual Set <char> GetResidueSetFromCharAndCheckThatValid(char ch)
        {
            ch = char.ToUpper(ch);
            //!!!move this to Biology?
            Helper.CheckCondition(Biology.GetInstance().OneLetterAminoAcidAbbrevTo3Letter.ContainsKey(ch),
                                  string.Format("The character {0} is not an amino acid", ch));
            string aminoAcid = Biology.GetInstance().OneLetterAminoAcidAbbrevTo3Letter[ch];

            Helper.CheckCondition(Biology.GetInstance().KnownAminoAcid(aminoAcid),
                                  string.Format("The character {0} is not a standard amino acid", ch));
            Set <char> charAsSet = Set <char> .GetInstance(ch);

            return(charAsSet);
        }
Пример #5
0
        static public string CodonToAACharSetString(string sCodon, bool dashAsMissing)
        {
            sCodon = sCodon.ToUpper();
            SimpleAminoAcidSet rgAminoAcid = Biology.GetInstance().GenticCode(22, sCodon, dashAsMissing);

            if (rgAminoAcid == null)
            {
                return("?");
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                foreach (string aminoAcid in rgAminoAcid.Positives)
                {
                    char aaChar = Biology.GetInstance().ThreeLetterAminoAcidAbbrevTo1Letter[aminoAcid];
                    sb.Append(aaChar);
                }
                return(sb.ToString());
            }
        }