public static int DumpScanHeaderDataForCompound(string RawFileName, string RawFileOut, bool IfHeader, string Compound, double PeakLeftRT, double PeakRightRT, double Tolerance) { List <string> _strExportRAW = new List <string>(); XRAWLib.XRawfile _rawfile = new XRAWLib.XRawfile(); //XRAWFILE2Lib.XRawfile _rawfile = new XRawfile(); _rawfile.Open(RawFileName); _rawfile.SetCurrentController(0, 1); //_rawfile.GetInstMethod() /* * int testSTLog = 0, testTuneData = 0, testerror = 0; * _rawfile.GetNumStatusLog(ref testSTLog); MessageBox.Show("testSTLog - " + testSTLog.ToString()); * _rawfile.GetNumTuneData(ref testTuneData); MessageBox.Show("testTuneData - " + testTuneData.ToString()); * _rawfile.GetNumErrorLog(ref testerror); MessageBox.Show("testerror - " + testerror.ToString()); */ string pbstrFileName = null, pbstrInstMethod = null; int pnNumPackets = 0; double dStartTime = 0.0, pdRT = 0.0, pdStatusLogRT = 0.0; double dLowMass = 0.0; double dHighMass = 0.0; double dTIC = 0.0; double dBasePeakMass = 0.0; double dBasePeakIntensity = 0.0; int nChannels = 0; int bUniformTime = 0; double dFrequency = 0.0; int pnFirstSpectrum = 0, pnLastSpectrum = 0, pnArraySizeTE = 0, pnArraySizeSL = 0; DateTime pCreationDate = DateTime.Now; _rawfile.GetFileName(ref pbstrFileName); _rawfile.GetInstMethod(1, ref pbstrInstMethod); _rawfile.GetCreationDate(ref pCreationDate); pbstrFileName = Path.GetFileNameWithoutExtension(pbstrFileName); _rawfile.GetFirstSpectrumNumber(ref pnFirstSpectrum); _rawfile.GetLastSpectrumNumber(ref pnLastSpectrum); int count = 0; for (int nScanNumber = pnFirstSpectrum; nScanNumber <= pnLastSpectrum; nScanNumber++) // all spectrums { List <IonData> _ScanMSDataList = InitIonsForQuantList(); double _tii = GetTotalIntensityOfIonFromScanNumber(_rawfile, nScanNumber, _ScanMSDataList, Tolerance); string pbstrFilter = null, pbstrScanEvent = null; object pvarLabelsTE = null, pvarValuesTE = null; object pvarLabelsSL = null, pvarValuesSL = null; _rawfile.GetScanHeaderInfoForScanNum(nScanNumber, ref pnNumPackets, ref dStartTime, ref dLowMass, ref dHighMass, ref dTIC, ref dBasePeakMass, ref dBasePeakIntensity, ref nChannels, ref bUniformTime, ref dFrequency); _rawfile.GetTrailerExtraForScanNum(nScanNumber, ref pvarLabelsTE, ref pvarValuesTE, ref pnArraySizeTE); _rawfile.GetFilterForScanNum(nScanNumber, ref pbstrFilter); string compoundName = CompoundFromFilter(pbstrFilter); if (!IfCompound(compoundName, Compound)) { continue; } count++; bool _ifPeak = false; _rawfile.RTFromScanNum(nScanNumber, ref pdRT); if (pdRT > PeakLeftRT && pdRT < PeakRightRT) { _ifPeak = true; } (_rawfile as XRAWLib.IXRawfile5).GetScanEventForScanNum(nScanNumber, ref pbstrScanEvent); _rawfile.GetStatusLogForScanNum(nScanNumber, ref pdStatusLogRT, ref pvarLabelsSL, ref pvarValuesSL, ref pnArraySizeSL); //MessageBox.Show(pnArraySizeSL.ToString()); string[] strTrailerLabels = (string[])pvarLabelsTE; string[] strTrailerValues = (string[])pvarValuesTE; string[] strStatusLabels = (string[])pvarLabelsSL; string[] strStatusValues = (string[])pvarValuesSL; string trailerExtra = "", trailerHeader = ""; string statusLog = "", statusHeader = ""; string quantIons = "", quantIonsHeader = ""; for (int i = 0; i < pnArraySizeTE; i++) // all TrailerExtra { trailerExtra += strTrailerValues[i]; trailerExtra += "; "; if (count == 1 && IfHeader) { trailerHeader += strTrailerLabels[i]; trailerHeader += "; "; } } foreach (IonData _ion in _ScanMSDataList) // all Quant MS ions-intens. { quantIons += _ion._Intensity.ToString(); quantIons += "; "; if (count == 1 && IfHeader) { quantIonsHeader += _ion._MassOverCharge.ToString(); quantIonsHeader += "; "; } } for (int i = 0; i < pnArraySizeSL; i++) // all StatusLog { statusLog += strStatusValues[i]; statusLog += "; "; //MessageBox.Show(strStatusLabels[i] + " - " + strStatusValues[i]); if (count == 1 && IfHeader) { statusHeader += strStatusLabels[i]; statusHeader += "; "; } } if (count == 1 && IfHeader) { _strExportRAW.Add("pbstrFileName; pCreationDate; nScanNumber; pbstrFilter; pdRT; pbstrScanEvent; pnNumPackets; dStartTime; dLowMass; " + "dHighMass; dTIC; dBasePeakMass; dBasePeakIntensity; nChannels; bUniformTime; dFrequency; ifPeak; compound; TII; PeakLeftRT; PeakRightRT; " + quantIonsHeader + trailerHeader); } _strExportRAW.Add( String.Format("{0}; {1}; {2}; {3}; {4}; {5}; {6}; {7}; {8}; {9}; {10}; {11}; {12}; {13}; {14}; {15}; {16}; {17}; {18}; {19}; {20}; {21} {22}", pbstrFileName, pCreationDate, nScanNumber, pbstrFilter, pdRT, pbstrScanEvent, pnNumPackets, dStartTime, dLowMass, dHighMass, dTIC, dBasePeakMass, dBasePeakIntensity, nChannels, bUniformTime, dFrequency, _ifPeak, compoundName, _tii, PeakLeftRT, PeakRightRT, quantIons, trailerExtra) ); } if (IfHeader) { File.WriteAllLines(RawFileOut, _strExportRAW.ToArray()); } else { File.AppendAllLines(RawFileOut, _strExportRAW.ToArray()); } _rawfile.Close(); return(count); }
public static PeptidePeaksExtra GetPeptideExtrasForCompound(string RawFileName, string Compound, double PeakLeftRT, double PeakRightRT) { PeptidePeaksExtra _peptideExtras = new PeptidePeaksExtra(); _peptideExtras._allInjectTimes = new List <CompoundInjectTime>(); _peptideExtras._Peptide = PeptideFromCompound(Compound); //List<CompoundInjectTime> _listCompVSInj = new List<CompoundInjectTime>(); XRAWLib.XRawfile _rawfile = new XRAWLib.XRawfile(); _rawfile.Open(RawFileName); _rawfile.SetCurrentController(0, 1); int pnFirstSpectrum = 0, pnLastSpectrum = 0, pnArraySizeTE = 0; _rawfile.ScanNumFromRT(PeakLeftRT, ref pnFirstSpectrum); _rawfile.ScanNumFromRT(PeakRightRT, ref pnLastSpectrum); int count = 0; for (int nScanNumber = pnFirstSpectrum; nScanNumber <= pnLastSpectrum; nScanNumber++) // all spectrums { string pbstrFilter = null, pbstrScanEvent = null; object pvarLabelsTE = null, pvarValuesTE = null; _rawfile.GetFilterForScanNum(nScanNumber, ref pbstrFilter); // MessageBox.Show(nScanNumber.ToString() +" - "+ pbstrFilter+" peakleft " + PeakLeftRT); // if (pbstrFilter == null) { MessageBox.Show(RawFileName + "have null filter"); continue; } string compoundName = CompoundFromFilter(pbstrFilter); string peptideName = PeptideFromFilter(pbstrFilter); if (!IfCompound(peptideName, Compound)) { continue; } count++; (_rawfile as XRAWLib.IXRawfile5).GetScanEventForScanNum(nScanNumber, ref pbstrScanEvent); _rawfile.GetTrailerExtraForScanNum(nScanNumber, ref pvarLabelsTE, ref pvarValuesTE, ref pnArraySizeTE); string[] strTrailerLabels = (string[])pvarLabelsTE; string[] strTrailerValues = (string[])pvarValuesTE; string trailerExtra = ""; //, trailerHeader = ""; string statusLog = "", statusHeader = ""; string quantIons = "", quantIonsHeader = ""; int _injectIndex = 2; for (int i = 0; i < strTrailerLabels.Length; i++) { if (strTrailerLabels[i].StartsWith("Ion Injection Time")) { trailerExtra = strTrailerValues[i]; _injectIndex = i; } } CompoundInjectTime _compInj = new CompoundInjectTime(); _compInj._ScanNum = nScanNumber; _compInj._Compound = compoundName; try { _compInj._InjectTime = float.Parse(strTrailerValues[_injectIndex]); } catch (Exception _ex) { MessageBox.Show("GetPeptideExtrasForCompound():float.Parse", "Cannot parse " + strTrailerValues[_injectIndex] + " to float;"); } _peptideExtras._allInjectTimes.Add(_compInj); } _rawfile.Close(); var AvgInjTimeQuery = from pair in _peptideExtras._allInjectTimes group pair by pair._Compound into gr select new { Compound = gr.Key, AvgInjTime = gr.Average(a => a._InjectTime), NumSpec = gr.Count() }; foreach (var _compound in AvgInjTimeQuery) { if (_compound.Compound.Contains("C13")) { _peptideExtras._AvgC13_InjT = _compound.AvgInjTime; _peptideExtras._NumSpecC13_InjT = _compound.NumSpec; } if (_compound.Compound.Contains("C12")) { _peptideExtras._AvgC12_InjT = _compound.AvgInjTime; _peptideExtras._NumSpecC12_InjT = _compound.NumSpec; } if (_compound.Compound.Contains("N15")) { _peptideExtras._AvgN15_InjT = _compound.AvgInjTime; _peptideExtras._NumSpecN15_InjT = _compound.NumSpec; } } _peptideExtras._TotScans = count; return(_peptideExtras); }
public static void DumpScanHeaderData(string RawFileName, string RawFileOut, bool IfHeader) { List <string> _strExportRAW = new List <string>(); XRAWLib.XRawfile _rawfile = new XRAWLib.XRawfile(); //XRAWFILE2Lib.XRawfile _rawfile = new XRawfile(); _rawfile.Open(RawFileName); _rawfile.SetCurrentController(0, 1); int testSTLog = 0, testTuneData = 0, testerror = 0; _rawfile.GetNumStatusLog(ref testSTLog); MessageBox.Show("testSTLog - " + testSTLog.ToString()); _rawfile.GetNumStatusLog(ref testTuneData); MessageBox.Show("testTuneData - " + testTuneData.ToString()); _rawfile.GetNumStatusLog(ref testerror); MessageBox.Show("testerror - " + testerror.ToString()); string pbstrFileName = null, pbstrInstMethod = null; int pnNumPackets = 0; double dStartTime = 0.0, pdRT = 0.0, pdStatusLogRT = 0.0; double dLowMass = 0.0; double dHighMass = 0.0; double dTIC = 0.0; double dBasePeakMass = 0.0; double dBasePeakIntensity = 0.0; int nChannels = 0; int bUniformTime = 0; double dFrequency = 0.0; int pnFirstSpectrum = 0, pnLastSpectrum = 0, pnArraySizeTE = 0, pnArraySizeSL = 0; DateTime pCreationDate = DateTime.Now; _rawfile.GetFileName(ref pbstrFileName); _rawfile.GetInstMethod(1, ref pbstrInstMethod); _rawfile.GetCreationDate(ref pCreationDate); _rawfile.GetFirstSpectrumNumber(ref pnFirstSpectrum); _rawfile.GetLastSpectrumNumber(ref pnLastSpectrum); int count = 0; for (int nScanNumber = pnFirstSpectrum; nScanNumber <= pnLastSpectrum; nScanNumber++) // all spectrums { string pbstrFilter = null, pbstrScanEvent = null; object pvarLabelsTE = null, pvarValuesTE = null; object pvarLabelsSL = null, pvarValuesSL = null; count++; _rawfile.GetScanHeaderInfoForScanNum(nScanNumber, ref pnNumPackets, ref dStartTime, ref dLowMass, ref dHighMass, ref dTIC, ref dBasePeakMass, ref dBasePeakIntensity, ref nChannels, ref bUniformTime, ref dFrequency); _rawfile.GetTrailerExtraForScanNum(nScanNumber, ref pvarLabelsTE, ref pvarValuesTE, ref pnArraySizeTE); _rawfile.GetFilterForScanNum(nScanNumber, ref pbstrFilter); //MessageBox.Show(pbstrFilter); _rawfile.RTFromScanNum(nScanNumber, ref pdRT); (_rawfile as XRAWLib.IXRawfile5).GetScanEventForScanNum(nScanNumber, ref pbstrScanEvent); _rawfile.GetStatusLogForScanNum(nScanNumber, ref pdStatusLogRT, ref pvarLabelsSL, ref pvarValuesSL, ref pnArraySizeSL); MessageBox.Show(pnArraySizeSL.ToString()); string[] strTrailerLabels = (string[])pvarLabelsTE; string[] strTrailerValues = (string[])pvarValuesTE; string[] strStatusLabels = (string[])pvarLabelsSL; string[] strStatusValues = (string[])pvarValuesSL; string trailerExtra = "", trailerHeader = ""; string statusLog = "", statusHeader = ""; for (int i = 0; i < pnArraySizeTE; i++) // all TrailerExtra { trailerExtra += strTrailerValues[i]; trailerExtra += "; "; if (count == 1) { trailerHeader += strTrailerLabels[i]; trailerHeader += "; "; } } for (int i = 0; i < pnArraySizeSL; i++) // all StatusLog { statusLog += strStatusValues[i]; statusLog += "; "; MessageBox.Show(strStatusLabels[i] + " - " + strStatusValues[i]); if (count == 1) { statusHeader += strStatusLabels[i]; statusHeader += "; "; } } if (count == 1) { _strExportRAW.Add("pbstrFileName; pCreationDate; nScanNumber; pbstrFilter; pdRT; pbstrScanEvent; pnNumPackets; dStartTime; dLowMass; " + "dHighMass; dTIC; dBasePeakMass; dBasePeakIntensity; nChannels; bUniformTime; dFrequency; " + trailerHeader); } _strExportRAW.Add( String.Format("{0}; {1}; {2}; {3}; {4}; {5}; {6}; {7}; {8}; {9}; {10}; {11}; {12}; {13}; {14}; {15}; {16}", pbstrFileName, pCreationDate, nScanNumber, pbstrFilter, pdRT, pbstrScanEvent, pnNumPackets, dStartTime, dLowMass, dHighMass, dTIC, dBasePeakMass, dBasePeakIntensity, nChannels, bUniformTime, dFrequency, trailerExtra) ); } if (IfHeader) { File.WriteAllLines(RawFileOut, _strExportRAW.ToArray()); } else { File.AppendAllLines(RawFileOut, _strExportRAW.ToArray()); } _rawfile.Close(); }