Exemple #1
0
#pragma warning disable CA1810 // Initialize reference type static fields inline
        static AminoAcids()
#pragma warning restore CA1810 // Initialize reference type static fields inline
        {
            // Create set of AtomContainers
            proteinogenics = new AminoAcid[20];

            #region Create proteinogenics
            {
                IChemFile list = new ChemFile();
                using (var reader = new CMLReader(ResourceLoader.GetAsStream("NCDK.Templates.Data.list_aminoacids.cml")))
                {
                    try
                    {
                        list = (IChemFile)reader.Read(list);
                        var containersList = ChemFileManipulator.GetAllAtomContainers(list);
                        int counter        = 0;
                        foreach (var ac in containersList)
                        {
                            Debug.WriteLine($"Adding AA: {ac}");
                            // convert into an AminoAcid
                            var aminoAcid = new AminoAcid();
                            foreach (var next in ac.GetProperties().Keys)
                            {
                                Debug.WriteLine("Prop: " + next.ToString());
                                if (next is DictRef dictRef)
                                {
                                    // Debug.WriteLine("DictRef type: " + dictRef.Type}");
                                    if (string.Equals(dictRef.Type, "pdb:residueName", StringComparison.Ordinal))
                                    {
                                        aminoAcid.SetProperty(ResidueNameKey, ac.GetProperty <string>(next).ToUpperInvariant());
                                        aminoAcid.MonomerName = ac.GetProperty <string>(next);
                                    }
                                    else if (string.Equals(dictRef.Type, "pdb:oneLetterCode", StringComparison.Ordinal))
                                    {
                                        aminoAcid.SetProperty(ResidueNameShortKey, ac.GetProperty <string>(next));
                                    }
                                    else if (string.Equals(dictRef.Type, "pdb:id", StringComparison.Ordinal))
                                    {
                                        aminoAcid.SetProperty(IdKey, ac.GetProperty <string>(next));
                                        Debug.WriteLine($"Set AA ID to: {ac.GetProperty<string>(next)}");
                                    }
                                    else
                                    {
                                        Trace.TraceError("Cannot deal with dictRef!");
                                    }
                                }
                            }
                            foreach (var atom in ac.Atoms)
                            {
                                string dictRef = atom.GetProperty <string>("org.openscience.cdk.dict");
                                switch (dictRef)
                                {
                                case "pdb:nTerminus":
                                    aminoAcid.AddNTerminus(atom);
                                    break;

                                case "pdb:cTerminus":
                                    aminoAcid.AddCTerminus(atom);
                                    break;

                                default:
                                    aminoAcid.Atoms.Add(atom);
                                    break;
                                }
                            }
                            foreach (var bond in ac.Bonds)
                            {
                                aminoAcid.Bonds.Add(bond);
                            }
                            AminoAcidManipulator.RemoveAcidicOxygen(aminoAcid);
                            aminoAcid.SetProperty(NoAtomsKey, "" + aminoAcid.Atoms.Count);
                            aminoAcid.SetProperty(NoBoundsKey, "" + aminoAcid.Bonds.Count);
                            if (counter < proteinogenics.Length)
                            {
                                proteinogenics[counter] = aminoAcid;
                            }
                            else
                            {
                                Trace.TraceError("Could not store AminoAcid! Array too short!");
                            }
                            counter++;
                        }
                    }
                    catch (Exception exception)
                    {
                        if (exception is CDKException | exception is IOException)
                        {
                            Trace.TraceError($"Failed reading file: {exception.Message}");
                            Debug.WriteLine(exception);
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
            #endregion

            int count = proteinogenics.Length;
            singleLetterCodeMap       = new Dictionary <string, IAminoAcid>(count);
            threeLetterCodeMap        = new Dictionary <string, IAminoAcid>(count);
            singleLetterToThreeLetter = new Dictionary <string, string>(count);
            threeLetterToSingleLetter = new Dictionary <string, string>(count);

            foreach (IAminoAcid aa in proteinogenics)
            {
                var single = aa.GetProperty <string>(ResidueNameShortKey);
                var three  = aa.GetProperty <string>(ResidueNameKey);
                singleLetterCodeMap[single]       = aa;
                threeLetterCodeMap[three]         = aa;
                singleLetterToThreeLetter[single] = three;
                threeLetterToSingleLetter[three]  = single;
            }
        }