public static List <XYData> Bin(List <XYData> data, double lowMass, double highMass, double binSize) { var newData = new List <XYData>(); var total = Convert.ToInt32((highMass - lowMass) / binSize); for (var i = 0; i < total; i++) { var part = new XYData(lowMass + (Convert.ToDouble(i) * binSize), 0.0); newData.Add(part); } for (var i = 0; i < data.Count; i++) { var intensity = data[i].Y; var bin = Math.Min(total - 1, System.Convert.ToInt32((data[i].X - lowMass) / binSize)); try { newData[bin].Y += intensity; } catch (Exception ex) { throw ex; } } return(newData); }
/// <summary> /// Finds the XIC based on the m/z and scan parameters. /// </summary> /// <param name="mz"></param> /// <param name="scan"></param> /// <returns></returns> public List<PNNLOmics.Data.XYData> FindXic(double mz, int scan, bool shouldSmooth) { LcmsFeatureTarget target = new LcmsFeatureTarget(); target.ID = 0; target.MZ = mz; target.ScanLCTarget = scan; target.ElutionTimeUnit = Globals.ElutionTimeUnit.ScanNum; m_run.CurrentMassTag = target; var result = m_run.ResultCollection.GetTargetedResult(m_run.CurrentMassTag); double chromPeakGeneratorTolInPPM = MzPpmWindow; Globals.ChromatogramGeneratorMode chromGeneratorMode = Globals.ChromatogramGeneratorMode.MZ_BASED; var chromGen = new PeakChromatogramGenerator( chromPeakGeneratorTolInPPM, chromGeneratorMode); chromGen.NETWindowWidthForNonAlignedData = Convert.ToSingle(NetWindow); int pointsToSmooth = 5; var chromSmoother = new SavitzkyGolaySmoother(pointsToSmooth, 2); double chromPeakDetectorPeakBR = 1; double chromPeakDetectorSigNoise = 1; var chromPeakDetector = new ChromPeakDetector( chromPeakDetectorPeakBR, chromPeakDetectorSigNoise); ChromPeakSelectorParameters chromPeakSelectorParameters = new ChromPeakSelectorParameters(); var chromPeakSelector = new BasicChromPeakSelector(chromPeakSelectorParameters); //this generates an extracted ion chromatogram // Since we are not using the built in generator, chromGen.Execute(m_run.ResultCollection); //this smooths the data - very important step! if (shouldSmooth) { chromSmoother.Execute(m_run.ResultCollection); } //this detects peaks within an extracted ion chromatogram chromPeakDetector.Execute(m_run.ResultCollection); //this selects the peak chromPeakSelector.Parameters.PeakSelectorMode = Globals.PeakSelectorMode.ClosestToTarget; chromPeakSelector.Execute(m_run.ResultCollection); //Here's the chromatogram data... List<PNNLOmics.Data.XYData> data = new List<PNNLOmics.Data.XYData>(); for (int i = 0; i < m_run.XYData.Xvalues.Length; i++) { PNNLOmics.Data.XYData datum = new PNNLOmics.Data.XYData(m_run.XYData.Xvalues[i], m_run.XYData.Yvalues[i]); data.Add(datum); } return data; }