private float CompareFragSpectraForParentIons( clsScanList scanList, clsSpectraCache spectraCache, int parentIonIndex1, int parentIonIndex2, clsBinningOptions binningOptions, MASICPeakFinder.clsBaselineNoiseOptions noiseThresholdOptions, DataInput.clsDataImport dataImportUtilities) { // Compare the fragmentation spectra for the two parent ions // Returns the highest similarity score (ranging from 0 to 1) // Returns 0 if no similarity or no spectra to compare // Returns -1 if an error float highestSimilarityScore; try { if (scanList.ParentIons[parentIonIndex1].CustomSICPeak || scanList.ParentIons[parentIonIndex2].CustomSICPeak) { // Custom SIC values do not have fragmentation spectra; nothing to compare highestSimilarityScore = 0; } else if (scanList.ParentIons[parentIonIndex1].MRMDaughterMZ > 0 || scanList.ParentIons[parentIonIndex2].MRMDaughterMZ > 0) { // MRM Spectra should not be compared highestSimilarityScore = 0; } else { highestSimilarityScore = 0; foreach (var fragSpectrumIndex1 in scanList.ParentIons[parentIonIndex1].FragScanIndices) { if (!spectraCache.GetSpectrum(scanList.FragScans[fragSpectrumIndex1].ScanNumber, out var spectrum1, false)) { SetLocalErrorCode(clsMASIC.eMasicErrorCodes.ErrorUncachingSpectrum); return(-1); } // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (!clsMASIC.DISCARD_LOW_INTENSITY_MSMS_DATA_ON_LOAD) #pragma warning disable 162 // ReSharper disable HeuristicUnreachableCode { dataImportUtilities.DiscardDataBelowNoiseThreshold(spectrum1, scanList.FragScans[fragSpectrumIndex1].BaselineNoiseStats.NoiseLevel, 0, 0, noiseThresholdOptions); } // ReSharper restore HeuristicUnreachableCode #pragma warning restore 162 foreach (var fragSpectrumIndex2 in scanList.ParentIons[parentIonIndex2].FragScanIndices) { if (!spectraCache.GetSpectrum(scanList.FragScans[fragSpectrumIndex2].ScanNumber, out var spectrum2, false)) { SetLocalErrorCode(clsMASIC.eMasicErrorCodes.ErrorUncachingSpectrum); return(-1); } // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (!clsMASIC.DISCARD_LOW_INTENSITY_MSMS_DATA_ON_LOAD) #pragma warning disable 162 // ReSharper disable HeuristicUnreachableCode { dataImportUtilities.DiscardDataBelowNoiseThreshold(spectrum2, scanList.FragScans[fragSpectrumIndex2].BaselineNoiseStats.NoiseLevel, 0, 0, noiseThresholdOptions); } // ReSharper restore HeuristicUnreachableCode #pragma warning restore 162 var similarityScore = CompareSpectra(spectrum1, spectrum2, binningOptions); if (similarityScore > highestSimilarityScore) { highestSimilarityScore = similarityScore; } } } } } catch (Exception ex) { ReportError("Error in CompareFragSpectraForParentIons", ex); return(-1); } return(highestSimilarityScore); }
/// <summary> /// Discard data below the noise threshold /// </summary> /// <param name="msSpectrum"></param> /// <param name="noiseThresholdIntensity"></param> /// <param name="mzIgnoreRangeStart"></param> /// <param name="mzIgnoreRangeEnd"></param> /// <param name="noiseThresholdOptions"></param> public void DiscardDataBelowNoiseThreshold( clsMSSpectrum msSpectrum, double noiseThresholdIntensity, double mzIgnoreRangeStart, double mzIgnoreRangeEnd, MASICPeakFinder.clsBaselineNoiseOptions noiseThresholdOptions) { var ionCountNew = 0; try { switch (noiseThresholdOptions.BaselineNoiseMode) { case MASICPeakFinder.clsMASICPeakFinder.eNoiseThresholdModes.AbsoluteThreshold: if (noiseThresholdOptions.BaselineNoiseLevelAbsolute > 0) { ionCountNew = 0; for (var ionIndex = 0; ionIndex < msSpectrum.IonCount; ionIndex++) { // Always keep points in the m/z ignore range // If CheckPointInMZIgnoreRange returns true, set pointPassesFilter to true var pointPassesFilter = clsUtilities.CheckPointInMZIgnoreRange(msSpectrum.IonsMZ[ionIndex], mzIgnoreRangeStart, mzIgnoreRangeEnd); if (!pointPassesFilter) { // Check the point's intensity against .BaselineNoiseLevelAbsolute if (msSpectrum.IonsIntensity[ionIndex] >= noiseThresholdOptions.BaselineNoiseLevelAbsolute) { pointPassesFilter = true; } } if (pointPassesFilter) { msSpectrum.IonsMZ[ionCountNew] = msSpectrum.IonsMZ[ionIndex]; msSpectrum.IonsIntensity[ionCountNew] = msSpectrum.IonsIntensity[ionIndex]; ionCountNew += 1; } } } else { ionCountNew = msSpectrum.IonCount; } break; case MASICPeakFinder.clsMASICPeakFinder.eNoiseThresholdModes.TrimmedMeanByAbundance: case MASICPeakFinder.clsMASICPeakFinder.eNoiseThresholdModes.TrimmedMeanByCount: case MASICPeakFinder.clsMASICPeakFinder.eNoiseThresholdModes.TrimmedMedianByAbundance: if (noiseThresholdOptions.MinimumSignalToNoiseRatio > 0) { ionCountNew = 0; for (var ionIndex = 0; ionIndex < msSpectrum.IonCount; ionIndex++) { // Always keep points in the m/z ignore range // If CheckPointInMZIgnoreRange returns true, set pointPassesFilter to true var pointPassesFilter = clsUtilities.CheckPointInMZIgnoreRange(msSpectrum.IonsMZ[ionIndex], mzIgnoreRangeStart, mzIgnoreRangeEnd); if (!pointPassesFilter) { // Check the point's intensity against .BaselineNoiseLevelAbsolute if (MASICPeakFinder.clsMASICPeakFinder.ComputeSignalToNoise(msSpectrum.IonsIntensity[ionIndex], noiseThresholdIntensity) >= noiseThresholdOptions.MinimumSignalToNoiseRatio) { pointPassesFilter = true; } } if (pointPassesFilter) { msSpectrum.IonsMZ[ionCountNew] = msSpectrum.IonsMZ[ionIndex]; msSpectrum.IonsIntensity[ionCountNew] = msSpectrum.IonsIntensity[ionIndex]; ionCountNew += 1; } } } else { ionCountNew = msSpectrum.IonCount; } break; default: ReportError("Unknown BaselineNoiseMode encountered in DiscardDataBelowNoiseThreshold: " + noiseThresholdOptions.BaselineNoiseMode.ToString()); break; } if (ionCountNew < msSpectrum.IonCount) { msSpectrum.ShrinkArrays(ionCountNew); } } catch (Exception ex) { ReportError("Error discarding data below the noise threshold", ex, clsMASIC.eMasicErrorCodes.UnspecifiedError); } }