private List <udtScansDataType> LoadScansFile(string strScansFilePath) { const string FILTERED_SCANS_SUFFIX = "_filtered_scans.csv"; var dctColumnInfo = new Dictionary <string, int> { { "type", -1 }, { "bpi", -1 }, { "bpi_mz", -1 }, { "tic", -1 }, { "num_peaks", -1 }, { "num_deisotoped", -1 } }; var intColIndexScanOrFrameNum = -1; var intColIndexScanOrFrameTime = -1; var lstScanData = new List <udtScansDataType>(); var intRowNumber = 0; var intColIndexScanInfo = -1; if (!File.Exists(strScansFilePath) && strScansFilePath.ToLower().EndsWith(FILTERED_SCANS_SUFFIX)) { strScansFilePath = strScansFilePath.Substring(0, strScansFilePath.Length - FILTERED_SCANS_SUFFIX.Length) + "_scans.csv"; } if (!File.Exists(strScansFilePath)) { OnWarningEvent("Warning: _scans.csv file is missing; will plot vs. scan number instead of vs. elution time"); return(lstScanData); } Console.WriteLine(" Reading the _scans.csv file"); using (var srIsosFile = new StreamReader(new FileStream(strScansFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { while (!srIsosFile.EndOfStream) { intRowNumber += 1; var strLineIn = srIsosFile.ReadLine(); if (strLineIn == null) { continue; } var lstData = strLineIn.Split(',').ToList(); if (intRowNumber == 1) { // Parse the header row ParseColumnHeaders(dctColumnInfo, lstData, "_scans.csv"); intColIndexScanOrFrameNum = GetScanOrFrameColIndex(lstData, "_scans.csv"); intColIndexScanOrFrameTime = lstData.IndexOf("frame_time"); if (intColIndexScanOrFrameTime < 0) { intColIndexScanOrFrameTime = lstData.IndexOf("scan_time"); } // The info column will have data of the form "FTMS + p NSI Full ms [400.00-2000.00]" for Thermo datasets // For .mzXML files, this fill will simply have an integer (and thus isn't useful) // It may not be present in older _scancs.csv files and is thus optional intColIndexScanInfo = lstData.IndexOf("info"); continue; } try { var udtScanData = new udtScansDataType(); int.TryParse(lstData[intColIndexScanOrFrameNum], out udtScanData.Scan); float.TryParse(lstData[intColIndexScanOrFrameTime], out udtScanData.ElutionTime); int.TryParse(lstData[dctColumnInfo["type"]], out udtScanData.MSLevel); double.TryParse(lstData[dctColumnInfo["bpi"]], out udtScanData.BasePeakIntensity); double.TryParse(lstData[dctColumnInfo["bpi_mz"]], out udtScanData.BasePeakMZ); double.TryParse(lstData[dctColumnInfo["tic"]], out udtScanData.TotalIonCurrent); int.TryParse(lstData[dctColumnInfo["num_peaks"]], out udtScanData.NumPeaks); int.TryParse(lstData[dctColumnInfo["num_deisotoped"]], out udtScanData.NumDeisotoped); if (intColIndexScanInfo > 0) { var infoText = lstData[intColIndexScanInfo]; // Only store infoText in .FilterText if infoText is not simply an integer if (!int.TryParse(infoText, out _)) { udtScanData.FilterText = infoText; } } lstScanData.Add(udtScanData); if (mSaveTICAndBPI) { mTICandBPIPlot.AddData(udtScanData.Scan, udtScanData.MSLevel, udtScanData.ElutionTime, udtScanData.BasePeakIntensity, udtScanData.TotalIonCurrent); } string scanTypeName; if (string.IsNullOrWhiteSpace(udtScanData.FilterText)) { udtScanData.FilterText = udtScanData.MSLevel > 1 ? "HMSn" : "HMS"; scanTypeName = udtScanData.FilterText; } else { scanTypeName = XRawFileIO.GetScanTypeNameFromFinniganScanFilterText(udtScanData.FilterText); } var objScanStatsEntry = new clsScanStatsEntry { ScanNumber = udtScanData.Scan, ScanType = udtScanData.MSLevel, ScanTypeName = scanTypeName, ScanFilterText = XRawFileIO.MakeGenericFinniganScanFilter(udtScanData.FilterText), ElutionTime = udtScanData.ElutionTime.ToString("0.0###"), TotalIonIntensity = StringUtilities.ValueToString(udtScanData.TotalIonCurrent, 5), BasePeakIntensity = StringUtilities.ValueToString(udtScanData.BasePeakIntensity, 5), BasePeakMZ = udtScanData.BasePeakMZ.ToString("0.0###"), BasePeakSignalToNoiseRatio = "0", IonCount = udtScanData.NumDeisotoped, IonCountRaw = udtScanData.NumPeaks, ExtendedScanInfo = { CollisionMode = string.Empty, ScanFilterText = udtScanData.FilterText } }; mDatasetStatsSummarizer.AddDatasetScan(objScanStatsEntry); } catch (Exception ex) { OnWarningEvent("Warning: Ignoring scan " + lstData[dctColumnInfo["scan_num"]] + " since data conversion error: " + ex.Message); } } } return(lstScanData); }
private void LoadData(FileInfo fiIsosFile, clsDatasetFileInfo datasetFileInfo) { // Cache the data in the _isos.csv and _scans.csv files if (mSaveTICAndBPI) { // Initialize the TIC and BPI arrays InitializeTICAndBPI(); } if (mSaveLCMS2DPlots) { InitializeLCMS2DPlot(); } var lstIsosData = LoadIsosFile(fiIsosFile.FullName, MaxFit); if (lstIsosData.Count == 0) { OnErrorEvent("No data found in the _isos.csv file: " + fiIsosFile.FullName); return; } var strScansFilePath = GetDatasetNameViaPath(fiIsosFile.Name) + DECONTOOLS_SCANS_FILE_SUFFIX; if (fiIsosFile.Directory != null) { strScansFilePath = Path.Combine(fiIsosFile.Directory.FullName, strScansFilePath); } var lstScanData = LoadScansFile(strScansFilePath); var scansFileIsMissing = false; if (lstScanData.Count > 0) { datasetFileInfo.AcqTimeEnd = datasetFileInfo.AcqTimeStart.AddMinutes(lstScanData.Last().ElutionTime); datasetFileInfo.ScanCount = lstScanData.Last().Scan; } else { scansFileIsMissing = true; datasetFileInfo.ScanCount = (from item in lstIsosData select item.Scan).Max(); for (var intScanIndex = 1; intScanIndex <= datasetFileInfo.ScanCount; intScanIndex++) { var udtScanData = new udtScansDataType { Scan = intScanIndex, ElutionTime = intScanIndex, MSLevel = 1 }; lstScanData.Add(udtScanData); } } // Step through the isos data and call mLCMS2DPlot.AddScan() for each scan var lstIons = new List <clsLCMSDataPlotter.udtMSIonType>(); var intCurrentScan = 0; // Note: we only need to update mLCMS2DPlot // The options for mLCMS2DPlotOverview will be cloned from mLCMS2DPlot.Options mLCMS2DPlot.Options.PlottingDeisotopedData = true; var dblMaxMonoMass = mLCMS2DPlot.Options.MaxMonoMassForDeisotopedPlot; for (var intIndex = 0; intIndex <= lstIsosData.Count - 1; intIndex++) { if (lstIsosData[intIndex].Scan > intCurrentScan || intIndex == lstIsosData.Count - 1) { // Store the cached values if (lstIons.Count > 0) { var udtCurrentScan = (from item in lstScanData where item.Scan == intCurrentScan select item).ToList().FirstOrDefault(); lstIons.Sort(new clsLCMSDataPlotter.udtMSIonTypeComparer()); mLCMS2DPlot.AddScan(intCurrentScan, udtCurrentScan.MSLevel, udtCurrentScan.ElutionTime, lstIons); if (scansFileIsMissing && mSaveTICAndBPI) { // Determine the TIC and BPI values using the data from the .isos file double tic = 0; double bpi = 0; for (var dataIndex = 0; dataIndex <= lstIons.Count - 1; dataIndex++) { tic += lstIons[dataIndex].Intensity; if (lstIons[dataIndex].Intensity > bpi) { bpi = lstIons[dataIndex].Intensity; } } mTICandBPIPlot.AddData(intCurrentScan, udtCurrentScan.MSLevel, udtCurrentScan.ElutionTime, bpi, tic); } } intCurrentScan = lstIsosData[intIndex].Scan; lstIons.Clear(); } if (lstIsosData[intIndex].MonoMass <= dblMaxMonoMass) { var udtIon = new clsLCMSDataPlotter.udtMSIonType { // Note that we store .MonoMass in a field called .mz; we'll still be plotting monoisotopic mass MZ = lstIsosData[intIndex].MonoMass, Intensity = lstIsosData[intIndex].Abundance, Charge = lstIsosData[intIndex].Charge }; lstIons.Add(udtIon); } } }