Пример #1
0
        public static double calMHmass(string _sequence,
                                       AminoacidList[] _aminoacids,
                                       isotList[][] _isotopes)
        {
            double protonMass = 1.007276;  //proton Mass in Da (or amu).

            double mass = 0.0;


            Comb.compStrt[] composition;
            if (_aminoacids.Length > 0)
            {
                composition = AminoacidList.calComposition(_sequence, _aminoacids);
            }
            else
            {
                return(0.0);
            }


            foreach (Comb.compStrt element in composition)
            {
                for (int i = 0; i < _isotopes.GetUpperBound(0); i++)
                {
                    if (element.Elem == _isotopes[i][0].Elem)
                    {
                        mass += (double)element.Nats * _isotopes[i][0].Mass;
                        break;
                    }
                }
            }



            //Add a proton

            // Not correct
            //string H = "H";
            //for (int i = 0; i < _isotopes.GetUpperBound(0); i++)
            //{
            //    if (_isotopes[i][0].Elem==H)
            //    {
            //        mass +=  _isotopes[i][0].Mass;
            //        break;
            //    }
            //}
            mass += protonMass;



            return(mass);
        }
Пример #2
0
        /// <summary>
        /// Reads a XML file with the aminoacids' list
        /// </summary>
        /// <param name="fileXml">XML with the aminoacids' list</param>
        /// <returns>(AminoacidList[])</returns>
        public static AminoacidList[] readXML(string fileXml)
        {
            //Initialize necessary objets for XML reading
            XmlTextReader reader = new XmlTextReader(fileXml);
            XmlNodeType   nType  = reader.NodeType;
            XmlDocument   xmldoc = new XmlDocument();

            xmldoc.Load(reader);

            //Initialize the AminoacidList[] tAaList
            XmlNodeList xmlnodeAminoacid = xmldoc.GetElementsByTagName("aminoacid");

            AminoacidList[] tAaList = new AminoacidList[xmlnodeAminoacid.Count];

            XmlNodeList xmlnodeElement = xmldoc.GetElementsByTagName("Element");


            //for each <aminoacid> entry
            for (int i = 0; i < xmlnodeAminoacid.Count; i++)
            {
                //for each child node of the <aminoacid> entry
                for (int j = 0; j < xmlnodeAminoacid[i].ChildNodes.Count; j++)
                {
                    string sNode = xmlnodeAminoacid[i].ChildNodes[j].Name.ToString();



                    if (sNode == "Formula")
                    {
                        int nElements = 0;
                        //Count in <Formula> entry the Element values.
                        for (int k = 0; k < xmlnodeAminoacid[i].ChildNodes[j].ChildNodes.Count; k++)
                        {
                            string sElement = xmlnodeAminoacid[i].ChildNodes[j].ChildNodes[k].Name.ToString();
                            if (sElement == "Element")
                            {
                                nElements++;
                            }
                        }
                        //Initialize the class tAaList[i] with the correct number of elements
                        tAaList[i] = new AminoacidList(nElements);


                        //Search in <Formula> entry for the Element values.
                        for (int k = 0; k < xmlnodeAminoacid[i].ChildNodes[j].ChildNodes.Count; k++)
                        {
                            string sElement = xmlnodeAminoacid[i].ChildNodes[j].ChildNodes[k].Name.ToString();
                            if (sElement == "Element")
                            {
                                string sElem = xmlnodeAminoacid[i].ChildNodes[j].ChildNodes[k].Attributes["id"].Value.ToString();
                                //Search for the number of atoms
                                int iNatoms = 0;
                                for (int l = 0; l < xmlnodeAminoacid[i].ChildNodes[j].ChildNodes[k].ChildNodes.Count; l++)
                                {
                                    string sAtoms = xmlnodeAminoacid[i].ChildNodes[j].ChildNodes[k].ChildNodes[l].Name.ToString();
                                    if (sAtoms == "Natoms")
                                    {
                                        iNatoms = int.Parse(xmlnodeAminoacid[i].ChildNodes[j].ChildNodes[k].ChildNodes[l].InnerText.ToString(), System.Globalization.CultureInfo.InvariantCulture);
                                    }
                                }
                                Comb.compStrt tElement = new Comb.compStrt(sElem, iNatoms);
                                tAaList[i].insert(tElement);
                            }
                        }
                    }
                }


                //Once you have initialized correctly the class, you can search for the <Name> tag, and so on
                for (int j = 0; j < xmlnodeAminoacid[i].ChildNodes.Count; j++)
                {
                    if (xmlnodeAminoacid[i].ChildNodes[j].Name.ToString() == "Name")
                    {
                        tAaList[i].name = xmlnodeAminoacid[i].ChildNodes[j].InnerText.ToString();
                    }
                    if (xmlnodeAminoacid[i].ChildNodes[j].Name.ToString() == "Code1")
                    {
                        tAaList[i].code1 = xmlnodeAminoacid[i].ChildNodes[j].InnerText.ToString();
                    }
                    if (xmlnodeAminoacid[i].ChildNodes[j].Name.ToString() == "Code3")
                    {
                        tAaList[i].code3 = xmlnodeAminoacid[i].ChildNodes[j].InnerText.ToString();
                    }
                    if (xmlnodeAminoacid[i].ChildNodes[j].Name.ToString() == "equivalent")
                    {
                        tAaList[i].equivalent = xmlnodeAminoacid[i].ChildNodes[j].InnerText.ToString();
                    }
                }
            }

            return(tAaList);
        }