public void Convert(TaskProgress progress) { // temporarily keep the previous MS1 and MS2 spectra for possible speeding up; MassSpectrum lastMS1Spec = null; int lastMS1ScanNum = -1; MassSpectrum lastMS2Spec = null; int lastMS2ScanNum = -1; int spectrumProcessed = 0; // get instrument method names; int pnNumInstMethods = 0; object pvarNames = null; _rawReader.GetInstMethodNames(ref pnNumInstMethods, ref pvarNames); // create instance for data preprocessing; PrecursorPredictor pp = null; if (expType == ExperimentType.DIA && predictPrecursors) { pp = new PrecursorPredictor(DEFAULT_DIA_ISO_WIN_SIZE, 1, 6, 0); } //Scan whole raw file to remember scan Number of MS1 if (correctPrecMz) { for (int scanNum = FirstScanNum; scanNum <= LastScanNum; scanNum++) { int MSOrder = 0; _rawReader.GetNumberOfMSOrdersFromScanNum(scanNum, ref MSOrder); // check the MS level; if (MSOrder == 0) { MS1ScanNum.Add(scanNum); } } } for (int scanNum = FirstScanNum; scanNum <= LastScanNum; scanNum++) { MassSpectrum spec = GetSpectrumByScanNum(scanNum); // Console.Write("^^^^^" + spec.Peaks.Count); if (spec == null) { continue; } // get the mass analyzer type; int pnMassAnalyzerType = 0; _rawReader.GetMassAnalyzerTypeForScanNum(scanNum, ref pnMassAnalyzerType); // get the precursors; //if (spec.MsLevel > 1) //{ // Object pvarPrecursorInfos = null; // int pnArraySize = 0; // _rawReader.GetPrecursorInfoFromScanNum(scanNum, ref pvarPrecursorInfos, ref pnArraySize); //} // if the spectrum has an empty peak list, abandon this spectrum; if (spec.Peaks.Count > 0) { if (spec.MsLevel > 1) { if (spec.PrecursorScanNumber == 0) { if (spec.MsLevel == 2) { spec.PrecursorScanNumber = lastMS1Spec == null ? 0 : lastMS1ScanNum; } else if (spec.MsLevel == 3) { spec.PrecursorScanNumber = lastMS2Spec == null ? 0 : lastMS2ScanNum; } } } if (spec.MsLevel == 2) { if (expType == ExperimentType.DDA) { if (spec.PrecursorScanNumber == lastMS1ScanNum) { // double check the precursor m/z value in the MS1 scan; ExtractPrecursorMz(spec, lastMS1Spec); if (correctPrecMz) { spec = CalCorrectPrecursor(spec, lastMS1Spec); } } else { // check whether the precursor scan number is available; if (spec.PrecursorScanNumber > 0) { MassSpectrum precSpec = GetSpectrumByScanNum(spec.PrecursorScanNumber); // double check the precursor m/z value in the MS1 scan; ExtractPrecursorMz(spec, precSpec); if (correctPrecMz) { spec = CalCorrectPrecursor(spec, lastMS1Spec); } } } } else if (expType == ExperimentType.DIA && predictPrecursors) { if (spec.PrecursorScanNumber == lastMS1ScanNum) { pp.PredictPrecursors(ref spec, ref lastMS1Spec); } else { // check whether the precursor scan number is available; if (spec.PrecursorScanNumber > 0) { MassSpectrum precSpec = GetSpectrumByScanNum(spec.PrecursorScanNumber); pp.PredictPrecursors(ref spec, ref precSpec); } } } } if (spec.MsLevel == 3) { if (expType == ExperimentType.DDA) { if (spec.PrecursorScanNumber == lastMS2ScanNum) { // double check the precursor m/z value in the MS2 scan; ExtractPrecursorMz(spec, lastMS2Spec); } else { // check whether the precursor scan number is available; if (spec.PrecursorScanNumber > 0) { // double check the precursor m/z value in the MS2 scan; MassSpectrum precSpec = GetSpectrumByScanNum(spec.PrecursorScanNumber); ExtractPrecursorMz(spec, precSpec); } } } else if (expType == ExperimentType.DIA && predictPrecursors) { if (spec.PrecursorScanNumber == lastMS1ScanNum) { pp.PredictPrecursors(ref spec, ref lastMS1Spec); } else { // check whether the precursor scan number is available; if (spec.PrecursorScanNumber > 0) { MassSpectrum precSpec = GetSpectrumByScanNum(spec.PrecursorScanNumber); pp.PredictPrecursors(ref spec, ref precSpec); } } } } if (spec.MsLevel == 2 && exportChargeState) { if (expType == ExperimentType.DDA) { //Collection charge of MS2 if (chargeNum.ContainsKey(spec.Precursors[0].Item2)) { chargeNum[spec.Precursors[0].Item2] += 1; } else { chargeNum.Add(spec.Precursors[0].Item2, 1); } } } // write into the output files; WriteToOutFiles(spec); } if (spec.MsLevel == 1) { lastMS1ScanNum = spec.ScanNumber; lastMS1Spec = spec; } else if (spec.MsLevel == 2) { lastMS2ScanNum = spec.ScanNumber; lastMS2Spec = spec; } if (progress.Aborted) { break; } spectrumProcessed++; progress.CurrentProgress = (int)((double)spectrumProcessed / (LastScanNum - FirstScanNum + 1) * 100); if (progress.CurrentProgress > lastProgress) { try { int currentLineCursor = Console.CursorTop; Console.SetCursorPosition(0, Console.CursorTop); lastProgress = progress.CurrentProgress; Console.WriteLine(" Reading RAW File: " + lastProgress + "%"); Console.SetCursorPosition(0, currentLineCursor); } catch (IOException ex) { if (progress.CurrentProgress - lastProgress >= 10 || progress.CurrentProgress == 100) { lastProgress = progress.CurrentProgress; Console.WriteLine(" Reading RAW File: " + lastProgress + "%"); } } } } if (expType == ExperimentType.DDA && exportChargeState) { _chargeNumWriter = new StreamWriter(outFileWithoutExtentionName + "txt"); //export charge states to file ExportChargeStatesToFile(chargeNum); } // complete mzXML file writing if mzXMLWriter is available; if (_mzXMLWriter != null) { _mzXMLWriter.WriteIndex(); _mzXMLWriter.WriteEnd(); } }