コード例 #1
0
        public QMatch FindBestScore(double MZ, int Charge, double IsoRatio, double MinRT, double MaxRT)
        {
            MSMatch First = null, Best = null;

            QMatch Res = new QMatch();

            Res.Clean();
            Res.MSMatches = new List <MSMatch>();

            double FirstIso = 0.0, SecondIso = 0.0;
            double BestScore = 0.0, fs = 0.0;
            int    BestIndex = 0;

            int    Scan  = 0;
            double AveRT = (MinRT + MaxRT) / 2;

            RawFile.ScanNumFromRT(AveRT, ref Scan);
            Scan = ms2index[Scan];

            //отступаем до минимального времени RT в массиве спектров
            double LowMZ = (MZ * Charge + (float)1.007277) / (Charge + 1);
            double HighMZ;

            if (Charge > 1)
            {
                HighMZ = (MZ * Charge - 1.007277) / (Charge - 1);
            }
            else
            {
                HighMZ = 0.0;
            }

            while (Scan > 0 && RawSpectra[Scan].RT >= MinRT)
            {
                Scan = IndexRev[Scan];
            }

            //цикл поиска лучшего
            while (Scan != -1 && RawSpectra[Scan].RT <= MaxRT)
            {
                if (Settings.Default.Deconvolution) //прихватываем другие зарядовые состояния
                {
                    First = FindMatchwithCharges(Scan, MZ, Charge, LowMZ, HighMZ);
                }
                else
                {
                    First = FindMatch(Scan, MZ, Charge);
                }

                //если не найден сам пик или его первый изотоп - сбрасываем
                if (First.Score == 0.0 || First.SecondIsotope == 0.0)
                {
                    Scan = IndexDir[Scan];
                    continue;
                }

                FirstIso = First.FirstIsotope +
                           (First.UpperCharges == null ? 0 : First.UpperCharges.FirstIsotope) +
                           (First.LowerCharges == null ? 0 : First.LowerCharges.FirstIsotope);
                SecondIso = First.SecondIsotope +
                            (First.UpperCharges == null ? 0 : First.UpperCharges.SecondIsotope) +
                            (First.LowerCharges == null ? 0 : First.LowerCharges.SecondIsotope);

                fs = SecondIso / FirstIso;

                double CurrentScore = First.Score +
                                      (First.UpperCharges == null ? 0 : First.UpperCharges.Score) +
                                      (First.LowerCharges == null ? 0 : First.LowerCharges.Score);

                //пик может распространяться за границы, но апекс должен быть внутри
                if (CurrentScore > BestScore && fs > IsoRatio * 0.5 && fs < IsoRatio * 2)
                {
                    BestScore = CurrentScore;
                    BestIndex = Scan;
                    Best      = First;
                }
                //переходим к следующему full-ms
                Scan = IndexDir[Scan];
            }

            if (BestScore == 0.0)
            {
                return(null);
            }

            //если хоть что-то нашли
            //добавляем наибольшее
            LowMZ = (Best.MZ * Charge + (float)1.007277) / (Charge + 1);
            if (Charge > 1)
            {
                HighMZ = (MZ * Charge - 1.007277) / (Charge - 1);
            }
            else
            {
                HighMZ = 0.0;
            }


            Res.ApexRT = Best.RT;
            Res.MSMatches.Add(Best);

            //берем сплошную область вокруг Best - вперед
            for (Scan = IndexDir[BestIndex]; Scan > 0; Scan = IndexDir[Scan])
            {
                if (Settings.Default.Deconvolution) //прихватываем другие зарядовые состояния
                {
                    First = FindMatchwithCharges(Scan, Best.MZ, Charge, LowMZ, HighMZ);
                }
                else
                {
                    First = FindMatch(Scan, Best.MZ, Charge);
                }

                if (First.Score == 0.0 || First.SecondIsotope == 0.0)
                {
                    Res.MSMatches.Add(First);
                    break;
                }
                fs = First.SecondIsotope / First.FirstIsotope;
                //включаем здесь контроль по соотношению изотопов
                //if (fs < IsoRatio*0.5 || fs > IsoRatio * 2 ){
                //    break;
                //}
                Res.MSMatches.Add(First);
            }

            //берем сплошную область вокруг Best - назад
            for (Scan = IndexRev[BestIndex]; Scan > 0; Scan = IndexRev[Scan])
            {
                if (Settings.Default.Deconvolution) //прихватываем другие зарядовые состояния
                {
                    First = FindMatchwithCharges(Scan, Best.MZ, Charge, LowMZ, HighMZ);
                }
                else
                {
                    First = FindMatch(Scan, Best.MZ, Charge);
                }

                if (First.Score == 0.0 || First.SecondIsotope == 0.0)
                {
                    Res.MSMatches.Add(First);
                    break;
                }
                fs = First.SecondIsotope / First.FirstIsotope;
                //включаем здесь контроль по соотношению изотопов
                //if (fs < IsoRatio*0.5 || fs > IsoRatio * 2 ){
                //    break;
                //}
                Res.MSMatches.Insert(0, First);
            }

            Res.Estimate(IsoRatio);
            Res.CleanUp();

            return(Res);
        }
コード例 #2
0
        public void CutTails(QMatch Ext)
        {
            //упрощенная версия - от апекса
            double Shift = ApexRT - Ext.ApexRT;
            //double Shift = -Ext.Shift;

            int CutOff, i;

            if (MSMatches == null || Ext.MSMatches == null)
            {
                return;
            }
            //сортируем
            //передние хвосты
            if (MSMatches[0].RT - Shift > Ext.MSMatches[0].RT)
            {
                //наш хвост короче
                for (i = 1; i < Ext.MSMatches.Count; i++)
                {
                    if (MSMatches[0].RT - Shift < Ext.MSMatches[i].RT)
                    {
                        break;
                    }
                }
                if (i < Ext.MSMatches.Count)
                {
                    //Ext.MSMatches.RemoveRange(0,i-1);
                    ////ноль будет объявлен там же где и ноль у образца
                    //Temp = ((MSMatches[0].RT - Shift) - Ext.MSMatches[i-1].RT)/2;
                    //Ext.MSMatches[i-1].RT = MSMatches[0].RT - Shift;
                    //Ext.MSMatches[i].RT = Ext.MSMatches[i].RT + Temp;

                    CutOff = (Math.Abs(MSMatches[0].RT - Shift - Ext.MSMatches[i].RT) < Math.Abs(MSMatches[0].RT - Shift - Ext.MSMatches[i - 1].RT))?i:i - 1;

                    //Ext.MSMatches.RemoveRange(0,CutOff); - предидущее
                    if (CutOff > 0)
                    {
                        Ext.MSMatches[CutOff - 1].Score = 0.0;
                        Ext.MSMatches.RemoveRange(0, CutOff - 1);
                    }
                }
            }
            else
            {
                //их хвост короче
                for (i = 1; i < MSMatches.Count; i++)
                {
                    if (Ext.MSMatches[0].RT + Shift < MSMatches[i].RT)
                    {
                        break;
                    }
                }
                if (i < MSMatches.Count)
                {
                    CutOff = (Math.Abs(MSMatches[i].RT - Shift - Ext.MSMatches[0].RT) < Math.Abs(MSMatches[i - 1].RT - Shift - Ext.MSMatches[0].RT))?i:i - 1;
                    //MSMatches.RemoveRange(0,CutOff);- предидущее
                    if (CutOff > 0)
                    {
                        MSMatches[CutOff - 1].Score = 0.0;
                        MSMatches.RemoveRange(0, CutOff - 1);
                    }
                }
            }

            //задние хвосты
            int IntCount = MSMatches.Count - 1;
            int ExtCount = Ext.MSMatches.Count - 1;

            if (MSMatches[IntCount].RT - Shift < Ext.MSMatches[ExtCount].RT)
            {
                //наш хвост короче
                for (i = ExtCount - 1; i >= 0; i--)
                {
                    if (MSMatches[IntCount].RT - Shift > Ext.MSMatches[i].RT)
                    {
                        break;
                    }
                }
                if (i >= 0)
                {
                    CutOff = (Math.Abs(MSMatches[IntCount].RT - Shift - Ext.MSMatches[i].RT) < Math.Abs(MSMatches[IntCount].RT - Shift - Ext.MSMatches[i + 1].RT))?i:i + 1;
                    //Ext.MSMatches.RemoveRange(CutOff+1, ExtCount-CutOff); - предыдущее
                    if (CutOff < Ext.MSMatches.Count - 1)
                    {
                        Ext.MSMatches[CutOff + 1].Score = 0.0;
                        Ext.MSMatches.RemoveRange(CutOff + 2, ExtCount - CutOff - 1);
                    }
                }
            }
            else
            {
                //их хвост короче
                for (i = IntCount - 1; i >= 0; i--)
                {
                    if (Ext.MSMatches[ExtCount].RT + Shift > MSMatches[i].RT)
                    {
                        break;
                    }
                }
                if (i >= 0)
                {
                    CutOff = (Math.Abs(MSMatches[i].RT - Shift - Ext.MSMatches[ExtCount].RT) < Math.Abs(MSMatches[i + 1].RT - Shift - Ext.MSMatches[ExtCount].RT))?i:i + 1;
                    //MSMatches.RemoveRange(CutOff+1, IntCount-CutOff);- предыдущее
                    if (CutOff < MSMatches.Count - 1)
                    {
                        MSMatches[CutOff + 1].Score = 0.0;
                        MSMatches.RemoveRange(CutOff + 2, IntCount - CutOff - 1);
                    }
                }
            }
            this.Estimate(IsotopeRatio);
            Ext.Estimate(Ext.IsotopeRatio);
        }
コード例 #3
0
        public void CutTails1(QMatch Ext)
        {
            double Shift0 = ApexRT - Ext.ApexRT;
            double Shift  = -Ext.Shift;
            double Temp;

            int i;

            if (MSMatches == null || Ext.MSMatches == null)
            {
                return;
            }
            //сортируем
            //передние хвосты
            if (MSMatches[0].RT - Shift > Ext.MSMatches[0].RT)
            {
                //наш хвост короче
                for (i = 1; i < Ext.MSMatches.Count; i++)
                {
                    if (MSMatches[0].RT - Shift < Ext.MSMatches[i].RT)
                    {
                        break;
                    }
                }
                if (i < Ext.MSMatches.Count)
                {
                    Ext.MSMatches.RemoveRange(0, i - 1);
                    //ноль будет объявлен там же где и ноль у образца
                    Temp = ((MSMatches[0].RT - Shift) - Ext.MSMatches[0].RT) / 2;
                    Ext.MSMatches[0].RT    = MSMatches[0].RT - Shift;
                    Ext.MSMatches[0].Score = 0.0;
                    Ext.MSMatches[1].RT    = Ext.MSMatches[1].RT + Temp;
//                    CutOff = (Math.Abs(MSMatches[0].RT - Shift - Ext.MSMatches[i].RT) <  Math.Abs(MSMatches[0].RT - Shift - Ext.MSMatches[i-1].RT))?i:i-1;
//                    Ext.MSMatches.RemoveRange(0,CutOff);
                }
            }
            else
            {
                //их хвост короче
                for (i = 1; i < MSMatches.Count; i++)
                {
                    if (Ext.MSMatches[0].RT + Shift < MSMatches[i].RT)
                    {
                        break;
                    }
                }
                if (i < MSMatches.Count)
                {
                    MSMatches.RemoveRange(0, i - 1);
                    //ноль будет объявлен там же где и ноль у образца
                    Temp               = (Ext.MSMatches[0].RT - (MSMatches[0].RT - Shift)) / 2;
                    MSMatches[0].RT    = Ext.MSMatches[0].RT + Shift;
                    MSMatches[0].Score = 0.0;
                    MSMatches[1].RT    = MSMatches[1].RT + Temp;

                    //CutOff = (Math.Abs(MSMatches[i].RT - Shift - Ext.MSMatches[0].RT) <  Math.Abs(MSMatches[i-1].RT - Shift - Ext.MSMatches[0].RT))?i:i-1;
                    //MSMatches.RemoveRange(0,CutOff);
                }
            }

            //задние хвосты
            int IntCount = MSMatches.Count - 1;
            int ExtCount = Ext.MSMatches.Count - 1;

            if (MSMatches[IntCount].RT - Shift < Ext.MSMatches[ExtCount].RT)
            {
                //наш хвост короче
                for (i = ExtCount - 1; i >= 0; i--)
                {
                    if (MSMatches[IntCount].RT - Shift > Ext.MSMatches[i].RT)
                    {
                        break;
                    }
                }
                if (i >= 0)
                {
                    Ext.MSMatches.RemoveRange(i + 2, Ext.MSMatches.Count - i - 2);
                    //ноль будет объявлен там же где и ноль у образца
                    Temp = ((MSMatches[MSMatches.Count - 1].RT - Shift) - Ext.MSMatches[Ext.MSMatches.Count - 1].RT) / 2;
                    Ext.MSMatches[Ext.MSMatches.Count - 1].RT    = MSMatches[MSMatches.Count - 1].RT - Shift;
                    Ext.MSMatches[Ext.MSMatches.Count - 1].Score = 0.0;
                    Ext.MSMatches[Ext.MSMatches.Count - 2].RT    = Ext.MSMatches[Ext.MSMatches.Count - 2].RT + Temp;

                    //CutOff = (Math.Abs(MSMatches[IntCount].RT - Shift - Ext.MSMatches[i].RT) <  Math.Abs(MSMatches[IntCount].RT - Shift - Ext.MSMatches[i+1].RT))?i:i+1;
                    //Ext.MSMatches.RemoveRange(CutOff+1, ExtCount-CutOff);
                }
            }
            else
            {
                //их хвост короче
                for (i = IntCount - 1; i >= 0; i--)
                {
                    if (Ext.MSMatches[ExtCount].RT + Shift > MSMatches[i].RT)
                    {
                        break;
                    }
                }
                if (i >= 0)
                {
                    MSMatches.RemoveRange(i + 2, MSMatches.Count - i - 2);
                    //ноль будет объявлен там же где и ноль у образца
                    Temp = (Ext.MSMatches[Ext.MSMatches.Count - 1].RT - (MSMatches[MSMatches.Count - 1].RT - Shift)) / 2;
                    MSMatches[MSMatches.Count - 1].RT    = Ext.MSMatches[Ext.MSMatches.Count - 1].RT + Shift;
                    MSMatches[MSMatches.Count - 1].Score = 0.0;
                    MSMatches[MSMatches.Count - 2].RT    = MSMatches[MSMatches.Count - 2].RT + Temp;

                    //CutOff = (Math.Abs(MSMatches[i].RT - Shift - Ext.MSMatches[ExtCount].RT) <  Math.Abs(MSMatches[i+1].RT - Shift - Ext.MSMatches[ExtCount].RT))?i:i+1;
                    //MSMatches.RemoveRange(CutOff+1, IntCount-CutOff);
                }
            }
            this.Estimate(IsotopeRatio);
            Ext.Estimate(Ext.IsotopeRatio);
        }