Exemplo n.º 1
0
        private LcMsPeakCluster CollectLcMsPeaks(double targetMass, int minRow, int maxRow, int minCol, int maxCol, bool reCollectAllPeaks = false)
        {
            var ms1ScanNums = Run.GetMs1ScanVector();
            var envelopes = new List<ObservedIsotopeEnvelope>();
            var bestBcDist = 100d;
            ObservedIsotopeEnvelope bestEnvelope = null;
            var mostAbuInternalIndex = _theoreticalEnvelope.IndexOrderByRanking[0];
            var tolerance = new Tolerance(Comparer.Ppm * 0.5);
            var massTol = tolerance.GetToleranceAsTh(targetMass);
            var nPeaksCutoff = NumberOfPeaksCutoff;

            var bcCutoff = GetSeedBcDistThreshold();
            var corrCutoff = GetSeedCorrThreshold();
            
            for (var i = minRow; i <= maxRow; i++)
            {
                for (var j = minCol; j <= maxCol; j++)
                {
                    if (reCollectAllPeaks) _featureMatrix[i][j].Init();

                    if (reCollectAllPeaks || !_featureMatrix[i][j].Exist || Math.Abs(_featureMatrix[i][j].AccurateMass - targetMass) > massTol)
                    {
                        var peaks = Ms1Spectra[j].GetAllIsotopePeaks(targetMass, i + _targetMinCharge, _theoreticalEnvelope, tolerance);

                        if (peaks.Count(p => p != null) > 0)
                        {
                            _featureMatrix[i][j].DivergenceDist = _theoreticalEnvelope.GetBhattacharyyaDistance(peaks); ;
                            _featureMatrix[i][j].AccurateMass = targetMass;
                            _featureMatrix[i][j].CorrelationCoeff = _theoreticalEnvelope.GetPearsonCorrelation(peaks); ;
                            Array.Copy(peaks, _featureMatrix[i][j].EnvelopePeaks, peaks.Length);    
                        }
                    }

                    if (!_featureMatrix[i][j].Exist) continue;
                    if (_featureMatrix[i][j].CountActivePeaks < nPeaksCutoff) continue;
                    if (_featureMatrix[i][j].DivergenceDist > bcCutoff && _featureMatrix[i][j].CorrelationCoeff < corrCutoff) continue; // exclude outliers
                    var envelope = new ObservedIsotopeEnvelope(_featureMatrix[i][j].AccurateMass, i + _targetMinCharge, ms1ScanNums[j], _featureMatrix[i][j].EnvelopePeaks, _theoreticalEnvelope);
                    envelopes.Add(envelope);

                    if (_featureMatrix[i][j].EnvelopePeaks[mostAbuInternalIndex] != null && _featureMatrix[i][j].DivergenceDist < bestBcDist)
                    {
                        bestBcDist = _featureMatrix[i][j].DivergenceDist;
                        bestEnvelope = envelope;
                    }
                }
            }

            if (bestEnvelope == null) return null;

            var cluster = new LcMsPeakCluster(Run, bestEnvelope);
            cluster.AddEnvelopes(minRow + _targetMinCharge, maxRow + _targetMinCharge, ms1ScanNums[minCol], ms1ScanNums[maxCol], envelopes);
            
            return cluster;
        }
Exemplo n.º 2
0
        public LcMsPeakCluster GetLcMsPeaksFromNoisePeaks(double targetMass, int targetCharge, int targetMinScanNum, int targetMaxScanNum, int targetMinCharge, int targetMaxCharge)
        {
            SetTargetMass(targetMass);

            var ms1ScanNums = Run.GetMs1ScanVector();
            var ms1ScanNumToIndex = Run.GetMs1ScanNumToIndex();

            if (Run.GetMsLevel(targetMinScanNum) > 1) targetMinScanNum = Run.GetPrevScanNum(targetMinScanNum, 1);
            if (Run.GetMsLevel(targetMaxScanNum) > 1) targetMaxScanNum = Run.GetNextScanNum(targetMaxScanNum, 1);

            var minCol = ms1ScanNumToIndex[targetMinScanNum];
            var maxCol = ms1ScanNumToIndex[targetMaxScanNum];

            var minRow = targetMinCharge - _targetMinCharge;
            var maxRow = targetMaxCharge - _targetMinCharge;
            var abundance = 0d;

            for (var j = minCol; j <= maxCol; j++)
            {
                abundance += Ms1Spectra[j].MedianIntensity;
            }

            var repScanNum = ms1ScanNums[(int)((minCol + maxCol) * 0.5)];
            var repMz = 0;
            var cluster = new LcMsPeakCluster(Run, _theoreticalEnvelope, targetMass, targetCharge, repMz, repScanNum, abundance);
            cluster.AddEnvelopes(minRow + _targetMinCharge, maxRow + _targetMinCharge, ms1ScanNums[minCol], ms1ScanNums[maxCol]);
            cluster.Score = float.MinValue;
            return cluster;
        }