Пример #1
0
        private List <MatchedData> GetMatchedData(XmlReader xmlReader)
        {
            List <MassPoint>   lstMassPoint   = new List <MassPoint>();
            List <MatchedData> lstMatchedData = new List <MatchedData>();
            List <MatchedData> lstTemp        = null;
            MassScan           scanMS         = new MassScan();

            PeptideModResBLL peModResBLL = new PeptideModResBLL(DBName);
            ParameterModel   model       = this.SaveControlToModel();

            peModResBLL.ParameterModel = model;

            bool bSingle    = false;
            int  iScanCount = 0;
            int  currentCnt = 0;
            int  allCnt     = (int)99998;
            int  avgCnt     = 0;
            int  surplusCnt = 0;

            if (allCnt >= 90)
            {
                avgCnt = allCnt / 90;
            }
            else
            {
                avgCnt     = (int)Math.Round(90.0 / allCnt, MidpointRounding.AwayFromZero);
                surplusCnt = (int)Math.Round((avgCnt - 90.0 / allCnt) * allCnt);
            }

            while (xmlReader.Read())
            {
                if (xmlReader.Name == "sha1")
                {
                    break;
                }

                if (xmlReader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (xmlReader.Name == "msRun")
                {
                    xmlReader.MoveToAttribute("scanCount");
                    iScanCount = int.Parse(xmlReader.Value);

                    if (allCnt > iScanCount)
                    {
                        allCnt = iScanCount;

                        if (allCnt >= 90)
                        {
                            avgCnt = allCnt / 90;
                        }
                        else
                        {
                            avgCnt     = (int)Math.Round(90.0 / allCnt, MidpointRounding.AwayFromZero);
                            surplusCnt = (int)Math.Round((avgCnt - 90.0 / allCnt) * allCnt);
                        }
                    }

                    if (iScanCount == 1)
                    {
                        bSingle = true;
                    }
                }

                if (xmlReader.Name == "scan")
                {
                    if (!xmlReader.HasAttributes)
                    {
                        continue;
                    }

                    //判断 是MS 还是MS2
                    xmlReader.MoveToAttribute("msLevel");

                    if ("1".Equals(xmlReader.Value))
                    {
                        xmlReader.MoveToAttribute("num");
                        scanMS.Index = UInt32.Parse(xmlReader.Value);

                        xmlReader.MoveToAttribute("msLevel");
                        scanMS.MsLevel = UInt32.Parse(xmlReader.Value);

                        xmlReader.MoveToAttribute("peaksCount");
                        scanMS.PeaksCount = UInt32.Parse(xmlReader.Value);

                        xmlReader.MoveToAttribute("polarity");
                        scanMS.Polarity = xmlReader.Value == "+" ? true : false;

                        xmlReader.MoveToAttribute("basePeakIntensity");
                        scanMS.BasePeakIntensity = double.Parse(xmlReader.Value);

                        while (xmlReader.Read())
                        {
                            if (xmlReader.Name == "peaks")
                            {
                                scanMS.IsPeaks = true;
                                scanMS.Peaks   = xmlReader.ReadInnerXml();
                                lstMassPoint   = Base64Convert.CalcMz(scanMS.Peaks, scanMS.PeaksCount);
                                break;
                            }
                        }
                    }
                    else if ("2".Equals(xmlReader.Value))
                    {
                        //读取属性
                        MassScan scanMS2 = new MassScan();

                        xmlReader.MoveToAttribute("num");
                        scanMS2.Index = UInt32.Parse(xmlReader.Value);

                        xmlReader.MoveToAttribute("msLevel");
                        scanMS2.MsLevel = UInt32.Parse(xmlReader.Value);

                        xmlReader.MoveToAttribute("peaksCount");
                        scanMS2.PeaksCount = UInt32.Parse(xmlReader.Value);

                        xmlReader.MoveToAttribute("polarity");
                        scanMS2.Polarity = xmlReader.Value == "+" ? true : false;

                        xmlReader.MoveToAttribute("basePeakIntensity");
                        scanMS2.BasePeakIntensity = double.Parse(xmlReader.Value);

                        while (xmlReader.Read())
                        {
                            if (xmlReader.NodeType != XmlNodeType.Element)
                            {
                                continue;
                            }

                            if (xmlReader.Name == "precursorMz")
                            {
                                xmlReader.MoveToAttribute("activationMethod");
                                scanMS2.ScanType = xmlReader.Value;
                                xmlReader.MoveToElement();
                                scanMS2.PrecursorMz = float.Parse(xmlReader.ReadInnerXml());
                            }
                            if (xmlReader.Name == "peaks")
                            {
                                scanMS2.Peaks = xmlReader.ReadInnerXml();
                                break;
                            }
                        }

                        if (bSingle == true)
                        {
                            if (scanMS2 == null)
                            {
                                return(null);
                            }

                            lstTemp = peModResBLL.getMSMatchs(scanMS2);

                            if (lstTemp != null && lstTemp.Count != 0)
                            {
                                lstMatchedData.AddRange(lstTemp);
                            }


                            return(lstMatchedData);
                        }

                        if (scanMS.IsPeaks == true)
                        {
                            if (scanMS2.Index >= 1 && scanMS2.Index <= 99999)
                            {
                                lstTemp = peModResBLL.getMSMatchs(scanMS, scanMS2);

                                if (lstTemp != null && lstTemp.Count != 0)
                                {
                                    lstMatchedData.AddRange(lstTemp);
                                }

                                if (allCnt <= 0)
                                {
                                }
                                else if (allCnt >= 90)
                                {
                                    currentCnt++;
                                }
                                else
                                {
                                    currentCnt++;
                                }
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            return(lstMatchedData);
        }
        public List<MatchedData> getMSMatchs(MassScan msScan2)
        {
            testParameter.IPMD = ParameterModel.MS_IPMD;
            testParameter.IPACO = ParameterModel.MS_IPACO;
            testParameter.IPAD = ParameterModel.MS_IPAD;
            testParameter.IPADOM = ParameterModel.MS_IPADOM;
            testParameter.IPMDOM = ParameterModel.MS_IPMDOM;
            testParameter.IPADO = ParameterModel.MS_IPADO;
            testParameter.IPMDO = ParameterModel.MS_IPMDO;

            if (testParameter.IPMD > testParameter.IPMDOM)
                testParameter.IPMDOM = testParameter.IPMD;

            if (testParameter.IPAD > testParameter.IPADOM)
                testParameter.IPADOM = testParameter.IPAD;

            //testParameter.Window = 5;
            testParameter.PAT = ParameterModel.MS_PAT;
            List<MatchedData> matchedDataList = new List<MatchedData>();
            List<ModResModel> modResFromDB = peptideModResDAL.getPmFromDB(testParameter.IPACO);
            MatchedData matchedData = null;
            List<MassPoint> msFromDB = null;
            for (int k = 0; k < modResFromDB.Count; k++)
            {
                msFromDB = modResFromDB[k].Mass_Point;
                matchedData = new MatchedData();
                //matchedData.MatchedMsDataExp = msReturn.ToList();
                matchedData.MatchedMsDataExp = new List<MassPoint>();
                //matchedData.MatchedMsDataExp = msReturn.ToList();
                matchedData.MatchedMsDataTheo = msFromDB;
                matchedData.ID = modResFromDB[k].ID;
                matchedData.MOD_RES = modResFromDB[k].Mod_Res;
                matchedData.Z = modResFromDB[k].Z;
                matchedData.Z = 15;
                matchedData.Repository = "";
                matchedData.TheoMZ = modResFromDB[k].M_Z.ToString(); matchedData.NMFS = "";
                matchedData.Sequence = modResFromDB[k].Sequence;
                matchedData.Actualpmfs = "";
                //matchedData.Index = 1;
                matchedDataList.Add(matchedData);
            }

            if (matchedDataList.Count > 0)
            {
                for (int j = 0; j < matchedDataList.Count; j++)
                {
                    matchedData = matchedDataList[j];

                    if (ParameterModel.MS2_SA == 1)
                    {
                        getMS2MatchsTopDown(msScan2, matchedData);
                        matchedDataList[j].ScreeningApproach = "TopDown";
                    }
                    else
                    {
                        getMS2MatchsTargeted(msScan2, matchedData);
                        matchedDataList[j].ScreeningApproach = "Targeted";
                    }
                    try
                    {
                        matchedDataList[j].NMFS = matchedDataList[j].MatchedMs2.Count().ToString();
                    }
                    catch
                    {
                        matchedDataList[j].NMFS = "0";
                    }
                    matchedData.Index = "1";
                    //Console.WriteLine("matched MS2:\t" + matchedData.MatchedMs2.Count.ToString());
                }
            }

            return matchedDataList;
        }
        public void getMS2MatchsTopDown(MassScan msScan2, MatchedData matchedData)
        {
            testParameter.IPMD = ParameterModel.MS2_IPMD;
            testParameter.IPACO = ParameterModel.MS2_IPACO;
            testParameter.IPAD = ParameterModel.MS2_IPAD;
            testParameter.IPADOM = ParameterModel.MS2_IPADOM;
            testParameter.IPMDOM = ParameterModel.MS2_IPMDOM;
            testParameter.IPADO = ParameterModel.MS2_IPADO;
            testParameter.IPMDO = ParameterModel.MS2_IPMDO;
            if (testParameter.IPMD > testParameter.IPMDOM)
                testParameter.IPMDOM = testParameter.IPMD;

            if (testParameter.IPAD > testParameter.IPADOM)
                testParameter.IPADOM = testParameter.IPAD;
            //testParameter.Window = 5;
            testParameter.PAT = ParameterModel.MS2_FAT;
            List<MassPoint> ms2FromFile = null;
            List<MassPoint> msFromDB = null;
            //ModResModel ms2Matched = new ModResModel();
            List<ModResModel> MatchedMs2 = new List<ModResModel>();
            double maxInten = msScan2.BasePeakIntensity;
            //���˵�5%���µķ�
            ms2FromFile = Base64Convert.CalcMz(msScan2.Peaks, msScan2.PeaksCount);
            List<MassPoint> msFromFileReal = getRealMS2FromFile(ms2FromFile, testParameter.PAT, maxInten);

            List<string[]> fmValue = peptideModResDAL.getFmFromDB(matchedData.ID, matchedData.MOD_RES, msScan2.ScanType, matchedData.Sequence);
            if (fmValue.Count == 0)
            {
                return;
            }
            while (true)
            {
                //ȡ����ߵ�1
                int maxMZIndex = getMaxMZ(msFromFileReal);
                if (maxMZIndex == -1)
                {
                    break;
                }
                if (maxMZIndex == 157)
                {
                    maxMZIndex = 157;
                }
                //����ƫ��
                double deviationInten = msFromFileReal[maxMZIndex].Mass - msFromFileReal[maxMZIndex].Mass / (testParameter.IPMD / 1000000.0 + 1.0);

                //MS��ߵ���DBƥ�� �������㴦��
                List<ModResModel> modResFromDB = getFMPointInfo(msFromFileReal[maxMZIndex].Mass, deviationInten, fmValue, matchedData.Z, testParameter.IPACO);
                msFromFileReal[maxMZIndex].IsSearch = false;
                if (modResFromDB == null)
                {
                    //û��ƥ����
                    continue;

                }
                else
                {
                    for (int k = 0; k < modResFromDB.Count; k++)
                    {
                        msFromDB = modResFromDB[k].Mass_Point;
                        int maxMZindex_DB = Convert.ToInt16(modResFromDB[k].M_Z);
                        //��һƥ����ͼ
                        List<MassPoint> msReturn = comparePMAll(msFromFileReal, maxMZIndex, maxMZindex_DB, msFromDB);
                        if (modResFromDB[k].ID == "B5")
                        {
                            modResFromDB[k].ID = "B5";
                        }
                        //��֤ƥ������ƥ��
                        if (getComparePercentage(msReturn, maxMZindex_DB, msFromDB))
                        {
                            ModResModel ms2Matched = new ModResModel();
                            double baseIntens = msFromFileReal[maxMZIndex].Intensity;
                            ms2Matched.Mass_Point = new List<MassPoint>(msFromDB.ToArray());
                            ms2Matched.Mass_Point_FromFile = new List<MassPoint>();
                            for (int j = 0; j < msReturn.Count; j++)
                            {
                                MassPoint massPoint = new MassPoint();
                                massPoint.Index = msReturn[j].Index;
                                //massPoint.Intensity = new Double();
                                massPoint.Intensity = msReturn[j].Intensity;
                                massPoint.IPAD_R = msReturn[j].IPAD_R;
                                massPoint.IPADOM_R = msReturn[j].IPADOM_R;
                                massPoint.IPMD_R = msReturn[j].IPMD_R;
                                massPoint.IPMDOM_R = msReturn[j].IPMDOM_R;
                                massPoint.Mass = msReturn[j].Mass;
                                massPoint.Index = msReturn[j].Index;
                                massPoint.IntensityPercentage = msReturn[j].IntensityPercentage;
                                ms2Matched.Mass_Point_FromFile.Add(massPoint);
                            }
                            ms2Matched.Z = modResFromDB[k].Z;
                            ms2Matched.ID = modResFromDB[k].ID;

                            MatchedMs2.Add(ms2Matched);
                            //matchedData.MatchedMs2DataExp = ms2Matched;

                            for (int j = 0; j < msReturn.Count; j++)
                            {
                                baseIntens = msFromFileReal[j].Intensity / msReturn[j].IntensityPercentage;
                                msFromFileReal[msReturn[j].MatchIndex].Intensity =
                                        msFromFileReal[msReturn[j].MatchIndex].Intensity - (baseIntens * msFromDB[j].Intensity);
                            }
                        }
                    }
                }
            }
            matchedData.MatchedMs2 = MatchedMs2;
        }
        public List<MatchedData> getMSMatchs(MassScan msScan, MassScan msScan2)
        {
            List<MatchedData> matchedDataList = new List<MatchedData>();

            testParameter.IPMD = ParameterModel.MS_IPMD;
            testParameter.IPACO = ParameterModel.MS_IPACO;
            testParameter.IPAD = ParameterModel.MS_IPAD;
            testParameter.IPADOM = ParameterModel.MS_IPADOM;
            testParameter.IPMDOM = ParameterModel.MS_IPMDOM;
            testParameter.IPADO = ParameterModel.MS_IPADO;
            testParameter.IPMDO = ParameterModel.MS_IPMDO;

            if (testParameter.IPMD > testParameter.IPMDOM)
                testParameter.IPMDOM = testParameter.IPMD;

            if (testParameter.IPAD > testParameter.IPADOM)
                testParameter.IPADOM = testParameter.IPAD;

            testParameter.Window = Convert.ToInt16(ParameterModel.MS_WINDOW / 2);
            testParameter.PAT = ParameterModel.MS_PAT;

            double ms2Point = msScan2.PrecursorMz;
            double maxInten = msScan.BasePeakIntensity;
            MatchedData matchedData = new MatchedData();
            //Console.WriteLine("scanMS.Index Begin2          " + DateTime.Now);

            //Console.WriteLine("scanMS.Index Begin3          " + DateTime.Now);
            List<MassPoint> msFromFile;
            List<MassPoint> msFromDB = null;
            //���ļ�ȡ��MS��ͼ
            msFromFile = Base64Convert.CalcMz(msScan.Peaks, msScan.PeaksCount);
            Console.WriteLine("scanMS.Index Begin4          " + DateTime.Now);
            //����MS2����
            List<MassPoint> msFromFileOpenWindow = getOpenWindowFromFile(msFromFile, testParameter.Window, ms2Point);
            //List<MassPoint>  msFromFileOpenWindow = msFromFile;
            Console.WriteLine("scanMS.Index Begin5          " + DateTime.Now);
            //���˵�5%���µķ�
            List<MassPoint> msFromFileReal = getRealMS2FromFile(msFromFileOpenWindow, testParameter.PAT, maxInten);
            // Console.WriteLine("scanMS.Index Begin6          " + DateTime.Now);
            //List<MassPoint> msFromFileReal = msFromFileOpenWindow;
            int timesFlag = 0;
            int maxMZIndex = 0;
            while (timesFlag < 1000)
            {
                //ȡ����ߵ�1
                maxMZIndex = getMaxMZ(msFromFileReal);
                //Console.WriteLine("maxMZIndex.ToString()maxMZIndex.ToString()maxMZIndex.ToString()maxMZIndex.ToString()                     " + maxMZIndex.ToString());
                if (maxMZIndex == -1)
                {
                    break;
                }
                else
                {
                    timesFlag = timesFlag + 1;
                }

                //����ƫ��
                double deviationInten = msFromFileReal[maxMZIndex].Mass - msFromFileReal[maxMZIndex].Mass / (testParameter.IPMD / 1000000.0 + 1.0);

                //MS��ߵ���DBƥ�� �������㴦��
                //Console.WriteLine("scanMS.Index Begin7          " + DateTime.Now);
                List<ModResModel> modResFromDB = peptideModResDAL.getPmFromDB(msFromFileReal[maxMZIndex].Mass, deviationInten, testParameter.IPACO);
                //Console.WriteLine("scanMS.Index Begin8          " + DateTime.Now);
                msFromFileReal[maxMZIndex].IsSearch = false;

                if (modResFromDB.Count == 0)
                {
                    //û��ƥ����
                    continue;

                }
                else
                {

                    //����ƥ��������߷������ƥ���ϵ��б��
                    bool compareFlag = false;
                    string Forumla = "";
                    List<MassPoint> msReturn = new List<MassPoint>(); ;
                    for (int k = 0; k < modResFromDB.Count; k++)
                    {

                        msFromDB = modResFromDB[k].Mass_Point;

                        if (Forumla == modResFromDB[k].Forumla && compareFlag == true)
                        {
                            matchedData = new MatchedData();
                            //matchedData.MatchedMsDataExp = msReturn.ToList();
                            matchedData.MatchedMsDataExp = new List<MassPoint>();
                            foreach (MassPoint item in msReturn)
                            {
                                MassPoint cloneMasspoint = new MassPoint();
                                cloneMasspoint.Index = item.Index;
                                cloneMasspoint.Intensity = item.Intensity;
                                cloneMasspoint.IntensityPercentage = item.IntensityPercentage;
                                cloneMasspoint.IPAD_R = item.IPAD_R;
                                cloneMasspoint.IPADOM_R = item.IPADOM_R;
                                cloneMasspoint.IPMD_R = item.IPMD_R;
                                cloneMasspoint.IPMDOM_R = item.IPMDOM_R;
                                cloneMasspoint.Mass = item.Mass;
                                cloneMasspoint.MatchIndex = item.MatchIndex;

                                matchedData.MatchedMsDataExp.Add(cloneMasspoint);
                            }
                            //matchedData.MatchedMsDataExp = msReturn.ToList();
                            matchedData.MatchedMsDataTheo = msFromDB;
                            matchedData.ID = modResFromDB[k].ID;
                            matchedData.MOD_RES = modResFromDB[k].Mod_Res;
                            matchedData.Z = modResFromDB[k].Z;
                            matchedData.Repository = "";
                            matchedData.ExpMZ = (msFromFileReal[maxMZIndex].Mass).ToString();
                            matchedData.TheoMZ = modResFromDB[k].M_Z.ToString();
                            matchedData.Error_PPM = Convert.ToString(((msFromFileReal[maxMZIndex].Mass - modResFromDB[k].M_Z) / modResFromDB[k].M_Z) * 1000000);
                            matchedData.Index = msScan2.Index.ToString();
                            matchedData.ExpMass_DA = Convert.ToString(((msFromFileReal[maxMZIndex].Mass - modResFromDB[k].M_Z) / modResFromDB[k].M_Z) * 1000000);
                            matchedData.NMFS = "";
                            matchedData.Actualpmfs = "";
                            matchedData.Sequence = modResFromDB[k].Sequence;
                            matchedDataList.Add(matchedData);
                            continue;
                        }
                        Forumla = modResFromDB[k].Forumla;
                        // MZ_FromDB = modResFromDB[0].M;
                        compareFlag = false;
                        int maxMZindex_DB = Convert.ToInt16(modResFromDB[k].M);
                        //��һƥ����ͼ

                        msReturn = comparePMAll(msFromFileReal, maxMZIndex, maxMZindex_DB, msFromDB);                        //��֤ƥ������ƥ��
                        if (getComparePercentage(msReturn, maxMZindex_DB, msFromDB))
                        {
                            compareFlag = true;
                            matchedData = new MatchedData();
                            //matchedData.MatchedMsDataExp = new List<MassPoint>();
                            matchedData.MatchedMsDataExp = new List<MassPoint>();
                            foreach (MassPoint item in msReturn)
                            {
                                MassPoint cloneMasspoint = new MassPoint();
                                cloneMasspoint.Index = item.Index;
                                cloneMasspoint.Intensity = item.Intensity;
                                cloneMasspoint.IntensityPercentage = item.IntensityPercentage;
                                cloneMasspoint.IPAD_R = item.IPAD_R;
                                cloneMasspoint.IPADOM_R = item.IPADOM_R;
                                cloneMasspoint.IPMD_R = item.IPMD_R;
                                cloneMasspoint.IPMDOM_R = item.IPMDOM_R;
                                cloneMasspoint.Mass = item.Mass;
                                cloneMasspoint.MatchIndex = item.MatchIndex;
                                matchedData.MatchedMsDataExp.Add(cloneMasspoint);
                            }
                            matchedData.MatchedMsDataTheo = msFromDB;
                            matchedData.ID = modResFromDB[k].ID;
                            matchedData.MOD_RES = modResFromDB[k].Mod_Res;
                            matchedData.Z = modResFromDB[k].Z;
                            matchedData.Index = msScan2.Index.ToString();
                            matchedData.Repository = "";
                            matchedData.ExpMZ = (msFromFileReal[maxMZIndex].Mass).ToString();
                            matchedData.TheoMZ = modResFromDB[k].M_Z.ToString();
                            matchedData.Error_PPM = Convert.ToString(((msFromFileReal[maxMZIndex].Mass - modResFromDB[k].M_Z) / modResFromDB[k].M_Z) * 1000000);

                            matchedData.ExpMass_DA = Convert.ToString(((msFromFileReal[maxMZIndex].Mass - modResFromDB[k].M_Z) / modResFromDB[k].M_Z) * 1000000);
                            matchedData.NMFS = "";
                            matchedData.Actualpmfs = "";
                            matchedData.Sequence = modResFromDB[k].Sequence;
                            matchedDataList.Add(matchedData);
                            //break;
                            for (int i = 0; i < msFromFileReal.Count; i++)
                            {

                                double baseIntens = 0.0;
                                for (int j = 0; j < msReturn.Count; j++)
                                {
                                    baseIntens = msFromFileReal[j].Intensity / msReturn[j].IntensityPercentage;
                                    msFromFileReal[msReturn[j].MatchIndex].Intensity =
                                            msFromFileReal[msReturn[j].MatchIndex].Intensity - (baseIntens * msFromDB[j].Intensity);
                                }
                            }

                        }
                    }
                    if (matchedData != null)
                        break;
                }
            }

            if (matchedDataList.Count > 0)
            {
                for (int j = 0; j < matchedDataList.Count; j++)
                {
                    matchedData = matchedDataList[j];

                    if (ParameterModel.MS2_SA == 1)
                    {
                        getMS2MatchsTopDown(msScan2, matchedData);
                        matchedDataList[j].ScreeningApproach = "TopDown";
                    }
                    else
                    {
                        getMS2MatchsTargeted(msScan2, matchedData);
                        matchedDataList[j].ScreeningApproach = "Targeted";
                    }

                    if (matchedDataList[j].MatchedMs2 == null)
                        matchedDataList[j].NMFS = "0";
                    else
                        matchedDataList[j].NMFS = matchedDataList[j].MatchedMs2.Count().ToString();

                    //Console.WriteLine("matched MS2:\t" + matchedData.MatchedMs2.Count.ToString());
                }
            }

            return matchedDataList;
        }
        public void getMS2MatchsTargeted(MassScan msScan2, MatchedData matchedData)
        {
            //testParameter.IPMD = 10;
            //testParameter.IPACO = 5;
            //testParameter.IPAD = 50;
            //testParameter.IPADOM = 100;
            //testParameter.IPMDOM = 30;
            //testParameter.IPADO = 20;
            //testParameter.IPMDO = 20;
            //testParameter.Window = 5;
            //testParameter.PAT = 0.2;

            testParameter.IPMD = ParameterModel.MS2_IPMD;
            testParameter.IPACO = ParameterModel.MS2_IPACO;
            testParameter.IPAD = ParameterModel.MS2_IPAD;
            testParameter.IPADOM = ParameterModel.MS2_IPADOM;
            testParameter.IPMDOM = ParameterModel.MS2_IPMDOM;
            testParameter.IPADO = ParameterModel.MS2_IPADO;
            testParameter.IPMDO = ParameterModel.MS2_IPMDO;
            if (testParameter.IPMD > testParameter.IPMDOM)
                testParameter.IPMDOM = testParameter.IPMD;

            if (testParameter.IPAD > testParameter.IPADOM)
                testParameter.IPADOM = testParameter.IPAD;

            //testParameter.Window = 5;
            testParameter.PAT = ParameterModel.MS2_FAT;

            //if (msScan2.ScanType == "CID")
            //{
            //    return;
            //}
            List<MassPoint> ms2FromFile = null;
            List<MassPoint> msFromDB = null;
            //ModResModel ms2Matched = new ModResModel();
            List<ModResModel> MatchedMs2 = new List<ModResModel>();
            double maxInten = msScan2.BasePeakIntensity;
            //���˵�5%���µķ�
            ms2FromFile = Base64Convert.CalcMz(msScan2.Peaks, msScan2.PeaksCount);
            List<MassPoint> msFromFileReal = getRealMS2FromFile(ms2FromFile, testParameter.PAT, maxInten);

            List<string[]> fmValue = peptideModResDAL.getFmFromDB(matchedData.ID, matchedData.MOD_RES, msScan2.ScanType, matchedData.Sequence);
            if (fmValue.Count == 0)
            {
                return;
            }
            //msFromDB = getFMDataPoints(fmValue);
            for (int i = 0; i < fmValue[0].Count(); i++)
            {
                //��һƥ����ͼ
                List<ModResModel> modResFromDB = comparePMFromDB(fmValue[0][i], fmValue[1][i], fmValue[2][i], msFromFileReal, matchedData.Z, testParameter.IPACO);
                if (modResFromDB.Count > 1)
                {
                    //modResFromDB = null;
                }
                for (int m = 0; m < modResFromDB.Count; m++)
                {
                    if (modResFromDB[m].ID == "Y40")
                    {
                        modResFromDB[m].ID = "Y40";
                    }
                    msFromDB = modResFromDB[m].Mass_Point;
                    int maxMZIndex = Convert.ToInt16(modResFromDB[m].M);//��ʱʹ��
                    int maxMZindex_DB = Convert.ToInt16(modResFromDB[m].M_Z);
                    //��һƥ����ͼ
                    List<MassPoint> msReturn = comparePMAll(msFromFileReal, maxMZIndex, maxMZindex_DB, msFromDB);
                    //��֤ƥ������ƥ��
                    if (getComparePercentage(msReturn, maxMZindex_DB, msFromDB))
                    {
                        ModResModel ms2Matched = new ModResModel();
                        double baseIntens = msFromFileReal[maxMZIndex].Intensity;
                        ms2Matched.Mass_Point = new List<MassPoint>(msFromDB.ToArray());
                        ms2Matched.Mass_Point_FromFile = new List<MassPoint>();
                        for (int j = 0; j < msReturn.Count; j++)
                        {
                            MassPoint massPoint = new MassPoint();
                            massPoint.Index = msReturn[j].Index;
                            //massPoint.Intensity = new Double();
                            massPoint.Intensity = msReturn[j].Intensity;
                            massPoint.IPAD_R = msReturn[j].IPAD_R;
                            massPoint.IPADOM_R = msReturn[j].IPADOM_R;
                            massPoint.IPMD_R = msReturn[j].IPMD_R;
                            massPoint.IPMDOM_R = msReturn[j].IPMDOM_R;
                            massPoint.Mass = msReturn[j].Mass;
                            massPoint.Index = msReturn[j].Index;
                            massPoint.IntensityPercentage = msReturn[j].IntensityPercentage;
                            ms2Matched.Mass_Point_FromFile.Add(massPoint);
                        }
                        //matchedData.ID = modResFromDB[0].ID;
                        //matchedData.MOD_RES = modResFromDB[0].Mod_Res;
                        //matchedData.Z = modResFromDB[0].Z;
                        ms2Matched.Z = modResFromDB[m].Z;
                        ms2Matched.ID = modResFromDB[m].ID;
                        MatchedMs2.Add(ms2Matched);
                        //matchedData.MatchedMs2DataExp = ms2Matched;

                        for (int j = 0; j < msReturn.Count; j++)
                        {
                            //ms2Matched.Mass_Point_FromFile[j].Intensity = new Double();
                            //ms2Matched.Mass_Point_FromFile[j].Intensity = msFromFileReal[msReturn[j].MatchIndex].Intensity;
                            baseIntens = msFromFileReal[j].Intensity / msReturn[j].IntensityPercentage;
                            msFromFileReal[msReturn[j].MatchIndex].Intensity =
                                    msFromFileReal[msReturn[j].MatchIndex].Intensity - (baseIntens * msFromDB[j].Intensity);
                            //if (maxInten * testParameter.IPACO / 100 > msFromFileReal[msReturn[j].MatchIndex].Intensity)
                            //{
                            //    msFromFileReal[msReturn[j].MatchIndex].Intensity = 0;
                            //}
                        }

                    }
                }
            }

            matchedData.MatchedMs2 = MatchedMs2;
            //for (int i = 0; i < MatchedMs2.Count; i++)
            //{
            //    Console.WriteLine("Ion:  " + MatchedMs2[i].ID + "\t" + "Z:  " + MatchedMs2[i].Z);
            //    for (int j = 0; j < MatchedMs2[i].Mass_Point.Count; j++)
            //    {
            //        Console.WriteLine("Mass: \t " + MatchedMs2[i].Mass_Point[j].Mass + "\t" + MatchedMs2[i].Mass_Point_FromFile[j].Mass + "\tIntensity: \t" + MatchedMs2[i].Mass_Point[j].Intensity + "\t" + MatchedMs2[i].Mass_Point_FromFile[j].IntensityPercentage + "\t" + MatchedMs2[i].Mass_Point_FromFile[j].IPAD_R);
            //    }

            //}
        }