public static void ExtractPrecursorScans(this RawDataCollection rawData, IRawDataPlus rawFile) { if (rawData.Performed.Contains(Operations.PrecursorScans)) { return; } if (!rawData.Performed.Contains(Operations.ScanIndex)) { rawData.ExtractScanIndex(rawFile); } Log.Information("Extracting scan dependents/precursor scans"); int ms2Scan = -1; int ms3Scan = -1; IEnumerable <int> scans = rawData.scanIndex.ScanEnumerators[MSOrderType.Ms]; ProgressIndicator progress = new ProgressIndicator(scans.Count(), "Indexing linked scan events"); foreach (int scan in scans) { var scanDependents = rawFile.GetScanDependents(scan, 4); // check if the ms1 scan has dependent scans if (scanDependents == null) { continue; } for (int i = 0; i < scanDependents.ScanDependentDetailArray.Length; i++) { if (rawData.scanIndex.AnalysisOrder == MSOrderType.Ms2) // it is ms2 { ms2Scan = scanDependents.ScanDependentDetailArray[i].ScanIndex; rawData.precursorScans.Add(ms2Scan, new PrecursorScanData(ms2scan: ms2Scan, masterScan: scan)); } else // it is ms3 { ms2Scan = scanDependents.ScanDependentDetailArray[i].ScanIndex; if (rawFile.GetScanDependents(ms2Scan, 4).ScanDependentDetailArray.Length != 0) // make sure there is ms3 data { ms3Scan = rawFile.GetScanDependents(ms2Scan, 4).ScanDependentDetailArray[0].ScanIndex; rawData.precursorScans.Add(ms2Scan, new PrecursorScanData(ms2scan: ms2Scan, masterScan: scan)); rawData.precursorScans.Add(ms3Scan, new PrecursorScanData(ms3scan: ms3Scan, ms2Scan: ms2Scan, masterScan: scan)); } else { // there is no ms3 scan, so we only add the ms2 scan rawData.precursorScans.Add(ms2Scan, new PrecursorScanData(ms2scan: ms2Scan, masterScan: scan)); } } } progress.Update(); } progress.Done(); rawData.Performed.Add(Operations.PrecursorScans); }
DependentsAndPrecursorScansByScanDependents(IRawDataPlus rawFile, ScanIndex index) { rawFile.SelectInstrument(Device.MS, 1); Log.Information("Extracting scan dependents/precursor scans"); PrecursorScanCollection precursorScans = new PrecursorScanCollection(); ScanDependentsCollections dependents = new ScanDependentsCollections(); int ms2Scan = -1; int ms3Scan = -1; IEnumerable <int> scans = index.ScanEnumerators[MSOrderType.Ms]; ProgressIndicator progress = new ProgressIndicator(scans.Count(), "Indexing linked scan events"); foreach (int scan in scans) { var scanDependents = rawFile.GetScanDependents(scan, 4); dependents[scan] = scanDependents; // check if the ms1 scan has dependent scans if (scanDependents == null) { continue; } for (int i = 0; i < scanDependents.ScanDependentDetailArray.Length; i++) { if (index.AnalysisOrder == MSOrderType.Ms2) // it is ms2 { ms2Scan = scanDependents.ScanDependentDetailArray[i].ScanIndex; precursorScans[ms2Scan] = new PrecursorScanData(ms2scan: ms2Scan, masterScan: scan); } else // it is ms3 { ms2Scan = scanDependents.ScanDependentDetailArray[i].ScanIndex; var ms2Dependents = rawFile.GetScanDependents(ms2Scan, 4).ScanDependentDetailArray; if (ms2Dependents.Length != 0) // make sure there is ms3 data { ms3Scan = ms2Dependents[0].ScanIndex; precursorScans[ms2Scan] = new PrecursorScanData(ms2scan: ms2Scan, masterScan: scan); precursorScans[ms3Scan] = new PrecursorScanData(ms3scan: ms3Scan, ms2Scan: ms2Scan, masterScan: scan); } else { // there is no ms3 scan, so we only add the ms2 scan precursorScans[ms2Scan] = new PrecursorScanData(ms2scan: ms2Scan, masterScan: scan); } } } progress.Update(); } progress.Done(); return(precursorScans, dependents); }
public static ScanDependentsCollections ScanDependents(IRawDataPlus rawFile, ScanIndex index) { rawFile.SelectInstrument(Device.MS, 1); ScanDependentsCollections scanDependents = new ScanDependentsCollections(); foreach (int scan in index.ScanEnumerators[MSOrderType.Ms]) { scanDependents[scan] = rawFile.GetScanDependents(scan, 4); } return(scanDependents); }
/// <summary> /// Populate information about parent scan numbers /// </summary> private void ReadScanParents() { int firstScan = rawFile.RunHeaderEx.FirstSpectrum; int lastScan = rawFile.RunHeaderEx.LastSpectrum; for (int scanNumber = firstScan; scanNumber <= lastScan; scanNumber++) { var dependents = rawFile.GetScanDependents(scanNumber, 1); if (dependents != null) { foreach (var depedent in dependents.ScanDependentDetailArray) { ScanParents[depedent.ScanIndex] = scanNumber; } } } }
public static void AggregateMetaData(this ScanMetaDataCollection metaData, RawDataCollection rawData, IRawDataPlus rawFile) { List <Operations> operations = new List <Operations>() { Operations.ScanIndex, Operations.MethodData, Operations.RetentionTimes, Operations.TrailerExtras, Operations.PrecursorScans }; if (rawData.methodData.MassAnalyzers[MSOrderType.Ms] == MassAnalyzerType.MassAnalyzerFTMS) { operations.Add(Operations.Ms1CentroidStreams); } else { operations.Add(Operations.Ms1SegmentedScans); } if (rawData.methodData.MassAnalyzers[MSOrderType.Ms2] == MassAnalyzerType.MassAnalyzerFTMS) { operations.Add(Operations.Ms2CentroidStreams); } else { operations.Add(Operations.Ms2SegmentedScans); } if (rawData.methodData.AnalysisOrder == MSOrderType.Ms3) { if (rawData.methodData.MassAnalyzers[MSOrderType.Ms3] == MassAnalyzerType.MassAnalyzerFTMS) { operations.Add(Operations.Ms3CentroidStreams); } else { operations.Add(Operations.Ms3SegmentedScans); } } rawData.Check(rawFile, operations); ProgressIndicator progress = new ProgressIndicator(rawData.scanIndex.ScanEnumerators[MSOrderType.Any].Count(), "Formatting scan meta data"); // add a new ScanMetaData class for each scan foreach (int scan in rawData.scanIndex.ScanEnumerators[MSOrderType.Any]) { metaData.Add(scan, new ScanMetaData()); } // get isolation window double isoWindow; if (rawData.methodData.AnalysisOrder == MSOrderType.Ms2) { isoWindow = rawData.methodData.IsolationWindow.MS2; } else { isoWindow = rawData.methodData.IsolationWindow.MS3.MS1Window; } // get topN foreach (int scan in rawData.scanIndex.ScanEnumerators[MSOrderType.Ms]) { // if the ms1 scan has no scan dependents then topN = 0 if (rawFile.GetScanDependents(scan, 0) == null) { metaData[scan].MS2ScansPerCycle = 0; } else { metaData[scan].MS2ScansPerCycle = rawFile.GetScanDependents(scan, 0).ScanDependentDetailArray.Length; } } // go through scans for each ms order sequentially foreach (MSOrderType MSOrder in new List <MSOrderType> { MSOrderType.Ms, MSOrderType.Ms2, MSOrderType.Ms3 }) { int[] scans = rawData.scanIndex.ScanEnumerators[MSOrder]; for (int i = 0; i < scans.Length; i++) { metaData[scans[i]].FillTime = rawData.trailerExtras[scans[i]].InjectionTime; // populate duty cycle if (i < scans.Length - 1) { metaData[scans[i]].DutyCycle = (rawData.retentionTimes[scans[i + 1]] - rawData.retentionTimes[scans[i]]) * 60; } else { metaData[scans[i]].DutyCycle = 0; } // populate scan rate if (MSOrder == MSOrderType.Ms2 | MSOrder == MSOrderType.Ms3) { metaData[scans[i]].MS2ScansPerCycle = metaData[rawData.precursorScans[scans[i]].MasterScan].MS2ScansPerCycle; } // populate intensity distributions if (rawData.methodData.MassAnalyzers[MSOrder] == MassAnalyzerType.MassAnalyzerFTMS) { metaData[scans[i]].IntensityDistribution = new Distribution(rawData.centroidStreams[scans[i]].Intensities); metaData[scans[i]].SummedIntensity = rawData.centroidStreams[scans[i]].Intensities.Sum(); } else { metaData[scans[i]].IntensityDistribution = new Distribution(rawData.segmentedScans[scans[i]].Intensities); metaData[scans[i]].SummedIntensity = rawData.segmentedScans[scans[i]].Intensities.Sum(); } // populate fraction of scans consuming 80% of total intensity if (rawData.methodData.MassAnalyzers[MSOrder] == MassAnalyzerType.MassAnalyzerFTMS) { metaData[scans[i]].FractionConsumingTop80PercentTotalIntensity = rawData.centroidStreams[scans[i]].Intensities.FractionOfScansConsumingTotalIntensity(percent: 80); } else { metaData[scans[i]].FractionConsumingTop80PercentTotalIntensity = rawData.segmentedScans[scans[i]].Intensities.FractionOfScansConsumingTotalIntensity(percent: 80); } // calculate ms1 isolation interference if (rawData.methodData.AnalysisOrder == MSOrder) { int preScan = rawData.precursorScans[scans[i]].MasterScan; metaData[scans[i]].Ms1IsolationInterference = Ms1Interference.CalculateForOneScan(rawData.centroidStreams[preScan], rawData.precursorMasses[scans[i]].MonoisotopicMZ, isoWindow, rawData.trailerExtras[scans[i]].ChargeState); } progress.Update(); } } progress.Done(); rawData.Performed.Add(Operations.MetaData); }