private static MSScan GetScanFromFile(int argScanNo, double argSingleToNoise, double argPeakBackground, double argPeptideBackground, short argMaxCharge, GlypID.Readers.clsRawData Raw) { float[] _cidMzs = null; float[] _cidIntensities = null; GlypID.Peaks.clsPeak[] _cidPeaks = new GlypID.Peaks.clsPeak[1]; GlypID.Peaks.clsPeak[] _parentPeaks = new GlypID.Peaks.clsPeak[1]; GlypID.HornTransform.clsHornTransform mobjTransform = new GlypID.HornTransform.clsHornTransform(); GlypID.HornTransform.clsHornTransformParameters mobjTransformParameters = new GlypID.HornTransform.clsHornTransformParameters() ; GlypID.HornTransform.clsHornTransformResults[] _transformResult; GlypID.Peaks.clsPeakProcessor cidPeakProcessor = new GlypID.Peaks.clsPeakProcessor(); GlypID.Peaks.clsPeakProcessorParameters cidPeakParameters = new GlypID.Peaks.clsPeakProcessorParameters(); GlypID.Peaks.clsPeakProcessor parentPeakProcessor = new GlypID.Peaks.clsPeakProcessor() ; GlypID.Peaks.clsPeakProcessorParameters parentPeakParameters = new GlypID.Peaks.clsPeakProcessorParameters(); //Start Read Scan MSScan scan = new MSScan(argScanNo); Raw.GetSpectrum(argScanNo, ref _cidMzs, ref _cidIntensities); scan.MsLevel = Raw.GetMSLevel(Convert.ToInt32(argScanNo)); double min_peptide_intensity = 0; scan.Time = Raw.GetScanTime(scan.ScanNo); scan.ScanHeader = Raw.GetScanDescription(scan.ScanNo); if (scan.MsLevel != 1) { float[] _parentRawMzs = null; float[] _parentRawIntensitys = null; string Header = Raw.GetScanDescription(argScanNo); cidPeakProcessor.ProfileType = GlypID.enmProfileType.CENTROIDED; if (Header.Substring(Header.IndexOf("+") + 1).Trim().StartsWith("p")) { cidPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE; } // cidPeakProcessor.DiscoverPeaks(ref _cidMzs, ref _cidIntensities, ref _cidPeaks, // Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), false); for (int chNum = 0; chNum < _cidMzs.Length; chNum++) { scan.MSPeaks.Add(new MSPeak( Convert.ToSingle(_cidMzs[chNum]), Convert.ToSingle(_cidIntensities[chNum]))); } //for (int chNum = 0; chNum < _cidMzs.Length; chNum++) //{ // scan.MSPeaks.Add(new MSPeak( // Convert.ToSingle(_cidMzs[chNum]), // Convert.ToSingle(_cidIntensities[chNum]))); //} // Get parent information scan.ParentScanNo = Raw.GetParentScan(scan.ScanNo); Raw.GetSpectrum(scan.ParentScanNo, ref _parentRawMzs, ref _parentRawIntensitys); parentPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE; parentPeakProcessor.DiscoverPeaks(ref _parentRawMzs, ref _parentRawIntensitys, ref _parentPeaks, Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), true); float _parentBackgroundIntensity = (float)parentPeakProcessor.GetBackgroundIntensity(ref _parentRawIntensitys); _transformResult = new GlypID.HornTransform.clsHornTransformResults[1]; bool found = false; if (Raw.IsFTScan(scan.ParentScanNo)) { // High resolution data found = mobjTransform.FindPrecursorTransform(Convert.ToSingle(_parentBackgroundIntensity), Convert.ToSingle(min_peptide_intensity), ref _parentRawMzs, ref _parentRawIntensitys, ref _parentPeaks, Convert.ToSingle(scan.ParentMZ), ref _transformResult); } if (!found)//de-isotope fail { // Low resolution data or bad high res spectra short cs = Raw.GetMonoChargeFromHeader(scan.ScanNo); double monoMZ = Raw.GetMonoMzFromHeader(scan.ScanNo); List<float> ParentMzs = new List<float>(_parentRawMzs); int CloseIdx = MassUtility.GetClosestMassIdx(ParentMzs, Convert.ToSingle(monoMZ)); if (cs > 0) { short[] charges = new short[1]; charges[0] = cs; mobjTransform.AllocateValuesToTransform(Convert.ToSingle(scan.ParentMZ), Convert.ToInt32(_parentRawIntensitys[CloseIdx]), ref charges, ref _transformResult); } else { // instrument has no charge just store 2 and 3. short[] charges = new short[2]; charges[0] = 2; charges[1] = 3; mobjTransform.AllocateValuesToTransform(Convert.ToSingle(scan.ParentMZ), Convert.ToInt32(_parentRawIntensitys[CloseIdx]), ref charges, ref _transformResult); } } if (_transformResult[0].mint_peak_index == -1) //De-isotope parent scan { //Get parent info MSScan _parentScan = GetScanFromFile(scan.ParentScanNo, argSingleToNoise, argPeakBackground, argPeptideBackground, argMaxCharge,Raw); float[] _MSMzs = null; float[] _MSIntensities = null; Raw.GetSpectrum(scan.ParentScanNo, ref _MSMzs, ref _MSIntensities); // Now find peaks parentPeakParameters.SignalToNoiseThreshold = 0; parentPeakParameters.PeakBackgroundRatio = 0.01; parentPeakProcessor.SetOptions(parentPeakParameters); parentPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE; parentPeakProcessor.DiscoverPeaks(ref _MSMzs, ref _MSIntensities, ref _cidPeaks, Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), true); //Look for charge and mono. float[] monoandcharge = FindChargeAndMono(_cidPeaks, Convert.ToSingle(Raw.GetParentMz(scan.ScanNo)), scan.ScanNo,Raw); //scan.ParentMonoMW = _parentScan.MSPeaks[ClosedIdx].MonoMass; //scan.ParentAVGMonoMW = _parentScan.MSPeaks[ClosedIdx].; scan.ParentMZ = monoandcharge[0]; if (monoandcharge[1] == 0.0f) { scan.ParentCharge = Convert.ToInt32(Raw.GetMonoChargeFromHeader(scan.ParentScanNo)); } else { scan.ParentCharge = Convert.ToInt32(monoandcharge[1]); } scan.ParentMonoMW = (monoandcharge[0] - Atoms.ProtonMass) * monoandcharge[1]; } else { scan.ParentMonoMW = (float)_transformResult[0].mdbl_mono_mw; scan.ParentAVGMonoMW = (float)_transformResult[0].mdbl_average_mw; scan.ParentMZ = (float)_transformResult[0].mdbl_mz; scan.ParentCharge = (int)_transformResult[0].mshort_cs; } scan.IsCIDScan = Raw.IsCIDScan(argScanNo); scan.IsFTScan = Raw.IsFTScan(argScanNo); Array.Clear(_transformResult, 0, _transformResult.Length); Array.Clear(_cidPeaks, 0, _cidPeaks.Length); Array.Clear(_cidMzs, 0, _cidMzs.Length); Array.Clear(_cidIntensities, 0, _cidIntensities.Length); Array.Clear(_parentRawMzs, 0, _parentRawMzs.Length); Array.Clear(_parentRawIntensitys, 0, _parentRawIntensitys.Length); } else //MS Scan { scan.ParentMZ = 0.0f; double mdbl_current_background_intensity = 0; // Now find peaks parentPeakParameters.SignalToNoiseThreshold = argSingleToNoise; parentPeakParameters.PeakBackgroundRatio = argPeakBackground; parentPeakProcessor.SetOptions(parentPeakParameters); parentPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE; parentPeakProcessor.DiscoverPeaks(ref _cidMzs, ref _cidIntensities, ref _cidPeaks, Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), true); mdbl_current_background_intensity = parentPeakProcessor.GetBackgroundIntensity(ref _cidIntensities); // Settings min_peptide_intensity = mdbl_current_background_intensity * mobjTransformParameters.PeptideMinBackgroundRatio; if (mobjTransformParameters.UseAbsolutePeptideIntensity) { if (min_peptide_intensity < mobjTransformParameters.AbsolutePeptideIntensity) min_peptide_intensity = mobjTransformParameters.AbsolutePeptideIntensity; } mobjTransformParameters.PeptideMinBackgroundRatio = argPeptideBackground; mobjTransformParameters.MaxCharge = argMaxCharge; mobjTransform.TransformParameters = mobjTransformParameters; // Now perform deisotoping _transformResult = new GlypID.HornTransform.clsHornTransformResults[1]; mobjTransform.PerformTransform(Convert.ToSingle(mdbl_current_background_intensity), Convert.ToSingle(min_peptide_intensity), ref _cidMzs, ref _cidIntensities, ref _cidPeaks, ref _transformResult); // for getting results for (int chNum = 0; chNum < _transformResult.Length; chNum++) { double sumintensity = 0.0; double mostIntenseIntensity = 0.0; for (int i = 0; i < _transformResult[chNum].marr_isotope_peak_indices.Length; i++) { sumintensity = sumintensity + _cidPeaks[_transformResult[chNum].marr_isotope_peak_indices[i]].mdbl_intensity; if (Math.Abs(_transformResult[chNum].mdbl_most_intense_mw - (_cidPeaks[_transformResult[chNum].marr_isotope_peak_indices[i]].mdbl_mz * _transformResult[chNum].mshort_cs - Atoms.ProtonMass * _transformResult[chNum].mshort_cs)) < 1.0 / _transformResult[chNum].mshort_cs) { mostIntenseIntensity = _cidPeaks[_transformResult[chNum].mint_peak_index].mdbl_intensity; } } scan.MSPeaks.Add(new MSPeak( Convert.ToSingle(_transformResult[chNum].mdbl_mono_mw), _transformResult[chNum].mint_mono_intensity, _transformResult[chNum].mshort_cs, Convert.ToSingle(_transformResult[chNum].mdbl_mz), Convert.ToSingle(_transformResult[chNum].mdbl_fit), Convert.ToSingle(_transformResult[chNum].mdbl_most_intense_mw), mostIntenseIntensity, sumintensity )); } Array.Clear(_transformResult, 0, _transformResult.Length); Array.Clear(_cidPeaks, 0, _cidPeaks.Length); Array.Clear(_cidMzs, 0, _cidMzs.Length); Array.Clear(_cidIntensities, 0, _cidIntensities.Length); } return scan; }
/// <summary> /// No HCD info the return will be null /// </summary> /// <param name="argReader"></param> /// <param name="argScanNo"></param> /// <returns></returns> private static HCDInfo GetHCDInfo(GlypID.Readers.clsRawData argReader, int argScanNo) { if(!argReader.IsHCDScan(argScanNo)) { return null; } HCDInfo HCDinfo = null; double _hcd_score; GlypID.enmGlycanType _gType; int ParentScan = argReader.GetParentScan(argScanNo); // Scorers and transforms GlypID.HCDScoring.clsHCDScoring HCDScoring = new GlypID.HCDScoring.clsHCDScoring(); GlypID.HornTransform.clsHornTransform Transform = new GlypID.HornTransform.clsHornTransform(); // mzs , intensities float[] hcd_mzs = null; float[] hcd_intensities = null; float[] parent_mzs = null; float[] parent_intensities = null; // Peaks GlypID.Peaks.clsPeak[] parent_peaks; GlypID.Peaks.clsPeak[] hcd_peaks; // Peak Processors GlypID.Peaks.clsPeakProcessor hcdPeakProcessor = new GlypID.Peaks.clsPeakProcessor(); GlypID.Peaks.clsPeakProcessor parentPeakProcessor = new GlypID.Peaks.clsPeakProcessor(); // Results GlypID.HCDScoring.clsHCDScoringScanResults[] hcd_scoring_results; GlypID.HornTransform.clsHornTransformResults[] transform_results; // Params GlypID.Scoring.clsScoringParameters scoring_parameters = new GlypID.Scoring.clsScoringParameters(); GlypID.HornTransform.clsHornTransformParameters transform_parameters = new GlypID.HornTransform.clsHornTransformParameters(); scoring_parameters.MinNumPeaksToConsider = 2; scoring_parameters.PPMTolerance = 10; scoring_parameters.UsePPM = true; // Init Transform.TransformParameters = transform_parameters; // Loading parent int parent_scan = argReader.GetParentScan(argScanNo); double parent_mz = argReader.GetParentMz(argScanNo); int scan_level = argReader.GetMSLevel(argScanNo); int parent_level = argReader.GetMSLevel(parent_scan); argReader.GetSpectrum(parent_scan, ref parent_mzs, ref parent_intensities); // Parent processing parent_peaks = new GlypID.Peaks.clsPeak[1]; parentPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE; parentPeakProcessor.DiscoverPeaks(ref parent_mzs, ref parent_intensities, ref parent_peaks, Convert.ToSingle(transform_parameters.MinMZ), Convert.ToSingle(transform_parameters.MaxMZ), true); double bkg_intensity = parentPeakProcessor.GetBackgroundIntensity(ref parent_intensities); double min_peptide_intensity = bkg_intensity * transform_parameters.PeptideMinBackgroundRatio; transform_results = new GlypID.HornTransform.clsHornTransformResults[1]; bool found = Transform.FindPrecursorTransform(Convert.ToSingle(bkg_intensity), Convert.ToSingle(min_peptide_intensity), ref parent_mzs, ref parent_intensities, ref parent_peaks, Convert.ToSingle(parent_mz), ref transform_results); if (!found && (argReader.GetMonoChargeFromHeader(ParentScan) > 0)) { found = true; double mono_mz = argReader.GetMonoMzFromHeader(ParentScan); if (mono_mz == 0) mono_mz = parent_mz; short[] charges = new short[1]; charges[0] = argReader.GetMonoChargeFromHeader(ParentScan); Transform.AllocateValuesToTransform(Convert.ToSingle(mono_mz), 0, ref charges, ref transform_results); // Change abundance value from 0 to parent_intensity if you wish } if (found && transform_results.Length == 1) { // Score HCD scan first argReader.GetSpectrum(argScanNo, ref hcd_mzs, ref hcd_intensities); double hcd_background_intensity = GlypID.Utils.GetAverage(ref hcd_intensities, ref hcd_mzs, Convert.ToSingle(scoring_parameters.MinHCDMz), Convert.ToSingle(scoring_parameters.MaxHCDMz)); hcdPeakProcessor.SetPeakIntensityThreshold(hcd_background_intensity); hcd_peaks = new GlypID.Peaks.clsPeak[1]; //Check Header string Header = argReader.GetScanDescription(argScanNo); hcdPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE; if (Header.Substring(Header.IndexOf("+") + 1).Trim().StartsWith("c")) { hcdPeakProcessor.ProfileType = GlypID.enmProfileType.CENTROIDED; } hcdPeakProcessor.DiscoverPeaks(ref hcd_mzs, ref hcd_intensities, ref hcd_peaks, Convert.ToSingle (scoring_parameters.MinHCDMz), Convert.ToSingle(scoring_parameters.MaxHCDMz), false); hcdPeakProcessor.InitializeUnprocessedData(); hcd_scoring_results = new GlypID.HCDScoring.clsHCDScoringScanResults[1]; HCDScoring.ScoringParameters = scoring_parameters; _hcd_score = HCDScoring.ScoreHCDSpectra(ref hcd_peaks, ref hcd_mzs, ref hcd_intensities, ref transform_results, ref hcd_scoring_results); _gType = (GlypID.enmGlycanType)hcd_scoring_results[0].menm_glycan_type; enumGlycanType GType; //Convert from GlypID.enumGlycanType to MassLib.enumGlycanType; if (_gType == GlypID.enmGlycanType.CA) { GType = enumGlycanType.CA; } else if (_gType == GlypID.enmGlycanType.CS) { GType = enumGlycanType.CS; } else if (_gType == GlypID.enmGlycanType.HM) { GType = enumGlycanType.HM; } else if (_gType == GlypID.enmGlycanType.HY) { GType = enumGlycanType.HY; } else { GType = enumGlycanType.NA; } HCDinfo = new HCDInfo(argScanNo, GType, _hcd_score); } return HCDinfo; }