/// <summary> /// 开始禁止判峰 /// </summary> private string StartInterdictPeak() { int idx = Math.Abs(GetPeakIndex()); string operates = ""; string operate = ""; if (SelectedPeak != null && SelectedPeak.PeakState == Peak.PeakStates.ps_noise) { operate = PeakProcessor.AddPeak(_list, idx); if (operate != "") { operates += operate; } } operate = BaselineCrossOperate(this.FrontIndexOf(idx)); if (operate != "") { operates += operate; } operate = PeakProcessor.DisableCheckPeak(_list, idx); if (operate != "") { operates += operate; } _interdictindex = idx; return(operates); }
/// <summary> /// 分离所有峰 /// </summary> /// <returns></returns> private string SeparatePeak(int end) { int idx = Math.Abs(GetPeakIndex()); string operates = ""; string operate = ""; _list[idx].BaseLineEnd = false; for (int i = idx; i <= end; i++) { //if (_list[i].BaseLineEnd) break; if (_list[i].PeakState == Peak.PeakStates.ps_natural) { if (!_list[i].BaseLineEnd) { operate = PeakProcessor.SeparatePeak(_list, i); } if (operate != "") { operates += operate; } operate = BaselineCrossOperate(i); if (operate != "") { operates += operate; } } } return(operates); }
public clsPeakProcessor() { _peakProcessor = new PeakProcessor(); _parameters = new clsPeakProcessorParameters(); _peakProcessor.SetOptions(_parameters.SignalToNoiseThreshold, 0, false, _parameters.PeakFitType); ProfileType = enmProfileType.PROFILE; }
//TODO: remove code duplication (see DeconToolsPeakDetector) public override List <Peak> FindPeaks(XYData xyData, double xMin = 0, double xMax = 0) { var peakList = new List <Peak>(); if (xyData == null) { return(peakList); } if (UseNewPeakDetector) { _peakDetectorV2.FindPeaks(xyData, xMin, xMax); } else { var xVals = xyData.Xvalues.ToList(); var yVals = xyData.Yvalues.ToList(); if (_oldPeakProcessor == null) { _oldPeakProcessor = new PeakProcessor(); } BackgroundIntensity = _oldPeakProcessor.GetBackgroundIntensity(yVals); _oldPeakProcessor.SetOptions(SigNoise, BackgroundIntensity * PeakBackgroundRatio, false, PeakFitType.Quadratic); //Find peaks using DeconEngine var largestXValue = xyData.Xvalues[xyData.Xvalues.Length - 1]; try { _oldPeakProcessor.DiscoverPeaks(xVals, yVals, 0, largestXValue); } catch (Exception ex) { Logger.Instance.AddEntry("ChromPeakDetector failed: " + ex.Message, true); throw; } _oldDeconEnginePeaklist = _oldPeakProcessor.PeakData.PeakTops; foreach (var peak in _oldDeconEnginePeaklist) { var chromPeak = new ChromPeak { XValue = peak.Mz, // here, mz is actually the scan / or NET Height = (float)peak.Intensity, SignalToNoise = peak.SignalToNoise, Width = (float)peak.FWHM }; peakList.Add(chromPeak); } } //resultList.Run.PeakList = new List<IPeak>(); return(peakList); }
/*[gord] the following is currently unused. The idea was to give weighting to the algorithm so that * the user could favor certain fitting parameters (i.e. space between isotopomers) over others * public double FindIsotopicDist(PeakProcessing.PeakData peakData, int cs, PeakProcessing.Peak peak, * IsotopeFitRecord isoRecord, double deleteIntensityThreshold, double spacingWeight, double spacingVar, * double signalToNoiseWeight, double signalToNoiseThresh, double ratioWeight, double ratioThreshold, * double fitWeight, double fitThreshold, bool debug = false) * { * if (cs <= 0) * { * Environment.Exit(1); * } * * //Get theoretical distribution using Mercury algorithm * double peakMass = (peak.mdbl_mz - ChargeCarrierMass) * cs; * double resolution = peak.mdbl_mz / peak.mdbl_FWHM; * GetIsotopeDistribution(peakMass, cs, resolution, out TheoreticalDistMzs, * out TheoreticalDistIntensities, * deleteIntensityThreshold, debug); * * double theorMostAbundantPeakMz = IsotopeDistribution.mdbl_max_peak_mz; * double delta = peak.mdbl_mz - theorMostAbundantPeakMz; * double spacingScore = 0; * double signalToNoiseScore = 0; * double ratioScore = 0; * double totalScore = 0; * double maximumScore = spacingWeight + signalToNoiseWeight + ratioWeight + fitWeight; * * //this will select peaks to the left until * for (double dd = 1.003 / cs; dd <= 10.03 / cs; dd += 1.003 / cs) * { * double theorLeftPeakMz = 0; * double theorLeftPeakIntensity = 0; * PeakProcessing.Peak leftPeak; * peakData.FindPeak(peak.mdbl_mz - dd - peak.mdbl_FWHM, peak.mdbl_mz - dd + peak.mdbl_FWHM, out leftPeak); * //PeakProcessing.FindPeak * IsotopeDistribution.FindPeak(theorMostAbundantPeakMz - dd - 0.2 / cs, * theorMostAbundantPeakMz - dd + 0.2 / cs, out theorLeftPeakMz, out theorLeftPeakIntensity); * * if (leftPeak.mdbl_mz > 0) //if there is an experimental peak... * { * //get spacing score * spacingScore = spacingWeight * 1; * * //get S/N score * if (leftPeak.mdbl_SN > signalToNoiseThresh) * { * signalToNoiseScore = signalToNoiseWeight * 1; * } * * //get Ratio score * double leftPeakRatio = leftPeak.mdbl_intensity / peak.mdbl_intensity; * double theorLeftPeakRatio = theorLeftPeakIntensity / 1; * //TODO: need to check if this most abundant theor peak's intensity is 1 * } * * //get Ratio score * } * //get S/N score * //get Fit score * //calculate maximum score * //get overall score * return 0; * }*/ public PeakData GetTheoreticalIsotopicDistributionPeakList(List <double> xvals, List <double> yvals) { var peakList = new PeakData(); var processor = new PeakProcessor(); processor.SetOptions(0.5, 1, false, PeakFitType.Apex); processor.DiscoverPeaks(xvals, yvals, 0, 10000); var numpeaks = processor.PeakData.GetNumPeaks(); for (var i = 0; i < numpeaks; i++) { ThrashV1Peak peak; processor.PeakData.GetPeak(i, out peak); peakList.AddPeak(peak); } return(peakList); }
/// <summary> /// 基线与峰相交处理 /// /// 保证基线不与峰上的点相交 /// </summary> /// <returns></returns> private string BaselineCrossOperate(int index) { try { if (index < 0 || index >= _list.Count) { return(""); } bool negative = (this[index].PeakPoint.Y < this[index].StartPoint.Y && this[index].PeakPoint.Y < this[index].EndPoint.Y); if (negative) { return(""); } string operates = ""; string operate = ""; PointF pt = PointF.Empty; //结束基线与峰相交 if (_list[index].PeakState != Peak.PeakStates.ps_natural) { return(""); } bool BaseLineStart = (FrontIndexOf(index) == -1); pt = GetStartBaselineCrossPoint(this[index], BaseLineStart); if (pt != PointF.Empty && !pt.Equals(this[index].StartPoint)) { operates = PeakProcessor.ChangeSEPoint(_list, index, Parent[pt.X], true); } pt = GetEndBaselineCrossPoint(this[index], BaseLineStart); if (pt != PointF.Empty && !pt.Equals(this[index].EndPoint)) { operate = PeakProcessor.ChangeSEPoint(_list, index, Parent[pt.X], false); } operates += operate; return(operates); } catch { return(""); } }
/// <summary> /// Finds peaks in XY Data within the specified range of X values. Optionally, to use all XY data points, enter 0 for both min and max values /// </summary> /// <param name="xydata"></param> /// <param name="minX"></param> /// <param name="maxX"></param> /// <returns></returns> public override List <Peak> FindPeaks(XYData xydata, double minX, double maxX) { if (xydata == null || xydata.Xvalues == null || xydata.Xvalues.Length == 0) { return(null); } var xvals = xydata.Xvalues.ToList(); var yvals = xydata.Yvalues.ToList(); //initialize DeconEngine's peakFinding class peakProcessor = new PeakProcessor(); //initialize options //this.isDataThresholded = resultList.Run.IsDataThresholded; [commented out: 2010_04_05 by gord] UpdateDeconEngineParameters(); BackgroundIntensity = peakProcessor.GetBackgroundIntensity(yvals); peakProcessor.SetOptions(SignalToNoiseThreshold, BackgroundIntensity * PeakToBackgroundRatio, IsDataThresholded, GetDeconPeakFitType(PeakFitType)); //Find peaks using DeconEngine if (minX == 0 && maxX == 0) { minX = xydata.Xvalues.First(); maxX = xydata.Xvalues.Last(); } try { peakProcessor.DiscoverPeaks(xvals, yvals, minX, maxX); } catch (Exception ex) { Logger.Instance.AddEntry("DeconToolsPeakDetector.FindPeaks exception: " + ex.Message, Logger.Instance.OutputFilename); throw; } DeconEnginePeakList = peakProcessor.PeakData.PeakTops; return(ConvertDeconEnginePeakList(DeconEnginePeakList)); }
/// <summary> /// 结束禁止判峰 /// </summary> private string EndInterdictPeak() { int idx = Math.Abs(GetPeakIndex()); string operate = ""; string operates = ""; operate = BaselineCrossOperate(this.BackIndexOf(idx)); if (operate != "") { operates += operate; } for (int i = idx; i >= _interdictindex; i--) { if (_interdictindex == -1) { continue; } if (_list[i].PeakState == Peak.PeakStates.ps_noise) { operate = PeakProcessor.AddPeak(_list, i); if (operate != "") { operates += operate; } } if (_list[i].PeakState == Peak.PeakStates.ps_natural) { operate = PeakProcessor.DisableCheckPeak(_list, i); if (operate != "") { operates += operate; } } } return(operates); }