예제 #1
0
        /// <summary>
        /// '-' means delete and must be part of "---"
        /// ' ' means missing and is treated just like 'N'
        /// null means that it could be anything
        /// </summary>
        public SimpleAminoAcidSet GenticCode(int ifCodeHasBeenReviewedAndWorksOKWithDeleteAndSpaceAndDashAsMissingSetTo22, string codon, bool dashAsMissing)
        {
            Helper.CheckCondition(ifCodeHasBeenReviewedAndWorksOKWithDeleteAndSpaceAndDashAsMissingSetTo22 == 22, "Need to review code to be sure that it is OK to treat '---' as the amino acid DELETE");

            if (codon.Contains("X") || codon.Contains("*") || codon.Contains("?"))
            {
                return(null);
            }
            if (codon.Contains("-"))
            {
                if (dashAsMissing)
                {
                    return(null);
                }
                else
                {
                    codon = "---";
                }
            }


            //Get the set of values
            SimpleAminoAcidSet aminoAcidCollection = SimpleAminoAcidSet.GetInstance();

            GenticCode(codon, ref aminoAcidCollection);

            if (aminoAcidCollection.PositiveCount == 21)
            {
                return(null);
            }
            return(aminoAcidCollection);
        }
예제 #2
0
 public bool AnyAminoAcidInCommon(SimpleAminoAcidSet aaCollection2)
 {
     foreach (string aminoAcid1 in Positives)
     {
         if (aaCollection2.Contains(aminoAcid1))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #3
0
        public bool AminoAcidSetEqual(SimpleAminoAcidSet aminoAcidCollection2)
        {
            if (PositiveCount != aminoAcidCollection2.PositiveCount)
            {
                return(false);
            }

            foreach (string sAminoAcid1 in Positives)
            {
                if (!aminoAcidCollection2.Contains(sAminoAcid1))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #4
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());
            }
        }
예제 #5
0
        public void GenticCode(string codon, ref SimpleAminoAcidSet aminoAcidCollection)
        {
            Helper.CheckCondition(codon.Length == 3);  //!!!raise error
            Debug.Assert(aminoAcidCollection != null); //real assert

            //If unambiguous, look it up and return it
            if (CodonToAminoAcid.ContainsKey(codon))
            {
                GeneticCodeMapping aGeneticCodeMapping = (GeneticCodeMapping)CodonToAminoAcid[codon];
                string             sAminoAcid          = aGeneticCodeMapping.AminoAcid;
                aminoAcidCollection.AddOrCheck(sAminoAcid);
                return;
            }

            //If ambiguous, try every possiblity for this 1st ambiguity and see if the results are the same (this is recursive)

            int  iFirstAmbiguity = 0;
            char c = char.MinValue;

            for (; iFirstAmbiguity < codon.Length; ++iFirstAmbiguity)
            {
                c = codon[iFirstAmbiguity];
                if (Ambiguous1LetterNucCodeToChoices.ContainsKey(c) && Ambiguous1LetterNucCodeToChoices[c].Length > 1)
                {
                    break;
                }
                Helper.CheckCondition("ATCG".Contains(c.ToString()), string.Format("Illegal nucleotide of '{0}'", c));
            }
            Helper.CheckCondition(iFirstAmbiguity < codon.Length); //!!!raise error - Is CodonToAminoAcid table missing a value?

            foreach (char cNucleotide in (string)Ambiguous1LetterNucCodeToChoices[c])
            {
                string sNewCodon = string.Format("{0}{1}{2}", codon.Substring(0, iFirstAmbiguity), cNucleotide, codon.Substring(iFirstAmbiguity + 1));
                Debug.Assert(sNewCodon.Length == 3); //real assert
                Debug.Assert(sNewCodon != codon);    // real assert
                GenticCode(sNewCodon, ref aminoAcidCollection);
            }
        }