private bool ProcessChemstationMSDataFile(string datafilePath, DatasetFileInfo datasetFileInfo) { bool success; var currentIndex = 0; try { using (var reader = new ChemstationMSFileReader.clsChemstationDataMSFileReader(datafilePath)) { datasetFileInfo.AcqTimeStart = reader.Header.AcqDate; datasetFileInfo.AcqTimeEnd = datasetFileInfo.AcqTimeStart.AddMinutes(reader.Header.RetentionTimeMinutesEnd); datasetFileInfo.ScanCount = reader.Header.SpectraCount; for (var spectrumIndex = 0; spectrumIndex <= datasetFileInfo.ScanCount - 1; spectrumIndex++) { currentIndex = spectrumIndex; ChemstationMSFileReader.clsSpectralRecord spectrum = null; List <float> mzList = null; List <int> intensityList = null; const int msLevel = 1; bool validSpectrum; try { reader.GetSpectrum(spectrumIndex, ref spectrum); mzList = spectrum.Mzs; intensityList = spectrum.Intensities; validSpectrum = true; } catch (Exception ex) { OnWarningEvent("Exception obtaining data from the MS file for spectrum index " + currentIndex + ": " + ex.Message); validSpectrum = false; } if (validSpectrum) { var scanStatsEntry = new ScanStatsEntry { ScanNumber = spectrumIndex + 1, ScanType = msLevel, ScanTypeName = "GC-MS", ScanFilterText = string.Empty, ElutionTime = spectrum.RetentionTimeMinutes.ToString("0.0###"), TotalIonIntensity = StringUtilities.ValueToString(spectrum.TIC, 1), BasePeakIntensity = StringUtilities.ValueToString(spectrum.BasePeakAbundance, 1), BasePeakMZ = spectrum.BasePeakMZ.ToString("0.0###"), BasePeakSignalToNoiseRatio = "0", IonCount = mzList.Count }; scanStatsEntry.IonCountRaw = scanStatsEntry.IonCount; mDatasetStatsSummarizer.AddDatasetScan(scanStatsEntry); if (mSaveTICAndBPI) { mTICAndBPIPlot.AddData(scanStatsEntry.ScanNumber, msLevel, spectrum.RetentionTimeMinutes, spectrum.BasePeakAbundance, spectrum.TIC); if (mzList.Count > 0) { var ionsMZ = new double[mzList.Count]; var ionsIntensity = new double[mzList.Count]; for (var index = 0; index <= mzList.Count - 1; index++) { ionsMZ[index] = mzList[index]; ionsIntensity[index] = intensityList[index]; } mLCMS2DPlot.AddScan(scanStatsEntry.ScanNumber, msLevel, spectrum.RetentionTimeMinutes, ionsMZ.Length, ionsMZ, ionsIntensity); } } if (mCheckCentroidingStatus) { var mzDoubles = new List <double>(mzList.Count); mzDoubles.AddRange(mzList.Select(ion => (double)ion)); mDatasetStatsSummarizer.ClassifySpectrum(mzDoubles, msLevel, "Scan " + scanStatsEntry.ScanNumber); } } } } success = true; } catch (Exception ex) { // Exception reading file OnWarningEvent("Exception reading data from the MS file at spectrum index " + currentIndex + ": " + ex.Message); success = false; } return(success); }
private bool ProcessChemstationMSDataFile(string strDatafilePath, clsDatasetFileInfo datasetFileInfo) { bool blnSuccess; var intCurrentIndex = 0; try { using (var oReader = new ChemstationMSFileReader.clsChemstationDataMSFileReader(strDatafilePath)) { datasetFileInfo.AcqTimeStart = oReader.Header.AcqDate; datasetFileInfo.AcqTimeEnd = datasetFileInfo.AcqTimeStart.AddMinutes(oReader.Header.RetentionTimeMinutesEnd); datasetFileInfo.ScanCount = oReader.Header.SpectraCount; for (var intSpectrumIndex = 0; intSpectrumIndex <= datasetFileInfo.ScanCount - 1; intSpectrumIndex++) { intCurrentIndex = intSpectrumIndex; ChemstationMSFileReader.clsSpectralRecord oSpectrum = null; List <float> lstMZs = null; List <Int32> lstIntensities = null; const int intMSLevel = 1; bool blnValidSpectrum; try { oReader.GetSpectrum(intSpectrumIndex, ref oSpectrum); lstMZs = oSpectrum.Mzs; lstIntensities = oSpectrum.Intensities; blnValidSpectrum = true; } catch (Exception ex) { OnWarningEvent("Exception obtaining data from the MS file for spectrum index " + intCurrentIndex + ": " + ex.Message); blnValidSpectrum = false; } if (blnValidSpectrum) { var objScanStatsEntry = new clsScanStatsEntry { ScanNumber = intSpectrumIndex + 1, ScanType = intMSLevel, ScanTypeName = "GC-MS", ScanFilterText = "", ElutionTime = oSpectrum.RetentionTimeMinutes.ToString("0.0###"), TotalIonIntensity = StringUtilities.ValueToString(oSpectrum.TIC, 1), BasePeakIntensity = StringUtilities.ValueToString(oSpectrum.BasePeakAbundance, 1), BasePeakMZ = oSpectrum.BasePeakMZ.ToString("0.0###"), BasePeakSignalToNoiseRatio = "0", IonCount = lstMZs.Count }; objScanStatsEntry.IonCountRaw = objScanStatsEntry.IonCount; mDatasetStatsSummarizer.AddDatasetScan(objScanStatsEntry); if (mSaveTICAndBPI) { mTICandBPIPlot.AddData(objScanStatsEntry.ScanNumber, intMSLevel, oSpectrum.RetentionTimeMinutes, oSpectrum.BasePeakAbundance, oSpectrum.TIC); if (lstMZs.Count > 0) { var dblIonsMZ = new double[lstMZs.Count]; var dblIonsIntensity = new double[lstMZs.Count]; for (var intIndex = 0; intIndex <= lstMZs.Count - 1; intIndex++) { dblIonsMZ[intIndex] = lstMZs[intIndex]; dblIonsIntensity[intIndex] = lstIntensities[intIndex]; } mLCMS2DPlot.AddScan(objScanStatsEntry.ScanNumber, intMSLevel, oSpectrum.RetentionTimeMinutes, dblIonsMZ.Length, dblIonsMZ, dblIonsIntensity); } } if (mCheckCentroidingStatus) { var lstMzDoubles = new List <double>(lstMZs.Count); lstMzDoubles.AddRange(lstMZs.Select(ion => (double)ion)); mDatasetStatsSummarizer.ClassifySpectrum(lstMzDoubles, intMSLevel); } } } } blnSuccess = true; } catch (Exception ex) { // Exception reading file OnWarningEvent("Exception reading data from the MS file at spectrum index " + intCurrentIndex + ": " + ex.Message); blnSuccess = false; } return(blnSuccess); }