private MSScan GetScanFromFile(int argScanNo, float argMinSN = 2) { int isProfile = 0; _rawConnection.IsProfileScanForScanNum(argScanNo, ref isProfile); object labels = null; object flags = null; _rawConnection.GetLabelData(ref labels, ref flags, ref argScanNo); double[,] LabeledPeaks = (double[, ])labels; //Start Read Scan MSScan scan = new MSScan(argScanNo); List <ThermoLabeledPeak> FullLabeledPeak = new List <ThermoLabeledPeak>(); float[] mz = new float[LabeledPeaks.GetLength(1)]; float[] intensity = new float[LabeledPeaks.GetLength(1)]; int j = 0; for (int i = 0; i < LabeledPeaks.GetLength(1); i++) { double sn = LabeledPeaks[1, i] / LabeledPeaks[4, i]; if (sn >= argMinSN) { mz[j] = Convert.ToSingle(LabeledPeaks[0, i]); intensity[j] = Convert.ToSingle(LabeledPeaks[1, i]); j++; FullLabeledPeak.Add(new ThermoLabeledPeak( Convert.ToSingle(LabeledPeaks[0, i]), Convert.ToSingle(LabeledPeaks[1, i]), Convert.ToInt32(LabeledPeaks[5, i]), Convert.ToSingle(LabeledPeaks[4, i]))); } } Array.Resize(ref mz, j); Array.Resize(ref intensity, j); //scan.MZs = ConvertDoubleArrayToFloatArray(CSMSLScan.MassSpectrum.GetMasses()); scan.MZs = mz; //scan.Intensities = ConvertDoubleArrayToFloatArray(CSMSLScan.MassSpectrum.GetIntensities()); scan.Intensities = intensity; scan.MsLevel = GetMsLevel(argScanNo); double retentionTime = 0; _rawConnection.RTFromScanNum(argScanNo, ref retentionTime); scan.Time = retentionTime; scan.ScanHeader = GetScanDescription(argScanNo); if (scan.MsLevel != 1) { for (int chNum = 0; chNum < scan.MZs.Length; chNum++) { scan.MSPeaks.Add(new MSPeak( Convert.ToSingle(scan.MZs[chNum]), Convert.ToSingle(scan.Intensities[chNum]))); } // Get parent information object value = null; _rawConnection.GetTrailerExtraValueForScanNum(argScanNo, "Master Scan Number:", ref value); scan.ParentScanNo = Convert.ToInt32(value); string ParentDesc = GetScanDescription(scan.ParentScanNo); //_rawConnection.GetPrecursorInfoFromScanNum(argScanNo, ref PrecursorInfo, ref PrecursorInfoSize); //scan.ParentMonoMW = Convert.ToSingle(PrecurorArray.); //scan.ParentMZ = Convert.ToSingle(PrecurorArray[1,0]); //scan.ParentCharge = Convert.ToInt32(PrecurorArray.nChargeState); scan.IsCIDScan = IsCIDScan(argScanNo); scan.IsFTScan = IsFTScan(argScanNo); //Array.Clear(_transformResult, 0, _transformResult.Length); //Array.Clear(_cidPeaks, 0, _cidPeaks.Length); //Array.Clear(_cidMzs, 0, _cidMzs.Length); //Array.Clear(_cidIntensities, 0, _cidIntensities.Length); //Array.Clear(_parentRawMzs, 0, _parentRawMzs.Length); //Array.Clear(_parentRawIntensitys, 0, _parentRawIntensitys.Length); } else //MS Scan { do { ThermoLabeledPeak BasePeak = FullLabeledPeak[0]; List <ThermoLabeledPeak> clusterPeaks = new List <ThermoLabeledPeak>(); List <int> RemoveIdx = new List <int>(); RemoveIdx.Add(0); clusterPeaks.Add(BasePeak); double Interval = 1 / (double)BasePeak.Charge; double FirstMZ = BasePeak.MZ; for (int i = 1; i < FullLabeledPeak.Count; i++) { if (FullLabeledPeak[i].MZ - FirstMZ > Interval * 10) { break; } if ((FullLabeledPeak[i].MZ - (BasePeak.MZ + Interval)) < 0.1 && (FullLabeledPeak[i].MZ - (BasePeak.MZ + Interval)) >= 0 && clusterPeaks[0].Charge == FullLabeledPeak[i].Charge) { BasePeak = FullLabeledPeak[i]; clusterPeaks.Add(FullLabeledPeak[i]); RemoveIdx.Add(i); } } if (clusterPeaks.Count < 3) { FullLabeledPeak.RemoveAt(RemoveIdx[0]); } else { float MostIntenseMZ = 0.0f; double MostIntenseIntneisty = 0; double ClusterIntensity = 0; RemoveIdx.Reverse(); for (int i = 0; i < RemoveIdx.Count; i++) { if (FullLabeledPeak[RemoveIdx[i]].Intensity > MostIntenseIntneisty) { MostIntenseIntneisty = FullLabeledPeak[RemoveIdx[i]].Intensity; MostIntenseMZ = FullLabeledPeak[RemoveIdx[i]].MZ; } ClusterIntensity = ClusterIntensity + FullLabeledPeak[RemoveIdx[i]].Intensity; FullLabeledPeak.RemoveAt(RemoveIdx[i]); } scan.MSPeaks.Add(new MSPeak(clusterPeaks[0].Mass, clusterPeaks[0].Intensity, clusterPeaks[0].Charge, clusterPeaks[0].MZ, clusterPeaks[0].SN, MostIntenseMZ, MostIntenseIntneisty, ClusterIntensity)); } } while (FullLabeledPeak.Count != 0); //Array.Clear(_transformResult, 0, _transformResult.Length); //Array.Clear(_cidPeaks, 0, _cidPeaks.Length); //Array.Clear(_cidMzs, 0, _cidMzs.Length); //Array.Clear(_cidIntensities, 0, _cidIntensities.Length); } return(scan); }
//private MSScan GetScanFromFile(int argScanNo) //{ // return GetScanFromFile(argScanNo); //} private MSScan GetScanFromFile(int argScanNo, float argMinSN = 2)//, float argPPM = 6, int argMinPeakCount=3) { MSDataScan DataScan = _raw.GetMsScan(argScanNo); tolSN = argMinSN; //tolMinPeakCount = argMinPeakCount; //tolPPM = argPPM; MZPeak[] peaks; List <ThermoLabeledPeak> TPeaks = new List <ThermoLabeledPeak>(); peaks = DataScan.MassSpectrum.GetPeaks(); //Start Read Scan MSScan scan = new MSScan(argScanNo); scan.MsLevel = GetMsLevel(argScanNo); scan.Time = _raw.GetRetentionTime(argScanNo); scan.ScanHeader = _raw.GetScanFilter(argScanNo); List <MSPeak> MSPsks = new List <MSPeak>(); #region MSScan if (scan.MsLevel == 1) { float[] RawMz = new float[peaks.Length]; float[] RawIntensity = new float[peaks.Length]; for (int i = 0; i < peaks.Length; i++) { RawMz[i] = Convert.ToSingle(peaks[i].MZ); RawIntensity[i] = Convert.ToSingle(peaks[i].Intensity); ThermoLabeledPeak TPeak = (ThermoLabeledPeak)peaks[i]; if (TPeak.SN >= tolSN) { TPeaks.Add(TPeak); } } float[] Mz = new float[TPeaks.Count]; float[] Intensity = new float[TPeaks.Count]; for (int i = 0; i < TPeaks.Count; i++) { Mz[i] = Convert.ToSingle(TPeaks[i].MZ); Intensity[i] = Convert.ToSingle(TPeaks[i].Intensity); } scan.RawMZs = RawMz; scan.RawIntensities = RawIntensity; scan.MZs = Mz; scan.Intensities = Intensity; //************************Peak Picking //scan.MSPeaks = MSPsks; //List<float> TPeaksMZ = new List<float>(); //for (int i = 0; i < TPeaks.Count; i++) //{ // TPeaksMZ.Add(Convert.ToSingle(TPeaks[i].MZ)); //} //do //{ // ThermoLabeledPeak BasePeak = TPeaks[0]; // List<ThermoLabeledPeak> clusterPeaks = new List<ThermoLabeledPeak>(); // List<int> RemoveIdx = new List<int>(); // RemoveIdx.Add(0); // clusterPeaks.Add(BasePeak); // double Interval = 1 / (double)BasePeak.Charge; // double FirstMZ = BasePeak.MZ; // for (int i = 1; i < TPeaks.Count; i++) // { // if (TPeaks[i].MZ - FirstMZ > Interval * 10) // { // break; // } // List<int> ClosePeaks = MassUtility.GetClosestMassIdxsWithinPPM(TPeaksMZ.ToArray(), Convert.ToSingle(BasePeak.MZ + Interval), argPPM); // if (ClosePeaks.Count == 1 && TPeaks[ClosePeaks[0]].Charge == BasePeak.Charge) // { // BasePeak = TPeaks[i]; // clusterPeaks.Add(TPeaks[i]); // RemoveIdx.Add(i); // } // else if (ClosePeaks.Count > 1) // { // double minPPM = 100; // int minPPMIdx = 0; // float maxIntensity = 0; // int maxIntensityIdx = 0; // for (int j = 0; j < ClosePeaks.Count; j++) // { // if (MassUtility.GetMassPPM(BasePeak.MZ + Interval, mz[ClosePeaks[j]]) < minPPM) // { // minPPMIdx = ClosePeaks[j]; // minPPM = MassUtility.GetMassPPM(BasePeak.MZ + Interval, mz[ClosePeaks[j]]); // } // if (intensity[ClosePeaks[j]] > maxIntensity) // { // maxIntensity = intensity[ClosePeaks[j]]; // maxIntensityIdx = ClosePeaks[j]; // } // } // BasePeak = TPeaks[minPPMIdx]; // clusterPeaks.Add(TPeaks[minPPMIdx]); // RemoveIdx.Add(minPPMIdx); // } // } // if (clusterPeaks.Count < argMinPeakCount) // { // TPeaks.RemoveAt(RemoveIdx[0]); // TPeaksMZ.RemoveAt(RemoveIdx[0]); // } // else // { // float MostIntenseMZ = 0.0f; // double MostIntenseIntneisty = 0; // double ClusterIntensity = 0; // RemoveIdx.Reverse(); // for (int i = 0; i < RemoveIdx.Count; i++) // { // if (TPeaks[RemoveIdx[i]].Intensity > MostIntenseIntneisty) // { // MostIntenseIntneisty = TPeaks[RemoveIdx[i]].Intensity; // MostIntenseMZ = Convert.ToSingle(TPeaks[RemoveIdx[i]].MZ); // } // ClusterIntensity = ClusterIntensity + TPeaks[RemoveIdx[i]].Intensity; // TPeaks.RemoveAt(RemoveIdx[i]); // TPeaksMZ.RemoveAt(RemoveIdx[i]); // } // scan.MSPeaks.Add(new MSPeak( // Convert.ToSingle(clusterPeaks[0].MZ), // Convert.ToSingle(clusterPeaks[0].Intensity), // clusterPeaks[0].Charge, // Convert.ToSingle(clusterPeaks[0].MZ), // Convert.ToSingle(clusterPeaks[0].SN), // MostIntenseMZ, // MostIntenseIntneisty, // ClusterIntensity)); // } //} while (TPeaks.Count != 0); } #endregion #region MS/MS Scan else { float[] mz = new float[peaks.Length]; float[] intensity = new float[peaks.Length]; for (int i = 0; i < peaks.Length; i++) { mz[i] = Convert.ToSingle(peaks[i].MZ); intensity[i] = Convert.ToSingle(peaks[i].Intensity); //MSPsks.Add(new MSPeak(mz[i], intensity[i])); } scan.MZs = mz; scan.Intensities = intensity; //scan.MSPeaks = MSPsks; // Get parent information scan.ParentScanNo = _raw.GetParentSpectrumNumber(argScanNo); scan.ParentMZ = Convert.ToSingle(_raw.GetPrecusorMz(argScanNo)); scan.ParentCharge = _raw.GetPrecusorCharge(argScanNo); //Parent Mono if (scan.ParentScanNo != 0) { MSScan ParentScan = GetScanFromFile(scan.ParentScanNo); int ClosedIdx = MassUtility.GetClosestMassIdx(ParentScan.MZs, scan.ParentMZ); List <int> Peaks = FindPeakIdx(ParentScan.MZs, ClosedIdx, scan.ParentCharge, 10); scan.ParentMonoMz = ParentScan.MZs[Peaks[0]]; } } #endregion scan.IsCIDScan = IsCIDScan(argScanNo); scan.IsHCDScan = IsHCDScan(argScanNo); scan.IsFTScan = IsFTScan(argScanNo); return(scan); }