コード例 #1
0
        private bool CompareSpectraBinData(
            clsCorrelation dataComparer,
            clsMSSpectrum fragSpectrum,
            clsBinnedData binnedSpectrum)
        {
            var xData = new List <float>(fragSpectrum.IonCount);
            var yData = new List <float>(fragSpectrum.IonCount);

            // Make a copy of the data, excluding any Reporter Ion data

            for (var index = 0; index < fragSpectrum.IonCount; index++)
            {
                if (!clsUtilities.CheckPointInMZIgnoreRange(fragSpectrum.IonsMZ[index],
                                                            mReporterIons.MZIntensityFilterIgnoreRangeStart,
                                                            mReporterIons.MZIntensityFilterIgnoreRangeEnd))
                {
                    xData.Add((float)(fragSpectrum.IonsMZ[index]));
                    yData.Add((float)(fragSpectrum.IonsIntensity[index]));
                }
            }

            binnedSpectrum.BinnedDataStartX = dataComparer.BinStartX;
            binnedSpectrum.BinSize          = dataComparer.BinSize;

            // Note that the data in xData and yData should have already been filtered to discard data points below the noise threshold intensity
            var success = dataComparer.BinData(xData, yData, binnedSpectrum.BinnedIntensities, binnedSpectrum.BinnedIntensitiesOffset);

            return(success);
        }
コード例 #2
0
        private float CompareSpectra(
            clsMSSpectrum fragSpectrum1,
            clsMSSpectrum fragSpectrum2,
            clsBinningOptions binningOptions,
            bool considerOffsetBinnedData = true)
        {
            // Compares the two spectra and returns a similarity score (ranging from 0 to 1)
            // Perfect match is 1; no similarity is 0
            // Note that both the standard binned data and the offset binned data are compared
            // If considerOffsetBinnedData = True, then the larger of the two scores is returned
            // similarity scores is returned
            //
            // If an error, returns -1

            var binnedSpectrum1 = new clsBinnedData();
            var binnedSpectrum2 = new clsBinnedData();

            try
            {
                var dataComparer = new clsCorrelation(binningOptions);
                RegisterEvents(dataComparer);

                const clsCorrelation.cmCorrelationMethodConstants eCorrelationMethod = clsCorrelation.cmCorrelationMethodConstants.Pearson;

                // Bin the data in the first spectrum
                var success = CompareSpectraBinData(dataComparer, fragSpectrum1, binnedSpectrum1);
                if (!success)
                {
                    return(-1);
                }

                // Bin the data in the second spectrum
                success = CompareSpectraBinData(dataComparer, fragSpectrum2, binnedSpectrum2);
                if (!success)
                {
                    return(-1);
                }

                // Now compare the binned spectra
                // Similarity will be 0 if either instance of BinnedIntensities has fewer than 5 data points
                var similarity1 = dataComparer.Correlate(binnedSpectrum1.BinnedIntensities, binnedSpectrum2.BinnedIntensities, eCorrelationMethod);

                if (!considerOffsetBinnedData)
                {
                    return(similarity1);
                }

                var similarity2 = dataComparer.Correlate(binnedSpectrum1.BinnedIntensitiesOffset, binnedSpectrum2.BinnedIntensitiesOffset, eCorrelationMethod);
                return(Math.Max(similarity1, similarity2));
            }
            catch (Exception ex)
            {
                ReportError("CompareSpectra: " + ex.Message, ex);
                return(-1);
            }
        }