Example #1
0
        private bool SimilarScore(LcMsPeakCluster f1, LcMsPeakCluster f2)
        {
            /*var maxScore = Math.Max(f1.Score, f2.Score);
             * var minScore = Math.Min(f1.Score, f2.Score);
             * if (minScore > 0 && maxScore > minScore*5) return false;*/

            if (f1.Score >= _scorer.ScoreThreshold && f1.GoodEnougth &&
                f2.Score >= _scorer.ScoreThreshold && f2.GoodEnougth)
            {
                return(true);
            }

            return(false);
        }
Example #2
0
        public double GetScore(LcMsPeakCluster feature)
        {
            var mi = (int)Math.Round((feature.Mass - _massBins[0]) / (_massBins[1] - _massBins[0]));

            mi = (int)Math.Min(Math.Max(mi, 0), _massBins.Length - 1);
            var score     = 0d;
            var abundance = feature.AbundanceDistributionAcrossCharge;

            for (var i = 0; i < 2; i++)
            {
                //score += _chargeScoreTable[mi][charge - 1];
                var abuScore = abundance[i];
                var k        = (int)Math.Min(Math.Max(Math.Round(abuScore / 0.001), 0), NumberOfBins - 1);
                score += _abuScoreTable[mi][k];

                //if (!(abuScore > 0)) continue;
                var distScore = Math.Min(feature.EnvelopeDistanceScoreAcrossCharge[i], 1.0d);
                k      = (int)Math.Min(Math.Max(Math.Round(distScore / 0.001), 0), NumberOfBins - 1);
                score += _distScoreTableSummed[mi][k];

                var corrScore = Math.Min(feature.EnvelopeCorrelationScoreAcrossCharge[i], 1.0d);
                k      = (int)Math.Min(Math.Max(Math.Round(corrScore / 0.001), 0), NumberOfBins - 1);
                score += _corrScoreTableSummed[mi][k];

                var intScore = Math.Min(feature.EnvelopeIntensityScoreAcrossCharge[i], 1.0d);
                k      = (int)Math.Min(Math.Max(Math.Round(intScore / 0.001), 0), NumberOfBins - 1);
                score += _intScoreTableSummed[mi][k];

                distScore = Math.Min(feature.BestDistanceScoreAcrossCharge[i], 1.0d);
                k         = (int)Math.Min(Math.Max(Math.Round(distScore / 0.001), 0), NumberOfBins - 1);
                score    += _distScoreTable[mi][k];

                corrScore = Math.Min(feature.BestCorrelationScoreAcrossCharge[i], 1.0d);
                k         = (int)Math.Min(Math.Max(Math.Round(corrScore / 0.001), 0), NumberOfBins - 1);
                score    += _corrScoreTable[mi][k];

                intScore = Math.Min(feature.BestIntensityScoreAcrossCharge[i], 1.0d);
                k        = (int)Math.Min(Math.Max(Math.Round(intScore / 0.001), 0), NumberOfBins - 1);
                score   += _intScoreTable[mi][k];

                var xicScore = Math.Min(feature.XicCorrelationBetweenBestCharges[i], 1.0d);
                k      = (int)Math.Min(Math.Max(Math.Round(xicScore / 0.001), 0), NumberOfBins - 1);
                score += (i == 0) ? _xicScoreTable1[mi][k] : _xicScoreTable2[mi][k];
            }
            return(score);
        }
Example #3
0
        public double GetScore(LcMsPeakCluster feature)
        {
            var mi = (int)Math.Round((feature.Mass - _massBins[0]) / (_massBins[1] - _massBins[0]));
            mi = (int) Math.Min(Math.Max(mi, 0), _massBins.Length - 1);
            var score = 0d;
            var abundance = feature.AbundanceDistributionAcrossCharge;

            for (var i = 0; i < 2; i++)
            {
                //score += _chargeScoreTable[mi][charge - 1];
                var abuScore = abundance[i];
                var k = (int)Math.Min(Math.Max(Math.Round(abuScore / 0.001), 0), NumberOfBins - 1);
                score += _abuScoreTable[mi][k];

                //if (!(abuScore > 0)) continue;
                var distScore = Math.Min(feature.EnvelopeDistanceScoreAcrossCharge[i], 1.0d);
                k = (int)Math.Min(Math.Max(Math.Round(distScore / 0.001), 0), NumberOfBins - 1);
                score += _distScoreTableSummed[mi][k];

                var corrScore = Math.Min(feature.EnvelopeCorrelationScoreAcrossCharge[i], 1.0d);
                k = (int)Math.Min(Math.Max(Math.Round(corrScore / 0.001), 0), NumberOfBins - 1);
                score += _corrScoreTableSummed[mi][k];

                var intScore = Math.Min(feature.EnvelopeIntensityScoreAcrossCharge[i], 1.0d);
                k = (int)Math.Min(Math.Max(Math.Round(intScore / 0.001), 0), NumberOfBins - 1);
                score += _intScoreTableSummed[mi][k];

                distScore = Math.Min(feature.BestDistanceScoreAcrossCharge[i], 1.0d);
                k = (int)Math.Min(Math.Max(Math.Round(distScore / 0.001), 0), NumberOfBins - 1);
                score += _distScoreTable[mi][k];

                corrScore = Math.Min(feature.BestCorrelationScoreAcrossCharge[i], 1.0d);
                k = (int)Math.Min(Math.Max(Math.Round(corrScore / 0.001), 0), NumberOfBins - 1);
                score += _corrScoreTable[mi][k];

                intScore = Math.Min(feature.BestIntensityScoreAcrossCharge[i], 1.0d);
                k = (int)Math.Min(Math.Max(Math.Round(intScore / 0.001), 0), NumberOfBins - 1);
                score += _intScoreTable[mi][k];

                var xicScore = Math.Min(feature.XicCorrelationBetweenBestCharges[i], 1.0d);
                k = (int)Math.Min(Math.Max(Math.Round(xicScore / 0.001), 0), NumberOfBins - 1);
                score += (i == 0) ? _xicScoreTable1[mi][k] : _xicScoreTable2[mi][k];
            }
            return score;
        }
Example #4
0
 public void TagMinorPeakOf(LcMsPeakCluster feature)
 {
     //if (_minorTaggedFeatures == null) _minorTaggedFeatures = new List<LcMsPeakCluster>();
     //_minorTaggedFeatures.Add(feature);
     if (_minorTaggedFeatures == null) 
     {
         _minorTaggedFeatures = new LcMsPeakCluster[2];
         _minorTaggedFeatures[_countMinorTaggedFeatures++] = feature;
     }
     else
     {
         if (_countMinorTaggedFeatures >= _minorTaggedFeatures.Length)
         {
             Array.Resize(ref _minorTaggedFeatures, _minorTaggedFeatures.Length * 2);
         }
         _minorTaggedFeatures[_countMinorTaggedFeatures++] = feature; 
     }
 }
Example #5
0
        public bool Add(LcMsPeakCluster newFeature)
        {
            if (newFeature.Score < _scorer.ScoreThreshold)
            {
                return(false);
            }
            if (!newFeature.GoodEnougth)
            {
                return(false);
            }

            for (var i = _featureList.Count - 1; i >= 0; i--)
            {
                var massDiff = Math.Abs(_featureList[i].RepresentativeMass - newFeature.RepresentativeMass);
                if (massDiff > 1.0d)
                {
                    break;
                }
                if (massDiff < 1e-4)
                {
                    var coeLen = _featureList[i].CoElutionLength(newFeature);
                    if (coeLen > _featureList[i].ElutionLength * 0.7 || coeLen > newFeature.ElutionLength * 0.7)
                    {
                        return(false);
                    }
                }
            }

            /*
             * foreach (var peak in newFeature.GetMajorPeaks())
             * {
             *  peak.TagMajorPeakOf(newFeature);
             * }
             *
             * foreach (var peak in newFeature.GetMinorPeaks())
             * {
             *  peak.TagMinorPeakOf(newFeature);
             * }
             */
            _featureList.Add(newFeature);

            return(true);
        }
        public static string GetString(LcMsPeakCluster feature, bool scoreReport = false)
        {
            // should be called after calling UpdateScore & UpdateAbundance
            var sb = new StringBuilder(string.Format("{0}\t{1}\t{2}\t{3}\t{4:0.0000}\t{5}\t{6}\t{7:0.0000}\t{8:0.00}",
                                        feature.MinScanNum, feature.MaxScanNum,
                                        feature.MinCharge, feature.MaxCharge,
                                        feature.RepresentativeMass,
                                        feature.RepresentativeScanNum,
                                        feature.RepresentativeCharge,
                                        feature.RepresentativeMz,
                                        feature.Abundance));

            sb.AppendFormat("\t{0:0}", feature.ApexScanNum);
            sb.AppendFormat("\t{0:0.00}", feature.ApexIntensity);

            sb.AppendFormat("\t{0:0.000}", feature.MinElutionTime);
            sb.AppendFormat("\t{0:0.000}", feature.MaxElutionTime);
            sb.AppendFormat("\t{0:0.000}", feature.ElutionLength);

            sb.Append("\t");
            var intensity = feature.RepresentativeSummedEnvelop;
            var maxIntensity = intensity.Max();
            for (var i = 0; i < intensity.Length; i++)
            {
                if (i != 0) sb.Append(";");
                sb.AppendFormat("{0},{1:0.000}", feature.TheoreticalEnvelope.Isotopes[i].Index, intensity[i] / maxIntensity);
            }

            sb.Append(string.Format("\t{0:0.0000}", feature.Score));
            if (scoreReport)
            {
                sb.AppendFormat("\t{0}", feature.BestCharge[LcMsPeakCluster.EvenCharge]);
                sb.AppendFormat("\t{0}", feature.BestCharge[LcMsPeakCluster.OddCharge]);

                sb.AppendFormat("\t{0:0.000}", feature.BestCorrelationScoreAcrossCharge[LcMsPeakCluster.EvenCharge]);
                sb.AppendFormat("\t{0:0.000}", feature.BestCorrelationScoreAcrossCharge[LcMsPeakCluster.OddCharge]);

                sb.AppendFormat("\t{0:0.000}", feature.BestIntensityScoreAcrossCharge[LcMsPeakCluster.EvenCharge]);
                sb.AppendFormat("\t{0:0.000}", feature.BestIntensityScoreAcrossCharge[LcMsPeakCluster.OddCharge]);

                sb.AppendFormat("\t{0:0.000}", feature.EnvelopeCorrelationScoreAcrossCharge[LcMsPeakCluster.EvenCharge]);
                sb.AppendFormat("\t{0:0.000}", feature.EnvelopeCorrelationScoreAcrossCharge[LcMsPeakCluster.OddCharge]);

                sb.AppendFormat("\t{0:0.000}", feature.EnvelopeIntensityScoreAcrossCharge[LcMsPeakCluster.EvenCharge]);
                sb.AppendFormat("\t{0:0.000}", feature.EnvelopeIntensityScoreAcrossCharge[LcMsPeakCluster.OddCharge]);

                sb.AppendFormat("\t{0:0.000}", feature.XicCorrelationBetweenBestCharges[LcMsPeakCluster.EvenCharge]);
                sb.AppendFormat("\t{0:0.000}", feature.XicCorrelationBetweenBestCharges[LcMsPeakCluster.OddCharge]);

                sb.AppendFormat("\t{0:0.000}", feature.AbundanceDistributionAcrossCharge[LcMsPeakCluster.EvenCharge]);
                sb.AppendFormat("\t{0:0.000}", feature.AbundanceDistributionAcrossCharge[LcMsPeakCluster.OddCharge]);

            }

            return sb.ToString();
        }
Example #7
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;
        }
Example #8
0
        private IList<LcMsPeakCluster> GetLcMs1PeakClusters(int binNumber)
        {
            const int chargeNeighborGap = 4;
            var targetMass = Comparer.GetMzAverage(binNumber);
            BuildFeatureMatrix(targetMass); // should be called first

            var clusters = new List<LcMsPeakCluster>();

            // todo : bottom up dataset??
            if (_rows.Length < 2 || _cols.Length < 1) return clusters;

            var tempEnvelope = new double[_theoreticalEnvelope.Size];
            var tempEnvelope2 = new double[_theoreticalEnvelope.Size];
            
            var ms1ScanNums = Run.GetMs1ScanVector();
            var ms1ScanNumToIndex = Run.GetMs1ScanNumToIndex();
            var mostAbuInternalIndex = _theoreticalEnvelope.IndexOrderByRanking[0];
            var tolerance = new Tolerance(Comparer.Ppm*0.5);

            foreach (var seed in _seedEnvelopes.OrderBy(s=>s.Key).Select(s=> s.Value))
            {
                var row = seed.Charge - _targetMinCharge;
                var col = ms1ScanNumToIndex[seed.ScanNum];
                
                if (_featureMatrix[row][col].CheckedOutFlag) continue;

                var mostAbuMz = _theoreticalEnvelope.GetIsotopeMz(seed.Charge, mostAbuInternalIndex);
                var seedLocalWin = Ms1Spectra[col].GetLocalMzWindow(mostAbuMz);
                var poissonPvalue = seedLocalWin.GetPoissonTestPvalue(_featureMatrix[row][col].EnvelopePeaks, _theoreticalEnvelope.Size);
                var rankSumPvalue = seedLocalWin.GetRankSumTestPvalue(_featureMatrix[row][col].EnvelopePeaks, _theoreticalEnvelope.Size);

                var goodEnvelope = (rankSumPvalue < 0.01 || poissonPvalue < 0.01);
                if (!goodEnvelope) continue;

                var chargeCheck = CorrectChargeState(seed, Ms1Spectra[col]);
                if (!chargeCheck) continue;
                
                var seedMass = _featureMatrix[row][col].AccurateMass;
                var massTol = tolerance.GetToleranceAsTh(seedMass);
                var newCluster = new LcMsPeakCluster(Run, seed);

                Array.Clear(tempEnvelope, 0, tempEnvelope.Length);
                seed.Peaks.SumEnvelopeTo(tempEnvelope);

                var neighbors = new Queue<ObservedIsotopeEnvelope>();
                neighbors.Enqueue(seed); // pick a seed
                _featureMatrix[row][col].CheckedOutFlag = true;

                var summedBcDist = _featureMatrix[row][col].DivergenceDist;
                var summedCorr = _featureMatrix[row][col].CorrelationCoeff;

                while (neighbors.Count > 0)
                {
                    var cell = neighbors.Dequeue();
                    var charge = cell.Charge;

                    var minRw = (int)Math.Max(charge - _targetMinCharge - chargeNeighborGap, _rows.First());
                    var maxRw = (int)Math.Min(charge - _targetMinCharge + chargeNeighborGap, _rows.Last());
                    var currCol = ms1ScanNumToIndex[cell.ScanNum];

                    for (var k = 0; k < 5; k++)
                    {
                        var j = currCol;
                        if (k < 3) j += k;
                        else j -= (k - 2);

                        if (j < _cols.First() || j > _cols.Last()) continue;

                        for (var i = minRw; i <= maxRw; i++)
                        {
                            if (_featureMatrix[i][j].CheckedOutFlag) continue;
                            if (!(_featureMatrix[i][j].AccurateMass > 0)) continue;
                            if (Math.Abs(seedMass - _featureMatrix[i][j].AccurateMass) > massTol) continue;
                            
                            Array.Copy(tempEnvelope, tempEnvelope2, tempEnvelope2.Length);

                            _featureMatrix[i][j].EnvelopePeaks.SumEnvelopeTo(tempEnvelope);
                            var newDivergence = _theoreticalEnvelope.GetBhattacharyyaDistance(tempEnvelope);
                            var newCorrelation = _theoreticalEnvelope.GetPearsonCorrelation(tempEnvelope);
                            
                            if (_featureMatrix[i][j].DivergenceDist < 0.02 ||_featureMatrix[i][j].CorrelationCoeff > 0.7 || newDivergence < summedBcDist || newCorrelation > summedCorr)
                            {
                                var envelope = new ObservedIsotopeEnvelope(_featureMatrix[i][j].AccurateMass,
                                    i + _targetMinCharge, ms1ScanNums[j], _featureMatrix[i][j].EnvelopePeaks,
                                    _theoreticalEnvelope);

                                neighbors.Enqueue(envelope);
                                newCluster.Expand(envelope);
                                _featureMatrix[i][j].CheckedOutFlag = true;

                                summedBcDist = newDivergence;
                                summedCorr = newCorrelation;
                            }
                            else
                            {
                                Array.Copy(tempEnvelope2, tempEnvelope, tempEnvelope.Length);
                            }
                        }
                    }
                }

                LcMsPeakCluster refinedCluster = null;
                if (summedCorr > 0.5 || summedBcDist < 0.15)
                {
                    // re-update check-out map
                    SetCheckOutFlag(newCluster.MinCharge - _targetMinCharge, newCluster.MaxCharge - _targetMinCharge, ms1ScanNumToIndex[newCluster.MinScanNum], ms1ScanNumToIndex[newCluster.MaxScanNum], false);
                    refinedCluster = GetLcMsPeakCluster(newCluster.RepresentativeMass, newCluster.RepresentativeCharge, newCluster.MinScanNum, newCluster.MaxScanNum, true);
                }

                if (refinedCluster != null && (_scorer == null || (_scorer != null && refinedCluster.GoodEnougth && refinedCluster.Score >= _scorer.ScoreThreshold)))
                {
                    SetCheckOutFlag(_rows.First(), _rows.Last(), ms1ScanNumToIndex[refinedCluster.MinScanNum], ms1ScanNumToIndex[refinedCluster.MaxScanNum], true);
                    clusters.Add(refinedCluster);
                }
                else
                {
                    SetCheckOutFlag(newCluster.MinCharge - _targetMinCharge, newCluster.MaxCharge - _targetMinCharge, ms1ScanNumToIndex[newCluster.MinScanNum], ms1ScanNumToIndex[newCluster.MaxScanNum], true);
                }
            }
            return clusters;            
        }
Example #9
0
        private double[] SetAbundanceByAuc(ref LcMsPeakCluster feature)
        {
            var ms1ScanNumToIndex = Run.GetMs1ScanNumToIndex();
            var ms1ScanNums = Run.GetMs1ScanVector();

            var minCol = ms1ScanNumToIndex[feature.MinScanNum];
            var maxCol = ms1ScanNumToIndex[feature.MaxScanNum];
            var minRow = feature.MinCharge - _targetMinCharge;
            var maxRow = feature.MaxCharge - _targetMinCharge;

            var simCutoff = GetDistanceCorrelationThreshold(minRow, maxRow, minCol, maxCol);
            var bcCutoff = Math.Max(0.07, simCutoff.Item1);
            var corrCutoff = Math.Min(0.7, simCutoff.Item2);
            
            var xic = new double[maxCol - minCol + 1 + 18];
            const int xicStartIndex = 9;

            foreach (var envelope in feature.EnumerateEnvelopes())
            {
                var envCol = ms1ScanNumToIndex[envelope.ScanNum];

                if (_featureMatrix[envelope.Charge - _targetMinCharge][envCol].DivergenceDist > bcCutoff &&
                    _featureMatrix[envelope.Charge - _targetMinCharge][envCol].CorrelationCoeff < corrCutoff) continue;
                xic[envCol - minCol + xicStartIndex] += envelope.Abundance;
            }
            
            var smoothedXic = Smoother.Smooth(xic);
            var abundance = 0d;
            var apexScanNum = feature.MinScanNum;
            var apexIntensity = 0d;
            var boundaryIntensity = 0d;

            for (var k = 0; k < smoothedXic.Length - 1; k++)
            {
                var col = k + minCol - xicStartIndex;
                if (col < 0 || col >= NColumns - 1) continue;

                var centerIntensity = 0.5 * (Math.Max(0, smoothedXic[k]) + Math.Max(0, smoothedXic[k + 1]));

                if (!(centerIntensity > 0)) continue;

                var timeInterval = Run.GetElutionTime(ms1ScanNums[col + 1]) - Run.GetElutionTime(ms1ScanNums[col]);
                var abu = centerIntensity*timeInterval;
                //abuList.Add(abu);
                abundance += abu;
                if (col >= minCol && col <= maxCol && apexIntensity < abu)
                {
                    apexIntensity = abu;
                    apexScanNum = ms1ScanNums[col];
                    if (col == minCol || col == maxCol)
                    {
                        boundaryIntensity += abu;
                    }
                }
            }

            feature.SetAbundance(abundance, apexScanNum, apexIntensity, boundaryIntensity*0.5);

            return smoothedXic;
        }
Example #10
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;
        }
Example #11
0
        private List <LcMsPeakCluster> MergeFeatures(LcMsPeakMatrix featureFinder, List <LcMsPeakCluster> features)
        {
            //foreach (var f in _featureList) f.ActivateAllPeaks();
            var featureSet = new NodeSet <LcMsPeakCluster>();

            featureSet.AddRange(features);

            var connectedFeatureSet = featureSet.ConnnectedComponents(_mergeComparer);
            var mergedFeatures      = new List <LcMsPeakCluster>();

            foreach (var fSet in connectedFeatureSet)
            {
                if (fSet.Count == 1)
                {
                    mergedFeatures.Add(fSet[0]);
                }
                else
                {
                    var             maxScan   = fSet.Max(f => f.MaxScanNum);
                    var             minScan   = fSet.Min(f => f.MinScanNum);
                    var             maxCharge = fSet.Max(f => f.MaxCharge);
                    var             minCharge = fSet.Min(f => f.MinCharge);
                    var             maxScore  = double.MinValue;//fSet.Max(f => f.Score);
                    LcMsPeakCluster maxScoredClusterOriginal = null;
                    LcMsPeakCluster maxScoredCluster         = null;
                    foreach (var f in fSet)
                    {
                        var newFeature = featureFinder.GetLcMsPeakCluster(f.RepresentativeMass, minCharge, maxCharge, minScan, maxScan);
                        if (newFeature != null && (maxScoredCluster == null || newFeature.Score > maxScoredCluster.Score))
                        {
                            maxScoredCluster = newFeature;
                        }

                        if (f.Score > maxScore)
                        {
                            maxScoredClusterOriginal = f;
                            maxScore = f.Score;
                        }
                    }
                    var feature = featureFinder.GetLcMsPeakCluster(fSet.Select(f => f.Mass).Mean(), minCharge, maxCharge, minScan, maxScan);
                    if (feature != null && (maxScoredCluster == null || feature.Score > maxScoredCluster.Score))
                    {
                        maxScoredCluster = feature;
                    }
                    //Console.WriteLine("------------- Merge -----------------");
                    //foreach (var f in fSet) Console.WriteLine("*\t{0}\t{1}\t{2}\t{3}", f.RepresentativeMass, f.MinScanNum, f.MaxScanNum, f.Score);
                    //Console.WriteLine("**\t{0}\t{1}\t{2}\t{3}", maxScoredCluster.RepresentativeMass, maxScoredCluster.MinScanNum, maxScoredCluster.MaxScanNum, maxScoredCluster.Score);
                    if (maxScoredCluster == null)
                    {
                        maxScoredCluster = maxScoredClusterOriginal;
                    }
                    if (maxScoredCluster.Score < maxScore)
                    {
                        maxScoredCluster.Score = maxScore;
                    }
                    mergedFeatures.Add(maxScoredCluster);
                }
                //if (selectedFeature != null) postFilteredSet.Add(selectedFeature);
            }
            //return postFilteredSet.OrderBy(f => f.RepresentativeMass);

            return(mergedFeatures);
        }
Example #12
0
        private void OutputEnvelopPeakStat(int id, LcMsPeakCluster feature, StreamWriter writer)
        {
            /*
            public double[] EnvelopeDistanceScoreAcrossCharge { get; internal set; }
            public double[] EnvelopeCorrelationScoreAcrossCharge { get; internal set; }
            public double[] EnvelopeIntensityScoreAcrossCharge { get; internal set; }
            public double[] AbundanceDistributionAcrossCharge { get; internal set; }
            public double[] BestCorrelationScoreAcrossCharge { get; private set; }
            public double[] BestDistanceScoreAcrossCharge { get; private set; }
            public double[] BestIntensityScoreAcrossCharge { get; private set; }            
            */

            //for(var charge = feature.MinCharge; charge <= feature.MaxCharge; charge++)
            for (var i = 0; i < 2; i++)
            {
                writer.Write(id);
                writer.Write("\t");

                writer.Write(feature.Mass);
                writer.Write("\t");

                writer.Write(feature.BestCharge[i]);
                writer.Write("\t");

                writer.Write(feature.EnvelopeDistanceScoreAcrossCharge[i]);
                writer.Write("\t");

                writer.Write(feature.EnvelopeCorrelationScoreAcrossCharge[i]);
                writer.Write("\t");

                writer.Write(feature.EnvelopeIntensityScoreAcrossCharge[i]);
                writer.Write("\t");

                writer.Write(feature.BestDistanceScoreAcrossCharge[i]);
                writer.Write("\t");

                writer.Write(feature.BestCorrelationScoreAcrossCharge[i]);
                writer.Write("\t");

                writer.Write(feature.BestIntensityScoreAcrossCharge[i]);
                writer.Write("\t");

                writer.Write(feature.AbundanceDistributionAcrossCharge[i]);
                writer.Write("\t");

                writer.Write(feature.XicCorrelationBetweenBestCharges[0]);
                writer.Write("\t");

                writer.Write(feature.XicCorrelationBetweenBestCharges[1]);
                //writer.Write("\t");

                writer.Write("\n");
            }
        }