private void StoreExtendedHeaderInfo( clsDataOutput dataOutputHandler, clsScanInfo scanInfo, IReadOnlyCollection <KeyValuePair <string, string> > statusEntries) { StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, statusEntries, new SortedSet <string>()); }
private bool ExtractScanInfoWork( XRawFileIO xcaliburAccessor, clsScanList scanList, clsSpectraCache spectraCache, clsDataOutput dataOutputHandler, clsSICOptions sicOptions, ThermoRawFileReader.clsScanInfo thermoScanInfo) { if (thermoScanInfo.ParentIonMZ > 0 && Math.Abs(mOptions.ParentIonDecoyMassDa) > 0) { thermoScanInfo.ParentIonMZ += mOptions.ParentIonDecoyMassDa; } bool success; // Determine if this was an MS/MS scan // If yes, determine the scan number of the survey scan if (thermoScanInfo.MSLevel <= 1) { // Survey Scan success = ExtractXcaliburSurveyScan(xcaliburAccessor, scanList, spectraCache, dataOutputHandler, sicOptions, thermoScanInfo); } else { // Fragmentation Scan success = ExtractXcaliburFragmentationScan(xcaliburAccessor, scanList, spectraCache, dataOutputHandler, sicOptions, mOptions.BinningOptions, thermoScanInfo); } return(success); }
/// <summary> /// Constructor /// </summary> public clsMRMProcessing(clsMASICOptions masicOptions, clsDataOutput dataOutputHandler) { mOptions = masicOptions; mDataAggregation = new clsDataAggregation(); RegisterEvents(mDataAggregation); mDataOutputHandler = dataOutputHandler; }
/// <summary> /// Write the tune method file to disk /// </summary> /// <param name="rawFileReader"></param> /// <param name="dataOutputHandler"></param> /// <returns></returns> public bool SaveMSTuneFile( XRawFileIO rawFileReader, clsDataOutput dataOutputHandler) { const char TAB_DELIMITER = '\t'; int tuneMethodCount; var outputFilePath = "?UndefinedFile?"; try { tuneMethodCount = rawFileReader.FileInfo.TuneMethods.Count; } catch (Exception ex) { ReportError("Error looking up TuneMethods length in rawFileReader.FileInfo", ex, clsMASIC.eMasicErrorCodes.OutputFileWriteError); return(false); } try { for (var index = 0; index < tuneMethodCount; index++) { string tuneInfoNum; if (index == 0 && rawFileReader.FileInfo.TuneMethods.Count == 1) { tuneInfoNum = string.Empty; } else { tuneInfoNum = (index + 1).ToString().Trim(); } outputFilePath = dataOutputHandler.OutputFileHandles.MSTuneFilePathBase + tuneInfoNum + ".txt"; using (var writer = new StreamWriter(outputFilePath, false)) { writer.WriteLine("Category" + TAB_DELIMITER + "Name" + TAB_DELIMITER + "Value"); foreach (var setting in rawFileReader.FileInfo.TuneMethods[index].Settings) { writer.WriteLine(setting.Category + TAB_DELIMITER + setting.Name + TAB_DELIMITER + setting.Value); } writer.WriteLine(); } } } catch (Exception ex) { ReportError("Error writing the MS Tune Settings to: " + outputFilePath, ex, clsMASIC.eMasicErrorCodes.OutputFileWriteError); return(false); } return(true); }
/// <summary> /// Write the instrument method file to disk /// </summary> /// <param name="rawFileReader"></param> /// <param name="dataOutputHandler"></param> /// <returns></returns> public bool SaveMSMethodFile( XRawFileIO rawFileReader, clsDataOutput dataOutputHandler) { int instMethodCount; var outputFilePath = "?UndefinedFile?"; try { instMethodCount = rawFileReader.FileInfo.InstMethods.Count; } catch (Exception ex) { ReportError("Error looking up InstMethod length in rawFileReader.FileInfo", ex, clsMASIC.eMasicErrorCodes.OutputFileWriteError); return(false); } try { for (var index = 0; index < instMethodCount; index++) { string methodNum; if (index == 0 && rawFileReader.FileInfo.InstMethods.Count == 1) { methodNum = string.Empty; } else { methodNum = (index + 1).ToString().Trim(); } outputFilePath = dataOutputHandler.OutputFileHandles.MSMethodFilePathBase + methodNum + ".txt"; using (var writer = new StreamWriter(outputFilePath, false)) { var fileInfo = rawFileReader.FileInfo; writer.WriteLine("Instrument model: " + fileInfo.InstModel); writer.WriteLine("Instrument name: " + fileInfo.InstName); writer.WriteLine("Instrument description: " + fileInfo.InstrumentDescription); writer.WriteLine("Instrument serial number: " + fileInfo.InstSerialNumber); writer.WriteLine(); writer.WriteLine(rawFileReader.FileInfo.InstMethods[index]); } } } catch (Exception ex) { ReportError("Error writing the MS Method to: " + outputFilePath, ex, clsMASIC.eMasicErrorCodes.OutputFileWriteError); return(false); } return(true); }
public bool XMLOutputFileFinalize( clsDataOutput dataOutputHandler, clsScanList scanList, clsSpectraCache spectraCache, clsProcessingStats processingStats, float processingTimeSec) { var writer = dataOutputHandler.OutputFileHandles.XMLFileForSICs; if (writer == null) { return(false); } try { writer.WriteStartElement("ProcessingStats"); writer.WriteElementString("CacheEventCount", spectraCache.CacheEventCount.ToString()); writer.WriteElementString("UnCacheEventCount", spectraCache.UnCacheEventCount.ToString()); writer.WriteElementString("SpectraPoolHitEventCount", spectraCache.SpectraPoolHitEventCount.ToString()); writer.WriteElementString("PeakMemoryUsageMB", StringUtilities.DblToString(processingStats.PeakMemoryUsageMB, 1)); var effectiveSeconds = processingTimeSec - processingStats.TotalProcessingTimeAtStart; writer.WriteElementString("TotalProcessingTimeSeconds", StringUtilities.DblToString(effectiveSeconds, 1)); writer.WriteEndElement(); if (scanList.ProcessingIncomplete) { writer.WriteElementString("ProcessingComplete", "False"); } else { writer.WriteElementString("ProcessingComplete", "True"); } writer.WriteEndElement(); // Close out the <SICData> element writer.WriteEndDocument(); writer.Close(); } catch (Exception ex) { ReportError("Error finalizing the XML output file", ex, clsMASIC.eMasicErrorCodes.OutputFileWriteError); return(false); } return(true); }
private void StoreExtendedHeaderInfo( clsDataOutput dataOutputHandler, clsScanInfo scanInfo, string entryName, string entryValue) { if (entryValue == null) { entryValue = string.Empty; } var statusEntries = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>(entryName, entryValue) }; StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, statusEntries); }
private bool ExtractScanInfoCheckRange( XRawFileIO xcaliburAccessor, ThermoRawFileReader.clsScanInfo thermoScanInfo, clsScanList scanList, clsSpectraCache spectraCache, clsDataOutput dataOutputHandler, double percentComplete) { bool success; if (mScanTracking.CheckScanInRange(thermoScanInfo.ScanNumber, thermoScanInfo.RetentionTime, mOptions.SICOptions)) { success = ExtractScanInfoWork(xcaliburAccessor, scanList, spectraCache, dataOutputHandler, mOptions.SICOptions, thermoScanInfo); } else { mScansOutOfRange += 1; success = true; } UpdateProgress((short)Math.Round(percentComplete, 0)); UpdateCacheStats(spectraCache); if (mOptions.AbortProcessing) { scanList.ProcessingIncomplete = true; return(false); } if (DateTime.UtcNow.Subtract(mLastLogTime).TotalSeconds >= 10 || thermoScanInfo.ScanNumber % 500 == 0 && ( thermoScanInfo.ScanNumber >= mOptions.SICOptions.ScanRangeStart && thermoScanInfo.ScanNumber <= mOptions.SICOptions.ScanRangeEnd)) { ReportMessage("Reading scan: " + thermoScanInfo.ScanNumber.ToString()); Console.Write("."); mLastLogTime = DateTime.UtcNow; } return(success); }
public bool SaveDataToXML( clsScanList scanList, int parentIonIndex, clsSICDetails sicDetails, MASICPeakFinder.clsSmoothedYDataSubset smoothedYDataSubset, clsDataOutput dataOutputHandler) { var lastGoodLoc = "Start"; try { // Populate SICDataScanIntervals with the scan intervals between each of the data points in sicDetails.SICScanNumbers // The first scan number is given by SICScanIndices(0) byte[] SICDataScanIntervals; if (sicDetails.SICDataCount == 0) { SICDataScanIntervals = new byte[1]; } else { SICDataScanIntervals = new byte[sicDetails.SICDataCount]; var sicScanNumbers = sicDetails.SICScanNumbers; for (var scanIndex = 1; scanIndex < sicDetails.SICDataCount; scanIndex++) { var scanDelta = sicScanNumbers[scanIndex] - sicScanNumbers[scanIndex - 1]; // When storing in SICDataScanIntervals, make sure the Scan Interval is, at most, 255; it will typically be 1 or 4 // However, for MRM data, field size can be much larger SICDataScanIntervals[scanIndex] = (byte)Math.Min(byte.MaxValue, scanDelta); } } var writer = dataOutputHandler.OutputFileHandles.XMLFileForSICs; if (writer == null) { return(false); } // Initialize the StringBuilder objects var sbIntensityDataList = new System.Text.StringBuilder(); var sbMassDataList = new System.Text.StringBuilder(); var sbPeakYDataSmoothed = new System.Text.StringBuilder(); var sicScanIndices = sicDetails.SICScanIndices; // Write the SIC's and computed peak stats and areas to the XML file for the given parent ion for (var fragScanIndex = 0; fragScanIndex < scanList.ParentIons[parentIonIndex].FragScanIndices.Count; fragScanIndex++) { lastGoodLoc = "fragScanIndex=" + fragScanIndex; writer.WriteStartElement("ParentIon"); writer.WriteAttributeString("Index", parentIonIndex.ToString()); // Parent ion Index writer.WriteAttributeString("FragScanIndex", fragScanIndex.ToString()); // Frag Scan Index lastGoodLoc = "currentParentIon = scanList.ParentIons(parentIonIndex)"; var currentParentIon = scanList.ParentIons[parentIonIndex]; writer.WriteElementString("MZ", StringUtilities.DblToString(currentParentIon.MZ, 4)); if (currentParentIon.SurveyScanIndex >= 0 && currentParentIon.SurveyScanIndex < scanList.SurveyScans.Count) { writer.WriteElementString("SurveyScanNumber", scanList.SurveyScans[currentParentIon.SurveyScanIndex].ScanNumber.ToString()); } else { writer.WriteElementString("SurveyScanNumber", "-1"); } lastGoodLoc = "Write FragScanNumber"; double interferenceScore; if (fragScanIndex < scanList.FragScans.Count) { var currentFragScan = scanList.FragScans[currentParentIon.FragScanIndices[fragScanIndex]]; writer.WriteElementString("FragScanNumber", currentFragScan.ScanNumber.ToString()); writer.WriteElementString("FragScanTime", currentFragScan.ScanTime.ToString(CultureInfo.InvariantCulture)); interferenceScore = currentFragScan.FragScanInfo.InterferenceScore; } else { // Fragmentation scan does not exist writer.WriteElementString("FragScanNumber", "0"); writer.WriteElementString("FragScanTime", "0"); interferenceScore = 0; } writer.WriteElementString("OptimalPeakApexScanNumber", currentParentIon.OptimalPeakApexScanNumber.ToString()); writer.WriteElementString("PeakApexOverrideParentIonIndex", currentParentIon.PeakApexOverrideParentIonIndex.ToString()); writer.WriteElementString("CustomSICPeak", currentParentIon.CustomSICPeak.ToString()); if (currentParentIon.CustomSICPeak) { writer.WriteElementString("CustomSICPeakComment", currentParentIon.CustomSICPeakComment); writer.WriteElementString("CustomSICPeakMZToleranceDa", currentParentIon.CustomSICPeakMZToleranceDa.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("CustomSICPeakScanTolerance", currentParentIon.CustomSICPeakScanOrAcqTimeTolerance.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("CustomSICPeakScanToleranceType", mOptions.CustomSICList.ScanToleranceType.ToString()); } lastGoodLoc = "sicStatsPeak = currentParentIon.SICStats.Peak"; var sicStatsPeak = currentParentIon.SICStats.Peak; if (sicDetails.SICScanType == clsScanList.eScanTypeConstants.FragScan) { writer.WriteElementString("SICScanType", "FragScan"); writer.WriteElementString("PeakScanStart", scanList.FragScans[sicScanIndices[sicStatsPeak.IndexBaseLeft]].ScanNumber.ToString()); writer.WriteElementString("PeakScanEnd", scanList.FragScans[sicScanIndices[sicStatsPeak.IndexBaseRight]].ScanNumber.ToString()); writer.WriteElementString("PeakScanMaxIntensity", scanList.FragScans[sicScanIndices[sicStatsPeak.IndexMax]].ScanNumber.ToString()); } else { writer.WriteElementString("SICScanType", "SurveyScan"); writer.WriteElementString("PeakScanStart", scanList.SurveyScans[sicScanIndices[sicStatsPeak.IndexBaseLeft]].ScanNumber.ToString()); writer.WriteElementString("PeakScanEnd", scanList.SurveyScans[sicScanIndices[sicStatsPeak.IndexBaseRight]].ScanNumber.ToString()); writer.WriteElementString("PeakScanMaxIntensity", scanList.SurveyScans[sicScanIndices[sicStatsPeak.IndexMax]].ScanNumber.ToString()); } writer.WriteElementString("PeakIntensity", StringUtilities.ValueToString(sicStatsPeak.MaxIntensityValue, 5)); writer.WriteElementString("PeakSignalToNoiseRatio", StringUtilities.ValueToString(sicStatsPeak.SignalToNoiseRatio, 4)); writer.WriteElementString("FWHMInScans", sicStatsPeak.FWHMScanWidth.ToString()); writer.WriteElementString("PeakArea", StringUtilities.ValueToString(sicStatsPeak.Area, 5)); writer.WriteElementString("ShoulderCount", sicStatsPeak.ShoulderCount.ToString()); writer.WriteElementString("ParentIonIntensity", StringUtilities.ValueToString(sicStatsPeak.ParentIonIntensity, 5)); var noiseStats = sicStatsPeak.BaselineNoiseStats; writer.WriteElementString("PeakBaselineNoiseLevel", StringUtilities.ValueToString(noiseStats.NoiseLevel, 5)); writer.WriteElementString("PeakBaselineNoiseStDev", StringUtilities.ValueToString(noiseStats.NoiseStDev, 3)); writer.WriteElementString("PeakBaselinePointsUsed", noiseStats.PointsUsed.ToString()); writer.WriteElementString("NoiseThresholdModeUsed", ((int)noiseStats.NoiseThresholdModeUsed).ToString()); var statMoments = sicStatsPeak.StatisticalMoments; writer.WriteElementString("StatMomentsArea", StringUtilities.ValueToString(statMoments.Area, 5)); writer.WriteElementString("CenterOfMassScan", statMoments.CenterOfMassScan.ToString()); writer.WriteElementString("PeakStDev", StringUtilities.ValueToString(statMoments.StDev, 3)); writer.WriteElementString("PeakSkew", StringUtilities.ValueToString(statMoments.Skew, 4)); writer.WriteElementString("PeakKSStat", StringUtilities.ValueToString(statMoments.KSStat, 4)); writer.WriteElementString("StatMomentsDataCountUsed", statMoments.DataCountUsed.ToString()); writer.WriteElementString("InterferenceScore", StringUtilities.ValueToString(interferenceScore, 4)); if (sicDetails.SICScanType == clsScanList.eScanTypeConstants.FragScan) { writer.WriteElementString("SICScanStart", scanList.FragScans[sicScanIndices[0]].ScanNumber.ToString()); } else { writer.WriteElementString("SICScanStart", scanList.SurveyScans[sicScanIndices[0]].ScanNumber.ToString()); } if (mOptions.UseBase64DataEncoding) { // Save scan interval list as base-64 encoded strings lastGoodLoc = "Call SaveDataToXMLEncodeArray with SICScanIntervals"; SaveDataToXMLEncodeArray(writer, "SICScanIntervals", SICDataScanIntervals); } else { // Save scan interval list as long list of numbers // There are no tab delimiters, since we require that all // of the SICDataScanInterval values be <= 61 // If the interval is <=9, then the interval is stored as a number // For intervals between 10 and 35, uses letters A to Z // For intervals between 36 and 61, uses letters A to Z lastGoodLoc = "Populate scanIntervalList"; var scanIntervalList = string.Empty; if (SICDataScanIntervals != null) { for (var scanIntervalIndex = 0; scanIntervalIndex < sicDetails.SICDataCount; scanIntervalIndex++) { if (SICDataScanIntervals[scanIntervalIndex] <= 9) { scanIntervalList += SICDataScanIntervals[scanIntervalIndex].ToString(); } else if (SICDataScanIntervals[scanIntervalIndex] <= 35) { scanIntervalList += ((char)(SICDataScanIntervals[scanIntervalIndex] + 55)).ToString(); // 55 = -10 + 65 } else if (SICDataScanIntervals[scanIntervalIndex] <= 61) { scanIntervalList += ((char)(SICDataScanIntervals[scanIntervalIndex] + 61)).ToString(); // 61 = -36 + 97 } else { scanIntervalList += "z"; } } } writer.WriteElementString("SICScanIntervals", scanIntervalList); } lastGoodLoc = "Write SICPeakIndexStart"; writer.WriteElementString("SICPeakIndexStart", currentParentIon.SICStats.Peak.IndexBaseLeft.ToString()); writer.WriteElementString("SICPeakIndexEnd", currentParentIon.SICStats.Peak.IndexBaseRight.ToString()); writer.WriteElementString("SICDataCount", sicDetails.SICDataCount.ToString()); if (mOptions.SICOptions.SaveSmoothedData) { writer.WriteElementString("SICSmoothedYDataIndexStart", smoothedYDataSubset.DataStartIndex.ToString()); } if (mOptions.UseBase64DataEncoding) { // Save intensity and mass data lists as base-64 encoded strings // Note that these field names are purposely different than the DataList names used below for comma separated lists lastGoodLoc = "Call SaveDataToXMLEncodeArray with SICIntensityData"; SaveDataToXMLEncodeArray(writer, "SICIntensityData", sicDetails.SICIntensitiesAsFloat); lastGoodLoc = "Call SaveDataToXMLEncodeArray with SICMassData"; SaveDataToXMLEncodeArray(writer, "SICMassData", sicDetails.SICMassesAsFloat); if (mOptions.SICOptions.SaveSmoothedData) { // Need to copy the data into an array with the correct number of elements var dataArray = new float[smoothedYDataSubset.DataCount]; Array.Copy(smoothedYDataSubset.Data, dataArray, smoothedYDataSubset.DataCount); SaveDataToXMLEncodeArray(writer, "SICSmoothedYData", dataArray); } } else { // Save intensity and mass data lists as tab-delimited text list var intensityDataListWritten = false; var massDataList = false; try { lastGoodLoc = "Populate sbIntensityDataList"; sbIntensityDataList.Length = 0; sbMassDataList.Length = 0; if (sicDetails.SICDataCount > 0) { foreach (var dataPoint in sicDetails.SICData) { if (dataPoint.Intensity > 0) { sbIntensityDataList.Append(StringUtilities.DblToString(dataPoint.Intensity, 1) + ","); } else { // Do not output any number if the intensity is 0 sbIntensityDataList.Append(','); } if (dataPoint.Mass > 0) { sbMassDataList.Append(StringUtilities.DblToString(dataPoint.Mass, 3) + ","); } else { // Do not output any number if the mass is 0 sbMassDataList.Append(','); } } // Trim the trailing comma if (sbIntensityDataList[sbIntensityDataList.Length - 1] == ',') { sbIntensityDataList.Length -= 1; sbMassDataList.Length -= 1; } } writer.WriteElementString("IntensityDataList", sbIntensityDataList.ToString()); intensityDataListWritten = true; writer.WriteElementString("MassDataList", sbMassDataList.ToString()); massDataList = true; } catch (OutOfMemoryException ex) { // Ignore the exception if this is an Out of Memory exception if (!intensityDataListWritten) { writer.WriteElementString("IntensityDataList", string.Empty); } if (!massDataList) { writer.WriteElementString("MassDataList", string.Empty); } } if (mOptions.SICOptions.SaveSmoothedData) { try { lastGoodLoc = "Populate sbPeakYDataSmoothed"; sbPeakYDataSmoothed.Length = 0; if (smoothedYDataSubset.Data != null && smoothedYDataSubset.DataCount > 0) { for (var index = 0; index < smoothedYDataSubset.DataCount; index++) { sbPeakYDataSmoothed.Append(Math.Round(smoothedYDataSubset.Data[index]).ToString(CultureInfo.InvariantCulture) + ","); } // Trim the trailing comma sbPeakYDataSmoothed.Length -= 1; } writer.WriteElementString("SmoothedYDataList", sbPeakYDataSmoothed.ToString()); } catch (OutOfMemoryException ex) { // Ignore the exception if this is an Out of Memory exception writer.WriteElementString("SmoothedYDataList", string.Empty); } } } writer.WriteEndElement(); } } catch (Exception ex) { ReportError("Error writing the XML data to the output file; Last good location: " + lastGoodLoc, ex, clsMASIC.eMasicErrorCodes.OutputFileWriteError); return(false); } return(true); }
public bool XMLOutputFileInitialize( string inputFilePathFull, string outputDirectoryPath, clsDataOutput dataOutputHandler, clsScanList scanList, clsSpectraCache spectraCache, clsSICOptions sicOptions, clsBinningOptions binningOptions) { var xmlOutputFilePath = string.Empty; try { xmlOutputFilePath = clsDataOutput.ConstructOutputFilePath(inputFilePathFull, outputDirectoryPath, clsDataOutput.eOutputFileTypeConstants.XMLFile); dataOutputHandler.OutputFileHandles.XMLFileForSICs = new XmlTextWriter(xmlOutputFilePath, System.Text.Encoding.UTF8); var writer = dataOutputHandler.OutputFileHandles.XMLFileForSICs; writer.Formatting = Formatting.Indented; writer.Indentation = 1; writer.WriteStartDocument(true); writer.WriteStartElement("SICData"); writer.WriteStartElement("ProcessingSummary"); writer.WriteElementString("DatasetID", sicOptions.DatasetID.ToString()); writer.WriteElementString("SourceFilePath", inputFilePathFull); string lastModTimeText; string fileSizeBytes; try { var inputFileInfo = new FileInfo(inputFilePathFull); var lastModTime = inputFileInfo.LastWriteTime; lastModTimeText = lastModTime.ToShortDateString() + " " + lastModTime.ToShortTimeString(); fileSizeBytes = inputFileInfo.Length.ToString(); } catch (Exception ex) { lastModTimeText = string.Empty; fileSizeBytes = "0"; } writer.WriteElementString("SourceFileDateTime", lastModTimeText); writer.WriteElementString("SourceFileSizeBytes", fileSizeBytes); writer.WriteElementString("MASICProcessingDate", DateTime.Now.ToString(clsDatasetStatsSummarizer.DATE_TIME_FORMAT_STRING)); writer.WriteElementString("MASICVersion", mOptions.MASICVersion); writer.WriteElementString("MASICPeakFinderDllVersion", mOptions.PeakFinderVersion); writer.WriteElementString("ScanCountTotal", scanList.MasterScanOrderCount.ToString()); writer.WriteElementString("SurveyScanCount", scanList.SurveyScans.Count.ToString()); writer.WriteElementString("FragScanCount", scanList.FragScans.Count.ToString()); writer.WriteElementString("SkipMSMSProcessing", mOptions.SkipMSMSProcessing.ToString()); writer.WriteElementString("ParentIonDecoyMassDa", mOptions.ParentIonDecoyMassDa.ToString("0.0000")); writer.WriteEndElement(); writer.WriteStartElement("MemoryOptions"); writer.WriteElementString("CacheAlwaysDisabled", spectraCache.DiskCachingAlwaysDisabled.ToString()); writer.WriteElementString("CacheSpectraToRetainInMemory", spectraCache.CacheSpectraToRetainInMemory.ToString()); writer.WriteEndElement(); writer.WriteStartElement("SICOptions"); // SIC Options // "SICToleranceDa" is a legacy parameter; If the SIC tolerance is in PPM, then "SICToleranceDa" is the Da tolerance at 1000 m/z writer.WriteElementString("SICToleranceDa", clsParentIonProcessing.GetParentIonToleranceDa(sicOptions, 1000).ToString("0.0000")); writer.WriteElementString("SICTolerance", sicOptions.SICTolerance.ToString("0.0000")); writer.WriteElementString("SICToleranceIsPPM", sicOptions.SICToleranceIsPPM.ToString()); writer.WriteElementString("RefineReportedParentIonMZ", sicOptions.RefineReportedParentIonMZ.ToString()); writer.WriteElementString("ScanRangeStart", sicOptions.ScanRangeStart.ToString()); writer.WriteElementString("ScanRangeEnd", sicOptions.ScanRangeEnd.ToString()); writer.WriteElementString("RTRangeStart", sicOptions.RTRangeStart.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("RTRangeEnd", sicOptions.RTRangeEnd.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("CompressMSSpectraData", sicOptions.CompressMSSpectraData.ToString()); writer.WriteElementString("CompressMSMSSpectraData", sicOptions.CompressMSMSSpectraData.ToString()); writer.WriteElementString("CompressToleranceDivisorForDa", sicOptions.CompressToleranceDivisorForDa.ToString("0.0")); writer.WriteElementString("CompressToleranceDivisorForPPM", sicOptions.CompressToleranceDivisorForPPM.ToString("0.0")); writer.WriteElementString("MaxSICPeakWidthMinutesBackward", sicOptions.MaxSICPeakWidthMinutesBackward.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("MaxSICPeakWidthMinutesForward", sicOptions.MaxSICPeakWidthMinutesForward.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("IntensityThresholdFractionMax", StringUtilities.DblToString(sicOptions.SICPeakFinderOptions.IntensityThresholdFractionMax, 5)); writer.WriteElementString("IntensityThresholdAbsoluteMinimum", sicOptions.SICPeakFinderOptions.IntensityThresholdAbsoluteMinimum.ToString(CultureInfo.InvariantCulture)); // Peak Finding Options var baselineNoiseOptions = sicOptions.SICPeakFinderOptions.SICBaselineNoiseOptions; writer.WriteElementString("SICNoiseThresholdMode", baselineNoiseOptions.BaselineNoiseMode.ToString()); writer.WriteElementString("SICNoiseThresholdIntensity", baselineNoiseOptions.BaselineNoiseLevelAbsolute.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("SICNoiseFractionLowIntensityDataToAverage", StringUtilities.DblToString(baselineNoiseOptions.TrimmedMeanFractionLowIntensityDataToAverage, 5)); writer.WriteElementString("SICNoiseMinimumSignalToNoiseRatio", baselineNoiseOptions.MinimumSignalToNoiseRatio.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("MaxDistanceScansNoOverlap", sicOptions.SICPeakFinderOptions.MaxDistanceScansNoOverlap.ToString()); writer.WriteElementString("MaxAllowedUpwardSpikeFractionMax", StringUtilities.DblToString(sicOptions.SICPeakFinderOptions.MaxAllowedUpwardSpikeFractionMax, 5)); writer.WriteElementString("InitialPeakWidthScansScaler", sicOptions.SICPeakFinderOptions.InitialPeakWidthScansScaler.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("InitialPeakWidthScansMaximum", sicOptions.SICPeakFinderOptions.InitialPeakWidthScansMaximum.ToString()); writer.WriteElementString("FindPeaksOnSmoothedData", sicOptions.SICPeakFinderOptions.FindPeaksOnSmoothedData.ToString()); writer.WriteElementString("SmoothDataRegardlessOfMinimumPeakWidth", sicOptions.SICPeakFinderOptions.SmoothDataRegardlessOfMinimumPeakWidth.ToString()); writer.WriteElementString("UseButterworthSmooth", sicOptions.SICPeakFinderOptions.UseButterworthSmooth.ToString()); writer.WriteElementString("ButterworthSamplingFrequency", StringUtilities.DblToString(sicOptions.SICPeakFinderOptions.ButterworthSamplingFrequency, 5)); writer.WriteElementString("ButterworthSamplingFrequencyDoubledForSIMData", sicOptions.SICPeakFinderOptions.ButterworthSamplingFrequencyDoubledForSIMData.ToString()); writer.WriteElementString("UseSavitzkyGolaySmooth", sicOptions.SICPeakFinderOptions.UseSavitzkyGolaySmooth.ToString()); writer.WriteElementString("SavitzkyGolayFilterOrder", sicOptions.SICPeakFinderOptions.SavitzkyGolayFilterOrder.ToString()); var noiseThresholdOptions = sicOptions.SICPeakFinderOptions.MassSpectraNoiseThresholdOptions; writer.WriteElementString("MassSpectraNoiseThresholdMode", noiseThresholdOptions.BaselineNoiseMode.ToString()); writer.WriteElementString("MassSpectraNoiseThresholdIntensity", noiseThresholdOptions.BaselineNoiseLevelAbsolute.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("MassSpectraNoiseFractionLowIntensityDataToAverage", StringUtilities.DblToString(noiseThresholdOptions.TrimmedMeanFractionLowIntensityDataToAverage, 5)); writer.WriteElementString("MassSpectraNoiseMinimumSignalToNoiseRatio", noiseThresholdOptions.MinimumSignalToNoiseRatio.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("ReplaceSICZeroesWithMinimumPositiveValueFromMSData", sicOptions.ReplaceSICZeroesWithMinimumPositiveValueFromMSData.ToString()); writer.WriteElementString("SaveSmoothedData", sicOptions.SaveSmoothedData.ToString()); // Similarity options writer.WriteElementString("SimilarIonMZToleranceHalfWidth", sicOptions.SimilarIonMZToleranceHalfWidth.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("SimilarIonToleranceHalfWidthMinutes", sicOptions.SimilarIonToleranceHalfWidthMinutes.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("SpectrumSimilarityMinimum", sicOptions.SpectrumSimilarityMinimum.ToString(CultureInfo.InvariantCulture)); writer.WriteEndElement(); writer.WriteStartElement("BinningOptions"); writer.WriteElementString("BinStartX", binningOptions.StartX.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("BinEndX", binningOptions.EndX.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("BinSize", binningOptions.BinSize.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("MaximumBinCount", binningOptions.MaximumBinCount.ToString()); writer.WriteElementString("IntensityPrecisionPercent", binningOptions.IntensityPrecisionPercent.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("Normalize", binningOptions.Normalize.ToString()); writer.WriteElementString("SumAllIntensitiesForBin", binningOptions.SumAllIntensitiesForBin.ToString()); writer.WriteEndElement(); writer.WriteStartElement("CustomSICValues"); writer.WriteElementString("MZList", mOptions.CustomSICList.RawTextMZList); writer.WriteElementString("MZToleranceDaList", CheckForEmptyToleranceList(mOptions.CustomSICList.RawTextMZToleranceDaList)); writer.WriteElementString("ScanCenterList", mOptions.CustomSICList.RawTextScanOrAcqTimeCenterList); writer.WriteElementString("ScanToleranceList", CheckForEmptyToleranceList(mOptions.CustomSICList.RawTextScanOrAcqTimeToleranceList)); writer.WriteElementString("ScanTolerance", mOptions.CustomSICList.ScanOrAcqTimeTolerance.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("ScanType", mOptions.CustomSICList.ScanToleranceType.ToString()); writer.WriteElementString("LimitSearchToCustomMZList", mOptions.CustomSICList.LimitSearchToCustomMZList.ToString()); writer.WriteEndElement(); } catch (Exception ex) { ReportError("Error initializing the XML output file: " + xmlOutputFilePath, ex, clsMASIC.eMasicErrorCodes.OutputFileWriteError); return(false); } return(true); }
/// <summary> /// Writes out a flat file containing identified peaks and statistics /// </summary> /// <param name="scanList"></param> /// <param name="inputFileName"></param> /// <param name="outputDirectoryPath"></param> /// <param name="masicOptions"></param> /// <param name="dataOutputHandler"></param> /// <returns></returns> public bool SaveSICStatsFlatFile( clsScanList scanList, string inputFileName, string outputDirectoryPath, clsMASICOptions masicOptions, clsDataOutput dataOutputHandler) { var outputFilePath = string.Empty; const char TAB_DELIMITER = '\t'; // Old: Populate scanListArray with the scan numbers in scanList.SurveyScans // PopulateScanListPointerArray(scanList.SurveyScans, scanList.SurveyScans.Count, out var scanListArray); try { UpdateProgress(0, "Saving SIC data to flat file"); outputFilePath = clsDataOutput.ConstructOutputFilePath(inputFileName, outputDirectoryPath, clsDataOutput.eOutputFileTypeConstants.SICStatsFlatFile); ReportMessage("Saving SIC flat file to disk: " + Path.GetFileName(outputFilePath)); using (var writer = new StreamWriter(outputFilePath, false)) { // Write the SIC stats to the output file // The file is tab delimited var includeScanTimesInSICStatsFile = masicOptions.IncludeScanTimesInSICStatsFile; if (masicOptions.IncludeHeadersInExportFile) { writer.WriteLine(dataOutputHandler.GetHeadersForOutputFile(scanList, clsDataOutput.eOutputFileTypeConstants.SICStatsFlatFile, TAB_DELIMITER)); } if (scanList.SurveyScans.Count == 0 && scanList.ParentIons.Count == 0) { // Write out fake values to the _SICStats.txt file so that downstream software can still access some of the information for (var fragScanIndex = 0; fragScanIndex < scanList.FragScans.Count; fragScanIndex++) { var fakeParentIon = GetFakeParentIonForFragScan(scanList, fragScanIndex); var parentIonIndex = 0; var surveyScanNumber = 0; float surveyScanTime = 0; WriteSICStatsFlatFileEntry(writer, TAB_DELIMITER, masicOptions.SICOptions, scanList, fakeParentIon, parentIonIndex, surveyScanNumber, surveyScanTime, 0, includeScanTimesInSICStatsFile); } } else { for (var parentIonIndex = 0; parentIonIndex < scanList.ParentIons.Count; parentIonIndex++) { bool includeParentIon; if (masicOptions.CustomSICList.LimitSearchToCustomMZList) { includeParentIon = scanList.ParentIons[parentIonIndex].CustomSICPeak; } else { includeParentIon = true; } if (includeParentIon) { for (var fragScanIndex = 0; fragScanIndex < scanList.ParentIons[parentIonIndex].FragScanIndices.Count; fragScanIndex++) { var parentIon = scanList.ParentIons[parentIonIndex]; int surveyScanNumber; float surveyScanTime; if (parentIon.SurveyScanIndex >= 0 && parentIon.SurveyScanIndex < scanList.SurveyScans.Count) { surveyScanNumber = scanList.SurveyScans[parentIon.SurveyScanIndex].ScanNumber; surveyScanTime = scanList.SurveyScans[parentIon.SurveyScanIndex].ScanTime; } else { surveyScanNumber = -1; surveyScanTime = 0; } WriteSICStatsFlatFileEntry(writer, TAB_DELIMITER, masicOptions.SICOptions, scanList, parentIon, parentIonIndex, surveyScanNumber, surveyScanTime, fragScanIndex, includeScanTimesInSICStatsFile); } } if (scanList.ParentIons.Count > 1) { if (parentIonIndex % 100 == 0) { UpdateProgress((short)(parentIonIndex / (double)(scanList.ParentIons.Count - 1) * 100)); } } else { UpdateProgress(1); } if (masicOptions.AbortProcessing) { scanList.ProcessingIncomplete = true; break; } } } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); ReportError("Error writing the Peak Stats to: " + outputFilePath, ex, clsMASIC.eMasicErrorCodes.OutputFileWriteError); return(false); } return(true); }
private void StoreExtendedHeaderInfo( clsDataOutput dataOutputHandler, clsScanInfo scanInfo, IReadOnlyCollection <KeyValuePair <string, string> > statusEntries, IReadOnlyCollection <string> keyNameFilterList) { var filterItems = false; try { if (statusEntries == null) { return; } if (keyNameFilterList != null && keyNameFilterList.Count > 0) { if (keyNameFilterList.Any(item => item.Length > 0)) { filterItems = true; } } foreach (var statusEntry in statusEntries) { if (string.IsNullOrWhiteSpace(statusEntry.Key)) { // Empty entry name; do not add continue; } bool saveItem; if (filterItems) { saveItem = false; foreach (var item in keyNameFilterList) { if (statusEntry.Key.ToLower().Contains(item.ToLower())) { saveItem = true; break; } } } else { saveItem = true; } if (string.IsNullOrWhiteSpace(statusEntry.Key) || statusEntry.Key.Equals("1")) { // Name is null; skip it saveItem = false; } if (saveItem) { var extendedHeaderID = dataOutputHandler.ExtendedStatsWriter.GetExtendedHeaderInfoIdByName(statusEntry.Key); // Add or update the value for extendedHeaderID scanInfo.ExtendedHeaderInfo[extendedHeaderID] = statusEntry.Value.Trim(); } } } catch (Exception ex) { // Ignore any errors here } }
private bool ExtractXcaliburFragmentationScan( XRawFileIO xcaliburAccessor, clsScanList scanList, clsSpectraCache spectraCache, clsDataOutput dataOutputHandler, clsSICOptions sicOptions, clsBinningOptions binningOptions, ThermoRawFileReader.clsScanInfo thermoScanInfo) { // Note that MinimumPositiveIntensity will be determined in LoadSpectraForThermoRawFile var scanInfo = new clsScanInfo(thermoScanInfo.ParentIonMZ) { ScanNumber = thermoScanInfo.ScanNumber, ScanTime = (float)thermoScanInfo.RetentionTime, ScanHeaderText = XRawFileIO.MakeGenericThermoScanFilter(thermoScanInfo.FilterText), ScanTypeName = XRawFileIO.GetScanTypeNameFromThermoScanFilterText(thermoScanInfo.FilterText), BasePeakIonMZ = thermoScanInfo.BasePeakMZ, BasePeakIonIntensity = thermoScanInfo.BasePeakIntensity, TotalIonIntensity = thermoScanInfo.TotalIonCurrent, MinimumPositiveIntensity = 0, ZoomScan = thermoScanInfo.ZoomScan, SIMScan = thermoScanInfo.SIMScan, MRMScanType = thermoScanInfo.MRMScanType }; // Typically .EventNumber is 1 for the parent-ion scan; 2 for 1st frag scan, 3 for 2nd frag scan, etc. // This resets for each new parent-ion scan scanInfo.FragScanInfo.FragScanNumber = thermoScanInfo.EventNumber - 1; // The .EventNumber value is sometimes wrong; need to check for this // For example, if the dataset only has MS2 scans and no parent-ion scan, .EventNumber will be 2 for every MS2 scan if (scanList.FragScans.Count > 0) { var prevFragScan = scanList.FragScans[scanList.FragScans.Count - 1]; if (prevFragScan.ScanNumber == scanInfo.ScanNumber - 1) { if (scanInfo.FragScanInfo.FragScanNumber <= prevFragScan.FragScanInfo.FragScanNumber) { scanInfo.FragScanInfo.FragScanNumber = prevFragScan.FragScanInfo.FragScanNumber + 1; } } } scanInfo.FragScanInfo.MSLevel = thermoScanInfo.MSLevel; if (scanInfo.MRMScanType != MRMScanTypeConstants.NotMRM) { // This is an MRM scan scanList.MRMDataPresent = true; scanInfo.MRMScanInfo = clsMRMProcessing.DuplicateMRMInfo(thermoScanInfo.MRMInfo, thermoScanInfo.ParentIonMZ); if (scanList.SurveyScans.Count == 0) { // Need to add a "fake" survey scan that we can map this parent ion to mLastNonZoomSurveyScanIndex = scanList.AddFakeSurveyScan(); } } else { scanInfo.MRMScanInfo.MRMMassCount = 0; } scanInfo.LowMass = thermoScanInfo.LowMass; scanInfo.HighMass = thermoScanInfo.HighMass; scanInfo.IsFTMS = thermoScanInfo.IsFTMS; // Store the ScanEvent values in .ExtendedHeaderInfo StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, thermoScanInfo.ScanEvents); // Store the collision mode and possibly the scan filter text scanInfo.FragScanInfo.CollisionMode = thermoScanInfo.CollisionMode; StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, clsExtendedStatsWriter.EXTENDED_STATS_HEADER_COLLISION_MODE, thermoScanInfo.CollisionMode); if (mOptions.WriteExtendedStatsIncludeScanFilterText) { StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, clsExtendedStatsWriter.EXTENDED_STATS_HEADER_SCAN_FILTER_TEXT, thermoScanInfo.FilterText); } if (mOptions.WriteExtendedStatsStatusLog) { // Store the StatusLog values in .ExtendedHeaderInfo StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, thermoScanInfo.StatusLog, mOptions.StatusLogKeyNameFilterList); } scanList.FragScans.Add(scanInfo); var fragScanIndex = scanList.FragScans.Count - 1; scanList.AddMasterScanEntry(clsScanList.eScanTypeConstants.FragScan, fragScanIndex); // Note: Even if keepRawSpectra = False, we still need to load the raw data so that we can compute the noise level for the spectrum var msDataResolution = binningOptions.BinSize / sicOptions.CompressToleranceDivisorForDa; var success = LoadSpectraForThermoRawFile( xcaliburAccessor, spectraCache, scanInfo, sicOptions.SICPeakFinderOptions.MassSpectraNoiseThresholdOptions, clsMASIC.DISCARD_LOW_INTENSITY_MSMS_DATA_ON_LOAD, sicOptions.CompressMSMSSpectraData, msDataResolution, mKeepRawSpectra && mKeepMSMSSpectra); if (!success) { return(false); } SaveScanStatEntry(dataOutputHandler.OutputFileHandles.ScanStats, clsScanList.eScanTypeConstants.FragScan, scanInfo, sicOptions.DatasetID); if (thermoScanInfo.MRMScanType == MRMScanTypeConstants.NotMRM) { // This is not an MRM scan mParentIonProcessor.AddUpdateParentIons(scanList, mLastNonZoomSurveyScanIndex, thermoScanInfo.ParentIonMZ, fragScanIndex, spectraCache, sicOptions); } else { // This is an MRM scan mParentIonProcessor.AddUpdateParentIons(scanList, mLastNonZoomSurveyScanIndex, thermoScanInfo.ParentIonMZ, scanInfo.MRMScanInfo, spectraCache, sicOptions); } if (mLastNonZoomSurveyScanIndex >= 0) { var precursorScanNumber = scanList.SurveyScans[mLastNonZoomSurveyScanIndex].ScanNumber; // Compute the interference of the parent ion in the MS1 spectrum for this frag scan scanInfo.FragScanInfo.InterferenceScore = ComputeInterference(xcaliburAccessor, thermoScanInfo, precursorScanNumber); } return(true); }
private bool ExtractXcaliburSurveyScan( XRawFileIO xcaliburAccessor, clsScanList scanList, clsSpectraCache spectraCache, clsDataOutput dataOutputHandler, clsSICOptions sicOptions, ThermoRawFileReader.clsScanInfo thermoScanInfo) { var scanInfo = new clsScanInfo() { ScanNumber = thermoScanInfo.ScanNumber, ScanTime = (float)thermoScanInfo.RetentionTime, ScanHeaderText = XRawFileIO.MakeGenericThermoScanFilter(thermoScanInfo.FilterText), ScanTypeName = XRawFileIO.GetScanTypeNameFromThermoScanFilterText(thermoScanInfo.FilterText), BasePeakIonMZ = thermoScanInfo.BasePeakMZ, BasePeakIonIntensity = thermoScanInfo.BasePeakIntensity, TotalIonIntensity = thermoScanInfo.TotalIonCurrent, MinimumPositiveIntensity = 0, // This will be determined in LoadSpectraForThermoRawFile ZoomScan = thermoScanInfo.ZoomScan, SIMScan = thermoScanInfo.SIMScan, MRMScanType = thermoScanInfo.MRMScanType, LowMass = thermoScanInfo.LowMass, HighMass = thermoScanInfo.HighMass, IsFTMS = thermoScanInfo.IsFTMS }; // Survey scans typically lead to multiple parent ions; we do not record them here scanInfo.FragScanInfo.ParentIonInfoIndex = -1; if (scanInfo.MRMScanType != MRMScanTypeConstants.NotMRM) { // This is an MRM scan scanList.MRMDataPresent = true; } if (scanInfo.SIMScan) { scanList.SIMDataPresent = true; var simKey = scanInfo.LowMass + "_" + scanInfo.HighMass; if (mSIMScanMapping.TryGetValue(simKey, out var simIndex)) { scanInfo.SIMIndex = simIndex; } else { scanInfo.SIMIndex = mSIMScanMapping.Count; mSIMScanMapping.Add(simKey, mSIMScanMapping.Count); } } // Store the ScanEvent values in .ExtendedHeaderInfo StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, thermoScanInfo.ScanEvents); // Store the collision mode and possibly the scan filter text scanInfo.FragScanInfo.CollisionMode = thermoScanInfo.CollisionMode; StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, clsExtendedStatsWriter.EXTENDED_STATS_HEADER_COLLISION_MODE, thermoScanInfo.CollisionMode); if (mOptions.WriteExtendedStatsIncludeScanFilterText) { StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, clsExtendedStatsWriter.EXTENDED_STATS_HEADER_SCAN_FILTER_TEXT, thermoScanInfo.FilterText); } if (mOptions.WriteExtendedStatsStatusLog) { // Store the StatusLog values in .ExtendedHeaderInfo StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, thermoScanInfo.StatusLog, mOptions.StatusLogKeyNameFilterList); } scanList.SurveyScans.Add(scanInfo); if (!scanInfo.ZoomScan) { mLastNonZoomSurveyScanIndex = scanList.SurveyScans.Count - 1; } scanList.AddMasterScanEntry(clsScanList.eScanTypeConstants.SurveyScan, scanList.SurveyScans.Count - 1); double msDataResolution; if (sicOptions.SICToleranceIsPPM) { // Define MSDataResolution based on the tolerance value that will be used at the lowest m/z in this spectrum, divided by sicOptions.CompressToleranceDivisorForPPM // However, if the lowest m/z value is < 100, then use 100 m/z if (thermoScanInfo.LowMass < 100) { msDataResolution = clsParentIonProcessing.GetParentIonToleranceDa(sicOptions, 100) / sicOptions.CompressToleranceDivisorForPPM; } else { msDataResolution = clsParentIonProcessing.GetParentIonToleranceDa(sicOptions, thermoScanInfo.LowMass) / sicOptions.CompressToleranceDivisorForPPM; } } else { msDataResolution = sicOptions.SICTolerance / sicOptions.CompressToleranceDivisorForDa; } // Note: Even if mKeepRawSpectra = False, we still need to load the raw data so that we can compute the noise level for the spectrum var success = LoadSpectraForThermoRawFile( xcaliburAccessor, spectraCache, scanInfo, sicOptions.SICPeakFinderOptions.MassSpectraNoiseThresholdOptions, clsMASIC.DISCARD_LOW_INTENSITY_MS_DATA_ON_LOAD, sicOptions.CompressMSSpectraData, msDataResolution, mKeepRawSpectra); if (!success) { return(false); } SaveScanStatEntry(dataOutputHandler.OutputFileHandles.ScanStats, clsScanList.eScanTypeConstants.SurveyScan, scanInfo, sicOptions.DatasetID); return(true); }
/// <summary> /// Read scan data and ions from a Thermo .raw file /// </summary> /// <param name="filePath"></param> /// <param name="scanList"></param> /// <param name="spectraCache"></param> /// <param name="dataOutputHandler"></param> /// <param name="keepRawSpectra"></param> /// <param name="keepMSMSSpectra"></param> /// <returns>True if Success, False if failure</returns> /// <remarks>Assumes filePath exists</remarks> public bool ExtractScanInfoFromXcaliburDataFile( string filePath, clsScanList scanList, clsSpectraCache spectraCache, clsDataOutput dataOutputHandler, bool keepRawSpectra, bool keepMSMSSpectra) { // Use XrawFileIO to read the .Raw files (it uses ThermoFisher.CommonCore) var readerOptions = new ThermoReaderOptions { LoadMSMethodInfo = mOptions.WriteMSMethodFile, LoadMSTuneInfo = mOptions.WriteMSTuneFile }; var xcaliburAccessor = new XRawFileIO(readerOptions) { ScanInfoCacheMaxSize = 0 // Don't cache scanInfo objects }; RegisterEvents(xcaliburAccessor); mBpiUpdateCount = 0; // Assume success for now var success = true; try { Console.Write("Reading Thermo .raw file "); ReportMessage("Reading Thermo .raw file"); UpdateProgress(0, "Opening data file:" + Environment.NewLine + Path.GetFileName(filePath)); // Obtain the full path to the file var rawFileInfo = new FileInfo(filePath); var inputFileFullPath = rawFileInfo.FullName; // Open a handle to the data file if (!xcaliburAccessor.OpenRawFile(inputFileFullPath)) { ReportError("Error opening input data file: " + inputFileFullPath + " (xcaliburAccessor.OpenRawFile returned False)"); SetLocalErrorCode(clsMASIC.eMasicErrorCodes.InputFileAccessError); return(false); } var datasetID = mOptions.SICOptions.DatasetID; success = UpdateDatasetFileStats(rawFileInfo, datasetID, xcaliburAccessor); var metadataWriter = new clsThermoMetadataWriter(); RegisterEvents(metadataWriter); if (mOptions.WriteMSMethodFile) { metadataWriter.SaveMSMethodFile(xcaliburAccessor, dataOutputHandler); } if (mOptions.WriteMSTuneFile) { metadataWriter.SaveMSTuneFile(xcaliburAccessor, dataOutputHandler); } var scanCount = xcaliburAccessor.GetNumScans(); if (scanCount <= 0) { // No scans found ReportError("No scans found in the input file: " + filePath); SetLocalErrorCode(clsMASIC.eMasicErrorCodes.InputFileAccessError); return(false); } var scanStart = xcaliburAccessor.ScanStart; var scanEnd = xcaliburAccessor.ScanEnd; InitOptions(scanList, keepRawSpectra, keepMSMSSpectra); UpdateProgress(string.Format("Reading Xcalibur data ({0:N0} scans){1}", scanCount, Environment.NewLine + Path.GetFileName(filePath))); ReportMessage(string.Format("Reading Xcalibur data; Total scan count: {0:N0}", scanCount)); var scanCountToRead = scanEnd - scanStart + 1; var scansEst = mOptions.SICOptions.ScanRangeCount; if (scansEst <= 0) { scansEst = scanCountToRead; } scanList.ReserveListCapacity(scansEst); mScanTracking.ReserveListCapacity(scansEst); spectraCache.SpectrumCount = Math.Max(spectraCache.SpectrumCount, scansEst); for (var scanNumber = scanStart; scanNumber <= scanEnd; scanNumber++) { if (!mScanTracking.CheckScanInRange(scanNumber, mOptions.SICOptions)) { mScansOutOfRange += 1; continue; } success = xcaliburAccessor.GetScanInfo(scanNumber, out ThermoRawFileReader.clsScanInfo thermoScanInfo); if (!success) { // GetScanInfo returned false ReportWarning("xcaliburAccessor.GetScanInfo returned false for scan " + scanNumber.ToString() + "; aborting read"); break; } var percentComplete = scanList.MasterScanOrderCount / (double)(scanCountToRead) * 100; var extractSuccess = ExtractScanInfoCheckRange(xcaliburAccessor, thermoScanInfo, scanList, spectraCache, dataOutputHandler, percentComplete); if (!extractSuccess) { break; } } Console.WriteLine(); scanList.SetListCapacityToCount(); mScanTracking.SetListCapacityToCount(); // Shrink the memory usage of the scanList arrays success = FinalizeScanList(scanList, rawFileInfo); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); ReportError("Error in ExtractScanInfoFromXcaliburDataFile", ex, clsMASIC.eMasicErrorCodes.InputFileDataReadError); } // Close the handle to the data file xcaliburAccessor.CloseRawFile(); return(success); }